%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/rappan/www/cgi_up_ava/
Upload File :
Create Path :
Current File : /home/rappan/www/cgi_up_ava/admin.cgi

#!/usr/bin/perl

#--------ライブラリ読込み------------------------

$commonpl='lib/common.pl';
if(!-e $commonpl){
	&error("$commonplがありません。");
}
require $commonpl;

$common2pl='lib/common2.cgi';
if(!-e $common2pl){
	&error("$common2plがありません。");
}
require $common2pl;

if(!-e $passlog){
	&error("passlogがありません。");
}
require $passlog;

#-------変数-------------------------------------

$maxsize='1000000';
$t_size='10pt';
$t_color='#000000';
$l_color='#0000ff';
$b_color='#ffffff';
$c_valid='365';
@avoid=('<table','<td','<tr','<meta','<form','<embed','script','<style','<body','<!--','<link','<input','style *=','<object','frame','on[a-zA-Z ]+=','expression');

#-------------------------------------------------


$FORM{'page'}=0;


if($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/){
	&DecodeMulti;
}
else{
	&Decode;
}

sub DecodeMulti{
my($buffsize,$d_len,$boundary,$b_len,
$left,$rsize,$r,$bnd_d,
$i,$limit,$header,$name,$hpos,$upflag,$bpos,$filename,$ctype,$okflag,$dum,$app,$upidx,$zflag,$reload,
$buf,$done,$sessid,$blen,$ext,$imgfile,$imgfilename,$dflag
);

$buffsize=1024;
$d_len=$ENV{'CONTENT_LENGTH'};
if(!$d_len){
	&error("no data");
}
if($d_len > $maxsize){
	&error("投稿の容量が大きすぎます。");
}

if($ENV{'REQUEST_METHOD'} ne "POST"){
	&error("method bad");
}
if($ENV{'CONTENT_TYPE'}=~/boundary="([^"]+)"/){
	$boundary=$1;
}
else{
	if($ENV{'CONTENT_TYPE'}=~/boundary=(\S+)/){
		$boundary=$1;
	}
}
if($boundary eq ""){
	&error("boundary bad");
}
$boundary='--'.$boundary;
$b_len=length $boundary;
if($b_len > $buffsize){
	&error("buffsize error");
}
$left=$d_len;

$rsize=$b_len+2;

binmode(STDIN);
binmode(STDOUT);

$r=read(STDIN,$buf,$rsize);
if($r != $rsize){
	&error("read error");
}
$left-=$rsize;
$bnd_d=$boundary."\x0D\x0A";
if($buf ne $bnd_d){
	&error("format error");
}

undef $buf;

$reload=0;

$i=0;
$limit=100000;
$upidx=0;
$left-=4;
$done=$left;
$dflag=0;
while($done > 0){
	$i++;
	if(($i == 1) || ($left && (index($buf, $boundary) == -1))){
		$blen=length($buf);
		$rsize=($left > $buffsize) ? $buffsize : $left;
		$r=read(STDIN,$buf,$rsize,$blen);
		if($r != $rsize){
			&error("read error1");
		}
		$left-=$rsize;
		if($left != 0){
			$done-=$rsize;
		}
		else{
			$done+=$blen;
			$dflag=1;
		}
	}
	undef $header;
	undef $name;
	$zflag=0;
	while(($hpos = index($buf, "\x0D\x0A\x0D\x0A")) == -1){
		if($zflag){
			&error("unknown error1");
		}
		$header .= substr($buf, 0, $buffsize);
        	$buf = substr($buf, $buffsize);
		$blen=length($buf);
		$rsize=($left > $buffsize) ? $buffsize : $left;
		$r=read(STDIN,$buf,$rsize,$blen);
		if($r != $rsize){
			&error("read error");
		}

        	$left -= $rsize;
		if($left != 0){
			$done-=$rsize;
		}
		else{
			if(!$dflag){
				$done+=$blen;
				$dflag=1;
			}
			$zflag=1;
		}
		$i++;
		if($i > $limit){
			&error("unknown error2");
		}
	}
	$header.=substr($buf,0,$hpos);
	if($header=~/\bname="([^"]+)"/i || $header=~/\bname=([^\s:;]+)/i) {
		$name=$1;
	}
	if($name eq ""){
		&error("header error1");
	}
	$upflag=0;
	$filename="";
	$ctype="";
	$okflag=0;
	if($name=~/^upfile/){
		if($header=~/\bfilename="([^"]*)"/i || $header=~/\bfilename=([^\s:;]*)/i) {
			$filename=$1;
			$FNAME{$name}=$filename;
		}
		if($header=~/Content-type:\s*"([^"]+)"/i || $header=~/Content-Type:\s*([^\s:;]+)/i) {
			$ctype=$1;
			$CTYPE{$name}=$ctype;
		}
		if($FORM{'mode'} eq "editregist"){
			$FORM{'num'}=$FORM{'editnum'};
		}

		if($filename){
			($dum,$app)=split(/\//,$ctype);
			if($app eq "gif"){
				$ext='.gif';
				$okflag=1;
			}
			elsif($app eq "pjpeg" || $app eq "jpeg"){
				$ext='.jpg';
				$okflag=1;
			}
			if(!$okflag){
				&error("アップできる画像はJPEG、GIFファイルのみです。");
			}
			if($FORM{'num'} eq ""){
				$FORM{'num'}=time;
			}
			$imgfile=$FORM{'num'}.$ext;
			if($FORM{'mode'} eq 'preview'){
				$upimgdir=$tmpimgdir;
			}
			$imgfilename = $upimgdir.$imgfile;
			$UPFNAME[$upidx++]=$imgfile;
			$FORM{'num'}="";
			unless(open(IMAGE,">$imgfilename")){
				&error("画像のアップロードに失敗しました");
			}
			binmode(IMAGE);
			$upflag=1;
		}
	}
	if($left == 0){
		$done-=($hpos+4);
	}
	substr($buf,0,$hpos+4)="";
	$zflag=0;
	while(($bpos = index($buf, $boundary)) == -1){
		if($zflag){
			&error("unknown error3");
		}
		if($upflag){
			print IMAGE substr($buf, 0, $buffsize);
		}
		else{
			$FORM{$name} .= substr($buf, 0, $buffsize);
		}
        	$buf = substr($buf, $buffsize);
		$blen=length($buf);
		$rsize=($left > $buffsize) ? $buffsize : $left;
		$r=read(STDIN,$buf,$rsize,$blen);
		if($r != $rsize){
			&error("read error3");
		}
        	$left -= $rsize;

		if($left != 0){
			$done-=$rsize;
		}
		else{
			if(!$dflag){
				$done+=$blen;
				$dflag=1;
			}
			$zflag=1;
		}
		$i++;
		if($i > $limit){
			&error("unknown error4");
		}
	}
	if($upflag){
		print IMAGE substr($buf,0,$bpos-2);
		close IMAGE;
	}
	else{
		$FORM{$name} .= substr($buf,0,$bpos-2);
	}
	if($left == 0){
		$done-=($bpos+$b_len+2);
	}
	substr($buf,0,$bpos+$b_len+2)="";

	$FORM{$name}=~s/&/&amp;/g;
	$FORM{$name}=~s/,/&#44;/g;
	$FORM{$name}=~s/'/&#039;/g;
	if($name eq "message"){
		if($hanren){
			if($FORM{$name}=~/([\x21-\x7E]{$hanren_m}?)/){
				&error("不適切な投稿である可能\性があります。");
			}
		}
		if(!$tag){
			$FORM{$name}=~s/</&lt;/g;
			$FORM{$name}=~s/>/&gt;/g;
			$FORM{$name}=~s/"/&quot;/g;
		}
		$FORM{$name}=~s/\x0D\x0A/<br>/g;
		$FORM{$name}=~s/\x0D/<br>/g;
		$FORM{$name}=~s/\x0A/<br>/g;
		if($tag){
			&TagCheck($FORM{$name});
		}
	}
	else{
		$FORM{$name}=~s/</&lt;/g;
		$FORM{$name}=~s/>/&gt;/g;
		$FORM{$name}=~s/"/&quot;/g;
		$FORM{$name}=~s/\x0D\x0A//g;
		$FORM{$name}=~s/\x0D//g;
		$FORM{$name}=~s/\x0A//g;
	}

	if($i > $limit){
		&error("unknown error5");
	}
}

}



sub Decode{
my($name,$value,$buff,@pairs,$pair,$d,$n);

if($ENV{'REQUEST_METHOD'} eq "POST"){
	if($ENV{'CONTENT_LENGTH'} > $maxsize){
		&error("投稿量が多すぎます。");
	}
	read(STDIN,$buff,$ENV{'CONTENT_LENGTH'});
}
else{
	$buff=$ENV{'QUERY_STRING'};
}

if($buff){
	@pairs=split(/&/,$buff);
	foreach $pair(@pairs){
		($name,$value)=split(/=/,$pair);
		$value=~tr/+/ /;
		$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("H2",$1)/eg;
		$value=~s/&/&amp;/g;
		$value=~s/,/&#44;/g;
		$value=~s/'/&#039;/g;
		if($name eq "message" || $name =~/^comment/){
			if(!$tag){
				$value=~s/</&lt;/g;
				$value=~s/>/&gt;/g;
				$value=~s/"/&quot;/g;
			}
			$value=~s/\x0D\x0A/<br>/g;
			$value=~s/\x0D/<br>/g;
			$value=~s/\x0A/<br>/g;
		}
		elsif($name eq "khost" || $name eq "kword"){
			$value=~s/\x0D\x0A/\n/g;
			$value=~s/\x0D/\n/g;
			$value=~s/\x0A/\n/g;
			$value=~s/"/&quot;/g;
		}
		else{
			$value=~s/</&lt;/g;
			$value=~s/>/&gt;/g;
			$value=~s/"/&quot;/g;
			$value=~s/\x0D\x0A//g;
			$value=~s/\x0D//g;
			$value=~s/\x0A//g;
		}
		if($name eq "number"){
			push(@delnum,$value);
		}
		elsif($name =~/^alist/){
			push @adtmp,$value;
		}
		$FORM{$name}=$value;
	}
}

}

$FORM{'name'}=~s/\://g;
$FORM{'home'}=~s/http\:\/\///g;

if($ENV{'SCRIPT_NAME'}){
	$c_name=$ENV{'SCRIPT_NAME'};
}
else{
	$c_name="diaryadmin";
}


if($FORM{'mode'} eq "menu"){
	&Menu;
}
elsif($FORM{'mode'} eq "form"){
	&Form;
}
elsif($FORM{'mode'} eq "kiji"){
	&Admin;
}
elsif($FORM{'mode'} eq "del"){
	&Del;
}
elsif($FORM{'mode'} eq "edit"){
	&Form('edit');
}
elsif($FORM{'mode'} eq "regist"){
	&Regist;
}
elsif($FORM{'mode'} eq "editregist"){
	&EditRegist;
}
elsif($FORM{'mode'} eq "login"){
	&Login;
}
elsif($FORM{'mode'} eq "admin"){
	&Admin;
}
elsif($FORM{'mode'} eq "dl"){
	&Dl;
}
elsif($FORM{'mode'} eq "env"){
	&Env;
}
elsif($FORM{'mode'} eq "envregist"){
	&EnvRegist;
}
elsif($FORM{'mode'} eq "preview"){
	&Preview;
}
else{
	&Login;
}

sub TagCheck{
my $v=$_[0];
$v=~s/font//g;
foreach(@avoid){
	if($v=~/$_/i){
		&error("$_禁止タグが含まれています。");
	}
}
}



sub GetCookie{
my($name,$value,$pair,@pairs,$cookies);
$cookies=$ENV{'HTTP_COOKIE'};
@pairs=split(/;/,$cookies);
foreach $pair(@pairs){
	($name, $value)=split(/=/,$pair);
	$name=~s/ //g;
	$DUMMY{$name}=$value;
}
$DUMMY{$c_name}=~ s/\+/ /g;
$DUMMY{$c_name}=~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg;
@pairs=split(/,/,$DUMMY{$c_name});
foreach $pair(@pairs){
	($name, $value)=split(/\:/,$pair);
	$COOKIE{$name}=$value;
}
}

sub SetCookie{
my($secg,$ming,$hourg,$mdayg,$mong,$yearg,$wdayg,$ydayg,$isdstg,
$timer,$date_gmt,$cook,@month,@week,
);
$timer=time;
($secg, $ming, $hourg, $mdayg, $mong, $yearg, $wdayg, $ydayg, $isdstg)=gmtime($timer+$c_valid*24*60*60);
@month=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
@week=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$date_gmt=sprintf("%s, %02d\-%s\-%04d %02d:%02d:%02d GMT",$week[$wdayg],$mdayg,$month[$mong],$yearg+1900,$hourg,$ming,$secg);
$cook="pass:$FORM{'pass'}";
$cook=~s/([^\w\=\& ])/'%' . unpack("H2", $1)/eg;
$cook=~tr/ /+/;
print "Set-Cookie: $c_name=$cook; expires=$date_gmt\n";
}

sub DelCookie{
print "Set-Cookie: $c_name=;\n";
}


sub CheckPass{
my($fopass,$passflag);
if($passwd eq ""){
	&error("パスワードが設定されていません。");
}
$fopass=$_[0];
if($passwd eq 'admin'){
	if($fopass ne $passwd){
		&error("パスワードが違います。");
	}
}
else{
	$passflag=&MatchPass($fopass,$passwd);
	if(!$passflag){
		&error("パスワードが違います。");
	}
}
return;
}


sub Login{
my($ck,$ok);
&GetCookie;

if($COOKIE{'pass'}){
	$ck=" checked";
	$ok="1";
}

&header;

print <<EOM;
<body>
<p>
<a href="${script}?">日記へ</a></p>
<br>
<br>
<br>
<div align=center>
<form method="POST" action="">
<input type="hidden" name="mode" value="form">
<input type="hidden" name="ok" value="$ok">
<table>
<tr>
<td>パスワード</td>
<td><input size="8" type="password" name="pass" maxlength="8" value="$COOKIE{'pass'}"></td>
<td><input type="submit" value="ログイン"></td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="cookie" value="1"$ck>クッキー</td>
<td></td>
</table>

</form>
</div>
</body>
</html>
EOM
exit;

}



sub Dl{
my(
$buffer,$len,$xflag,$ua,
$filename,@tmp,
);

&CheckPass($FORM{'pass'});

open FILE,$logfile || &error("$logfileが開けません。ファイルを確認してください。");
while(<FILE>){
	$buffer.=$_;
}
close FILE;

$ua=$ENV{'HTTP_USER_AGENT'};

if($ua=~/Win/) {
#	$buffer=~s/\x0A/\x0D\x0A/g;
}
elsif($ua=~/Mac/) {
	$xflag=0;
	if($ua =~ /OS X/){
		$xflag=1;
	}
	elsif($ua =~ /MSIE/){
		if($ua =~ /5\.2/){
			$xflag=1;
		}
	}
	if(!$xflag){
		$buffer=~s/\x0A/\x0D/g;
	}
}


$len=length($buffer);

@tmp=split(/\//,$logfile);
$filename=$tmp[$#tmp];
print "Content-Disposition: attachment; filename=\"$filename\"\n";
print "Content-Type: application/octet-stream\n";
print "Content-length: $len\n\n";
print $buffer;

exit;


}


sub Table1{

print <<EOM;
<table width="1000" border="0">
<tr>
<td width="150" valign="top">
EOM

&PrintMenu;

print <<EOM;
</td>
<td align="center">
EOM
}

sub Table2{
print <<EOM;
</td>
</tr>
</table>
<form name="fomove_form" action="" method="POST" style="margin:0px">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="mode" value="form">
</form>
<form name="fomove_kiji" action="" method="POST" style="margin:0px">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="mode" value="kiji">
</form>
<form name="fomove_dl" action="" method="POST" style="margin:0px">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="mode" value="dl">
</form>
<form name="fomove_env" action="" method="POST" style="margin:0px">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="mode" value="env">
</form>
<form name="fomove_login" action="" method="POST" style="margin:0px">
</form>
EOM
}


sub PrintMenu{
print <<EOM;
<table cellpadding="1" style="background-color:#fbfbfb;border-width:1px;border-color:#bbbbbb;border-style:solid">
<tr>
<td>
<table border="0" cellpadding="2">
<tr>
<td>・<a href="javascript:void(0)" onclick="document.fomove_form.submit();">書き込み</a></td>
</tr>
<tr>
<td>・<a href="javascript:void(0)" onclick="document.fomove_kiji.submit();">記事の削除と編集</a></td>
</tr>
<tr>
<td>・<a href="javascript:void(0)" onclick="document.fomove_dl.submit();">ログのダウンロード</a></td>
</tr>
<tr>
<td>・<a href="javascript:void(0)" onclick="document.fomove_env.submit();">環境設定</a></td>
</tr>
<tr>
<td>・<a href="javascript:void(0)" onclick="document.fomove_login.submit();">ログインに戻る</a></td>
</tr>
</table>
</td>
</tr>
</table>
EOM


}

sub Form{
my($hd,$flag,$checkkey,
$no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,$imgfile,$w,$h,
$mode,$w_max,
$w_o,$image,$year,$mon,$d_d,$week,$midasi,
$sec,$min,$hour,$mday,$wday,$yday,$isdst,
@week,$ck,$iconline,$day,@files,$num
);

&CheckPass($FORM{'pass'});


if(!$FORM{'ok'} && $FORM{'cookie'}){
	&SetCookie;
}
elsif($FORM{'ok'} && !$FORM{'cookie'}){
	&DelCookie;
}


if($_[0] eq 'edit'){
	unless(open(FILE, $logfile)){
		&error("$logfileが開けません。ファイルを確認してください。");
	}
	$hd=<FILE>;
	$flag=0;
	$checkkey=0;
	while (<FILE>){
		($no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,$imgfile,$w,$h)=split(/,/,$_);
		if($no == $FORM{'editnum'}){
			$flag=1;
			last;
		}
	}
	close(FILE);
	if(!$flag){
		&error("$FORM{'editnum'}のデータがありません。");
	}
	$mode='editregist';
	$w_max=100;

	if($imgfile){
		$w_o=$w;
		$w=$w_max;
		$h=int($w*$h/$w_o);
		$image="<br>現在の画像<img src=\"$upimgdir$imgfile\" width=\"$w\" height=\"$h\"><br>";
	}
	($year,$mon,$d_d)=split(/\//,$date);

	($day,$w)=split(/\(/,$d_d);
	($week)=split(/\)/,$w);
	if($inlink){
		$message=~s/<\/a>//sg;
		$message=~s/<a href.*?>//sg;
	}
	$message=~s/<br>/\n/g;
	if(!$tag){
		$message=~s/&lt;/</g;
		$message=~s/&gt;/>/g;
	}
	$midasi='編集';

}
else{

	$mode='regist';
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
	$mon++;
	$min=sprintf("%02d",$min);
	$year=$year+1900;
	@week=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	$day=$mday;
	$week=$week[$wday];
	$midasi='書き込み';

	unless(open(FILE, $logfile)){
		&error("$logfileが開けません。ファイルを確認してください。");
	}
	$hd=<FILE>;
	($num)=split(/,/,$hd);
	close(FILE);
	if($num eq ""){
		$num=0;
	}
	$num++;
}

unless(opendir(DIR,$imgdir)){
	&error("imgdirが開けません。");
}

@files=readdir DIR;
closedir DIR;

foreach(@files){
	if($_=~/^icon/){
		push @ICON,$_;
	}

}

$flag=0;
foreach(@ICON){
	if($_ eq $icon){
		$ck=" checked";
		if(!$flag){
			$flag=1;
		}
	}
	else{
		$ck="";
	}
	$iconline.="<input type=\"radio\" name=\"icon\" value=\"$_\"$ck><img src=\"$imgdir$_\">\n";
}

if(!$flag){
	$ck=" checked";
}
else{
	$ck="";
}

$iconline="<input type=\"radio\" name=\"icon\" value=\"\"$ck>なし".$iconline;


&header($_[0],$_[1]);

print <<EOM;
<body>
EOM

&Table1;

print <<EOM;
<table width="800"> 
<tr>
<td bgcolor="#999999" align=center>
<b><font color="#ffffff">$midasi</font></b>
</td>
</tr>
</table>
<form name="fo" method="POST" action="" enctype="multipart/form-data" onsubmit="return Check()">
<input type="hidden" name="mode" value="$mode">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="editnum" value="$FORM{'editnum'}">
<input type="hidden" name="num" value="$num">
<table align=center border=0>
<tr>
<td>タイトル:
<input type="text" name="subject" size="60" value="$subject">
</td>
</tr>
<tr>
<td>日付:  
<input type="text" name="year" size="4" value="$year">
年
<input type="text" name="mon" size="2" value="$mon">
月 
<input type="text" name="day" size="2" value="$day">
日 
<input type="text" name="week" size="3" value="$week">
</td>
</tr>
<tr> 
<td> 
<textarea name="message" rows="15" cols="65" wrap="soft">$message</textarea>
</td>
</tr>
<tr>
<td>
アイコン:
$iconline
</td>
</tr>
<tr>
<td>ファイル:
$image
<input type="file" name="upfile" size="40">
 (GIF、JPEGのみ)

</td>
</table>
<br>
<input type="submit" value="  書き込む  " class="bt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="プレビュー" onclick="Preview()">

</form>

EOM

&Table2;

print <<EOM;
</body>
</html>
EOM

exit;
}




sub encode{
my(@saltset,$salt,$newcode);
@saltset=('a'..'z','A'..'Z','0'..'9');
srand;
$salt=$saltset[int(rand(@saltset))].$saltset[int(rand(@saltset))];
eval{$newcode=crypt($_[0],$salt);};
if($@){
	&error("暗号化の関数がサポートされていないのでこのサーバーでは使えません。");
}
if($newcode=~/^\$1\$/){
	$newcode=crypt($_[0],'$1$');
}
return $newcode;
}

sub MatchPass{
my($pass,$coded,$salt,$passflag);
$pass=$_[0];
$coded=$_[1];
$passflag=0;
if($coded=~/^\$1\$/){
	if(crypt($pass,'$1$') eq $coded){
		$passflag=1;
	}
}
else{
	$salt=substr($coded,0,2);
	if(crypt($pass,$salt) eq $coded){
		$passflag=1;
	}
}
return $passflag;
}

sub Regist{
my($hd,@all,$no,
$imgfile,$imgfilename,@tmp,$ext,$w,$h,
$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
@week,$day,$date,$tmp,$delline,$dmy,$imgfile_d,$oya,$week,
);

&CheckPass($FORM{'pass'});

if($FORM{'message'} eq ""){
	&error("本文が記入されていません。");
}



if($FORM{'subject'} eq "" && $titlealt){
	$FORM{'subject'}=$titlealt;
}

unless(open(FILE, $logfile)){
	&error("$logfileが開けません。ファイルを確認してください。");
}
$hd=<FILE>;
@all=<FILE>;
close(FILE);

($no)=split(/,/,$hd);

if($no eq ""){
	$no=0;
}
$no++;

if($UPFNAME[0]){
	$imgfile=$UPFNAME[0];
	$imgfilename=$upimgdir.$imgfile;
	@tmp=split(/\./,$imgfile);
	$ext=$tmp[$#tmp];
	($w,$h)=&GetSize($ext,$imgfilename);
}

if($FORM{'mon'} eq ""){
	($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time);
	$mon++;
	$min=sprintf("%02d",$min);
	$year=$year+1900;
	@week=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	$day=$mday;
	$week=$week[$wday];
}
else{
	$year=$FORM{'year'};
	$mon=$FORM{'mon'};
	$day=$FORM{'day'};
	$week=$FORM{'week'};
}


$date="$year/$mon/$day($week)";

if($inlink){
	$FORM{'message'}=~s/([^=^"])(https?:\/\/[\w\+\.\?\-\/_:~&=#%]+)/$1<a href=\"$2\" target=\"_blank\">$2<\/a>/g;
}


$tmp="$no,$FORM{'name'},$FORM{'fukidashi'},$FORM{'subject'},$date,$FORM{'message'},$FORM{'icon'},$FORM{'weather'},$FORM{'color'},$imgfile,$w,$h,\n";

unshift(@all,$tmp);


if(@all > $max){
	$delline=pop @all;
	($dmy,$dmy,$dmy,$dmy,$dmy,$dmy,$dmy,$dmy,$dmy,$imgfile_d)=split(/,/, $delline);
	if($imgfile_d){
		if(-e "$upimgdir$imgfile_d"){
			unlink("$upimgdir$imgfile_d") || &error("$upimgdir$imgfile_dが削除できません。");
		}
	}
}


$oya=@all;
$hd="$no,$oya,\n";

unless(open(FILE, ">$logfile")){
	&error("$logfileに書き込みできません。パーミッションを確認してください。");
}
print FILE $hd;
print FILE @all;

close FILE;

&Form('','投稿しました。');

}


sub Admin{
my(
$hd,
$no,$resno,$name,$fukidashi,$subject,$email,$homepage,$date,$message,$icon,$color,$pass,
$x,@pagetmp,$page_next,$oya,$pagetmp,$i,$cl,$s,$j,$start,$end,$imgfile,$w,$h,$k,$weather
);

&CheckPass($FORM{'pass'});

if($FORM{'editpass'}){
	$FORM{'pass'}=$FORM{'editpass'};
}
if($FORM{'newpass'}){
	$FORM{'pass'}=$FORM{'newpass'};
}

unless(open(FILE, $logfile)){&error("$logfileが開けません。ファイルを確認してください。");}
$hd=<FILE>;

($no,$oya)=split(/,/,$hd);

$x=1;
$page_next=0;

if($pagemax > 0 && $oya > 0){
	while($oya > 0){
		if($FORM{'page'} == $page_next){
			push @pagetmp,"$x";
		}
		else{
			push @pagetmp,"<a href=\"javascript:void(0)\" onclick=\"Move_admin('$page_next');\">$x</a>";
		}
		$x++;
		$page_next=$page_next+$pagemax;
		$oya=$oya-$pagemax;
	}
}
$pagetmp=join(" | ",@pagetmp);

$start=$FORM{'page'}+1;
$end=$FORM{'page'}+$pagemax;

&header;

print <<EOM;
<body>
EOM

&Table1;

print <<EOM;
<table width="800"> 
<tr>
<td bgcolor="#999999" align=center>
<b><font color="#ffffff">記事の削除と編集</font></b>
</td>
</tr>
<tr>
<td><br>
記事を削除するときは、チェックボックスに印をつけて
削除ボタンを押してください。(複数選択可。親記事を
削除すると、レスも削除されます。) 記事の編集をするときは、
編集ボタンを押してください。入力フォームが
出ますので、それで編集して送信ボタンを押してください。
</td>
</tr>
</table>
<br>
<table width="800">
<tr>
<td>ページ:$pagetmp</td>
</tr>
</table>
<form action="" name="fo" method="POST">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="mode" value="edit">
<input type="hidden" name="editnum" value="">
</form>
<form action="" method="POST">
<input type="hidden" name="mode" value="del">
<input type="hidden" name="pass" value="$FORM{'pass'}">

<table border="0" width="800">
<tr>
<td align="center" width="50"><b>番号</b></td><td align="center" width="120"><b>日付</b></td><td align="center" width="200"><b>タイトル</b></td><td align="center" width="400"><b>コメント</b></td><td align="center" width="50"><input type="submit" name="edt" value="削除"></td><td width="50">&nbsp;</td>
</tr>
EOM
$i=0;
$k=0;
while(<FILE>){
	($no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,$imgfile,$w,$h)=split(/,/,$_);
	$i++;
	if($i > $end){
		last;
	}
	if($i < $start){
		next;
	}
	$s="";
	$j=0;
	if($tag){
		$message=~s/<.*?>//g;
	}
	while($message=~/([\xE0-\xEF][\x80-\xBF][\x80-\xBF]|[\xC0-\xDF][\x80-\xBF]|[\x21-\x7E])/go){
		$s.=$1;
		$j++;
		if($j>=10){
			$s.="...";
			$s=~s/<br>//g;
			last;
		}
	}
	if($k){
		$cl=" bgcolor=\"#e0e0e0\"";
		$k=0;
	}
	else{
		$cl=" bgcolor=\"#eeeeee\"";
		$k=1;
	}
	print "<tr$cl>\n";
	print "<td align=\"center\">$no</td><td>$date</td><td>$subject</td><td>$s</td><td align=\"center\"><input type=\"checkbox\" name=\"number\" value=\"$no\"></td><td align=\"center\"><input type=\"button\" value=\"編集\" onclick=\"Jump('$no')\"></td>\n";
	print "</tr>\n";



}
close(FILE);

print <<EOM;
</table>
</form>
<table width="800">
<tr>
<td>ページ:$pagetmp</td>
</tr>
</table>
EOM

&Table2;

print <<EOM;
<form name="fomove_admin" action="" method="POST" style="margin:0px">
<input type="hidden" name="pass" value="$FORM{'pass'}">
<input type="hidden" name="mode" value="admin">
<input type="hidden" name="page" value="">
</form>
<script type="text/javascript">
function Move_admin(p){
document.fomove_admin.page.value=p;
document.fomove_admin.submit();
}
</script>
</body>
</html>
EOM
exit;
}


sub Del{
my(
$hd,$t_no,$oya,$checkkey,$newpass,$flag,
$no,$resno,$dum,$pass,$line,@new,$idx,$imgfile_d,@delimg,$imgfile,$w,$h,$color,$weather,$icon,$message,$date,$subject,$name,
$fukidashi,
);
&CheckPass($FORM{'pass'});

if($delnum[0] eq ""){
	&error("チェックを入れてください。");
}

unless(open(FILE, $logfile)){
	&error("$logfileが開けません。ファイルを確認してください。");
}
$hd=<FILE>;
($t_no,$oya)=split(/,/,$hd);


$checkkey=0;
$newpass="";
$idx=0;
while(<FILE>){
	$flag=0;
	($no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,$imgfile,$w,$h)=split(/,/,$_);
	foreach $line(@delnum){
		if($no == $line){
			if($imgfile){
				push(@delimg,$imgfile);
			}
			$flag=1;
			$checkkey=1;
			if($no == $line){
				$newpass=$pass;
			}
			last;
		}
	}
	if($flag==0){
		$new[$idx]=$_;
		$idx++;
	}
}
close FILE;

$oya=scalar(@new);

$hd="$t_no,$oya,\n";

unless(open(FILE, ">$logfile")){&error("$logfileに書き込みできません。パーミッションを確認してください。");}
print FILE $hd;
print FILE @new;
close(FILE);

foreach(@delimg){
	if(-e "$upimgdir$_"){
		unlink("$upimgdir$_") || &error("$upimgdir$_が削除できません。");
	}
}

&Admin;

}

sub MakeSess{
my(@saltset,$newcode);
@saltset=('a'..'z','A'..'Z','0'..'9');
srand(time^$$);
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
$newcode.=$saltset[int(rand(@saltset))];
return $newcode;
}



sub EditRegist{
my(
$hd,
$no,$resno,$name,$fukidashi,$subject,$email,$homepage,$date,$message,$icon,$color,$pass,$bg,
@new,$idx,$imgfile,$w,$h,$imgfile_d,$imgfilename,@tmp,$weather
);
;

&CheckPass($FORM{'pass'});


if($inlink){
	$FORM{'message'}=~s/([^=^"])(https?:\/\/[\w\+\.\?\-\/_:~&=#%]+)/$1<a href=\"$2\" target=\"_blank\">$2<\/a>/g;
}

unless(open(FILE, $logfile)){
	&error("$logfileが開けません。ファイルを確認してください。");
}
$hd=<FILE>;

$idx=0;
while(<FILE>){
	($no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,$imgfile,$w,$h)=split(/,/,$_);
	if($no == $FORM{'editnum'}){
		if($UPFNAME[0]){
			$imgfile_d=$UPFNAME[0];
			if($imgfile && ($imgfile_d ne $imgfile)){
				if(-e "$upimgdir$imgfile"){
					unlink("$upimgdir$imgfile") || &error("$upimgdir$imgfileが削除できません。");
				}
			}
			$imgfile=$imgfile_d;
			$imgfilename=$upimgdir.$imgfile;
			@tmp=split(/\./,$imgfile);
			$ext=$tmp[$#tmp];
			($w,$h)=&GetSize($ext,$imgfilename);
		}
		else{
			if($FORM{'imgdel'}){
				if(-e "$upimgdir$imgfile"){
					unlink("$upimgdir$imgfile") || &error("$upimgdir$imgfileが削除できません。");
				}
				$imgfile="";
				$w="";
				$h="";
			}
		}
		$_="$no,$FORM{'name'},$FORM{'fukidashi'},$FORM{'subject'},$date,$FORM{'message'},$FORM{'icon'},$FORM{'weather'},$FORM{'color'},$imgfile,$w,$h,\n";
	}
	$new[$idx++]=$_;
}

close(FILE);

unless(open(FILE, ">$logfile")){&error("$logfileに書き込みできません。パーミッションを確認してください。");}
print FILE $hd;
print FILE @new;
close(FILE);

&Admin('','変更しました。');

}

sub End{
print <<EOM;
Content-type: text/html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>BBS</title>
<script type="text/javascript">
function cl(){
opener.fomove_admin.submit();
window.close();
}
</script>
</head>
<body onload="cl()">
</body>
</html>
EOM
exit;
}


sub GetDate{
my($timer,$sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst,
@week,$date
);
$timer=time;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime($timer);
$mon++;
$min=sprintf("%02d",$min);
$sec=sprintf("%02d",$sec);
$year=$year+1900;
@week=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$date="$year/$mon/$mday($week[$wday]) $hour:$min";
return $date;
}
sub GetHost{
my($host);
$host=$ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'};
return $host;
}



sub Env{
my($kword,$khost,%CK);
&CheckPass($FORM{'pass'});

if($tag){
	$CK{'tag2'}=" checked";
}
else{
	$CK{'tag1'}=" checked";
}

if($tag){
	$CK{'tag2'}=" checked";
}
else{
	$CK{'tag1'}=" checked";
}



if($inlink){
	$CK{'inlink2'}=" checked";
}
else{
	$CK{'inlink1'}=" checked";
}

if($cook_on){
	$CK{'cook_on2'}=" checked";
}
else{
	$CK{'cook_on1'}=" checked";
}

if($hostdeny){
	$CK{'hostdeny2'}=" checked";
}
else{
	$CK{'hostdeny1'}=" checked";
}


&header;

foreach(@kinsiword){
	$kword.=$_."\n";
}

foreach(@kinsihost){
	$khost.=$_."\n";
}

$img_style=~s/"/&quot;/g;
$iconsize=~s/"/&quot;/g;
$fukidashisize=~s/"/&quot;/g;


print <<EOM;
<body>
EOM

&Table1;

print <<EOM;
<table width="800"> 
<tr>
<td bgcolor="#999999" align=center>
<b><font color="#ffffff">環境設定</font></b>
</td>
</tr>
</table>
<br>
<div>
<font color="#cc0000">*</font>は入力必須です。
</div>

<form action="" method="POST">
<input type="hidden" name="mode" value="envregist">
<input type="hidden" name="pass" value="$FORM{'pass'}">

<table width="560" cellpadding="4" class="settbl">
<tr>
<td colspan="2" class="komoku" align=center><b>基本設定</b> </td>
</tr>
<tr>
<td width="220" class="bg">管理パスワード</td><td width=""><input type="password" size="10" name="newpass" value="">(変更するときは入力)</td>
</tr>
<tr>
<td class="bg">記録する記事の数<font color="#cc0000">*</font></td><td width="400"><input type="text" size="10" name="max" value="$max"></td>
</tr>
<tr>
<td class="bg">1ページに表\示する数<font color="#cc0000">*</font></td><td><input type="text" size="10" name="pagemax" value="$pagemax"></td>
</tr>
<tr>
<td class="bg">タイトルが未入力のときのタイトル</td><td><input type="text" size="30" name="titlealt" value="$titlealt"></td>
</tr>
<tr>
<td class="bg">タグを許可するか</td><td>

1.<input type="radio" name="tag" value="0"$CK{'tag1'}>しない<br>
2.<input type="radio" name="tag" value="1"$CK{'tag2'}>する<br>
</td>
</tr>
<tr>
<td class="bg">URLを自動リンクするか</td><td>

1.<input type="radio" name="inlink" value="0"$CK{'inlink1'}>しない<br>
2.<input type="radio" name="inlink" value="1"$CK{'inlink2'}>する<br>
</td>
</tr>
<tr>
<td class="bg">アップする画像の最大横サイズ</td><td><input type="text" size="20" name="w_max" value="$w_max">
これより大きい場合は縮小します。
</td>
</tr>
<tr>
<td class="bg">アップした画像の回り込み</td><td><input type="text" size="40" name="i_align" value="$i_align">
</td>
</tr>
<tr>
<td class="bg">アップした画像のスタイル</td><td><input type="text" size="40" name="img_style" value="$img_style">
<br>
スタイルシートでマージンなどを設定
</td>
</tr>
<tr>
<td class="bg">アイコン画像のサイズ</td><td><input type="text" size="20" name="iconsize" value="$iconsize">
(例)width="50" height="50"
<br>
アイコンの縦横サイズが全て同じときは、指定すると表\示がスムーズになります。
</td>
</tr>

<tr>
<td colspan="2" class="komoku" align=center><b>セキュリティ</b> </td>
</tr>

<tr>
<td class="bg">ホスト名でアクセスを拒否するか</td><td>
1.<input type="radio" name="hostdeny" value="0"$CK{'hostdeny1'}>拒否しない<br>
2.<input type="radio" name="hostdeny" value="1"$CK{'hostdeny2'}>拒否する<br>
<br>
上を2にしたとき禁止するホスト名を設定<br>
<textarea name="khost" rows="10" cols="30">$khost</textarea>
<br>
禁止ホストA<br>
禁止ホストB<br>
のように改行して複数登録可
(123hoge.ne.jp、456hoge.ne.jpのように変化する部分があるときは同じ部分(この場合hoge.ne.jp)を記入)

</td>
</tr>


<tr>
<td colspan="2" class="komoku" align=center><b>その他</b> </td>
</tr>
<tr>
<td class="bg">管理パスワードをクッキーに保存するか</td><td>
1.<input type="radio" name="cook_on" value="0"$CK{'cook_on1'}>しない<br>
2.<input type="radio" name="cook_on" value="1"$CK{'cook_on2'}>する<br>
</td>
</tr>
</table>

<br>
<input type="submit" value="送信する">
</form>
EOM

&Table2;

print <<EOM;
</body>
</html>
EOM
exit;
}


sub EnvRegist{
my($i,$adline,$hostline,$wordline,@wordtmp,$evalline,@hosttmp,$coded);

&CheckPass($FORM{'pass'});

if($FORM{'max'} eq ""){
	&error("記録する記事の数が入力されていません。");
}
if($FORM{'pagemax'} eq ""){
	&error("1ページに表示する数が入力されていません。");
}


unless(open(FILE,">$commonpl")){
	&error("$commonplが開けません。ファイルを確認してください。");
}


$i=0;
foreach(@adtmp){
	if($_){
		$adline.="'".$_."'";
	}
}
$adline=~s/,$//;

@hosttmp=split(/\n/,$FORM{'khost'});
foreach(@hosttmp){
	$hostline.="'".$_."'".",";
}
$hostline=~s/,$//;

@wordtmp=split(/\n/,$FORM{'kword'});
foreach(@wordtmp){
	$wordline.="'".$_."'".",";
}
$wordline=~s/,$//;


$FORM{'img_style'}=~s/&quot;/"/g;
$FORM{'iconsize'}=~s/&quot;/"/g;
$FORM{'fukidashisize'}=~s/&quot;/"/g;

print FILE <<EOM;
\$max='$FORM{'max'}';
\$pagemax='$FORM{'pagemax'}';
\$titlealt='$FORM{'titlealt'}';
\$tag='$FORM{'tag'}';
\$inlink='$FORM{'inlink'}';
\$w_max='$FORM{'w_max'}';
\$i_align='$FORM{'i_align'}';
\$img_style='$FORM{'img_style'}';
\$iconsize='$FORM{'iconsize'}';
\$hostdeny='$FORM{'hostdeny'}';
\@kinsihost=($hostline);
\$cook_on='$FORM{'cook_on'}';
EOM

print FILE "1;\n";
close FILE;

open FILE,"$commonpl" || &error("$commonplが開けません。ファイルを確認してください。");
$evalline = join('',<FILE>);
close(FILE);

$evalline=~s/\n$//;
$evalline=~s/1;$//;

&EvalCheck(\$evalline);

eval $evalline;

if($FORM{'newpass'}){
	$coded=&encode($FORM{'newpass'});
	unless(open(FILE, ">$passlog")){
		&error("passlogに書き込みできません。パーミッションを確認してください。");
	}
	print FILE "\$passwd='$coded';";
	print FILE "\n";
	print FILE "1;\n";
	close FILE;

	$FORM{'pass'}=$FORM{'newpass'};
	$passwd=$coded;
}

&Env;

}

sub EvalCheck{
my($err,$ref);
$err=0;

$ref=$_[0];

if(${$ref}=~/system/){
	$err=1;
}
if(${$ref}=~/`[\x20-\x7E]*`/){
	$err=1;
}
if(${$ref}=~/exec/){
	$err=1;
}
if(${$ref}=~/open/){
	$err=1;
}

if($err){
	&error("危険な文字列が含まれています。");
}

}

sub GetSize{
my($w,$h,$size,$i,$mark,$code,$len);
if($_[0] eq "gif"){
	open(GIF, "$_[1]") || return(0,0);
	seek(GIF, 6, 0);
	read(GIF, $size, 4);
	close(GIF);
	($w,$h)=unpack("vv",$size);
	return($w,$h);
}
elsif($_[0] eq "jpg"){
	open(JPEG, "$_[1]") || return(0,0);
	binmode JPEG;
	read JPEG, $b, 2;
	$w=0;
	$h=0;
	for($i=0;$i<10;$i++) {
		read JPEG, $b, 4;
		($mark, $code, $len) = unpack("a a n", $b);
		if ($mark ne "\xFF") {
			$w=0;
			$h=0;
			last;
		}
		elsif ((ord($code) >= 0xC0) && (ord($code) <= 0xC3)) {
      			read JPEG, $b, 5;
     			($h, $w) = unpack("xnn", $b);
     			last;
        	}
		else {
 			read JPEG, $b, ($len - 2);
		}

	}
    	close JPEG;
    	return($w, $h);
}
}

sub Preview{
my($now,$limit,@files,
$file,$mtime,
$imgfile,$imgfilename,@tmp,$ext,$w,$h,
$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
$tmp,$skinline,$head,$dummy,
$table,$footer,$hd,$dmy,$oya,
$no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,
$href,$href2,$real_w,$real_h,$wh,$table_d,$bodytag,$week,$day,@week
);
$now=time;
$limit=60*60*24;

opendir(DIR, $tmpimgdir) || &error("$tmpimgdirが開けません。");
@files=readdir(DIR);
closedir(DIR);

foreach (@files){
	if($_ ne '.' && $_ ne '..'){
		$file=$tmpimgdir.$_;
		($mtime) = (stat($file))[9];
		if ($mtime < ($now - $limit)) {
			unlink $file || &error("$fileが削除できません。");
		}
	}
}


if($FORM{'message'} eq ""){
	&error("本文が記入されていません。");
}


if($FORM{'subject'} eq "" && $titlealt){
	$FORM{'subject'}=$titlealt;
}


if($UPFNAME[0]){
	$imgfile=$UPFNAME[0];
	$imgfilename=$tmpimgdir.$imgfile;
	@tmp=split(/\./,$imgfile);
	$ext=$tmp[$#tmp];
	($w,$h)=&GetSize($ext,$imgfilename);

}

if($inlink){
	$FORM{'message'}=~s/([^=^"])(https?:\/\/[\w\+\.\?\-\/_:~&=#%]+)/$1<a href=\"$2\" target=\"_blank\">$2<\/a>/g;
}

if($FORM{'mon'} eq ""){
	($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time);
	$mon++;
	$min=sprintf("%02d",$min);
	$year=$year+1900;
	@week=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	$day=$mday;
	$week=$week[$wday];
}
else{
	$year=$FORM{'year'};
	$mon=$FORM{'mon'};
	$day=$FORM{'day'};
	$week=$FORM{'week'};
}

$date="$year/$mon/$day($week)";

$tmp="$no,$FORM{'name'},$FORM{'fukidashi'},$FORM{'subject'},$date,$FORM{'message'},$FORM{'icon'},$FORM{'weather'},$FORM{'color'},$imgfile,$w,$h,\n";

unless(open(HTML, $html)){
	&error("$htmlが開けません。ファイルを確認してください。");
}

$skinline=join('',<HTML>);
close(HTML);
($head,$dummy)=split(/<!--msgstart-->/,$skinline);
if($head eq ""){
	&error("スキンに&lt;!--msgstart--&gt;が書かれていません。");
}
($table,$footer)=split(/<!--msgend-->/,$dummy);
if($footer eq ""){
	&error("スキンに&lt;!--msgend--&gt;が書かれていません。");
}

if($head=~/(<body.*?>)/i){
	$bodytag=$1;
}
else{
	&error("スキンにbodyタグが書かれていません。");
}
($head,$dummy)=split(/<\/head>/i,$head);
if($dummy eq ""){
	&error("スキンに&lt;/head&gt;が書かれていません。");
}
$head.="</head>";
$head.=$bodytag;

print "Content-type: text/html\n\n";
print $head;

($no,$name,$fukidashi,$subject,$date,$message,$icon,$weather,$color,$imgfile,$w,$h)=split(/,/,$tmp);


if($tmpimgdir_http){
	$tmpimgdir=$tmpimgdir_http;
}
if($imgdir_http){
	$imgdir=$imgdir_http;
}

if($icon){
	$icon="<img src=\"$imgdir$icon\" border=\"0\" alt=\"\" ${iconsize}>";
}


if($imgfile){
	$href="";
	$href2="";
	if($w && $h && $w > 0 && $h > 0){
		$real_w=$w+40;
		$real_h=$h+40;
		if($w > $w_max) {
			$w_o=$w;
			$w=$w_max;
			$h=int($w*$h/$w_o);
			$href=qq(<a href="javascript:void(0);" onclick="openwin('${tmpimgdir}$imgfile',${real_w},${real_h});">);
			$href2="</a>";
		}
		$wh="width=\"$w\" height=\"$h\"";
	}
	$imgfile=qq(${href}<img src="${tmpimgdir}$imgfile" border="0" align="${i_align}" ${wh} ${img_style}>${href2});
}

$table_d=$table;
$table_d=~s/<!--icon-->/$icon/;
$table_d=~s/#color/$color/;
$table_d=~s/<!--weather-->/$weather/;
$table_d=~s/<!--fukidashi-->/$fukidashi/;
$table_d=~s/<!--subject-->/$subject/;
$table_d=~s/<!--upfile-->/$imgfile/;
$table_d=~s/<!--message-->/$message/;
$table_d=~s/<!--name-->/$name/;
$table_d=~s/<!--date-->/$date/;
print $table_d;

print <<EOM;
</body>
</html>
EOM


exit;
}


sub header{


print <<EOM;
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>管理用</title>
<style type="text/css">
<!--
body{
color: ${t_color};
background-color: ${b_color};
font-family: "MS Pゴシック";
}
p,td,li,div{
font-size: ${t_size};
}
a{
color: ${l_color};
/*text-decoration:none;*/
}
.tb{
border-style:solid;
border-color:#999999;
border-width:1px;
}
.line{
border-color:#999999;
border-style:dashed;
height:1px;
}
.pad{
padding:4px 0px 0px 4px;
}

.settbl{ 
border:1px solid #999999;
border-collapse:collapse;
}
.settbl td{ 
border:1px solid #999999;
border-collapse:collapse;
}
.bg{
background-color:#eeeeee;
}

.komoku{
background-color:#e0e0e0;
}

-->
</style>
<script type="text/javascript">

function openwin(win,w,h){
	var features="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=0,"+"width="+w+",height="+h;
	window.open(win,"s_win",features);
}

function openwin2(){
	var features="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=0,width=500,height=400";
	window.open("","new",features);
}

function Jump(v){
	document.fo.editnum.value=v;
	document.fo.submit();
}
function Alert(v){
	alert(v);
}
function Preview(){
	if(document.fo.message.value == ""){
		alert("本文が記入されていません。");
		return false;
	}
	var v=document.fo.mode.value;
	document.fo.target="new";
	document.fo.mode.value="preview";
	openwin2();
	document.fo.submit();
	document.fo.target="";
	document.fo.mode.value=v;

}

function Check(){
	if(document.fo.message.value == ""){
		alert("本文が記入されていません。");
		return false;
	}
}
EOM


if($_[1]){
print <<EOM;
window.onload = function(){
Alert('$_[1]');
}
EOM
}

print <<EOM;
</script>
</head>
EOM
}



sub error{

&header;

print <<EOM;
<body>
<br>
<br>
<div align="center"><font color="#ff0000">ERROR</font><br><br>
EOM

print"$_[0]\n";

print <<EOM;
</div>
</body>
</html>
EOM
exit;
}
exit;

Zerion Mini Shell 1.0