📄 topsites.cgi
字号:
#!/usr/bin/perl
#
&set_defaults;
eval {
require "variables.pl";
};
if ($@) {
print "Content-type: text/html\n\n";
&header;
print <<EOF;
A Fatal Error has occurred in the running of Top Sites.
<BR><BR>
Something is wrong with your variables.pl file. Please look carefully at the error
listed below and double check the settings in the variables.pl file.<BR><BR>
The error is:
<BR><font color=red>
$@</FONT>
<BR><BR>
EOF
&error_footer("error_variables.shtml");
exit;
}
unless ($topsite_location =~ /http:\/\//) { &error(5); }
unless ($topsite_location_cgi =~ /http:\/\//) { &error(6); }
if ($path_to_topsites =~ /http:\/\//) { &error(7); }
$topsite_location =~ s/\/$//;
$topsite_location_cgi =~ s/\/$//;
$path_to_topsites =~ s/\/$//;
$current_time = time();
$member=$ENV{'QUERY_STRING'};
$cgiurl = $ENV{'SCRIPT_NAME'};
$all_right = "<font face=\"Verdana\" size=\"1\"><HR NOSHADE SIZE=1 WIDTH=90\%><CENTER>Top Sites v$version, created by <a href=\"http://solutionscripts.com\"><B>Solution Scripts</B></A><BR>\"Enhancing the web with cgi\"<BR></font>";
if ($member) {
@pairs=split(/&/,$member);
foreach $item(@pairs) {
($name,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$content; }
else { $INPUT{$name} = $content; }
}
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
else { $INPUT{$name} = $value; }
}
}
if ($INPUT{'action'} eq "stats") { &stats; }
elsif ($INPUT{'action'} eq "variables") { &show_vari; }
elsif ($INPUT{'editfinal'}) { &editfinal; }
elsif ($INPUT{'edit'}) { &edit; }
elsif ($INPUT{'new_pass'}) { &new_pass; }
elsif ($INPUT{'html_dis'}) { &html_dis; }
elsif ($INPUT{'locate'}) { &locate; }
elsif ($INPUT{'newaccount'}) {&newaccount; }
else { &hit_in; }
exit;
sub stats {
print "Content-type: text/html\n\n";
&header;
open (DAT,"<members.db");
if ($use_flock) {
flock DAT, 2;
}
@database_array = <DAT>;
close (DAT);
$total=0;
$num = push(@database_array);
foreach $line(@database_array) {
@member_array = split(/\|/,$line);
$total += $member_array[1];
}
print <<EOF;
Number of members: <font color=red>$num</FONT><BR>
Total click thrus to your Top Sites: <font color=red>$total</FONT><BR>
<BR>
With Top Sites Professional detailed stats are taken for each member and the
Top Sites program. For example each member can view their daily stats which contain
the number of hits they sent on each day, the number of people your Top Sites sent them
ech day, and the rank their site was on that day. It is set up in table format so they may see if
they are falling or increasing their rank. Through the admininstrative screen in Top Sites
Professional you can also see daily, weekly, and monthly stats for the total system. You can also view how many sites are
active (sent hits) today, this week, and this month.
<BR><BR>
<a href="http://www.21xyz.com"><B>More information on Top Sites Professional</B></A>
<BR><BR>
EOF
&footer;
exit;
}
## INCOMING ##
sub hit_in {
$member =~ s/ID\=//gi;
unless ($member) {
&thehtml;
print "Location: $topsite_location/topsites.html\n\n";
exit;
}
open (DAT,"+<members.db") || &error(1);
if ($use_flock) {
flock DAT, 2;
}
@database_array = <DAT>;
$found=0;
$a=0;
foreach $line(@database_array) {
@member_array = split(/\|/,$line);
if ($member_array[9] == $member) {
$member_array[1]++;
$member_array[0] = $member_array[1];
unless ($member_array[7]) {
$member_array[7] = $current_time;
}
$line = join("\|",@member_array);
}
}
seek (DAT, 0, 0);
print DAT @database_array;
close (DAT);
open (LASTTIME,"<time.txt");
if ($use_flock) {
flock LASTTIME, 2;
}
$last = <LASTTIME>;
close (LASTTIME);
$doit = $current_time - $last;
if ($doit > $update_time) {
open (NEWTIME,">time.txt") || &error(3);
if ($use_flock) {
flock NEWTIME, 2;
}
print NEWTIME "$current_time";
close (NEWTIME);
&thehtml
}
print "Location: $topsite_location/topsites.html\n\n";
exit;
}
##### CREATES THE HTML RANKING
sub thehtml {
open (DAT,"<members.db");
if ($use_flock) {
flock DAT, 2;
}
@database_array = <DAT>;
close (DAT);
unless ($rank) {
$rank = "Hits/Day";
}
unless ($all_right) {
&error(4);
}
foreach $line(@database_array) {
@member_array = split(/\|/,$line);
unless ($member_array[5]) { next; }
if ($rank eq "Hits/Day") {
if ($member_array[7]) {
$total_time = $current_time - $member_array[7];
$total_time = $total_time /86400;
if ($total_time > 1) {
$member_array[0] = $member_array[1] / $total_time;
$line = join("\|",@member_array);
}
else {
$member_array[0] = "0";
$line = join("\|",@member_array);
$member_array[0] = $member_array[1];
$nline[$nn] = join("\|",@member_array);
$nn++;
}
}
else {
$member_array[0] = 0;
$line = join("\|",@member_array);
$member_array[0] = $member_array[1];
$nline[$nn] = join("\|",@member_array);
$nn++;
}
}
else {
$member_array[0] = $member_array[1];
$line = join("\|",@member_array);
}
}
@sorted = sort { $a <=> $b }@database_array;
@sort = reverse(@sorted);
@nsorted = sort { $a <=> $b }@nline;
@nsort = reverse(@nsorted);
$html .= "<HTML>\n<HEAD>\n<TITLE>$topsite_name</TITLE>\n</HEAD>\n";
$html .= "<body bgcolor=$over_bg text=$text_color link=$link_color vlink=$link_color>\n";
open (HEAD, "header.txt");
@head = <HEAD>;
close (HEAD);
foreach $line (@head) {
$html .= "$line";
}
$html .= "<center><br><br>\n";
$html .= "<table cellspacing =$table_spacing bgcolor=$table_bg border=$table_border cellpadding =$table_padding width=$table_width>\n";
$html .= "<TR bgcolor=$table_head_bg align=center>\n";
$html .= "<TD><FONT SIZE=$font_size FACE=$font_face color=$text_table_head><B>序号</B></td>\n";
$html .= "<TD><FONT SIZE=$font_size FACE=$font_face color=$text_table_head><B>网站名称</B></td>\n";
if ($rank eq "Hits/Day") {
$html .= "<TD><FONT SIZE=$font_size FACE=$font_face color=$text_table_head><B>Hits/天</B></td>\n";
}
$html .= "<TD><FONT SIZE=$font_size FACE=$font_face color=$text_table_head><B>Hits in</B></td></tr>\n";
$ranks = 0;
$nn=0;
while ($ranks < $num_to_show) {
@members_array = split(/\|/,$sort[$ranks]);
if (($members_array[0] == 0) && ($rank eq "Hits/Day")) {
@members_array = split(/\|/,$nsort[$nn]);
$nn++;
$members_array[0] = 0;
}
$s_rank = $ranks + 1;
$x++;
$z++;
$html .= "<tr align=center><td><FONT SIZE=$font_size FACE=$font_face color=$text_table>$s_rank</td>\n";
if ($members_array[9]) {
$html .= "<td><FONT SIZE=$font_size FACE=$font_face color=$text_table><a href=\"$members_array[3]\" target=\"_blank\">$members_array[5]</a><br>\n";
if (($ranks < $num_banners) && $members_array[4]){
$html .= "<a href=\"$members_array[3]\">";
$html .= "<img src=\"$members_array[4]\" border=0>";
$html .= "</a>";
}
$html .= "</td>\n";
if ($members_array[0] && ($rank eq "Hits/Day")) {
# $hpd = int($members_array[0]);
$hpd = $members_array[0];
$hpd = sprintf ("%.".$round_int."f",$hpd);
unless ($hpd) {
$hpd =1;
}
}
else {
$total_time = $current_time - $members_array[7];
$total_time = $total_time /86400;
if ($total_time < 1) {
$hpd = "NEW";
}
else { $hpd = 0; }
}
if ($rank eq "Hits/Day") {
$html .= "<td><FONT SIZE=$font_size FACE=$font_face color=$text_table>$hpd</td>\n";
}
$html .= "<td><FONT SIZE=$font_size FACE=$font_face color=$text_table>$members_array[1]</td></tr>\n";
}
else {
$html .= "<td><FONT SIZE=$font_size FACE=$font_face color=$text_table><a href=\"$topsite_location_cgi/newuser.cgi\">- Your Site Here -</a></TD>\n";
if ($rank eq "Hits/Day") {
$html .= "<td><FONT SIZE=$font_size FACE=$font_face color=$text_table>-</td>\n";
}
$html .= "<td><FONT SIZE=$font_size FACE=$font_face color=$text_table>-</td></tr>\n";
}
$ranks++;
}
$html .="</table><br><FONT SIZE=$font_size FACE=$font_face><a href=\"$topsite_location_cgi/newuser.cgi\">按此加入你的网站Click Here</a></B></FONT><BR><BR>\n";
open (HEAD, "footer.txt");
@foot = <HEAD>;
close (HEAD);
foreach $line (@foot) {
$html .= "$line";
}
$html .= $all_right;
open (HTML,">$path_to_topsites/topsites.html") || &error(2);
print HTML "$html";
close (HTML);
}
sub set_defaults {
# SET DEFAULTS #
$version = "2.01";
$over_bg = "white";
$text_color = "black";
$link_color = "blue";
$font_size = "1";
$font_face = "verdana";
$table_border = 1;
$table_padding = 5;
$table_spacing = 0;
$table_width = 575;
$table_bg = $over_bg;
$table_head_bg = $over_bg;
$text_table_head = $text_color;
$round_int = 1;
}
sub error{
print "Content-type: text/html\n\n";
$errors = $_[0] ;
&header;
if ($errors == 1) {
print <<EOF;
<b>An error has occured reading and writing to members.db</B><BR><BR>
More information on the problem:<BR>
<font color=red>$!</FONT>
<BR><BR>
EOF
&error_footer("rw_members.shtml");
}
elsif ($errors == 2) {
print <<EOF;
<b>An error has occured trying to write/create the file topsites.html</B><BR><BR>
topsites.html is set to be created in the dir:<BR>
<font color=red>$path_to_topsites</font>
<BR><BR>
More information on the problem:<BR>
<font color=red>$!</FONT>
<BR><BR>
EOF
&error_footer("wc_topsites.shtml");
}
elsif ($errors == 3) {
print <<EOF;
<b>An error has occured trying to write/create the file time.txt</B><BR><BR>
More information on the problem:<BR>
<font color=red>$!</FONT>
<BR><BR>
EOF
&error_footer("wc_time.shtml");
}
elsif ($errors == 4) {
print <<EOF;
Editing topsites.cgi has created and error where the script is no longer able
to function properly, we suggest uploading an original unedited Top Sites.
<BR><BR>
Thank you
<BR><BR>
EOF
&footer;
}
elsif ($errors == 5) {
print <<EOF;
<b>You have your <font color=red>variables.pl</FONT> configured wrong</B><BR><BR>
The value you have entered for \$topsite_location does not contain <font color=red>http://</FONT>
<BR><BR>
EOF
&error_footer("variables.shtml");
}
elsif ($errors == 6) {
print <<EOF;
<b>You have your <font color=red>variables.pl</FONT> configured wrong</B><BR><BR>
The value you have entered for \$topsite_location_cgi does not contain <font color=red>http://</FONT>
<BR><BR>
EOF
&error_footer("variables.shtml");
}
elsif ($errors == 7) {
print <<EOF;
<b>You have your <font color=red>variables.pl</FONT> configured wrong</B><BR><BR>
The value you have entered for \$path_to_topsites contains <font color=red>http://</FONT> which is for urls, not paths
<BR><BR>
EOF
&error_footer("variables.shtml");
}
exit;
}
sub header {
print <<EOF;
<HTML><HEAD>
<TITLE>Top Sites -- From Solution Scripts</TITLE></HEAD>
<BODY bgcolor=white text=black link=slateblue vlink=slateblue>
<CENTER>
<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0 BGCOLOR=#778899 WIDTH=500>
<TR><TD>
<TABLE CELLPADDING=8 CELLSPACING=0 WIDTH=100\% BGCOLOR=white BORDER=0><TR><TD>
<font face="Verdana" size="1">
EOF
}
sub error_footer {
$error_url = $_[0];
print <<EOF;
If you need more assistance, come take a look at our online manual. The frontpage
of the manual can be found at:<BR>
<a href="http://solutionscripts.com/man/top_sites"><B>http://solutionscripts.com/man/top_sites</B></A><BR><BR>
or you can jump straight to the page containing more information on your error at:
<a href="http://solutionscripts.com/man/top_sites/$error_url"><B>http://solutionscripts.com/man/top_sites/$error_url</B></A>
<BR><BR>We also host a Help Forum where people can come and ask questions about Solution Scripts' scripts and
questions they are having about them. The url for the Help Forum is:<BR>
<a href="http://solutionscripts.com/forum"><B>http://solutionscripts.com/forum</B></A><BR><BR>
Who knows, someone might have the posted the same question you have and the answer might already be there.
<BR><BR><HR NOSHADE SIZE=1>
<CENTER>
Top Sites, created by <a href="http://solutionscripts.com"><B>Solution Scripts</B></A><BR>
汉化:<a href="http://www.21xyz.com"><B>[轩辕工作室]站长之家</B></A><BR>
</TD></TR></TABLE>
</TD></TR></TABLE>
EOF
}
sub footer {
$error_url = $_[0];
print <<EOF;
<HR NOSHADE SIZE=1>
<CENTER>
Top Sites, created by <a href="http://solutionscripts.com"><B>Solution Scripts</B></A><BR>
汉化:<a href="http://www.21xyz.com"><B>[轩辕工作室]站长之家</B></A><BR>
</TD></TR></TABLE>
</TD></TR></TABLE>
EOF
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -