<html><body bgcolor=/"#FFFFFF/" text=/"#000000/">#!/usr/local/bin/perl
#####################################################################
$guestbookurl = "http://www.xxxx.com/note/guestbook.htm";
$guestbookreal = "/usr/home/userxxxxxxx/www/note/guestbook.htm";
$guestbook_cgiurl = "http://www.xxxx.com/cgi-bin/guestbook.cgi";
#####################################################################
$date_command = "/bin/date";
#change variable done .. 改变参数到此为止,以下参数不要随便改动
# Set Your Options:
$linkmail = 1; # 1 = Yes; 0 = No
$separator = 1; # 1 = <hr>; 0 = <p>
$redirection = 0; # 1 = Yes; 0 = No
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$allow_html = 0; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No
# Done
##############################################################################
# Get the Date for Entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|/n)*-->//g;
if ($allow_html != 1) {
$value =~ s/<([^>]|/n)*>//g;
}
$FORM{$name} = $value;
}
unless(-w "$guestbookreal")
{
print "Content-type: text/html/n/n";
print "留言薄配置错误,不能写文件!<br>/n";
print "$guestbookurl/n";
exit;
}
# Print the Blank Response Subroutines
&no_comments unless $FORM{'comments'};
&no_name unless $FORM{'realname'};
# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!/n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;
# Open Link File to Output
open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!/n";
for ($i=0;$i<=$SIZE;$i++) {
$_=$LINES[$i];
if (/<!--begin-->/) {
if ($entry_order eq '1') {
print GUEST "<!--begin-->/n";
}
if ($line_breaks == 1) {
$FORM{'comments'} =~ s//cM/n/<br>/n/g;
}
print GUEST "<b>$FORM{'comments'}</b><br>/n";
if ($FORM{'url'}) {
print GUEST "<a href=/"$FORM{'url'}/">$FORM{'realname'}</a>";
}
else {
print GUEST "$FORM{'realname'}";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print GUEST " /&lt;<a href=/"mailto:$FORM{'username'}/">";
print GUEST "$FORM{'username'}</a>/&gt;";
}
else {
print GUEST " &lt;$FORM{'username'}&gt;";
}
}
print GUEST "<br>/n";
if ( $FORM{'city'} ){
print GUEST "$FORM{'city'},";
}
if ( $FORM{'state'} ){
print GUEST " $FORM{'state'}";
}
if ( $FORM{'country'} ){
print GUEST " $FORM{'country'}";
}
if ($separator eq '1') {
print GUEST " - $date From $ENV{'REMOTE_ADDR'}<hr>/n/n";
}
else {
print GUEST " - $date<p>/n/n";
}
if ($entry_order eq '0') {
print GUEST "<!--begin-->/n";
}
}
else {
print GUEST $_;
}
}
close (GUEST);
#########
# Options
# Print Out Initial Output Location Heading
if ($redirection eq '1') {
print "Location: $guestbookurl/n/n";
}
else {
&no_redirection;
}
#######################
# Subroutines
sub no_comments {
print "Content-type: text/html/n/n";
print "<head><title>忘了写留言</title>
<meta http-equiv=/"Content-Type/" content=/"text/html; charset=gb2312/"></head>/n";
print "<h1>忘了写留言</h1>/n";
print <<E1
><form method="POST" action="$guestbook_cgiurl">
<p><a name="add_guestbook"></a>添加留言:<br>
您的姓名:<input type="text" name="realname" size="40" value="$FORM{'realname'}"><br>
电子邮件:<input type="text" name="username" size="40" value="$FORM{'username'}"><br>
主页地址:<input type="text" name="url" size="40" value="$FORM{'url'}"><br>
您来自于:<input type="text" name="city" size="11" value="$FORM{'city'}">市, <input type="text"
name="state" size="6" value="$FORM{'state'}">省,<input type="text" value="中国" name="country" size="15"></p>
<p>您的留言:<br>
<textarea name="comments" COLS="60" ROWS="4" value="$FORM{'comments'}"></textarea></p>
<p><input type="submit" value="添加留言"> * <input type="reset" value="擦除重写"> </p>
<input type="hidden" value="$FORM{'user'}" name="user">
</form>
<hr>
<p><a href="/">返回主页</a></p>
E1
;
exit;
}
sub no_name {
print "Content-type: text/html/n/n";
print "<head><title>忘了写姓名</title>
<meta http-equiv=/"Content-Type/" content=/"text/html; charset=gb2312/"></head>/n";
print "<h1>忘了写姓名</h1>/n";
print <<E2
><form method="POST" action="$guestbook_cgiurl">
<p><a name="add_guestbook"></a>添加留言:<br>
您的姓名:<input type="text" name="realname" size="40" value="$FORM{'realname'}"><br>
电子邮件:<input type="text" name="username" size="40" value="$FORM{'username'}"><br>
主页地址:<input type="text" name="url" size="40" value="$FORM{'url'}"><br>
您来自于:<input type="text" name="city" size="11" value="$FORM{'city'}">市, <input type="text"
name="state" size="6" value="$FORM{'state'}">省,<input type="text" value="中国" name="country" size="15"></p>
<p>您的留言:已被保存,只输入姓名即可,修改留言请到前一页<br>
<input type=hidden name="comments" "value="$FORM{'comments'}">
<p><input type="submit" value="添加留言"> * <input type="reset" value="擦除重写"> </p>
<input type="hidden" value="$FORM{'user'}" name="user">
</form>
<hr>
<p><a href="/">返回主页</a></p>
E2
;
exit;
}
# Redirection Option
sub no_redirection {
# Print Beginning of HTML
print "Content-Type: text/html/n/n";
print "<head><title>Thank You</title>
<meta http-equiv=/"Content-Type/" content=/"text/html; charset=gb2312/"></head>/n";
print "<h1>感谢您的留言</h1>/n";
# Print Response
print "感谢您的留言,以下是添加到留言簿的详细信息:/n";
print "<b>$FORM{'comments'}</b><br>/n";
if ($FORM{'url'}) {
print "<a href=/"$FORM{'url'}/">$FORM{'realname'}</a>";
}
else {
print "$FORM{'realname'}";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print " &lt;<a href=/"mailto:$FORM{'username'}/">";
print "$FORM{'username'}</a>&gt;";
}
else {
print " &lt;$FORM{'username'}&gt;";
}
}
print "<br>/n";
if ( $FORM{'city'} ){
print "$FORM{'city'},";
}
if ( $FORM{'state'} ){
print " $FORM{'state'}";
}
if ( $FORM{'country'} ){
print " $FORM{'country'}";
}
print " - $date<p>/n";
# Print End of HTML
print "<hr>/n";
print "<a href=/"$guestbookurl/">返回到留言薄</a>/n";
print "- 您需要按览浏器的刷新才能看到您的留言./n";
print "/n";
exit;
}
</body>
</html>