#!/usr/local/bin/perl5 # ########################################################## ## ## NADDGUES.CGI - Process input from "NGUESTBOOK.CGI" form ## ########################################################### ## This script is called by submitting an entry ## from the guestbook page. This script mails the owner that a person has ## signed the guest book with a private comment. If no name is ## specified, error page is shown to the guest. ## Otherwise the guest gets a thank you page with a pointer to ## their name in the guestbook, the guestbook itself, ## and the return page specified. ################################ # # # Get info from form and parse it # read(STDIN, $raw_data, $ENV{CONTENT_LENGTH}); # form does POST $items = split('&', $raw_data); for ($i = 0; $i < $items; $i++) { ($key,$value) = split('=', $_[$i]); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $data{"$key"} = $value; } $mailprog = "/usr/lib/sendmail -t"; # Set the values passed in # get name of person whose page this is on, $yourname = $data{'caler'}; # script user's address $guestpage = $data{'guestpage'}; # name of the guest page $gold = $data{'oldentries'}; # old entries file name $returnpage = "http://www.best.com/~$yourname/"; # return page = home # "$rname" is the name submitted by the person $rname = $data{'name'}; $rname =~ tr/ /+/; $rname =~ tr/[A-Z]/[a-z]/; # Do date and time stuff @DoW = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); @MoY = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time); $tizo = ($isdst == 1) ? "PDT" : "PST"; if ($hour < 12){ $AMPM = 'AM'; } if ($hour == 12) { $AMPM = 'PM'; } if ($hour > 12){ $hour = $hour - 12; $AMPM = 'PM'; } if ($hour == 0) { $hour = 12; $AMPM = 'AM'; } $year += ($year < 90) ? 2000 : 1900; $min = (sprintf ("%02d",$min)); $time = $hour . ":" . $min . $AMPM . " " . $tizo; $daweek = $DoW[$wday]; $month = $MoY[$mon]; $dayth = $mday . &ordinalize($mday); $date = "$daweek, $month $dayth at $time"; # Check for name, if not, put out "Oops" page (way down at the bottom) if ($data{'name'}) { # check for only default value, or not starting with "http://"clear if it is if ($data{'html'} eq "http://") {$data{'html'} = "";} # only "http://" # not "http:"at start check if (($data{'html'} !~ /^http:\/\//)) {$data{'html'} = "";} if ($data{'html'}) # Get a URL entry? { # Yes, get rid of attempts to insert tags $data{'html'} =~ s//\>\;/g; # change ">" $data{'html'} =~ s/\s/ /g; # change carriage return to space } # if page name is missing, make it = HTML reference if (!$data{'pname'}) { $data{'pname'} = $data{'html'}; } # check to see if e-mail starts with "@", no name if ($data{'email'} =~ /^\@/) { $dataemail = $data{'email'}; $data{'email'} = ""; } ################################ # open guest.html, and add to it ################################ # First, get the current file open (OLD, "$guestpage") || die; @LINES=; # read them all in at once close OLD; $size=@LINES; # get the size of the array # Check for new month here. If it is, save off old month # and start new one. # Check for month change $thismo = 0; # flag, 1 if current month found $newmo = 0; # not a new month $curmonth = "\n"; # checker for current month for ($i=0;$i<=$size;$i++) { if (($LINES[$i] eq $curmonth)){$thismo=1;last;} # no change } # If month changed, put out old stuff if (!$thismo) { open (GOLD, ">>$gold") ||die; $found=0; # flag for end of header stuff $beginning = "\n"; # indicator of end of header for ($i=0;$i<=$size;$i++) { if ($found) {print GOLD $LINES[$i];} # if flag is set, write if (($LINES[$i] eq $beginning)) { $found=1; # set flag past header print GOLD "\n\n"; print GOLD "
New Month Starts Below

"; } } close(GOLD); $newmo = 1; } # No, continue # Now, write header and this entry to the file open(GUESTS, ">$guestpage") || die "Can't open guest book: $!\n"; flock (GUESTS,2); #header stuff # Since we will be in the (sub) directory where the files are, we need to # strip off the directory info from the "$gold" variable, which is the # "./file" or "./directory/file" for the old entries @breakout = (split /\//, $gold); # split on " / " $guestold = $breakout[$#breakout]; # get last element, file name print GUESTS "Guest Book"; print GUESTS "\n"; print GUESTS "
\n"; print GUESTS "

\n"; print GUESTS " $month $year Guest Book Entries\n"; print GUESTS "


Click here to see "; print GUESTS "Old"; print GUESTS " Guest Book Entries (Why?)"; print GUESTS "
\n"; print GUESTS "\n"; print GUESTS "\n"; # write out new entry print GUESTS "
\n"; print GUESTS "$data{'name'}
\n"; print GUESTS "$data{'from'}
\n" if $data{'from'}; print GUESTS "$data{'country'}
\n" if $data{'country'}; print GUESTS "$data{'email'}
\n" if $data{'email'}; print GUESTS "Link: $data{'pname'}
\n" if $data{'html'}; print GUESTS "Link Comment: $data{'pname'}
" if ( (!$data{'html'}) && ($data{'pname'}) ); if ($data{'note'}) { # get a public note? $data{'note'} =~ s//\>\;/g; # change ">" $data{'note'} =~ s/\s/ /g; # change carriage return to space $dataout = "$data{'note'}"; # set up for format write GUESTS; # output formatted 3 lines print GUESTS "
"; } print GUESTS "\n" if $data{'comment'}; print GUESTS "Signed on: $date
\n\n"; flock (GUESTS,8); close(GUESTS); # Now, write out old entries if it isn't a new month if (!$newmo){ open (GUESTS, ">>$guestpage") ||die; $found=0; # flag for end of header stuff $beginning = "\n"; # indicator of end of header for ($i=0;$i<=$size;$i++) { if ($found) {print GUESTS $LINES[$i];} # if flag is set, write if (($LINES[$i] eq $beginning)){$found=1;} # set flag past header } close(GUESTS); } ########################### # Display Thank You page ########################### $host = $ENV{'REMOTE_HOST'}; $AOL = "aol.com"; if ($host =~ /$AOL/) { # AOL's lame browser can't do a "Location:" print < Thank You

Thank you for the entry, $data{'name'}from AOL.

You can now do one of the following:
view your entry in the guest book;
view the guest book;
or return to my home page.


NEWPAGE } else { $LOCATION = "$guestpage"; # The lines below the "Location:" are for some browsers that also # can't handle the call, and the server, which seems to need more # than just a "Location:" line output..... print < Thank You

Thank you for the entry, $data{'name'}.

You can now do one of the following:
view your entry in the guest book;
view the guest book;
or return to my home page.


NEWPAGE } # check for private comment and send e-mail if it is there if ($data{'comment'}) { $maildone = ".\n"; # end of mail input $dnote = " $data{'note'}"; # offest by one, in case its a "." $dcomment = " $data{'comment'}"; open(MAIL, "| $mailprog") || die "Can't open mailprog $mailprog, stopped"; print MAIL "From: $yourname\@best.com\n"; print MAIL "To: $yourname\@best.com\n"; # print MAIL "To: jwong@jwassociates.com\n"; print MAIL "Subject: Guest Book Signed by $data{'name'}\n"; print MAIL " \n"; print MAIL "Used name: $data{'name'}\n"; print MAIL "Was from $ENV{REMOTE_ADDR}\n"; print MAIL "Said was logged in from: $data{'from'}, $data{'country'}\n"; print MAIL "HREF: $data{'html'}, $data{'pname'}\n" if $data{'html'}; print MAIL "Email: $data{'email'}\n" if $data{'email'}; print MAIL "Email From Form: $dataemail\n" if $dataemail; print MAIL "\n"; print MAIL "Public Note:\n"; $dataout = $dnote; # set up to format data write MAIL; # write out formatted lines print MAIL "\n"; print MAIL "Private Comment:\n"; $dataout = $dcomment; # set up to format data write MAIL; print MAIL $maildone; # send end of mail line - "." close(MAIL) || die "mail pipe exited $?"; } # This occurs if no name was input } else { print < Oops...

Aw, Rats!...

You may have hit the wrong key!. If you would like to submit an entry, I will need at least your name. Lets go back...

Thanks...


NEWPAGE } # All done, get out exit; ################## format statements ################################ # format for HTML format GUESTS = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout . # format for mailing to me format MAIL = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout . # subroutine # ###################################### # ordinalize number ###################################### sub ordinalize { local($count) = @_; local($last,$last2); $last2 = $count % 100; $last = $count % 10; if ($last2 < 10 || $last2 > 13){ return "st" if $last == 1; # for 1st return "nd" if $last == 2; # for 2nd return "rd" if $last == 3; # for 3rd } return "th"; # for 10th, 11th, 12th, 13th } ########################end of script################