#!/usr/bin/perl print "Content-type: text/html\n\n"; $directory = $0; $directory =~ s#/[^/]*$##; $program = $0; $program =~ s#^.*/##; $directory="." if ($directory eq $program); unshift(@INC, $directory); # please enter full path to your guestbook page on the line below # Please, note if you are using virtual server absolute paths # may/will likely be different with the paths from your main (your "root") # directory. Please, ask your provider what absolute paths you should use. # You can also telnet to your account and on the command line type: # pwd # The output will tell you absolute path to the directory you are in. # Examples: # $file="/home/sites/site#/web/guestbook/index.htm"; # $file="/home/sites/site1/users/username/web/guestbook/index.htm"; $file="/home/sites/site1/web/guestbook.html"; ####################################################################################### ####################### Don't edit anything below this line ####################### ####################################################################################### $separator=""; $formdata=; $formdata=~s/\s+$//; foreach (split(/&/, $formdata)) { ($name, $value)=split(/=/, $_); $name=~s/\+/ /g; $name=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg; $name=~s/<.*?>//g; $value=~s/\+/ /g; $value=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg; $value=~s/<.*?>//g; $data{$name}=$value; } if ($data{'name'} eq ''){ $errors.="You didn't enter your name.
"; } if ($data{'comments'} eq ''){ $errors.="You didn't enter a comment.
"; } if ($errors ne ''){ print "You made the following mistakes:
$errors"; print "Press the back button on your browser and try again."; exit; } if ($data{'e_mail'} eq ''){ $email="(no email)"; } else { $email="($data{'e_mail'})"; } $message=$data{"comments"}; $new=$separator."\n

$message
$data{'name'} $email
\n"; $time=&get_time; if ($data{'city'}){ $new.="$data{'city'}, \n"; } if ($data{'state'}){ $new.="$data{'state'}, \n"; } if ($data{'country'}){ $new.="$data{'country'} - \n"; } $new.="$time
"; unless (open (FILE, "$file")) { print "Cannot open $file for reading. The path to your guestbook file must be specified incorrectly."; exit; } flock (FILE, 2); undef ($/); $page=; $page=~s/$separator\s*/$new/; close FILE; unless (open (FILE, ">$file")) { print "Cannot open $file for writing. Please check permissions on this file, it should be set to 666 (read+write)."; exit; } print FILE $page; flock (FILE, 8); close FILE; open (FILE, "$file"); print (); sub get_time { @months = ('January','February','March','April','May','June','July','August','September','October','November','December'); @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); # (Local Server Time Zone) #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # option one # (Greenwich Mean Time Zone) ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time); # uncomment for GMT # $mon goes from 0 to 11 $month = $months[$mon]; $mon++; # $wday goes from 0 to 6 $weekday = $days[$wday]; # $year starts at 1900 $year += 1900; # ugly number formatting - use sprintf() instead if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($mday < 10) { $mday = "0$mday"; } if ($mon < 10) { $mon = "0$mon"; } # Format: Weekday, Month Mday, Year at hh:mm:ss $date = "$weekday, $month $mday, $year at $hour:$min:$sec (GMT)"; return($date); }