%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/rappan/www/cgi_up_gam/
Upload File :
Create Path :
Current File : /home/rappan/www/cgi_up_gam/srh.cgi

#!/usr/local/bin/perl

#******************************************************************************
#srh.cgi - Smart Renewal History - Ver.1.02
#
#Version   	:1.02
#modified  	:2001/01/16
#Copyright 	:The Room
#E-Mail		:dream@lib.net
#URL		:http://dream.lib.net/room/
#
#これはフリー素材です。
#転載・商用目的の利用の際には、メールをお願いします。
#
#******************************************************************************
#1行目のperlのディレクトリ指定は、サーバによって異なります。
#詳しくは、管理者にお聞きください。
#******************************************************************************
#パス指定は、全て相対パスまたはサーバ内絶対パスで指定してください。

#jcode.plのパス
$jcode = './jcode.pl';

#履歴保存用ファイルのパス
$logfile = './log.dat';

#最大履歴保存数
$maxlog = 1000;

#SSIでのプレビュー画面で表示する履歴数
$ssiview = 4;

#通常の履歴表示画面で表示する履歴数
$mainview = 10;

#編集画面で表示する履歴数
$editview = 10;

#CGIを使用する時間帯のグリニッジ標準時からのズレ(秒単位)
# 日本は 9時間x60分x60秒=32400秒 です。
$timecheck = 32400;

#表示する時間形式のゼロ補完
# 例えば 1月なら 01 のように、2桁に満たない場合に 0 を追加します。
# 年表示は常に西暦4桁です。
$zeroexst[4] = 1;#月
$zeroexst[3] = 1;#月
$zeroexst[2] = 1;#時
$zeroexst[1] = 1;#分
$zeroexst[0] = 1;#秒

#曜日
@weekday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

#管理用パスワード
$adminpass= '58325832';

#プレビュー用テンプレートファイルのパス
$ssi_templete = './templete1.html';

#履歴表示用テンプレートファイルのパス
$main_templete = './templete2.html';

#******************************************************************************

require $jcode;

#データ受け取り
$cl = $ENV{"CONTENT_LENGTH"};
if($cl > 0){
	read(STDIN, $qs, $cl );
}else{
	$qs = $ENV{"QUERY_STRING"};
}

@contents = split(/&/,$qs);
foreach $i (0 .. $#contents) {
	local($key,$text)= split(/=/,$contents[$i]);
	$text =~ s/\+/ /g;
	$text =~ s/%(..)/pack("c",hex($1))/ge;
	$text =~ s/\r\n/\n/g;
	$text =~ s/\r/\n/g;
	&jcode'convert(*text,"sjis");
	$act = $text if $key eq 'act';
	$page =  $text if $key eq 'page';
	$pass =  $text if $key eq 'pass';

	$wyear = $text if $key eq 'wyear';
	$wmonth = $text if $key eq 'wmonth';
	$wday = $text if $key eq 'wday';
	$whour = $text if $key eq 'whour';
	$wmin = $text if $key eq 'wmin';
	$wsec = $text if $key eq 'wsec';
	$wweek = $text if $key eq 'wweek';
	$wcheck = $text if $key eq 'wcheck';
	$msg = $text if $key eq 'msg';
	$sel = $text if $key eq 'sel';
}
$msg =~ s/\n/<br>/g;
$page||=0;
if ((($act =~ /^ad/) && ($pass ne $adminpass)) || ($act eq "edit")){&enter;}
elsif ($act eq "adminmenu"){&dataload;&adminmenu;}
elsif ($act eq "adminadd"){&add;&adminmenu;}
elsif ($act eq "admindel"){&del;&adminmenu;}
elsif ($act eq "adminchg"){&chg;&adminmenu;}
elsif ($act eq "list"){&list;}
else{&preview;}

exit;
#******************************************************************************
sub list{
#履歴表示

my ($flag,@templete,$ct,$nextflag,@temp1,$temp2,$buffer);
$flag = 0;
open (IN,"$main_templete");
while(<IN>){
	$_ =~ s/\r\n/\n/g;
	$_ =~ s/\r/\n/g;
	$flag = 1 if $_ =~ /<!--START TEMPLETE-->/i;
	$flag = 0 if $_ =~ /<!--END TEMPLETE-->/i;
	$templete[$flag].=$_;
	}
close(IN);

$templete[1] =~ s/<!--START TEMPLETE-->//i;
$ct = 0;
open (IN,"$logfile");
while(<IN>){
	$ct++;
	if ($ct > ($page+1)*$mainview){
		$nextflag = 1;
		last;
		}
	elsif ($ct > $page*$mainview){
		@temp1 = split(/<>/,$_);
	#	next if $temp1[0] eq "";
		for($i=0;$i<=4;$i++){$temp1[$i] = "0".$temp1[$i] if ($temp1[$i] < 10) && ($zeroexst[$i]);}
		$temp2 = $templete[1];
		$temp2 =~ s/\$week/$weekday[$temp1[6]]/ig;
		$temp2 =~ s/\$year/$temp1[5]/ig;
		$temp2 =~ s/\$month/$temp1[4]/ig;
		$temp2 =~ s/\$day/$temp1[3]/ig;
		$temp2 =~ s/\$hour/$temp1[2]/ig;
		$temp2 =~ s/\$min/$temp1[1]/ig;
		$temp2 =~ s/\$sec/$temp1[0]/ig;
		$temp2 =~ s/\$message/$temp1[8]/ig;
		$buffer.=$temp2;
		}
	}

close(IN);

$templete[0] =~ s/<!--END TEMPLETE-->/$buffer/i;

if ($page != 0){
	$temp1 = $page - 1;
	$templete[0] =~ s/\$prevpage/\.\/srh\.cgi\?act=list&page=$temp1/ig;
	}else{
	$templete[0] =~ s/\n[^\n]*\$prevpage[^\n]*\n/\n/ig;
	}

if ($nextflag != 0){
	$temp1 = $page + 1;
	$templete[0] =~ s/\$nextpage/\.\/srh\.cgi\?act=list&page=$temp1/ig;
	}else{
	$templete[0] =~ s/\n[^\n]*\$nextpage[^\n]*\n/\n/ig;
	}

print "Content-type:text/html; charset=shift_jis\n\n";
print $templete[0];

exit;
}
#******************************************************************************
sub preview{
#プレビュー表示
my ($templete,@temp1,$temp2);

print "Content-type:text/html; charset=shift_jis\n\n";

open (IN,"$ssi_templete");
while(<IN>){$templete.=$_;}
close(IN);

open (IN,"$logfile");
eval{flock(IN,1)};
for(1 .. $ssiview){
	@temp1 = split(/<>/,<IN>);
	last if $temp1[0] eq "";
	for($i=0;$i<=4;$i++){$temp1[$i] = "0".$temp1[$i] if ($temp1[$i] < 10) && ($zeroexst[$i]);}
	$temp2 = $templete;
	$temp2 =~ s/\$week/$weekday[$temp1[6]]/ig;
	$temp2 =~ s/\$year/$temp1[5]/ig;
	$temp2 =~ s/\$month/$temp1[4]/ig;
	$temp2 =~ s/\$day/$temp1[3]/ig;
	$temp2 =~ s/\$hour/$temp1[2]/ig;
	$temp2 =~ s/\$min/$temp1[1]/ig;
	$temp2 =~ s/\$sec/$temp1[0]/ig;
	$temp2 =~ s/\$message/$temp1[8]/ig;
	print $temp2;
	}
close(IN);
exit;
}
#******************************************************************************
sub del{
#履歴追加
my $flag = 0;
my @temp1;
open (IO,"+<$logfile");
eval{flock(IO,2)};
while(<IO>){
	@temp1=split(/<>/,$_);
	if ($temp1[7] == $sel){
		$flag = 1;
		}else{
		push(@log,$_);
		}
	}
if ($flag == 0){
	$admsg = "削除元が見つかりませんでした。";
	}else{
	truncate(IO,0);
	seek(IO,0,0);
	print IO @log;
	$admsg = "履歴を削除しました。";
	}
close (IO);
&adminmenu;
}
#******************************************************************************
sub chg{
#履歴追加
if ($msg eq ""){
	$admsg = "履歴の内容を入力してください。";
	&dataload;
	}else{
	&entertime;
	my $flag = 0;
	my @temp1;
	open (IO,"+<$logfile");
	eval{flock(IO,2)};
	while(<IO>){
		@temp1=split(/<>/,$_);
		if ($temp1[7] == $sel){
			if ($wcheck){
				push(@log,"$wsec<>$wmin<>$whour<>$wday<>$wmonth<>$wyear<>$wweek<>".time()."<>$msg\n");
				}else{
				push(@log,"$temp1[0]<>$temp1[1]<>$temp1[2]<>$temp1[3]<>$temp1[4]<>$temp1[5]<>$temp1[6]<>$temp1[7]<>$msg\n");
				}
			$flag = 1;
			}else{
			push(@log,$_);
			}
		}
	if ($flag == 0){
		$admsg = "変更元が見つかりませんでした。";
		}else{
		truncate(IO,0);
		seek(IO,0,0);
		print IO @log;
		$admsg = "履歴を変更しました。";
		}
	close (IO);
	&adminmenu;
	}
}
#******************************************************************************
sub add{
#履歴追加
if ($msg eq ""){
	$admsg = "履歴の内容を入力してください。";
	&dataload;
	}else{
	&entertime;
	my $flag = 0;
	my @temp1;
	open (IO,"+<$logfile");
	eval{flock(IO,2)};
	while(<IO>){
		@temp1=split(/<>/,$_);
		if ($temp1[7] == $sel){
			push(@log,"$wsec<>$wmin<>$whour<>$wday<>$wmonth<>$wyear<>$wweek<>".time()."<>$msg\n");
			$flag = 1;
			}
		push(@log,$_);
		}
	push(@log,"$wsec<>$wmin<>$whour<>$wday<>$wmonth<>$wyear<>$wweek<>".time()."<>$msg\n") if ($flag == 0);
	pop(@log) if $#log >= $maxlog;
	truncate(IO,0);
	seek(IO,0,0);
	print IO @log;
	close (IO);
	$admsg = "履歴を追加しました。";
	&adminmenu;
	}
}
#******************************************************************************
sub adminmenu{
#メニュー
my ($prevpage,$nextpage,$a1,@temp1,@temp2);
$prevpage = 1 if $page != 0;
$nextpage = 1 if $log[($page+1)*$editview] ne "";

&hphead;
print "<br><div align=center><b><font color=red>$admsg</font></b></div><br><br>" if ($admsg);
print "<table align=center><tr>";
print "<form method=\"post\" action=\"./srh.cgi\"><td><input type=\"submit\" value=\"前のページ\"><input type=\"hidden\" name=\"pass\" value=\"$pass\"><input type=\"hidden\" name=\"act\" value=\"adminmenu\"><input type=\"hidden\" name=\"page\" value=\"".($page-1)."\"></td></form>" if ($prevpage);
print "<form method=\"post\" action=\"./srh.cgi\"><td><input type=\"submit\" value=\"次のページ\"><input type=\"hidden\" name=\"pass\" value=\"$pass\"><input type=\"hidden\" name=\"act\" value=\"adminmenu\"><input type=\"hidden\" name=\"page\" value=\"".($page+1)."\"></td></form>" if ($nextpage);
print <<EOD;
</tr></table>
<table align=center width=95% bgcolor=#a0a0ff cellpadding=0 cellspacing=0>
<tr>
<form method="post" action="./srh.cgi">
<input type="hidden" name="pass" value="$pass">
<td>
<table width=100%>
EOD
$a1 = " checked";
for ($page*$editview .. ($page+1)*$editview-1){
	last if $log[$_] eq "";
	@temp1 = split(/<>/,$log[$_]);
	for(0 .. 4){$temp1[$_] = "0".$temp1[$_] if ($temp1[$_] < 10) && ($zeroexst[$_]);}
	print "<tr><td bgcolor=#e0e0ff width=1><input type=\"radio\" name=\"sel\" value=\"$temp1[7]\"$a1></td>";
	print "<td bgcolor=#e0e0ff nowrap valign=top>$temp1[5]/$temp1[4]/$temp1[3]($weekday[$temp1[6]])<br>$temp1[2]:$temp1[1]:$temp1[0]</td>";
	print "<td bgcolor=#e0e0ff width=100% valign=top>$temp1[8]</td></tr>";
	$a1 = "";
	}
@temp1=gmtime(time()+$timecheck);$temp1[5]+=1900;$temp1[4]++;
print <<EOD;
</table>
</td></tr>
</table>
<br>
<table width=85% align=center><tr><td>
<b>メニュー</b>
<select name="act">
<option value="adminadd" selected>追加(選択した履歴の上に挿入)
<option value="adminchg">選択した履歴の変更
<option value="admindel">選択した履歴の削除
</select><br><br>
<b>書込日時</b>
<input type="text" name="wyear" value="$temp1[5]" size=4 maxlength=4>年
<input type="text" name="wmonth" value="$temp1[4]" size=2 maxlength=2>月
<input type="text" name="wday" value="$temp1[3]" size=2 maxlength=2>日/
<input type="text" name="whour" value="$temp1[2]" size=2 maxlength=2>時
<input type="text" name="wmin" value="$temp1[1]" size=2 maxlength=2>分
<input type="text" name="wsec" value="$temp1[0]" size=2 maxlength=2>秒
<select name="wweek">
EOD
for(0 .. 6){
	if ($_ == $temp1[6]){print "<option value=\"$_\" selected>$weekday[$_]\n";}
	else{print "<option value=\"$_\">$weekday[$_]\n";}
	}
print <<EOD;
</select>
<input type="checkbox" name="wcheck" value="1">日付も変更する(変更時のみ有効)
<br><br>
<b>履歴の内容</b>(タグ自由。改行した場所は自動的にBRタグが入ります。)<br>
<textarea name="msg" cols=60 rows=10></textarea>
<input type="submit" value="実行">
</td></tr></table>
</form>
EOD
&hpfoot;
}
#******************************************************************************
sub dataload{
#読み込み
open (IN,"$logfile");
eval{flock(IN,1)};
@log = <IN>;
close (IN);
}
#******************************************************************************
sub enter{
#管理人確認
&hphead;
print <<EOD;
<br><br><br>
<div align=center>
これより先は、管理人以外入ることが出来ません。<br>
<br>
<form method="post" action="./srh.cgi">
パスワード
<input type="password" name="pass" size=8>
<input type="submit" value="認証">
<input type="hidden" name="act" value="adminmenu">
</form>
<br><br><br>
</div>
EOD
&hpfoot;
}
#******************************************************************************
sub entertime{
#入力された日時の修正
if ($wyear < 0){$wyear = 0;}
if ($wmonth > 12){$wmonth = 12;}
if ($wmonth < 1){$wmonth = 1;}
if ($wday > 31){$wday = 31;}
if ($wday < 1){$wday = 1;}
if ($whour > 23){$whour = 23;}
if ($whour < 0){$whour = 0;}
if ($wmin > 59){$wmin = 59;}
if ($wmin < 0){$wmin = 0;}
if ($wsec > 59){$wsec = 59;}
if ($wsec < 0){$wsec = 0;}
if ($wweek > 6){$wweek = 6;}
if ($wweek < 0){$wweek = 0;}
}
#******************************************************************************
sub hphead{
#ヘッダ表示
print "Content-type:text/html; charset=shift_jis\n\n";
print <<EOD;
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=shift_jis">
<meta http-equiv="pragma" content="no-cache">
<title>[年がら年じゅう] 人生はワンツーパンチ♪>更新履歴管理</title>
</head>
<body bgcolor=#ffffff text=#000000 link=#6060a0 vlink=#6060a0 alink=#a0a0ff>
<div align=center>
<font size=6><b>更新履歴 管理ページ</b></font><br>
</div>
<br><A href="../s_gam/game_top.html">トップ</A> > 更新履歴 <BR>
<BR>
<table width=90% align=center>
<tr><td bgcolor=#6060a0><font color=#ffffff>管理モード</font></td></tr>
<tr><td><br>
EOD
}
#******************************************************************************
sub hpfoot{
#フッタ表示
print <<EOD;
<br></td></tr>
<tr><td bgcolor=#6060a0 align=right><font color=#ffffff>管理モード</font></td></tr>
</table>
<br>
<div align=center>
<a href="http://dream.lib.net/room/" target="_blank">Smart Renewal History by The Room</a>
</div><br>
<br>
</body>
</html>
EOD
exit;
}
#******************************************************************************

Zerion Mini Shell 1.0