⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guest.cgi

📁 BBS3000 sourceCode
💻 CGI
字号:
#!/usr/bin/perl
#------------------------------------------------------#
#                 本程序为Yuzi工作室提供	       #
#                Yuzi论坛3000 v3.20 免费版             #
#------------------------------------------------------#
require "cgi-lib.pl";
require "setup.cgi";
######################
## 以下部分不需修改 ##
######################
$datadir = "$filepath/guest";
$dcscript = "guest.cgi";
$adminurl = "guest.cgi";
$htmlurl = "$filepath/guest.htm";
$num_view = 20;
&GetCookies;
##########
@guest_fields = qw(
ID
Name
guest
Date
Comment
);
@required_fields = qw(Name Comment);
%field_input_type = (
"Comment" => "textarea"
);
@badwords = qw( fuck shit pussy dick ass asshole blowjob cock tits );
$allow_html = "yes";
%bgcolor = (
'0'=>'#FFFFFF',
'1'=>'#000099',
'2'=>'#FFFFEE',
'3'=>'#CCCCCC'
);
%fontcolor = (
'0'=>'#000099',
'1'=>'#FFFFCC',
'2'=>'#000099',
'3'=>'#000099'
);
%fontsize = (
'0'=>'2',
'1'=>'2',
'2'=>'2',
'3'=>'2'
);
%fontface = (
'0'=>'Verdana',
'1'=>'Verdana',
'2'=>'Verdana',
'3'=>'Verdana'
);

$guest_layout = qq~
<TABLE cellSpacing=1 cellPadding=4 border=0 width=500>
<TR bgColor=#6699ff><TD vAlign=center width=100><FONT color=#ffffff>留言者</FONT> </TD>
<TD vAlign=center colspan=2><FONT color=#ffffff>&nbsp;留言内容</FONT></TD></TR>
<TR bgColor=#f7f7f7><TD vAlign=top width=100 rowSpan=2><FONT color=blue><B><!--Name--></B></FONT></TD>
<TD vAlign=top colspan=2><TABLE cellSpacing=0 cellPadding=0 width=100% border=0>
<TBODY><TR><TD><P align=left> <IMG height=16 alt=回复该留言 src=$imagurl/lytu.gif border=0> <FONT color=#0000ff>留言于: <!--Date--></FONT></P></TD>
<TD width=25%><P align=right>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="guest.cgi?action=remove&records=<!--ID-->&guest=<!--guest-->"><IMG height=16 alt=删除该留言 src=$imagurl/del.gif border=0></a></P></TD></TR></TBODY></TABLE>
<HR><!--Comment--> </TD><TR bgColor=#f7f7f7><TD vAlign=bottom> <IMG height=16 alt=回复该留言 src=$imagurl/hf.gif border=0>
<a href="guest.cgi?action=add_form&guest=<!--Name-->">回复该留言</a></TD>
<TD vAlign=bottom><IMG height=16 alt="查看 <!--Name--> 的个人资料" src=$imagurl/pro.gif border=0> <a href="yhreg.cgi?menu=viewuser&username=<!--Name-->">查看 <!--Name--> 的个人资料</a></TD></TABLE></BODY>
~;
$display_guest_header = qq~
<font face="华文彩云" color="#6898FF" size="+3">$Cookies{username}的私人留言本</font><br><br>
~;
$display_err_header = qq~
<font face="$fontface{0}" size="$fontsize{0}"  color="$fontcolor{0}">
error!
</font>
~;
$display_err_sub_header = qq~
~;
$display_guest_sub_header = qq~
~;
$add_guest_sub_header = qq~
~;
$thank_you_header = qq~
<font face="$fontface{0}" size="$fontsize{0}"  color="$fontcolor{0}">
留言本
</font>
~;
$thank_you_sub_header = qq~
<font face="$fontface{3}" size="$fontsize{3}"  color="$fontcolor{3}">
<script language=javascript>
<!--
var TimerID=null;
TimerID=setTimeout('window.close()',3000);
//-->
</script>
<br><br>留言完成<br><br>3秒后窗口自动关闭<br><br>
</font>
~;
$thank_you_message .= qq~
~;
$display_remove_header = "删除留言";
$display_remove_sub_header = "";
$display_remove_sub_header .= qq~
[ <a href="javascript:history.back(-2)">返回留言本</a> ]
<p>
Select Links to Remove from the database
~;
$display_removedone_header = "删除留言";
$display_removedone_sub_header == "";
$display_removedone_sub_header .= qq~
<br>[ <a href="javascript:history.back()">返回留言本</a> ]
<p>
以下留言已经删除!
~;
1;
&ReadParse();
print "Content-type: text/html\n\n";
if ($in{'guest'}) {
$guest=$in{'guest'};}
else
{
$guest="guest";
}
if ($in{'name'}) {
$name=$in{'name'};}
$datafile = "$datadir/1$guest.cgi";
$counter = "$datadir/2$guest.cgi";
check_datafile($datafile);
check_datafile($counter);
$pwd=$in{'password'};
if ($in{'Comment'}) {
$in{'Comment'} =~ s/</&lt;/g;
$in{'Comment'} =~ s/>/&gt;/g;
$in{'Comment'} =~ s/\cM//g;
$in{'Comment'} =~ s/\n\n/<P>/g;
$in{'Comment'} =~ s/\r\n/<P>/g;
$in{'Comment'} =~ s/\n/<br>/g;
}
if ($in{'action'} eq "add_form") {
$header = $add_guest_header;
$sub_header = $add_guest_sub_header;
&add_form();
}
elsif ($in{'action'} eq "add_guest") {
$header = $thank_you_header;
$sub_header = $thank_you_sub_header;
&check_required_fields;
&add_guest();
}
elsif ($in{action} eq "remove") {
print "\n";
$header = $display_removedone_header;
$sub_header = $display_removedone_sub_header;
&remove_links;
}
else {
$true=0;
open(PSD,"$filepath/yhzl/$guest.cgi");
@lines=<PSD>;
close(PSD);
foreach $line (@lines) {
$line=~ s/\n//g;
($rdpassword,$rdname,$rdmail,$rdhome,$rdlasttime,$rdicq,$rdsex,$rdwork,$rdcity,$rdlove,$rdfy,$rdhf,$tu,$jiao,$iewin)=split(/\t/,$line);
if ($guest eq $rdname){
if ($rdpassword eq $pwd){$true=1;}
}
}
if ($true==1){
$header = $display_guest_header;
$sub_header = $display_guest_sub_header;
&display_guests();
} else {
$header = $display_err_header;
$sub_header = $display_err_sub_header;
&err();
}
}
&display_output();
exit(0);
sub err {
$html_output .= qq~
<FONT SIZE="2" FACE="Verdana">
<P align="center">
您是访客没有自己的留言本!
<P align="center">
<a href=javascript:history.back(1)>[返回上一页]</a>
~;
}
sub display_guests {
my $marker;
if ($in{'marker'}) {
$marker = $in{'marker'};
}
else {
$marker = 1;
}
my ($num_guests,$guest,$start_num,$stop_num) =
get_guests($datafile,$marker);
my $num_blocks = int(($num_guests-1)/$num_view) + 1;
$html_output .= qq~
<TITLE>$in{'guest'}的私人留言本</TITLE>
<table border=0 width=500><tr><td><FONT color=#8000ff>总共有<FONT color=#ff0000> $num_guests </FONT>条留言 当前浏览第 <FONT color=#ff0000>$start_num - $stop_num </FONT>条留言</FONT></td>
    <td align=right>
~;
for ($j=1; $j<= $num_blocks; $j++) {
$j_start = ($j-1)*$num_view + 1;
$j_stop = $j*$num_view;
if ($j_stop > $num_guests) {
$j_stop = $num_guests;
}
if ($start_num == $j_start) {
$html_output .= "[$j] ";
}
else {
$html_output .= "[<a href=\"$dcscript?guest=$rdname&password=$rdpassword&marker=$j_start\">$j</a>] ";
}
}
$html_output .= qq~
</td></tr></table>
~;
foreach (reverse sort {$a <=> $b} keys %{$guest}){
my $temp = $guest_layout;
$guest->{$_}->{'Date'} = y2k($guest->{$_}->{'Date'});
$temp =~ s/<!--([\w]+)-->/$guest->{$_}->{$1}/g;
$html_output .= $temp;
}
}
sub check_required_fields {
foreach $require_field (@required_fields) {
if ($in{$require_field} eq "" || $in{$required_field} eq " ") {
$flag = "1";
$header = "error!";
$sub_header = "请填写您的姓名和内容";
&add_form;
&display_output();
&exit;
}
}
}
sub add_guest {
open(GUESTBOOK,"$datafile")
or my_die("Can't open $datafile",$!);
@guestdata = <GUESTBOOK>;
close(GUESTBOOK);
$id = &get_number();
($date,$localtime) = &get_date();
$date = $localtime." ".$date;
$in{'ID'} = $id;
$in{'Date'} = $date;
foreach $field (@guest_fields) {
unless ($allow_html eq "yes") {
$in{$field} =~ s/<([^>]|\n)*>//g;
}
$in{$field} =~ s/\|/\s/g;
$in{$field} = remove_badwords($in{$field});
$newline .= $in{$field}."|";
}
chop($newline);
$newline .= "\n";
open(GUESTBOOK,">$datafile")
or my_die("Can't open $datafile",$!);
print GUESTBOOK $newline;
print GUESTBOOK @guestdata;
close(GUESTBOOK);
}
sub remove_badwords {
my $body = shift;
foreach (@badwords) {
$body =~ s/$_/####/gi;
}
$body;
}
sub add_form {
$html_output .= qq~
<SCRIPT language=JavaScript>
var i=0;
function check(theForm) {
	if(theForm.Name.value == "") {
		alert("您当前的身份是访客,请登陆后再留言!");
		return false;
	}
	if(theForm.Comment.value == "" ) {
		alert("您的留言内容不能为空!");
		return false;
	}
	if (theForm.Comment.value.length > 1000){
		alert("对不起,你的留言不能超过 1000 个字节!");
		return false;
	}
i++;
if (i>1) {alert('帖子已经发出,请耐心等待!'); return false;}
return true;
}
function confirm_reset(){
	if (confirm("该项操作要清除全部的内容,你确定要清除吗?")){
		return true;
	}
	return false;
}
</SCRIPT>
<center>
<form action="$dcscript" method="post">
<input type="hidden" name="guest" value=$guest>
<input type="hidden" name="action" value="add_guest">~;
$html_output .= qq~
<TABLE cellSpacing=1 cellPadding=4 width="70%" border=0>
<TBODY><tr><TD vAlign=top align="center"><font face size="2">给 $guest 留言</font> </TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="70%" border=0>
<TBODY><tr><TD bgColor=#dedfdf><TABLE cellSpacing=1 cellPadding=4 width="100%" border=0><TBODY><tr bgColor=#6699ff><td></td><TD vAlign=top><FONT color=#ffffff>注意:以下 * 星号标出的项目必需填写.
</FONT></TD></TR><tr bgColor=#f7f7f7><TD align=middle><FONT size=2>* 你的名字:</FONT></TD>
<TD><INPUT class=text maxLength=15 size=15 name=Name readonly value="$Cookies{username}">
</TD></TR><tr bgColor=#ffffff><TD vAlign=top align=middle><FONT size=2>* 你的留言:</FONT>
</TD><TD><TEXTAREA name=Comment rows=6 cols=40></TEXTAREA> </TD></TR><tr bgColor=#f7f7f7><TD vAlign=top>&nbsp;</TD>
<TD>注意:目前这个留言簿的 HTML 功能是被不允许的。</TD></TR></TBODY></TABLE><CENTER></CENTER></TD></TR></TBODY></TABLE>
<CENTER><P><INPUT onclick="return check(this.form)" type=submit value="  确  定 留  言  " name=SUBMIT>
<INPUT onclick="return confirm_reset()" type=reset value="  清 除 内 容  " name=RESET>
</CENTER></FORM>
</center>~;
}
sub table_row {
my ($field,$type) = @_;
my ($table_row);
if ($type eq "text"){
$table_row .= qq~
<tr>
<td valign="top" bgcolor="$bgcolor{1}">
<font size="$fontsize{1}" color="$fontcolor{1}" face="$fontface{1}">
$field
</font>
</td>
<td valign="top" bgcolor="$bgcolor{2}">
<input type="$type" name="$field" size="40">
</td>
</tr>
~;
}
elsif ($type eq "textarea")
{
$table_row .= qq~
<tr>
<td valign="top" bgcolor="$bgcolor{1}">
<font size="$fontsize{1}" color="$fontcolor{1}" face="$fontface{1}">
$field
</font>
</td>
<td valign="top" bgcolor="$bgcolor{2}">
<textarea name="$field" rows="6" cols="40" wrap="physical"></textarea>
</td>
</tr>
~;
}
$table_row;
}
sub get_number {
my $num;
open(NUMBER,"$counter")
or my_die("Error in function get_number during read",$!);
@NUMBER=<NUMBER>;
close(NUMBER);
foreach $NUMBER (@NUMBER) {
($num,$oldlys,$money,$charm)=split(/\t/,$NUMBER);
}
$num++;
open(NUMBER,">$counter")
or my_die("Error in function get_number during write",$!);
print NUMBER "$num"."\t"."$oldlys"."\t"."$money"."\t"."$charm";
close(NUMBER);
$num;
}
sub display_output {
my %name = (
HEADER => $header,
SUBHEADER => $sub_header,
HTMLOUTPUT => $html_output
);
open(TEMPLATE,"$htmlurl") or my_die("can't open $htmlurl",$!);
{
local($/) = undef;
$template = <TEMPLATE>;
}
close(TEMPLATE);
$template =~ s/\$([A-Z]+)/$name{$1}/g;
print $template;
}
sub get_date {
local($date,$localtime);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) {
$sec = "0$sec";
}
if ($min < 10) {
$min = "0$min";
}
if ($hour < 10) {
$hour = "0$hour";
}
if ($mon < 10) {
$mon = "0$mon";
}
if ($mday < 10) {
$mday = "0$mday";
}
$month = ($mon + 1);
@months = ("January","February","March","April","May","June","July","August","September","October","November","December");
$year += 1900;
$localtime = "$hour\:$min\:$sec";
$date = "$month/$mday/$year";
chop($date) if ($date =~ /\n$/);
chop($local) if ($local =~ /\n$/);
($date,$localtime);
}
sub trim {
my $string = shift;
my @sentence = split(/\s+/,$string);
my $j = 0;
my $word_length_max = 40;
foreach $word (@sentence) {
my $s_length = length($word);
if ($s_length > $word_length_max) {
my $num = int($s_length / $word_length_max);
for ($i=0;$i<$num;$i++) {
$sentence[$j] = substr($word,0,$word_length_max-1) . '-';
$j++;
}
$char_index += $word_length_max;
$sentence[$j] = substr($word,0,-1);
$j++;
}
else {
$sentence[$j] = $word;
$j++;
}
}
$string = join(" ",@sentence);
return $string;
}
sub my_die {
my($my_mesg, $sys_mesg) = @_;
print "\n";
print qq~
<html>
<head>
<title>$my_mesg</title>
</head>
<body bgcolor="#FFFFFF" background="$imagurl/bg.jpg">
<font face="verdana" size="5"><b>SCRIPT ERROR!!!</b></font>
<hr>
<font face="verdana" size="3">
<b>
There was an error in processing your request.<br>
Following is the error message:
<ul>
<li>Script Message: $my_mesg
<li>System Message: $sys_mesg
</ul>
<hr>
Please contact the <a href="mailto:$admin_email">administrator</a> of this site.
<p>
Thank you.
</b>
</font>
</body>
</html>
~;
exit;
}
sub check_datafile {
my($datafile) = @_;
unless (-e $datafile) {
open(FILE,">$datafile") or
my_die("Error in subroutine check_datafile: Can't open $datafile",$!);
close(FILE);
chmod(0666,$datafile);
}
}
sub get_guests {
my $datafile = shift;
my $marker = shift;
my @guestdata;
my %guest;
open(GUESTBOOK,"$datafile") ;
@guestdata = <GUESTBOOK>;
close(GUESTBOOK);
my $num_guests = @guestdata;
my $start_num = $marker;
my $stop_num = $marker + $num_view - 1;
unless ($start_num) {
$start_num = 1;
}
if ($stop_num > $num_guests ) {
$stop_num = $num_guests;
}
@guestdata = @guestdata[$start_num-1..$stop_num -1];
foreach (@guestdata) {
chomp;
my @data = split /\|/;
my $id = shift(@data);
$guest{$id}->{$guest_fields[0]} = $id;
for ($j=1; $j<@guest_fields; $j++) {
$guest{$id}->{$guest_fields[$j]} = $data[$j-1];
}
}
return ($num_guests, \%guest, $start_num, $stop_num);
}
sub y2k {
my $date = shift;
my ($t,$d) = split(/\s/,$date);
my @fields = split(/\//,$d);
$fields[2]  = 1900 if ($fields[2] < 101);
$d = join("\/",@fields);
return "$t $d";
}
sub remove_links {
if ($in{'guest'}) {
$guest=$in{'guest'};}
else
{
$guest="guest";
}
$datafile = "$datadir/1$guest.cgi";
$counter = "$datadir/2$guest.cgi";
@records = split(/\0/,$in{'records'});
open(G,"$datafile") ;
@guestdata = <G>;
close(G);
$new_links = "";
$html_output .= qq~
<table border="0" cellpadding="2" width="500">
<tr>
<th valign="top" bgcolor="#689CFF" width="150">
<font size="$fontsize{1}" color="$fontcolor{1}" face="$fontface{1}">
留言作者</font></th>
<th valign="top" bgcolor="#689CFF" width="350">
<font size="$fontsize{1}" color="$fontcolor{1}" face="$fontface{1}">
内容</font></th>
</tr>
~;
foreach (@guestdata) {
chomp;
@row = split(/\|/,$_);
$hit = "no";
foreach ($j = 0;$j <= @row-1;$j++) {
$rowdata{$guest_fields[$j]} = $row[$j];
}
foreach $record (@records) {
if ($rowdata{"ID"} == $record) {
$hit="yes";
$html_output .= qq~
<tr>
<td bgcolor="$bgcolor{2}">
<font size="$fontsize{2}" color="$fontcolor{2}">
$rowdata{"Name"}
</font></td>
<th bgcolor="$bgcolor{2}">
<font size="$fontsize{2}" color="$fontcolor{2}">
$rowdata{"Comment"}
</font>
</th>
</tr>
~;
$last;
}
}
unless ($hit eq "yes") {
$new_links .= "$_\n";
}
}
$html_output .= qq~
</table>
~;
open(LINKSDATA,">$datafile") ;
print LINKSDATA $new_links;
close(LINKSDATA);
}
######################### END OF SCRIPT #########################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -