";
# 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 "
\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;