源代码如下:
1)dayx
#
## ------------------------------------------------------------------------
## ---[使
用
说
明]-----------------------------------------------------
## 总的人数 <img src="count/dayx.cgi?mode=gif&id=??">
## 今日人数 <img src="count/dayx.cgi?mode=today&id=??">
## 昨日人数 <img src="count/dayx.cgi?mode=yes&id=??">
## 今月人数 <img src="count/dayx.cgi?mode=month&id=??">
## 上月人数 <img src="count/dayx.cgi?mode=yesmon&id=??">
## 今天日期 <img src="count/dayx.cgi?mode=date&id=??">
## 现在时间 <img src="count/dayx.cgi?mode=time&id=??">
## 对方的IP <img src="count/dayx.cgi?mode=ip&id=??">
## ---[日/月的浏览统计观看]-----------------------------------------------
## <a href="count/dayxmgr.cgi?id=??>流量统计</a>
## ------------------------------------------------------------------------
## ---[程式构成图例 (括弧内表示所属的属性,使用chmod) ]--------------------
##
## public_html / index.html ... 安装计数器的网页
## |
## +-- count[777] / dayx.cgi [755]
## | edit.cgi [755]
## | dayxmgr.cgi [755]
## | gifcat.pl [755]
## |
## +-- user[777] / log.txt[666] ??.da1 ??.da2 ...(??档案由程式建立)
## |
## +-- gif1 / 1.gif 2.gif ... 0.gif d.gif c.gif point.gif
## |
## +-- gif2 / 1.gif 2.gif ... 0.gif d.gif c.gif point.gif
##
## -------------------------------------------------------------------
require './gifcat.pl'; # gifcat.pl绘图共用Perl文件
## 基本设定
$lockkey = 0; # lock的使用 (0=不使用 1=symlink 2=打开)
$lockfile = './dayx.lock'; # lock档的位置
$type = 1; # 准确性 (0=不使用延时来使计数器更准确 1=使用)
$defo_dir = "./gif1"; # 预设的GIF路径
$g_path = "."; # 统计的画像(blue.gif,red.gif)的位置
$timetype = 24; # 使用的小时制式
$time_miss = 0; # 和Server的时锺调整
$min_miss = 0; # 和Server的分钟调整
$err_gif = "error.gif"; # 错误的图片的路径
$data_dir = "./user"; # 使用者的储存目录
## 设定完成
$buffer = $ENV{'QUERY_STRING'};
$ref_url = $ENV{'HTTP_REFERER'};
$ref_url =~ s/\?(.|\n)*//ig;
$ref_url =~ s/\%7E/\~/ig;
if ($buffer) {
@pairs = split(/&/,$buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$mode = $FORM{'mode'};
$gif = $FORM{'gif'};
$fig = $FORM{'fig'};
$id = $FORM{'id'};
}
## ID 参数的应用设定
$logfile = "$data_dir/$id.da1"; # 总的记录档
$dayfile = "$data_dir/$id.da2"; # 每日的记录档
$monfile = "$data_dir/$id.da3"; # 每月的记录档
## GIF 参数的应用设定
$gif_path = "./gif$gif"; # gif画像的使用路径
if ($gif eq "") { $gif_path = "$defo_dir"; }
## 时差参数的应用设定
if ($FORM{'timetype'} ne "") { $timetype = $FORM{'timetype'}; } # 使用的小时制式
if ($FORM{'tmiss'} ne "") { $time_miss = $FORM{'tmiss'}; } # 和Server的时锺调整
if ($FORM{'mmiss'} ne "") { $min_miss = $FORM{'mmiss'}; } # 和Server的分钟调整
$visiterip=$ENV{'REMOTE_ADDR'};
# 更新处理时要等待1-2秒
if ($type == 1 && $mode eq "yes") { sleep(2); }
elsif ($type == 1 && $mode eq "today") { sleep(1); }
elsif ($type == 0 && $mode eq "yes") { sleep(1); }
elsif ($type == 1 && $mode eq "month") { sleep(1); }
elsif ($type == 0 && $mode eq "yesmon") { sleep(1); }
elsif ($type == 1 && $mode eq "yesmon") { sleep(2); }
# 程式的开始
if ($type == 1 && $mode eq "gif" && $lockkey == 1) { &lock1; }
elsif ($type == 0 && $mode eq "today" && $lockkey == 1) { &lock1; }
elsif ($type == 0 && $mode eq "month" && $lockkey == 1) { &lock1; }
elsif ($type == 1 && $mode eq "gif" && $lockkey == 2) { &lock2; }
elsif ($type == 0 && $mode eq "today" && $lockkey == 2) { &lock2; }
elsif ($type == 0 && $mode eq "month" && $lockkey == 2) { &lock2; }
# 记录的读入
open(IN, "$logfile") || &error;
$line = <IN>;
close(IN);
$line =~ s/\n//;
# 日期记录的分解
($day_key,$mon_key,$yes,$today,$yesmon,$month,$count,$youbi,$userpass,$useurl) = split(/<>/, $line);
if ($id eq "") { &error;}
if (!($ref_url =~ /$useurl/i)) { &error;}
# 日期时间的取得
#$ENV{'TZ'} = "JST-9";
($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+(3600*$time_miss)+(60*$min_miss));
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($mon < 10) { $mon = "0$mon"; }
if ($mday < 10) { $mday = "0$mday"; }
$year=$year+1900;
$mon++;
$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday];
$date = "$year\/$mon";
if ($mode eq "ip"){
($vip1,$vip2,$vip3,$vip4) = split(/\./, $visiterip);
}
if ($mode eq "time"){
# 使用24时间制式的情况
if ($timetype == 24) {
($t1,$t2) = split(//,$hour);
($t3,$t4) = split(//,$min);
@caras = ("$t1","$t2","c","$t3","$t4");
}
# 使用12时间制式的情况
else {
if ($hour >= 12) { $hour = $hour - 12; $head = p; }
else { $head = a; }
if ($hour < 10) { $hour = "0$hour"; }
($t1,$t2) = split(//,$hour);
($t3,$t4) = split(//,$min);
@caras = ("$head","$t1","$t2","c","$t3","$t4");
}
}
## 日期的处理
elsif ($mode eq "date") {
($d1,$d2,$d3,$d4) = split(//,$year);
($d5,$d6) = split(//,$mon);
($d7,$d8) = split(//,$mday);
@caras = ("$d5","$d6","d","$d7","$d8","d","$d1","$d2","$d3","$d4");
}
# 本日的人数和总的人数的增加
if (($type eq 1 && $mode eq 'gif') || ($type eq 0 && $mode eq 'today')) {
$count++;
## 今日的处理
if ($day_key eq $mday) {
$today++;
$month++;
# 更新记录
open(OUT,">$logfile") || &error;
eval 'flock(OUT,2);';
print OUT "$mday<>$mon<>$yes<>$today<>$yesmon<>$month<>$count<>$thisday<>$userpass<>$useurl";
eval 'flock(OUT,8);';
close(OUT);
}
## 昨日的处理
else {
if ($mon_key == $mon) {
$month++;
# 更新记录
open(OUT,">$logfile") || &error;
eval 'flock(OUT,2);';
print OUT "$mday<>$mon<>$today<>1<>$yesmon<>$month<>$count<>$thisday<>$userpass<>$useurl";
eval 'flock(OUT,8);';
close(OUT);
}
## 昨日的处理
else {
# 更新记录
open(OUT,">$logfile") || &error;
eval 'flock(OUT,2);';
print OUT "$mday<>$mon<>$today<>1<>$month<>1<>$count<>$thisday<>$userpass<>$useurl";
eval 'flock(OUT,8);';
close(OUT);
}
&day_count;
&mon_count;
}
}
# lock的解除
if ($type == 1 && $mode eq 'gif' || $type == 0 && $mode eq 'today') {
unlink($lockfile) if (-e $lockfile);
}
# 绘出图像
&count_view;
exit;
# 图像绘出处理
# (这是参考自 wwwcounter 的部分)
sub count_view {
$count += 0;
$cntstr = sprintf(sprintf("%%0%dld", $fig), $count);
$cntstr2 = sprintf(sprintf("%%0%dld", $fig), $today);
$cntstr3 = sprintf(sprintf("%%0%dld", $fig), $yes);
$cntstr5 = sprintf(sprintf("%%0%dld", $fig), $month);
$cntstr6 = sprintf(sprintf("%%0%dld", $fig), $yesmon);
printf("Content-type: image/gif\n");
printf("\n");
if ($mode eq "gif") {
for ($i=0; $i<length($cntstr); $i++) {
$n = substr($cntstr, $i, 1);
push(@files, "$gif_path/$n.gif");
}
} elsif ($mode eq "today") {
for ($i=0; $i<length($cntstr2); $i++) {
$n = substr($cntstr2, $i, 1);
push(@files, "$gif_path/$n.gif");
}
} elsif ($mode eq "yes") {
for ($i=0; $i<length($cntstr3); $i++) {
$n = substr($cntstr3, $i, 1);
push(@files, "$gif_path/$n.gif");
}
} elsif ($mode eq "month") {
for ($i=0; $i<length($cntstr5); $i++) {
$n = substr($cntstr5, $i, 1);
push(@files, "$gif_path/$n.gif");
}
} elsif ($mode eq "yesmon") {
for ($i=0; $i<length($cntstr6); $i++) {
$n = substr($cntstr6, $i, 1);
push(@files, "$gif_path/$n.gif");
}
} elsif ($mode eq "time" || $mode eq "date") {
foreach (0 .. $#caras) {
push(@files, "$gif_path/$caras[$_].gif");
}
} elsif ($mode eq "ip") {
for ($i=0; $i<length($vip1); $i++) {
$n = substr($vip1, $i, 1);
push(@files, "$gif_path/$n.gif");
}
push(@files, "$gif_path/point.gif");
for ($i=0; $i<length($vip2); $i++) {
$n = substr($vip2, $i, 1);
push(@files, "$gif_path/$n.gif");
}
push(@files, "$gif_path/point.gif");
for ($i=0; $i<length($vip3); $i++) {
$n = substr($vip3, $i, 1);
push(@files, "$gif_path/$n.gif");
}
push(@files, "$gif_path/point.gif");
for ($i=0; $i<length($vip4); $i++) {
$n = substr($vip4, $i, 1);
push(@files, "$gif_path/$n.gif");
}
}
# 用gifcat.pl绘出画像
binmode(STDOUT);
print &gifcat'gifcat(@files);
}
# lock的处理(symlink参数)
sub lock1 {
local($retry) = 5;
while (!symlink(".", $lockfile)) {
if (--$retry <= 0) {
unlink($lockfile) if (-e $lockfile);
exit;
}
sleep(1);
}
}
# lock的处理(open参数)
sub lock2 {
$lockflag = 0;
foreach (1 .. 5) {
unless (-e "$lockfile") { $lockflag = 1; next; }
sleep(1);
}
if ($lockflag) {
open(LOCK,">$lockfile") || &error;
close(LOCK);
} else {
unlink($lockfile) if (-e $lockfile);
exit;
}
}
# 每日人数的档案处理
sub day_count {
# 判断是否有日期的变更
if ($mday < $day_key) {
open(DB,">$dayfile") || &error;
print DB "";
close(DB);
}
# 月内的处理
else {
open(DB,">>$dayfile") || &error;
print DB "$mon\/$day_key \($youbi\)<>$today\n";
close(DB);
}
}
# 每月人数的档案的处理
sub mon_count {
# 初始化月的人数内容
if (-z $monfile) {
$mons[0] = "$date<>$today\n";
}
else {
open(LOG,"$monfile") || &error;
@mons = <LOG>;
close(LOG);
# 行列的最后一行的分解
$mons[$#mons] =~ s/\n//;
($y_m,$cnt) = split(/<>/,$mons[$#mons]);
# 当月的处理
if ($y_m eq "$date") {
$cnt = $cnt + $today;
$mons[$#mons] = "$y_m<>$cnt\n";
}
# 下月的处理
#(行列的最后一行的 $date 的变更、判断月份的变更)
else {
$cnt = $cnt + $today;
$mons[$#mons] = "$y_m<>$cnt\n";
push(@mons,"$date<>0\n");
}
}
# 记录档的更新
open(LOG,">$monfile") || &error;
eval 'flock(DB,2);';
print LOG @mons;
eval 'flock(DB,8);';
close(LOG);
}
#显示出错图片
sub error {
if (-e $lockfile) { unlink($lockfile); }
# IIS的对应
if ($ENV{PERLXS} eq "PerlIS") {
print "HTTP/1.0 302 Temporary Redirection\r\n";
print "Content-type: text/html\n";
}
print "Location: $err_gif" . "\n\n";
exit;
}
2)dayxmgr
$ver = 'DayX v2.1'; # 版本资料(不要修改的)
## 基本设定
$script = "./dayxmgr.cgi"; # 程式档名
$logdir = "./user"; # 用者档的目录
$mcolor = "#0000E3"; # 每月统计的比例图色
$dcolor = "#D900D9"; # 每日统计的比例图色
$title = "DayX V1.5流量统计"; # 流量统计的标题
# 月份统计的调整
$mKEY = 60;
# 每日统计的调整
$dKEY = 6;
$bground = ""; # 背景图的使用
$bgcolor = "#F1F1F1"; # 背景颜色
$text = "#000000"; # 文字颜色
$link = "#0000FF"; # 连接颜色(未连接)
$vlink = "#800080"; # 连接颜色(连接过)
$alink = "#FF0000"; # 连接颜色(连接中)
## 设定完了
# 引数解释
$buffer = $ENV{'QUERY_STRING'};
if ($buffer) {
@pairs = split(/&/,$buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$mode = $FORM{'mode'};
$id = $FORM{'id'};
}
$logfile = "$logdir/$id.da1";
$dayfile = "$logdir/$id.da2";
$monfile = "$logdir/$id.da3";
if ($mode eq "mon") { &mon_view; }
&day_view;
## --- 每月计数的表示
sub mon_view {
open(IN,"$monfile");
@mlines = <IN>;
close(IN);
# HTML的表示
&header;
print "<table border=1 cellpadding=5>\n";
print "<caption><h4>每月计数一览</h4></caption>\n";
print "<tr><th bgcolor=#D5FFD5>年月</th><th bgcolor=#D5FFD5>人数</th>\n";
print "<th bgcolor=#D5FFD5>比例图</th></tr>\n";
$flag = 0;
foreach (@mlines) {
($y_m,$mcnt) = split(/<>/, $_);
$width = $mcnt / $mKEY;
$width = int($width);
$mcnt = &filler($mcnt);
print "<tr><th nowrap>$y_m</th><td align=right>$mcnt</td>";
print "<td><Table Width=$width Height=10 CellSpacing=0 CellPadding=0><Tr><Td BgColor=$mcolor><Img Width=1 Height=1></Td></Tr></Table></td></tr>\n";
}
print "</table>\n";
&footer;
exit;
}
## --- 每日统计的表示
sub day_view {
open(IN,"$dayfile");
@dlines = <IN>;
close(IN);
# HTML的表示
&header;
print "<table border=1 cellpadding=5>\n";
print "<caption><h4>每日计数一览</h4></caption>\n";
print "<tr><th bgcolor=#D5FFD5>月日</th><th bgcolor=#D5FFD5>人数</th>\n";
print "<th bgcolor=#D5FFD5>比例图</th></tr>\n";
$flag = 0;
foreach (@dlines) {
($m_d,$dcnt) = split(/<>/, $_);
$width = $dcnt / $dKEY;
$width = int($width);
$dcnt = &filler($dcnt);
print "<tr><th nowrap>$m_d</th><td align=right>$dcnt</td>\n";
print "<td><Table Width=$width Height=10 CellSpacing=0 CellPadding=0><Tr><Td BgColor=$dcolor><Img Width=1 Height=1></Td></Tr></Table></td></tr>\n";
}
print "</table>\n";
&footer;
exit;
}
## --- HTML的开始
sub header {
print "Content-type: text/html\n\n";
print "<html>\n<head>\n";
print "<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=big5">\n";
print "<title>$title</title></head>\n";
# body的指定
if ($bground) {
print "<body background="$bground" bgcolor=$bgcolor text=$text link=$link vlink=$vlink alink=$alink>\n";
} else {
print "<body bgcolor=$bgcolor text=$text link=$link vlink=$vlink alink=$alink>\n";
}
print "[<a href="Javascript:history.go(-1)">回上页</a>]\n";
if ($mode eq "mon") {
print "[<a href="$script?id=$id">每日统计</a>]\n";
} else {
print "[<a href="$script?id=$id&mode=mon">每月统计</a>]\n";
}
print "<table width=100%><tr><th bgcolor=#008080>\n";
print "<font color=#FFFFFF>$title <font size=-2>ID=$id</font></font></th></tr></table>\n";
print "<P><center>\n";
}
## --- HTML结束
sub footer {
# 著作权表示(不可删除)
print "<P><small><!-- $ver -->\n";
print "- <a href="http://www.lemon.ne.jp/~kent/" target=_blank>Day Counter-EX</a> -\n";
print "授权中文化和加强:<a href=http://freedy.i.am/ target=_blank>飞天</a> <a href=mailto:freedy82\@hotmail.com>电邮</a>";
print "</small></center>\n";
print "</body></html>\n";
}
sub filler {
local($_) = $_[0];
1 while s/(.*\d)(\d\d\d)/$1,$2/;
return $_;
}
#
#_____________________________________________
#
3)edit
## 基本设定
$pass = '0123'; # 管理密码(英数字)
$script = './edit.cgi'; # 程式的路径
$dayxscript = 'http://127.0.0.1/count/dayx.cgi'; # DayX程式的完整网址
$mgrscript = 'http://127.0.0.1/count/dayxmgr.cgi'; # DayXMgr程式的完整网址
$method = 'POST'; # method形式(POST/GET)
$log_dir ="./user"; # 产生的新的档案的位置
$userlog ="./user/log.txt"; # 使用者的资料档
$time_miss = 0; # 和Server的时锺调整
$min_miss = 0; # 和Server的分钟调整
$helppage = "./help.html"; # 线上辅助说明页
## 设定完了
## --- Dayx Editor的开始处理 ---------- ##
&form_deco;
if ($usermode eq "userlogin") { &userlogin; }
if (($FORM{'pass'} ne "") && ($FORM{'pass'} eq $chkpass)) {}
elsif ($FORM{'pass'} eq "$pass") {}
else { &enter; }
if ($mode eq "mente") { &mente; }
elsif ($mode eq "make") { &make; }
elsif ($mode eq "del") { &id_del; }
&admin;
## --- 处理完了 ----------------------- ##
## --- 管理画面
sub admin {
&header;
print <<"EOM";
<table width=100%><tr><th bgcolor=#008080>
<font color=#FFFFFF>管理者管理画面</font>
</th></tr></table>
<blockquote>
<P>
<OL>
<B><LI>用者计数器值的变更</B>
<P>
<DL>
<DT>请输入ID名、然后按变更。
</DL>
<P>
<form action="$script" method="$method">
<input type=hidden name=mode value="mente">
<input type=hidden name=pass value="$FORM{'pass'}">
ID名 <input type=text name=id size=12>
<input type=submit value="变更">
</form>
<hr>
<P>
<B><LI>用者计数器的删除</B>
<P>
<DL>
<DT>请输入ID名、然后按删除。
</DL>
<P>
<form action="$script" method="$method">
<input type=hidden name=mode value="del">
<input type=hidden name=pass value="$FORM{'pass'}">
ID名 <input type=text name=id size=12>
<input type=submit value="删除">
</form>
<hr>
<P>
<B><LI>用者计数器的产生</B>
<P>
<DL>
<DT>请输入ID名、开始的数、ID的密码、然后按产生。
</DL>
<P>
<form action="$script" method="$method">
<input type=hidden name=mode value="make">
<input type=hidden name=pass value="$FORM{'pass'}">
用者ID名 <input type=text name=id size=12> (必须是英文数字)
ID的密码 <input type=text name=countpass size=12>
开始的今天计数值 <input type=text name=todaycount size=12 value="0">
开始的昨天计数值 <input type=text name=yescount size=12 value="0">
开始的今月计数值 <input type=text name=moncount size=12 value="0">
开始的上月计数值 <input type=text name=yesmoncount size=12 value="0">
开始的总数计数值 <input type=text name=totalcount size=12 value="0">
使用的网页的网址 <input type=text name=useurl size=24 value="http://">
(建议指向你真正的首页,并不是指网址捷径。)
系统时间: $mday日$hour点$min分 时差<input type=text name=tmiss size=3 value="+13">
分差<input type=text name=mmiss size=3 value="-4">
时间格式<select name=timetype><option>12<option>24</select>
<input type=submit value="产生">
</form>
</OL>
</blockquote>
EOM
print "<table width=100%><tr><th bgcolor=#008080><font color=#FFFFFF>使用者ID列表</font></th></tr></table>\n";
print "<center><table width=80%><tr bgcolor=#008080><td width=15%><center><font color=#FFFFFF>.:ID:.</font></td><td width=10%><center><font color=#FFFFFF>总数</font></td><td><center><font color=#FFFFFF>.:连接网址:.</font></td></tr>\n";
open(IN,"$userlog") || &error("Can't open $userlog");
@user_log = <IN>;
close(IN);
for ($i=0;$i<=$#user_log;$i++) {
$user_log[$i] =~ s/\n//g;
$userid=$user_log[$i];
$logfile1 = "$log_dir\/$userid\.da1";
open(IN,"$logfile1") || ();
@lines = <IN>;
close(IN);
$lines[0] =~ s/\n//g;
($day,$mmon,$yescount,$todaycount,$yesmoncount,$moncount,$totalcount,$thiswday,$chkpass,$useurl) = split(/<>/,$lines[0]);
print "<tr><td align=center>$userid</td><td align=center>$totalcount</td><td><a href=$useurl>$useurl</a></td></tr>";
}
print "</table></body></html>";
exit;
}
## --- 管理模式的进入画面
sub enter {
&header;
print <<"EOM";
<table width=100%><tr><th bgcolor=#008080>
<font color=FFFFFF>使用者管理模式</font>
</th></tr></table>
<center>
<form action="$script" method="$method">
<input type=hidden name=usermode value="userlogin">
<INPUT TYPE=radio NAME="usermethod" VALUE="mente" CHECKED>更改
<INPUT TYPE=radio NAME="usermethod" VALUE="del">删除
用者ID名 <input type=text name=id size=12>
ID的密码 <input type=text name=countpass size=12>
<input type=submit value="确定">
</form>
<table width=100%><tr><th bgcolor=#008080>
<font color=FFFFFF>进入程式管理者模式</font>
</th></tr></table>
<P><center><b>请输入你的管理密码。</b>
<form action="$script" method="$method">
<input type=password name=pass size=10><input type=submit value="确定">
</form>
<hr><center><font size=-1>
<a href=http://www.lemon.ne.jp/~kent/ target=_blank>Day Counter-EX</a>
授权中文化和加强:<a href=http://freedy.i.am/ target=_blank>飞天</a> (<a href=mailto:freedy82\@hotmail.com>电邮</a>)
</center>
</body></html>
EOM
exit;
}
## --- 更新的处理画面
sub mente {
# 用者档的定义
$logfile1 = "$log_dir\/$id\.da1";
# 用者档的存在
unless (-e $logfile1) { &error("指定的ID名 <B>$id</B> 的资料档并不存在。"); }
# 用者档的读入
open(IN,"$logfile1") || &error("Can't open $logfile1");
@lines = <IN>;
close(IN);
# 档案内容的分解
$lines[0] =~ s/\n//g;
($day,$mmon,$yescount,$todaycount,$yesmoncount,$moncount,$totalcount,$thiswday,$countpass,$useurl) = split(/<>/,$lines[0]);
# 更新的实行
if ($flag) {
$cpass = crypt($FORM{'newcountpass'}, "FD");
$lines[0] = "$day<>$mmon<>$FORM{'yescount'}<>$FORM{'todaycount'}<>$FORM{'yesmoncount'}<>$FORM{'moncount'}<>$FORM{'totalcount'}<>$thisday<>$cpass<>$FORM{'useurl'}\n";
# 档案更新
open(OUT,">$logfile1") || &error("Can't write $logfile1");
print OUT @lines;
close(OUT);
# 完成通知
&header;
print "<center><b>更新处理正常完成。</b><hr>\n";
print "<table><tr><td>ID的名称:<b>$id</b>\n";
print "<tr><td>ID的密码:<b>$FORM{'newcountpass'}</b></td></tr>\n";
print "<tr><td>今天计数器值:<b>$FORM{'todaycount'}</b></td></tr>\n";
print "<tr><td>昨天计数器值:<b>$FORM{'yescount'}</b></td></tr>\n";
print "<tr><td>今月计数器值:<b>$FORM{'moncount'}</b></td></tr>\n";
print "<tr><td>上月计数器值:<b>$FORM{'yesmoncount'}</b></td></tr>\n";
print "<tr><td>总数计数器值:<b>$FORM{'totalcount'}</b></td></tr>\n";
print "<tr><td>网页的网址:<b><a href=$FORM{'useurl'} target=_new>$FORM{'useurl'}</a></b></td></tr>\n";
print "<tr><td>线上辆助说明:<a href=$helppage target=_new>辅助说明</a></td></tr></table><hr></center>\n";
print "<font size=-1>总的人数<img src="$dayxscript?mode=gif&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">今日人数<img src="$dayxscript?mode=today&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">昨日人数<img src="$dayxscript?mode=yes&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">今月人数<img src="$dayxscript?mode=month&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">上月人数<img src="$dayxscript?mode=yesmon&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">\n";
print "今天日期<img src="$dayxscript?mode=date&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">现在时间<img src="$dayxscript?mode=time&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}&timetype=$FORM{'timetype'}">对方位址<img src="$dayxscript?mode=ip&id=$id"><a href="$mgrscript?id=$id">流量统计</a><hr>\n";
print "<center>\[<a href="$script?mode=admin&pass=$FORM{'pass'}">回管理画面</a>\]";
print "</center>\n</body></html>\n";
}
# 更新的画面的表示
else {
&header;
print <<"EOM";
<center>
■<b>$id</b>的计数值的修改。<P>
<form action="$script" method="$method">
<input type=hidden name=pass value="$FORM{'pass'}">
<input type=hidden name=mode value="mente">
<input type=hidden name=id value="$id">
<input type=hidden name=flag value="1">
今天计数值 <input type=text name=todaycount size=12 value="$todaycount">
昨天计数值 <input type=text name=yescount size=12 value="$yescount">
今月计数值 <input type=text name=moncount size=12 value="$moncount">
上月计数值 <input type=text name=yesmoncount size=12 value="$yesmoncount">
总数计数值 <input type=text name=totalcount size=12 value="$totalcount">
用者的密码 <input type=text name=newcountpass size=12 value="$FORM{'countpass'}">
使用的网页的网址 <input type=text name=useurl size=24 value="$useurl">
(建议指向你真正的首页,并不是指网址捷径。)
系统时间: $mday日$hour点$min分 时差<input type=text name=tmiss size=3 value="+13">
分差<input type=text name=mmiss size=3 value="-4">
时间格式<select name=timetype><option>12<option>24</select>
<input type=submit value="修改">
</form>
</center>
</body></html>
EOM
}
exit;
}
## --- ID的删除处理
sub id_del {
# 用者档的定义
$logfile1 = "$log_dir\/$id\.da1";
$logfile2 = "$log_dir\/$id\.da2";
$logfile3 = "$log_dir\/$id\.da3";
# 用者档的存在
unless (-e $logfile1) { &error("指定的ID名 <B>$id</B> 的资料档并不存在。"); }
# 删除实行
if ($flag) {
unlink($logfile1);
unlink($logfile2);
unlink($logfile3);
open(IN,"$userlog") || &error("Can't open $userlog");
@user_log = <IN>;
close(IN);
open(OUT,">$userlog") || &error("Can't write $userlog");
for ($i=0;$i<=$#user_log;$i++) {
$user_log[$i] =~ s/\n//g;
$userid=$user_log[$i];
if ($userid ne $id) {
print OUT "$userid\n";
}
}
close(OUT);
# 完成通知
&header;
print <<"EOM";
<center><hr size=1 width=80%>
<b>ID名 <B>$id</B> 已删除了。</b>
<hr size=1 width=80%>
[<a href="$script?mode=admin&pass=$FORM{'pass'}">回管理画面</a>]
</center>
</body></html>
EOM
}
# 再确认画面
else {
&header;
print <<"EOM";
<center><hr size=1 width=80%>
ID名 <font color=#DD0000><B>$id</B></font> 的资料档真的要删除了吗?
<hr size=1 width=80%>
<P><form action="$script" method="$method">
<input type=hidden name=id value="$id">
<input type=hidden name=pass value="$FORM{'pass'}">
<input type=hidden name=mode value="del">
<input type=hidden name=flag value="1">
<input type=hidden name=countpass size=12 value="$countpass">
<input type=submit value="删除"></form>
</center>
</body></html>
EOM
}
exit;
}
## --- ID产生处理
sub make {
if ($id =~ /\W/) {
&error("ID名必须使用英文数字。");
}
# 使用者档案的定义
$logfile1 = "$log_dir\/$id\.da1";
$logfile2 = "$log_dir\/$id\.da2";
$logfile3 = "$log_dir\/$id\.da3";
# 使用者档案的存在
if (-e $logfile1) {
&error("指定的ID <B>$id</B> 正在使用中。请使用别的ID名。");
}
$cpass = crypt($FORM{'countpass'}, "FD");
# 档案的内容
$new_file1 = "$mday<>$mon<>$FORM{'yescount'}<>$FORM{'todaycount'}<>$FORM{'yesmoncount'}<>$FORM{'moncount'}<>$FORM{'totalcount'}<>$thisday<>$cpass<>$FORM{'useurl'}\n";
# 档案的产生
open(OUT,">$logfile1") || &error("Can't write $logfile1");
print OUT $new_file1;
close(OUT);
open(OUT,">$logfile2") || &error("Can't write $logfile2");
print OUT "";
close(OUT);
open(OUT,">$logfile3") || &error("Can't write $logfile3");
print OUT "";
close(OUT);
open(USERLOG,">>$userlog");
print USERLOG "$id\n";
close(USERLOG);
# 改变档案的属性成 666
chmod (0666,$logfile1);
chmod (0666,$logfile2);
chmod (0666,$logfile3);
# 完了通知
&header;
print "<center><b>ID生成处理正常完成。</b><hr>\n";
print "<table><tr><td>生成ID名:<b>$id</b></td></tr>\n";
print "<tr><td>ID的密码:<b>$FORM{'countpass'}</b></td></tr>\n";
print "<tr><td>今天计数器值:<b>$FORM{'todaycount'}</b></td></tr>\n";
print "<tr><td>昨天计数器值:<b>$FORM{'yescount'}</b></td></tr>\n";
print "<tr><td>今月计数器值:<b>$FORM{'moncount'}</b></td></tr>\n";
print "<tr><td>上月计数器值:<b>$FORM{'yesmoncount'}</b></td></tr>\n";
print "<tr><td>总数计数器值:<b>$FORM{'totalcount'}</b></td></tr>\n";
print "<tr><td>网页的网址:<b>$FORM{'useurl'}</b></td></tr></table><hr>\n";
print "<font size=-1>总的人数<img src="$dayxscript?mode=gif&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">今日人数<img src="$dayxscript?mode=today&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">昨日人数<img src="$dayxscript?mode=yes&id=$id">今月人数<img src="$dayxscript?mode=month&id=$id">上月人数<img src="$dayxscript?mode=yesmon&id=$id">\n";
print "今天日期<img src="$dayxscript?mode=date&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">现在时间<img src="$dayxscript?mode=time&id=$id&tmiss=$FORM{'tmiss'}&mmiss=$FORM{'mmiss'}">对方位址<img src="$dayxscript?mode=ip&id=$id"><a href="$mgrscript?id=$id">流量统计</a><hr>\n";
print "\[<a href="$script\?mode=admin\&pass=$FORM{'pass'}">回管理画面</a>\]";
print "</center>\n</body></html>\n";
exit;
}
## --- 管理画面资料的处理
sub form_deco {
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else { $buffer = $ENV{'QUERY_STRING'}; }
@pairs = split(/&/,$buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$id = $FORM{'id'};
$mode = $FORM{'mode'};
$flag = $FORM{'flag'};
$usermethod = $FORM{'usermethod'};
$usermode = $FORM{'usermode'};
# 时间的取得
($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+(3600*$time_miss)+(60*$min_miss));
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($mon < 10) { $mon = "0$mon"; }
if ($mday < 10) { $mday = "0$mday"; }
$year=$year+1900;
$mon++;
$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday];
$date = "$year\/$mon";
$logfile1 = "$log_dir\/$id\.da1";
open(IN,"$logfile1") || ();
@lines = <IN>;
close(IN);
$lines[0] =~ s/\n//g;
chmod (0666,$userlog);
($day,$mon,$yescount,$todaycount,$yesmoncount,$moncount,$totalcount,$thiswday,$chkpass,$useurl) = split(/<>/,$lines[0]);
}
## --- HTML的开始
sub header {
print "Content-type: text/html\n\n";
print "<html>\n<head>\n";
print "<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=big5">\n";
print "<title>DayX计数器多人加强版1.5编辑器</title>\n";
print "<style type='text/css'><!--\n";
print "a {text-decoration:none;font-weight:none;color:#ff8888}\n";
print "// -->\n";
print "</style></head>\n";
print "<body bgcolor=#F5F5F5>\n";
}
## --- 错误的处理
sub error {
# if (-e $lockfile) { unlink($lockfile); }
&header;
print "<center><hr width=75%><h3>错误发生!</h3>\n";
print "<font color=#DD0000><B>$_[0]</B></font>\n";
print "<hr width=75%></center>\n";
print "</body></html>\n";
exit;
}
sub userlogin {
$logfile1 = "$log_dir\/$id\.da1";
# 用者档的存在
unless (-e $logfile1) { &error("指定的ID名 <B>$id</B> 的资料档并不存在。"); }
# 用者档的读入
open(IN,"$logfile1") || &error("Can't open $logfile1");
@lines = <IN>;
close(IN);
# 档案内容的分解
$lines[0] =~ s/\n//g;
($day,$mon,$yescount,$todaycount,$yesmoncount,$moncount,$totalcount,$thiswday,$countpass,$useurl) = split(/<>/,$lines[0]);
$cpass = crypt($FORM{'countpass'}, "FD");
if ($countpass ne $cpass) {&error("指定的ID名 <B>$id</B> 的密码并不符合。"); }
$FORM{'pass'} = $cpass;
if ($usermethod eq "mente") { &mente; }
if ($usermethod eq "del") { &id_del; }
exit;
}
4)gifcat
;# ====================================================================
;# 基本的使用方法
;# require "gifcat.pl";
;# open(OUT, "> out.gif");
;# binmode(OUT); # MS-DOS 和 Windows 的情况是必须的。
;# print OUT &gifcat'gifcat("xx.gif", "yy.gif", "zz.gif");
;# close(OUT);
;#
;# 简单用法(GIF的显示出)
;# require "gifcat.pl";
;# &gifcat'gifprint("xx.gif", "yy.gif", "zz.gif");
;#
;# 限制事项
;# 这一程式只限对GIF有作用,不支援其他格式。
;# 而连接的GIF的尺寸大小也必须相同,要不会出现错误。
;#
;# 最新版可在以下网址得到
;# http://www2e.biglobe.ne.jp/~s-hasei/cgi-bin/gifcat.pl
;#
;# 更新记录:
;# 1997.05.03 初版。
;# 1997.05.10 スペルミス修正。
;# 1997.05.29 サイズの异なるカラ
テ
ブルに对应。
;# 1997.07.07 エラ
发生时にexit()しないように修正。
;# 1998.05.05 Trailerを持たないGIFファイルを连结できないバグを修正。
;# 1998.05.05 产生超过长256长的GIF的显示错误修正。
;# 1998.05.05 gifprint()的连结结果的显示错误修正。
;# 1998.05.10 连结できないGIF画像があるというバグを修正。
;# 1998.08.20 Ver1.50 初期化变数的行数的修正。
;# 1998.08.20 Ver1.50 透明GIF的支援。
;#
;# ====================================================================
package gifcat;
;# =====================================================
;# gifcat'gifprint() - print out GIF diagnostics.
;# =====================================================
sub gifprint {
$pflag = 1;
&gifcat(@_);
}
;# =====================================================
;# gifcat'gifcat() - get a concatenated GIF image.
;# =====================================================
sub gifcat {
$Gif = 0;
$useLocalColorTable = 0;
@files = @_;
for $file (@files) {
($dev,$ino,$mode,$nlink,$uid,$gif,$rdev,
$size,$atime,$mtime,$ctime,$blksize,$blocks)
= stat($file);
open(IN, "$file");
binmode(IN);
sysread(IN, $buf, $size);
close(IN);
$cnt = 0;
&GifHeader();
while (1) {
$x1 = ord(substr($buf, $cnt, 1));
if ($x1 == 0x2c) {
&ImageBlock();
} elsif ($x1 == 0x21) {
$x2 = ord(substr($buf, $cnt + 1, 1));
if ($x2 == 0xf9) {
&GraphicControlExtension();
} elsif ($x2 == 0xfe) {
&CommentExtension();
} elsif ($x2 == 0x01) {
&PlainTextExtension();
} elsif ($x2 == 0xff) {
&ApplicationExtension();
} else {
return("ERROR");
}
} elsif ($x1 == 0x3b) {
&Trailer();
last;
} elsif ($cnt == $size) {
last;
} else {
return("ERROR");
}
}
undef($buf);
$Gif++;
}
if ($pflag == 1) {
return;
}
$GifImage .= "GIF89a";
$GifImage .= pack("C", $logicalScreenWidth & 0x00ff);
$GifImage .= pack("C", ($logicalScreenWidth & 0xff00) >> 8);
$GifImage .= pack("C", $logicalScreenHeight & 0x00ff);
$GifImage .= pack("C", ($logicalScreenHeight & 0xff00) >> 8);
if ($useLocalColorTable) {
$PackedFields18[0] &= ~0x80;
}
$GifImage .= pack("C", $PackedFields18[0]);
$GifImage .= pack("C", $BackgroundColorIndex);
$GifImage .= pack("C", $PixelAspectRatio);
if ($useLocalColorTable == 0) {
$GifImage .= $globalColorTable[0];
}
for ($i = 0; $i < $Gif; $i++) {
$GifImage .= pack("CCC", 0x21, 0xf9, 0x04);
$GifImage .= pack("C", $PackedFields23 | $TransparentColorFlag[$i]);
$GifImage .= pack("CC", 0x00, 0x00);
$GifImage .= pack("C", $TransparentColorIndex[$i]);
$GifImage .= pack("C", 0x00);
$GifImage .= pack("C", 0x2c);
$n = $ImageWidth * $i;
$GifImage .= pack("C", $n & 0x00ff);
$GifImage .= pack("C", ($n & 0xff00) >> 8);
$GifImage .= pack("CC", 0x00, 0x00);
$GifImage .= pack("C", $ImageWidth & 0x00ff);
$GifImage .= pack("C", ($ImageWidth & 0xff00) >> 8);
$GifImage .= pack("C", $ImageHeight & 0x00ff);
$GifImage .= pack("C", ($ImageHeight & 0xff00) >> 8);
if ($useLocalColorTable) {
$PackedFields20[$i] |= 0x80;
$PackedFields20[$i] &= ~0x07;
$PackedFields20[$i] |= ($PackedFields18[$i] & 0x07);
$GifImage .= pack("C", $PackedFields20[$i]);
$GifImage .= $globalColorTable[$i];
} else {
$GifImage .= pack("C", $PackedFields20[$i]);
}
$GifImage .= pack("C", $LzwMinimumCodeSize[$i]);
$GifImage .= $ImageData[$i];
}
$GifImage .= pack("C", 0x3b);
}
;# =====================================
;# GifHeader
;# =====================================
sub GifHeader {
$Signature = substr($buf, $cnt, 3); $cnt += 3;
$Version = substr($buf, $cnt, 3); $cnt += 3;
$LogicalScreenWidth
= ord(substr($buf, $cnt + 0, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$LogicalScreenHeight
= ord(substr($buf, $cnt + 0, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$PackedFields18[$Gif] = ord(substr($buf, $cnt, 1)); $cnt++;
$GlobalColorTableFlag = ($PackedFields18[$Gif] & 0x80) >> 7;
$ColorResolution = (($PackedFields18[$Gif] & 0x70) >> 4) + 1;
$SortFlag = ($PackedFields18[$Gif] & 0x08) >> 3;
$SizeOfGlobalColorTable = 2 ** (($PackedFields18[$Gif] & 0x07) + 1);
$BackgroundColorIndex = ord(substr($buf, $cnt, 1)); $cnt++;
$PixelAspectRatio = ord(substr($buf, $cnt, 1)); $cnt++;
if ($GlobalColorTableFlag) {
$GlobalColorTable
= substr($buf, $cnt, $SizeOfGlobalColorTable * 3);
$cnt += $SizeOfGlobalColorTable * 3;
}
$logicalScreenWidth += $LogicalScreenWidth;
if ($logicalScreenHeight < $LogicalScreenHeight) {
$logicalScreenHeight = $LogicalScreenHeight;
}
if ($GlobalColorTableFlag) {
$globalColorTable[$Gif] = $GlobalColorTable;
if ($Gif > 0) {
if ($GlobalColorTable ne $globalColorTable[$Gif - 1]) {
$useLocalColorTable = 1;
}
}
}
if ($pflag) {
printf("=====================================\n");
printf("GifHeader\n");
printf("=====================================\n");
printf("Signature: %s\n", $Signature);
printf("Version: %s\n", $Version);
printf("Logical Screen Width: %d\n", $LogicalScreenWidth);
printf("Logical Screen Height: %d\n", $LogicalScreenHeight);
printf("Global Color Table Flag: %d\n", $GlobalColorTableFlag);
printf("Color Resolution: %d\n", $ColorResolution);
printf("Sort Flag: %d\n", $SortFlag);
printf("Size of Global Color Table: %d\n", $SizeOfGlobalColorTable);
printf("Background Color Index: %d\n", $BackgroundColorIndex);
printf("Pixel Aspect Ratio: %d\n", $PixelAspectRatio);
printf("Global Color Table: ...\n");
}
}
;# =====================================
;# Image Block
;# =====================================
sub ImageBlock {
$ImageSeparator = ord(substr($buf, $cnt, 1)); $cnt++;
$ImageLeftPosition = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$ImageTopPosition = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$ImageWidth = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$ImageHeight = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$PackedFields20[$Gif] = ord(substr($buf, $cnt, 1)); $cnt++;
$LocalColorTableFlag = ($PackedFields20[$Gif] & 0x80) >> 7;
$InterlaceFlag = ($packedFields20[$Gif] & 0x40) >> 6;
$SortFlag = ($PackedFields20[$Gif] & 0x20) >> 5;
$Reserved = ($PackedFields20[$Gif] & 0x18) >> 3;
$SizeOfLocalColorTable = 2 ** (($PackedFields20[$Gif] & 0x07) + 1);
if ($LocalColorTableFlag) {
$cnt += $SizeOfLocalColorTable * 3;
}
$LzwMinimumCodeSize[$Gif] = ord(substr($buf, $cnt, 1)); $cnt++;
$ImageData[$Gif] = &DataSubBlock();
if ($pflag) {
printf("=====================================\n");
printf("Image Block\n");
printf("=====================================\n");
printf("Image Separator: 0x%02x\n", $ImageSeparator);
printf("Image Left Position: %d\n", $ImageLeftPosition);
printf("Image Top Position: %d\n", $ImageTopPosition);
printf("Image Width: %d\n", $ImageWidth);
printf("Image Height: %d\n", $ImageHeight);
printf("Local Color Table Flag: %d\n", $LocalColorTableFlag);
printf("Interlace Flag: %d\n", $InterlaceFlag);
printf("Sort Flag: %d\n", $SortFlag);
printf("Reserved: --\n");
printf("Size of Local Color Table: %d\n", $SizeOfLocalColorTable);
printf("Local Color Table: ...\n");
printf("LZW Minimum Code Size: %d\n", $LzwMinimumCodeSize[$Gif]);
printf("Image Data: ...\n");
printf("Block Terminator: 0x00\n");
}
}
;# =====================================
;# Graphic Control Extension
;# =====================================
sub GraphicControlExtension {
$ExtensionIntroducer = ord(substr($buf, $cnt, 1)); $cnt++;
$GraphicControlLabel = ord(substr($buf, $cnt, 1)); $cnt++;
$BlockSize = ord(substr($buf, $cnt, 1)); $cnt++;
$PackedFields23 = ord(substr($buf, $cnt, 1)); $cnt++;
$Reserved = ($PackedFields23 & 0xe0) >> 5;
$DisposalMethod = ($PackedFields23 & 0x1c) >> 5;
$UserInputFlag = ($PackedFields23 & 0x02) >> 1;
$TransparentColorFlag[$Gif] = $PackedFields23 & 0x01;
$DelayTime = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt+1, 1)) * 256; $cnt += 2;
$TransparentColorIndex[$Gif] = ord(substr($buf, $cnt, 1)); $cnt++;
$BlockTerminator = ord(substr($buf, $cnt, 1)); $cnt++;
if ($pflag) {
printf("=====================================\n");
printf("Graphic Control Extension\n");
printf("=====================================\n");
printf("Extension Introducer: 0x%02x\n", $ExtensionIntroducer);
printf("Graphic Control Label: 0x%02x\n", $GraphicControlLabel);
printf("Block Size: %d\n", $BlockSize);
printf("Reserved: --\n");
printf("Disposal Method: %d\n", $DisposalMethod);
printf("User Input Flag: %d\n", $UserInputFlag);
printf("Transparent Color Flag: %d\n", $TransparentColorFlag[$Gif]);
printf("Delay Time: %d\n", $DelayTime);
printf("Transparent Color Index: %d\n", $TransparentColorIndex[$Gif]);
printf("Block Terminator: 0x00\n");
}
}
;# =====================================
;# Comment Extension
;# =====================================
sub CommentExtension {
$ExtensionIntroducer = ord(substr($buf, $cnt, 1)); $cnt++;
$CommentLabel = ord(substr($buf, $cnt, 1)); $cnt++;
&DataSubBlock();
if ($pflag) {
printf("=====================================\n");
printf("Comment Extension\n");
printf("=====================================\n");
printf("Extension Introducer: 0x%02x\n", $ExtensionIntroducer);
printf("Comment Label: 0x%02x\n", $CommentLabel);
printf("Comment Data: ...\n");
printf("Block Terminator: 0x%02x\n", $BlockTerminator);
}
}
;# =====================================
;# Plain Text Extension
;# =====================================
sub PlainTextExtension {
$ExtensionIntroducer = ord(substr($buf, $cnt, 1)); $cnt++;
$PlainTextLabel = ord(substr($buf, $cnt, 1)); $cnt++;
$BlockSize = ord(substr($buf, $cnt, 1)); $cnt++;
$TextGridLeftPosition = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$TextGridTopPosition = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$TextGridWidth = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$TextGridHeight = ord(substr($buf, $cnt, 1))
+ ord(substr($buf, $cnt + 1, 1)) * 256; $cnt += 2;
$CharacterCellWidth = ord(substr($buf, $cnt, 1)); $cnt++;
$CharacterCellHeight = ord(substr($buf, $cnt, 1)); $cnt++;
$TextForegroundColorIndex = ord(substr($buf, $cnt, 1)); $cnt++;
$TextBackgroundColorIndex = ord(substr($buf, $cnt, 1)); $cnt++;
&DataSubBlock();
if ($pflag) {
printf("=====================================\n");
printf("Plain Text Extension\n");
printf("=====================================\n");
printf("Extension Introducer: 0x%02x\n", $ExtensionIntroducer);
printf("Plain Text Label: 0x%02x\n", $PlainTextLabel);
printf("Block Size: 0x%02x\n", $BlockSize);
printf("Text Grid Left Position: %d\n", $TextGridLeftPosition);
printf("Text Grid Top Position: %d\n", $TextGridTopPosition);
printf("Text Grid Width: %d\n", $TextGridWidth);
printf("Text Grid Height: %d\n", $TextGridHeight);
printf("Text Foreground Color Index: %d\n", $TextForegroundColorIndex);
printf("Text Background Color Index: %d\n", $TextBackgroundColorIndex);
printf("Plain Text Data: ...\n");
printf("Block Terminator: 0x00\n");
}
}
;# =====================================
;# Application Extension
;# =====================================
sub ApplicationExtension {
$ExtensionIntroducer = ord(substr($buf, $cnt, 1)); $cnt++;
$ExtentionLabel = ord(substr($buf, $cnt, 1)); $cnt++;
$BlockSize = ord(substr($buf, $cnt, 1)); $cnt++;
$ApplicationIdentifire = substr($buf, $cnt, 8); $cnt += 8;
$ApplicationAuthenticationCode = substr($buf, $cnt, 3); $cnt += 3;
&DataSubBlock();
if ($pflag) {
printf("=====================================\n");
printf("Application Extension\n");
printf("=====================================\n");
printf("Extension Introducer: 0x%02x\n",
$ExtensionIntroducer);
printf("Extension Label: 0x%02x\n",
$PlainTextLabel);
printf("Block Size: 0x%02x\n",
$BlockSize);
printf("Application Identifire: ...\n");
printf("ApplicationAuthenticationCode: ...\n");
printf("Block Terminator: 0x00\n");
}
}
;# =====================================
;# Trailer
;# =====================================
sub Trailer {
$cnt++;
if ($pflag) {
printf("=====================================\n");
printf("Trailer\n");
printf("=====================================\n");
printf("Trailer: 0x3b\n");
printf("\n");
}
}
;# =====================================
;# Data Sub Block
;# =====================================
sub DataSubBlock {
local($n, $from);
$from = $cnt;
while ($n = ord(substr($buf, $cnt, 1))) {
$cnt++;
$cnt += $n;
}
$cnt++;
return(substr($buf, $from, $cnt - $from));
}
1;
运行结果如下:
总的人数
今日人数
昨日人数
今月人数
上月人数
现在时间
今日日期
你的位址
1、 report
源代码如下:
1) cgilib
#####################################################
($sec,$min,$hour,$day,$mon,$year)=localtime(time);
$mon=$mon+1;
$year=$year+1900;
$date = sprintf ("%04d年%02d月%02d日",$year,$mon,$mday);
$time = sprintf ("%02d时%02d分",$hour,$min);
sub htmlhead
{
print "Content-type: text/html\n\n";
}
sub getform
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/ //g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/\<\/br\>/g;
$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/<([^>]|\n)*>/\<\/br\>/g;
$FORM{$name} = $value;
}
@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach $query (@querys)
{
($name, $value) = split(/=/, $query);
$FORM{$name} = $value;
}
}
sub error
{
open(FILE,"error.htm");
@file = <FILE>;
close(FILE);
&htmlhead;
foreach (@file)
{
$_ =~ s/\$picurl/$picurl/g;
$_ =~ s/\$error/$_[0]/g;
print $_;
}
exit;
}
1;
2) ip
#####################################################
#################### 程序设置部分 ####################
$cgiurl="http://www.agedoor.com/cgi-bin/ip"; #程序的URL
$weburl="http://www.agedoor.com"; #网站的URL
$picurl="http://www.agedoor.com/images"; #图片的URL
$path="/home/agedoor/cgi-bin/ip/data"; #数据文件的绝对路径
$mailprog="/usr/sbin/sendmail -t"; #服务器发送邮件的程序路径
$adminemail="agedoor\@21cn.com"; #管理员的EMAIL
############# 完成设置,以下部分不需要修改 #############
require "cgilib.cgi";
#获取用户IP地址,并打开该IP段相应的记录文件
$ip="$ENV{'REMOTE_ADDR'}";
($i1,$i2,$i3,$i4) = split(/\./,$ip);
$ipnum = $i1*1e9+$i2*1e6+$i3*1e3+$i4;
#若IP属于202段,则打开/cgi-bin/ip/data/202/下的相应数据文件,(按IP的第二组数字,查找相应文件)
#增加这一功能,主要是由于大部分中国的IP属于202段,将202段独立出来,再按IP第二组数字分段查找,
#大大加快查找的速度,而且减低服务器的负载。
if ($i1==202)
{
unless(-f "$path/202/$i2.dat")
{
$file="$path/202/255.dat";
}
else
{
$file="$path/202/$i2.dat";
}
open(IP,"$file");
@ip = <IP>;
close(IP);
}
#非202段的IP,执行以下程序,打开/cgi-bin/ip/data/下的相应记录文件
else
{
unless(-f "$path/$i1.dat")
{
$file="$path/255.dat";
}
else
{
$file="$path/$i1.dat";
}
open(IP,"$file");
@ip = <IP>;
close(IP);
}
#处理打开了的数据文件,搜索记录,查找该IP所属的地理位置并输出信息
foreach $data (@ip)
{
($ipbegin,$ipend,$location,$detail,$thankfor) = split(/\|/,$data);
($b1,$b2,$b3,$b4) = split(/\./,$ipbegin);
$beginnum = $b1*1e9+$b2*1e6+$b3*1e3+$b4;
($e1,$e2,$e3,$e4) = split(/\./,$ipend);
$endnum = $e1*1e9+$e2*1e6+$e3*1e3+$e4;
if ($ipnum >= $beginnum && $ipnum <= $endnum)
{
$lastlocation=$location;
$lastdetail=$detail;
if ($ipnum == $beginnum)
{
&foundhost;
exit;
}
}
}
if (($lastlocation eq "")&&($lastdetail eq ""))
{
&unfound;
exit;
}
&found;
sub foundhost
{
&htmlhead;
print "document.write('<a href="$cgiurl/report.cgi"><acronym title="我认为这个IP地址的信息不对\!请修改\!">您的IP是:$ip 来自:$lastlocation $lastdetail<\/acronym><\/a>');\n";
}
sub unfound
{
&htmlhead;
print "document.write('<a href="$cgiurl/report.cgi"><acronym title="我们暂时没有这个地址的资料,请点击这里告诉我们,谢谢。">您的IP是:$ip,点击这里告诉我们,谢谢。<\/acronym><\/a>');\n";
}
sub found
{
&htmlhead;
print "document.write('<a href="$cgiurl/report.cgi"><acronym title="我认为这个IP地址的信息不对\!请修改\!">您的IP是:$ip 来自:$lastlocation $lastdetail<\/acronym><\/a>');\n";
}
1;
3)report
#####################################################
require "cgilib.cgi";
$ip="$ENV{'REMOTE_ADDR'}";
&getform;
if ($FORM{type}==2)
{
if($FORM{province} eq "")
{
&error("您还没有填写省份名!");
}
if($FORM{city} eq "")
{
&error("您还没有填写城市名!");
}
&htmlhead;
&sendmail();
&sendok();
exit;
}
&htmlhead;
&printreport();
sub printreport
{
open(FILE,"report.htm");
@file = <FILE>;
close(FILE);
foreach (@file)
{
$_ =~ s/\$weburl/$weburl/g;
$_ =~ s/\$picurl/$picurl/g;
$_ =~ s/\$cgiurl/$cgiurl/g;
$_ =~ s/\$ip/$ip/g;
print $_;
}
}
sub sendmail
{
open (MAIL, "|$mailprog");
print MAIL <<CONTENT;
To:$adminemail
From:IP资料\<\>
Subject:请核对 $ip 的资料
您好!
$date$time 来自 $ip 的访问者认为本IP地址的正确资料应该是:
省份:$FORM{province}
城市:$FORM{city}
网络属性:$FORM{nettype}
机构:$FORM{from}
访问者的名字:$FORM{name}
访问者的邮箱:$FORM{email}
他的其他意见:$FORM{other}
========================================
Agedoor.com IP追踪者 V1.0
$weburl
\cZ
CONTENT
close(MAIL);
}
sub sendok
{
open(FILE,"sendok.htm");
@file = <FILE>;
close(FILE);
foreach (@file)
{
$_ =~ s/\$weburl/$weburl/g;
$_ =~ s/\$picurl/$picurl/g;
print $_;
}
}