#!/usr/bin/perl # $mailprog = '/usr/lib/sendmail'; # Add URL for New Category # *Version 2.3.1.1 # *Modified by Ranson Johnson # *Last Modified: 12/10/96 ########################################################################## # If you put all the files in the same directory, the script will work # as it is presently configured. Create a directory called, guestbook, and # place all the files in that directory. Next we need to give the files # permisions. chmod the cgi to 755 or (rwx-rx-rx) chmod the log files # to 666 or (rw-rw-rw). To call the guestbook with your browser, type in # the path to that directory - http://www.where_is_it.com/guestbook # The directory this script is in needs 777 permisions (rwx-rwx-rwx) # so that the 'filelock' will work # # In the add.htm there is a required tag # # If you remove this tag the guestbook can not be written to. # # Please report any bugs you find to scripts@rlaj.com # # Feel free to copy, change, reference, sample, or borrow, the contents. # The script is provided as is, there is no warranty expressed or implied. # If you would, email me and let me know you are using the script, so I can # show you on my list of links. # If you would like to support public domain freeware, contributions are # accepted. # Last but certainly not least, if you find a better way of doing something, # I would really like to know. Thanks and have fun. # # Anything you add to the script that has a quote (") or an @ in it must be # escaped with a backslash (\) Example: # and an email address must have a backslash - ranson\@infoave.net # ########################################################################## ################# Things you will need to configure ###################### # Enter path to guest.log file # This holds all the entries to your guestbook page $guest_log = "guest.log"; # Enter the path and name for this file $guest_cgi = "guestbook.cgi"; # Page Title $title = "Beavis's Guestbook"; # Use this for META TAGS $meta = " "; # Enter the BODY TAG information $body = ""; # Enter the top of your page, ie gifs and information for the page $top_of_page = "

Beavis's Guestbook

Please sign my
guestbook.

"; # Enter the information for the bottom of the page $bottom_of_page = "

Copyright 1996/1997 Guestbook Central

Return to Beavis's Home Page

"; # Do you want the users email address to be hyper-linked 1 = yes $hyper_link = 1; # 1 = Yes; 0 = No # Do you want to allow people to use HTML in their comments 1 = yes $allow_html = 1; # 1 = Yes; 0 = No # What kind of separetor do you want between entries 1 =

0 =


$seperate = 1; #1 =

0 =


# Do you want to use the page counter - 1 = yes $counter = 1; # 1 = Yes; 0 = No # Enter path to count.log $count_log = "count.log"; # The following controls the font size, color, and centering of the count $font_color = ""; $font_size = ""; $center = 1; $before = "You are visitor number "; $after = "to the guestbook."; ########## Mail Section ########## # Do you want an email each time someone makes an entry to the guestbook $mail = 0; # 1 = yes 0 = no $recipient = "root\@beavis.bwave.com"; # Don't forget the (\) backslash $subject = "Guestbook Entry"; # Do you want to send the user a reciept? This can be helpful for getting # Links back to your page by asking the user to link back. $reciept = 1; # 1 = yes 0 = no $reply_subject = "Thank you for your comments"; # This is the body of the email reciept. You can use the (\n) carrage return # where you want a return, otherwise the text is in one long string. Be sure # to leave the beginning (") and ending (";) or you will get an error. $mail_body = "Thank you for signing the Beavis.intercom.net guestbook.\n Here is the generic plug that came with the CGI program we use:\n It would be great if you would like to link back to my page,\n you can use the following code:\n Ranson's CGI Scripts\n Ranson"; ################### End of configuration section ######################## # 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; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } $FORM{$name} = $value; } if ($FORM{'new'}){ &no_name unless $FORM{'name'}; &no_comments unless $FORM{'comments'}; &no_email unless $FORM{'emailadd'}; &no_email unless $FORM{'emailadd'}; &no_valid_email unless (($FORM{'emailadd'} eq '') || (($FORM{'emailadd'} ne '') && ($FORM{'emailadd'} =~ /\w*@\w*/))); } &GetFileLock; print "Content-Type: text/html\n\n"; if ($FORM{'new'}){ #We have a new entry open(GUESTLOG, "$guest_log"); @FILE = ; close(GUESTLOG); print GUESTLOG "Content-Type: text/plain\n\n"; open(GUESTLOG, ">$guest_log"); if ($FORM{'url'}){ print GUESTLOG ""; print GUESTLOG "$FORM{'name'}
"; }else{ print GUESTLOG "$FORM{'name'}
"; } print GUESTLOG "$FORM{'comments'}

"; if ($hyper_link eq '1'){ print GUESTLOG "$FORM{'emailadd'}"; }else{ print GUESTLOG "$FORM{'emailadd'}"; } if ($seperate eq '1'){ print GUESTLOG "

\n"; }else{ print GUESTLOG "


\n"; } print GUESTLOG @FILE; close(GUESTLOG); ###################### Print thank you to user ########################## print "\n"; print "$meta\n"; print "$title\n"; print "$body
\n"; print "Thank you $FORM{'name'} for your entry to my guestbook.
\n"; print "

\n"; print "Your comments:
$FORM{'comments'}


\n"; print "

Back to Guestbook\n"; }else{ # We just want to view the guestbook ########### This section opens the guest_bk file and prints it ########### print "\n"; print "$meta\n"; print "$title\n"; print "$body\n"; print "$top_of_page
\n"; open(GUESTLOG, "$guest_log"); @filein = ; close(GUESTLOG); print @filein; ################### This section is the page counter ##################### { open LOG,"$count_log"; @log_lines = ; close LOG; chop($last_line = $log_lines[$#log_lines]); undef @log_lines; #release storage for log lines if ($last_line =~ /(\d+)/) { $next_number = $1 + 1; } open LOG,">$count_log"; print LOG "H$next_number\n"; close LOG; } if ($center eq '1'){ print "

"; } else{ print "
"; } print "
$font_color\n"; print "$font_size $before $next_number $after\n"; print "
\n"; if ($center eq '1'){ print ""; } print "


$bottom_of_page"; } ######################## sub no_comments { print "Content-type: text/html\n\n"; print "No Comments\n"; print "

Your comments appear to be blank.

\n"; print " Please use the BACK BUTTON on your browser to Go Back\n"; print " and enter your comments.

\n"; print "\n\n"; exit; } sub no_name { print "Content-type: text/html\n\n"; print "No Name\n"; print "

Your Name appears to be blank.

\n"; print " Please use the BACK BUTTON on your browser to Go Back\n"; print " and enter your name.

\n"; print "\n\n"; exit; } sub no_email { print "Content-type: text/html\n\n"; print "No Email Address\n"; print "

Your Email Address appears to be blank

\n"; print "Please use the BACK BUTTON on your browser to Go Back\n"; print " and enter your Email Address.

\n"; print "\n\n"; exit; } # Subroutine for error in email address sub no_valid_email { print "Content-type: text/html\n\n"; print "Invalid E-Mail Address\n"; print "\n"; print "

Invalid E-Mail Address

\n"; print "You must specify a valid email address.\n"; print "Please use the BACK BUTTON on your browser to Go Back\n"; print " and enter your Email Address.

\n"; print "\n"; exit; } if ($FORM{'new'} && $mail eq '1') { open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "Reply-to: $FORM{'emailadd'} ($FORM{'name'})\n"; print MAIL "From: $FORM{'emailadd'} ($FORM{'name'})\n"; print MAIL "Subject: $subject\n"; print MAIL "$FORM{'comments'}\n"; close (MAIL); } if ($FORM{'new'} && $reciept eq '1') { $emailadd = $FORM{'emailadd'}; open (MAIL, "|$mailprog $emailadd") || die "Can't open $mailprog!\n"; #print MAIL "Reply-to: $recipient\n"; print MAIL "From: $recipient ($title)\n"; print MAIL "Subject: $reply_subject\n"; print MAIL "$mail_body\n"; close (MAIL); } &ReleaseFileLock; ####################################################################### # GetFileLock # ####################################################################### sub GetFileLock { local ($lock_file) = 'file.lock'; local ($endtime); $endtime = 10; $endtime = time + $endtime; # We set endtime to wait 10 seconds while (-e $lock_file && time < $endtime) { # Do Nothing } open(LOCK_FILE, ">$lock_file"); # flock(LOCK_FILE, 2); # 2 exclusively locks the file } # end of get_file_lock ####################################################################### # ReleaseFileLock # ####################################################################### sub ReleaseFileLock { local ($lock_file) = 'file.lock'; # 8 unlocks the file # flock(LOCK_FILE, 8); close(LOCK_FILE); unlink($lock_file); } # end of ReleaseFileLock exit;