#!/usr/bin/perl -w # Guestbook for the World Wide Web # Created by Matt Wright Version 2.3.1 # Created: 4/21/95 Last Modified: 10/29/95 # Enhanced by David Efflandt, efflandt@xnet.com # Added built-in form and test viewing before saving entry # Made `date` formats and remote host log compatible for more systems # Created 11/22/95 Last Modified: 12/4/95 beta test version ############################################################################# # Automatic Variables $server = "http://$ENV{'SERVER_NAME'}"; $cgiurl = "$ENV{'SCRIPT_NAME'}"; # Set Variables $guestbookurl = "/guestbook/guestbook.html"; $guestbookreal = "/www/$ENV{'SERVER_NAME'}/guestbook/guestbook.html"; $guestlog = "/www/$ENV{'SERVER_NAME'}/guestbook/guestlog.html"; $guestbooktmp = "/tmp/guest.tmp"; $guestbookreal = "/tmp/guest.html"; $headofform = "/www/$ENV{'SERVER_NAME'}/guestbook/headofform"; $tailofform = "/www/$ENV{'SERVER_NAME'}/guestbook/tailofform"; $date_command = "/usr/bin/date"; $tz = "GMT+7"; # Standard Time zone (set for your time zone) $dst = "CDT"; # Daylight Savings Time zone (use $tz if none) # Set Your Options: $mail = 1; # 1 = Yes; 0 = No $uselog = 1; # 1 = Yes; 0 = No $linkmail = 1; # 1 = Yes; 0 = No $separator = 1; # 1 =
$redirection = 0; # 1 = Yes; 0 = No
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$remote_mail = 0; # 1 = Yes; 0 = No
$allow_html = 1; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No
# If you answered 1 to $mail or $remote_mail you will need to fill out
# these variables below:
$mailprog = '/usr/lib/sendmail';
#$recipient = "$ENV{'SERVER_NAME'}_admin";
$recipient = 'moderator';
# Done
#############################################################################
# Get the Date (strip seconds)
$date = `$date_command +"%a %h %d, %y at %T"`; chop($date);
$date =~ s/:\d+$/ /;
$shortdate = `$date_command +"%D %T"`; chop($shortdate);
$shortdate =~ s/:\d+$/ /;
# Daylight Savings Time?
if ((localtime)[8]) {
$date .= "$dst";
$shortdate .= "$dst";
} else {
$date .= "$tz";
$shortdate .= "$tz";
}
# GET guest entry form and exit unless POST
&make_form unless ($ENV{'REQUEST_METHOD'} eq "POST");
# 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///g;
$value =~ s/<([^>]|\n)*>//g unless ($allow_html = 1);
$FORM{$name} = $value;
}
# Print the Blank Response Subroutines
&no_comments unless $FORM{'comments'};
&no_name unless $FORM{'realname'};
$h_comments = $FORM{'comments'};
$h_comments =~ s/\r\n/ ";
&form_body;
# Log The Error
&log('no_comments') if ($uselog eq '1');
exit;
}
sub no_name {
&begin_html("No Name");
print " \n$h_comments \n$h_comments
\n/g if $line_breaks;
# Print test form and exit if not 'final' submission
if (!$FORM{'final'}) {
&response;
exit;
}
# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal");
@LINES=
Return to the Guestbook.Add to The Guestbook
\n";
&form_body;
exit;
}
# Print Out Initial Output Location Heading
sub response {
if ($FORM{'final'} && $redirection eq '1') {
print "Location: $server$guestbookurl\n\n";
} else {
&no_redirection;
}
}
sub no_comments {
&begin_html("No Comments");
print "Your Comments appear to be blank
Your Name appears to be blank
\n" if ($log_type eq 'entry');
print LOG "$host - [$shortdate] - ERR: No Name
\n" if ($log_type eq 'no_n
ame');
print LOG "$host - [$shortdate] - ERR: No Comments
\n" if ($log_type eq '
no_comments');
}
# Redirection Option
sub no_redirection {
# Print Response
&begin_html("Thank You");
if ($FORM{'final'}) {
print "Thank You For Signing The Guestbook
\n";
} else {
print "This Is How It Will Look
\n";
}
print "Here is what you submitted:
\n";
if ($FORM{'url'}) {
print "$FORM{'realname'}";
} else {
print "$FORM{'realname'}";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print " <";
print "$FORM{'username'}>";
} else {
print " <$FORM{'username'}>";
}
}
print "
\n";
print "$FORM{'city'}," if ( $FORM{'city'} );
print " $FORM{'state'}" if ( $FORM{'state'} );
print " $FORM{'country'}" if ( $FORM{'country'} );
print " - $date
\n";
&to_moderator;
# if click on "final" botton then mail it to moderator
if ($FORM{'final'}) {
&mail_it;
}
# Print End of HTML
if ($FORM{'final'}) {
print "
\n";
if ($FORM{'url'}) {
print TMPFILE "$FORM{'realname'}";
} else {
print TMPFILE "$FORM{'realname'}";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print TMPFILE "\n <";
print TMPFILE "$FORM{'username'}>";
} else {
print TMPFILE "\n <$FORM{'username'}>";
}
}
print TMPFILE "
\n";
print TMPFILE "$FORM{'city'}," if ( $FORM{'city'} );
print TMPFILE " $FORM{'state'}" if ( $FORM{'state'} );
print TMPFILE " $FORM{'country'}" if ( $FORM{'country'} );
print TMPFILE " - $date
\n";
}
sub mail_it {
# Mail it to moderator
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
open (TMPFILE, "$guestbooktmp");
print MAIL "Subject: New entry in guestbook, $ENV{'SERVER_NAME'}.\n";
print MAIL