📄 board.cgi
字号:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
&readparse;
($min,$hour,$day,$mon)=(localtime(time))[1,2,3,4];
#####setting####
$serverpath="D:/www/5";
$cfg_file="$serverpath/5user_lists/config.log";
open(file,"<$cfg_file")||die"不能打开文件\n";
@config=<file>;
close file;
foreach $line(@config){
chop $line;
@d=split(/=/,$line);
push (@cfg,"$d[1]");}
$path=$cfg[1];
$board_cgi=$cfg[2];
$user_cgi=$cfg[3];
$user_file="$cfg[4]/$cgi{'room'}.log";
$user_list_file=$cfg[5];
$his_file=$cfg[6];
$his_path=$cfg[7];
$img_path=$cfg[8];
$pro_name=$cgi{'name'};
$web_name=pack("h*",$pro_name);
$title=$cfg[9];
$user_data=$cfg[10];
################
#print "pass\n\n";
@lists=();@entries=();
open(file,"<$user_list_file")||die"不能打开文件$user_list_file\n";
@lists=<file>;
close file;
if ($cgi{'mu'} eq "gate"){$web_name=$cgi{'name'};$pro_name=unpack("h*",$web_name);&welcome}
if ($cgi{'mu'} eq ""){&hall}
if ($cgi{'mu'} eq "new"){&new}
if ($cgi{'mu'} eq "exit"){&ready_close_room}
if ($cgi{'mu'} eq "close_room"){&close_room}
if ($cgi{'mu'} eq "his"){&his}
exit;
sub his{
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</head><body scroll="auto"><table border=1 width="100%"><tr bgcolor="#b0c4de"><td>***五子沙龙对战纪录·点击察看(完善中)***</td></tr>
eof
open(file,"<$his_file")||die"不能打开文件$his_file\n";
@lists=<file>;
close file;
foreach $line(@lists){@each_his=split(/&&/,$line);
$pro_room=unpack("h*",$each_his[0]);$pro_hisroom=unpack("h*",$each_his[0]);
print "<tr><td><a href=$user_cgi?mu=joinhis&name=$pro_name&room=$pro_room&hisroom=$pro_hisroom$each_his[3]-$each_his[4]-$each_his[5]-$each_his[6]>$each_his[0] VS $each_his[1]</a> [$each_his[7]胜利]($each_his[3]月$each_his[4]日 $each_his[5]:$each_his[6])</td></tr>";
}
print <<eof;
</table><form action="$board_cgi" method="POST">
<input type=hidden name=mu value="">
<input type=hidden name=name value=$pro_name>
<input type=submit value=返回大厅></form></body></html>
eof
}
sub welcome{
$prs_file="$user_data/$pro_name.dat";
opendir (DIRECTORY,"$user_data")||die"不能打开dir\n";
@dirlist=readdir(DIRECTORY);shift @dirlist;shift @dirlist;
closedir DIRECTORY;
#foreach $line(@dirlist){print $line;}
#exit;
if (-e "$prs_file"){
open(file,"<$prs_file")||die"不能打开文件\n";
@prs_data=<file>;
close file;
chop $prs_data[0];
if ($prs_data[0] ne $cgi{'pw'}){print "sorry,wrong password.\n\n";exit;}
}else{
open(file,">$prs_file")||die"不能打开文件\n";
print file"$cgi{'pw'}\n";
close file;
}
&hall;
}
sub hall{
$bai=1;$playing=0;$autoname=unpack("h*","机器人");
push (@ready,"<a href=$user_cgi?mu=vsrobot&name=$pro_name>机器人</a><br>");
foreach $line(@lists){@each_room=split(/&&/,$line);
$pro_room=unpack("h*",$each_room[0]);
$target=($each_room[1] eq "")?"所有人":$each_room[1];
chop $line;
open(file,"<$serverpath/5user_file/$pro_room.log")||die"不能打开文件\n";
@his_data=<file>;
close file;
($winer2,$emp2,$dummy)=split(/:/,$his_data[2]);
($winer,$emp3)=split(/:/,$his_data[3]);
#超过15分钟或者已经完成的棋局,放入历史记录
if (-M "$serverpath/5user_file/$pro_room.log" > 15/24/60 or $emp2 eq "胜利"){
if ($winer ne ""){
open(file,">>$his_file")||die"不能打开文件\n";
print file"$line$winer&&\n";
close file;
open(file,">$his_path/$pro_room$each_room[3]-$each_room[4]-$each_room[5]-$each_room[6].log")||die"不能打开文件\n";
foreach $his_line(@his_data){print file"$his_line";}
close file;
}
unlink("$serverpath/5user_file/$pro_room.log")
}else {
push (@re_list,"$line\n");
if ($each_room[2] eq "ready"){
if (($each_room[1] eq $web_name) || ($each_room[1] eq "") || ($each_room[0] eq $web_name))
{$bai++;push (@ready,"<a href=$user_cgi?mu=join&name=$pro_name&room=$pro_room>$each_room[0]向$target宣战</a>($each_room[5]:$each_room[6])<br>")}
}else{$playing++;push (@ing,"<a href=$user_cgi?mu=join&name=$pro_name&room=$pro_room>$each_room[0] VS $each_room[1]</a>($each_room[5]:$each_room[6])<br>")}}
}
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<SCRIPT Language="JavaScript1.2">
<!--
function reload(mode){document.f.mu.value=mode;document.f.submit();}
// -->
</SCRIPT>
</head>
<body scroll="auto"><table border=1><tr bgcolor="#b0c4de"><td colspan="1">***欢迎来到五子沙龙***</td><td align="right" colspan="2">-$web_name-</td></tr>
<tr bgcolor="#66cdaa"><td colspan="3"><center>【说明】</center>
<li>擂台摆好后<b>15分钟内</b>没有人应战将会被<b>拆除;</b>
<li>一个用户名限制摆<b>一个</b>擂台,但作为<b>打擂者</b>可以同时打<b>多个</b>擂台.
<li>对于没有完成的比赛,将以电脑<b>自动估胜</b>作为评判标准。
</td></tr>
<tr><td colspan="3" align="center"><form name="f" action="$board_cgi" method="POST">
<input type="hidden" name=mu value=new>
<input type="hidden" name=name value=$pro_name>
<input type="hidden" name=room value=$pro_name>
<input type="submit" value=摆擂台><input type=checkbox name=check value=1>指名:<input type=text name=target value="" size=10><a href='javaScript:reload("");'> 刷新</A>
</form><a href='javaScript:reload("his");'>对战纪录</a></td></tr>
<tr><th>正在摆擂者:$bai 人</th><th>正在热战中:$playing 组</th></tr><tr><td valign=top>
eof
foreach $line(@ready){print "$line\n";}
print "</td><td valign=top>";
foreach $line(@ing){print "$line\n";}
print "</td></tr></table></body></html>";
open(file,">$user_list_file")||die"不能打开文件\n";
foreach $line(@re_list){print file"$line";}
close file;
exit;
}
sub new{
foreach $line(@lists){
@each_room=split(/&&/,$line);
if ($web_name eq $each_room[0]){&err_find_room}}
$cgi{'target'}="" if ($cgi{'check'} ne "1");
open(file,">>$user_list_file")||die"不能打开文件\n";
print file"$web_name&&$cgi{'target'}&&ready&&$mon&&$day&&$hour&&$min&&\n";
close file;
open(file,">$user_file")||die"不能打开文件\n";
$a[0]="$web_name&&";
$a[1]="&&";
foreach $line(@a){print file"$line\n";}
close file;
&print_frame;
}
sub print_frame{
print <<eof;
<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>$title</title></head>
<FRAMESET COLS="310,*">
<FRAME SRC="$user_cgi?mu=wmaps&room=$cgi{'room'}&name=$pro_name" NAME="map_frm" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no">
<FRAME SRC="$user_cgi?mu=play&room=$cgi{'room'}&name=$pro_name" NAME="5msg_frm" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="auto">
</FRAMESET></html>
eof
exit;}
sub err_find_room{
print <<eof;
<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"><title>$title</title></head>
<body><table border="0" width="100%"><tr bgcolor="#b0c4de"><th>错误!</th></tr><tr><td>如想新摆擂台,必须<b>拆除</b>现有擂台.
<form action="$board_cgi" method="POST">
<input type=hidden name=mu value=>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=返回大厅></form>
<form action="$user_cgi" method="POST">
<input type=hidden name=mu value=join>
<input type=hidden name=name value=$pro_name>
<input type=hidden name=room value=$pro_name>
<input type=submit value=返回游戏></form>
<form action="$board_cgi" method="POST">
<input type=hidden name=mu value=exit>
<input type=hidden name=name value=$pro_name>
<input type=submit value=拆除擂台></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub ready_close_room{
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</head><body>
<table border="0" width="100%"><tr bgcolor="#b0c4de"><th>注意!是否真的拆除???</th></tr><tr><td>如果现在有人正在或者试图向你挑战,他将被强行赶出.</td></tr>
<tr><td><form action="$board_cgi" method="POST">
<input type=hidden name=mu value="">
<input type=hidden name=name value=$pro_name>
<input type=submit value=返回大厅></form>
</td></tr><tr><td><form action="$board_cgi" method="POST">
<input type=hidden name=mu value=close_room>
<input type=hidden name=name value=$pro_name>
<input type=submit value=拆除擂台></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub close_room{
@re_list=();
unlink("$serverpath/5user_file/$pro_name.log");
foreach $line(@lists){@each_room=split(/&&/,$line);push (@re_list,"$line") if ($each_room[0] ne $web_name);}
open(file,">$user_list_file")||die"不能打开文件\n";
foreach $line(@re_list){print file"$line";}
close file;
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</head><body>
<table border="0" width="100%"><tr bgcolor="#b0c4de"><th>拆除完毕.</th></tr>
<tr><td><form action="$board_cgi" method="POST">
<input type=hidden name=mu value="">
<input type=hidden name=name value=$pro_name>
<input type=submit value=返回大厅></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub err_find_room{
print <<eof;
<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"><title>$title</title></head>
<body><table border="0" width="100%"><tr bgcolor="#b0c4de"><th>错误!</th></tr><tr><td>如想新摆擂台,必须<b>拆除</b>现有擂台.
<form action="$board_cgi" method="POST">
<input type=hidden name=mu value="">
<input type=hidden name=name value=$pro_name>
<input type=submit value=返回大厅></form>
<form action="$user_cgi" method="POST">
<input type=hidden name=mu value=join>
<input type=hidden name=name value=$pro_name>
<input type=hidden name=room value=$pro_name>
<input type=submit value=返回游戏></form>
<form action="$board_cgi" method="POST">
<input type=hidden name=mu value=exit>
<input type=hidden name=name value=$pro_name>
<input type=submit value=拆除擂台></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub readparse {
read(STDIN,$user_string,$ENV{'CONTENT_LENGTH'});
if (length($ENV{'QUERY_STRING'})>0) {$user_string=$ENV{'QUERY_STRING'}};
$user_string =~ s/\+/ /g;
@name_value_pairs = split(/&/,$user_string);
foreach $name_value_pair (@name_value_pairs) {
($keyword,$value) = split(/=/,$name_value_pair);
#print "$keyword=$value<br>";
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/ge;
$value =~s/</</g;
$value =~s/>/>/g;
$value =~s/&/&/g;
$value =~s/:/:/g;
push(@value, "$value");
$cgi{$keyword} = $value;
if ($value=~/<!--\#exec/) {
print "Content-type: text/html\n\nNo SSI permitted";
exit;
}
}
}
exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -