#!/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 =
; 0 =

$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/
\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=; close FILE; $SIZE=@LINES; # Resolve remote host for servers that don't $ip_address = $ENV{'REMOTE_ADDR'}; @numbers = split(/\./, $ip_address); $ip_number = pack("C4", @numbers); ($host) = (gethostbyaddr($ip_number, 2))[0]; $host = $ip_address unless $host; # Log The Entry &log('entry') if ($uselog eq '1'); ######### # Options # Mail Option if ($mail eq '1') { open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n"; print MAIL "From: $FORM{'username'} ($FORM{'realname'})\n"; print MAIL "Subject: Entry to Guestbook\n\n"; print MAIL "You have a new entry in your guestbook:\n", ("-" x 55), "\n"; print MAIL "$FORM{'comments'}\n$FORM{'realname'}"; print MAIL " <$FORM{'username'}>" if ( $FORM{'username'} ); print MAIL "\nURL: $FORM{'url'}" if $FORM{'url'}; print MAIL "\n"; print MAIL "$FORM{'city'}," if $FORM{'city'}; print MAIL " $FORM{'state'}" if $FORM{'state'}; print MAIL " $FORM{'country'}" if $FORM{'country'}; print MAIL " - $date\n", ('-' x 55), "\n"; print MAIL "$ENV{'HTTP_USER_AGENT'}\n", "$host\n"; close MAIL; } if ($remote_mail eq '1' && $FORM{'username'}) { open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n"; print MAIL "To: $FORM{'username'}\n"; print MAIL "From: $recipient\n"; print MAIL "Subject: Entry to Guestbook\n\n"; print MAIL "Thank you for adding to my guestbook.\n", ("-" x 55), "\n"; print MAIL "$FORM{'comments'}\n$FORM{'realname'}"; print MAIL " <$FORM{'username'}>" if $FORM{'username'}; print MAIL "\nURL: $FORM{'url'}" if $FORM{'url'}; print MAIL "\n"; print MAIL "$FORM{'city'}," if $FORM{'city'}; print MAIL " $FORM{'state'}" if $FORM{'state'}; print MAIL " $FORM{'country'}" if $FORM{'country'}; print MAIL " - $date\n", "$host\n", ('-' x 55), "\n"; close MAIL; } # Print final entry &response; ####################### # Subroutines sub begin_html { local ($title) = @_; print "Content-type: text/html\n\n"; open (HEAD,$headofform); print ; close HEAD; } sub form_body { print <
Your Name:
E-Mail:
URL:
City: ,
State:
Country:

Comments:

Test Entry to see what your entry will look like. Final Entry submits to guestbook.

* *


Return to the Guestbook.
FORM open (TAIL,$tailofform); print ; close TAIL; } sub make_form { &begin_html("Guest Entry"); print "

Add to The Guestbook

\n"; print "Fill in the blanks below to add to the guestbook. \nThe only blanks "; print "that you have to fill in are the comments and name section. \n"; print "Your comments will be forwarded to the moderator. Recheck your entry soon."; print "Thanks!
\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

\n"; print "The comment section in the guestbook fillout form appears to be blank and therefore "; print "the Guestbook Addition was not added. Please enter your comments bel ow.

"; &form_body; # Log The Error &log('no_comments') if ($uselog eq '1'); exit; } sub no_name { &begin_html("No Name"); print "

Your Name appears to be blank

\nThe Name Sec tion "; print "in the guestbook fillout form appears to be blank \nand therefore you r entry to the "; print "guestbook was not added. \n Please add your name in the blank below.< p>\n"; &form_body; # Log The Error &log('no_name') if ($uselog eq '1'); exit; } # Log the Entry or Error sub log { ($log_type) = @_; open (LOG, ">>$guestlog"); print LOG "$host - [$shortdate]
\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"; print "Thank you for filling in the guestbook form. \n"; print "Your entry has been forwarded to the moderator.
\n"; } else { print "

This Is How It Will Look

\n"; print "This is you entry as it will appear in my guestbook. \n"; print "If this is acceptible then press the Final Entry button. \n"; print "If not, then revise the form below and Test again.
\n"; } print "Here is what you submitted:

\n$h_comments
\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 "
Return to the Guestbook.
"; open (TAIL,$tailofform); print ; close TAIL; # print <$tailofform>; } else { &form_body; } exit; } sub to_moderator { open (TMPFILE,">$guestbooktmp"); print TMPFILE "New Entry\n"; print TMPFILE "---------\n"; print TMPFILE "

\n$h_comments
\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 ; close MAIL; close TMPFILE; }