#!/usr/bin/perl
# Set Variables
$guestbookurl = "http://www.MYSITEURL.com/stories.htm";
$guestbookreal = "/PATH/TO/MY/STORIES/PAGE/stories.htm";
$guestlog = "/PATH/TO/MY/LOG/storyguestlog.html";
$cgiurl = "http://www.royandstellawood.com/cgi-bin/storyguestbook.pl";
$date_command = "/bin/date";
# Set Your Options:
$mail = 1; # 1 = Yes; 0 = No
$uselog = 0; # 1 = Yes; 0 = No
$linkmail = 0; # 1 = Yes; 0 = No
$separator = 1; # 1 = <hr>; 0 = <p>
$redirection = 0; # 1 = Yes; 0 = No
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$remote_mail = 1; # 1 = Yes; 0 = No
$allow_html = 0; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No
$fromaddress = 'EMAILADDRESS@MYURL.com';
# If you answered 1 to $mail or $remote_mail you will need to fill out
# these variables below:
$mailprog = '/usr/lib/sendmail';
$recipient = 'EMAILADDRESS@MYURL.com';
# Done
##############################################################################
# Get the Date for Entry
$date = `$date_command +"%A, %B %d, %Y"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);
# 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/<!--(.|\n)*-->//g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
$FORM{$name} = $value;
}
# Print the Blank Response Subroutines
#&no_comments unless $FORM{'comments'};
#&no_name unless $FORM{'realname'};
# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;
# Open Link File to Output
open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
for ($i=0;$i<=$SIZE;$i++) {
$_=$LINES[$i];
if (/<!--begin-->/) {
if ($entry_order eq '1') {
print GUEST "<!--begin-->\n";
}
if ( $FORM{'storyname'} ){
print GUEST "<h1><b><center>$FORM{'storyname'}</center></h1></b><br>\n";
}
print GUEST "<a href=\"#Top\"><u>(return to top)</u></a><br>\n";
if ($FORM{'url'}) {
print GUEST "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
}
else {
print GUEST "Submitted by: <b>$FORM{'realname'}</b><br>";
}
if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print GUEST " \<<a href=\"mailto:$FORM{'username'}\">";
print GUEST "$FORM{'username'}</a>\>";
}
else {
print GUEST "Email: <b>$FORM{'username'}</b>";
}
}
print GUEST "<br>\n";
print GUEST "Date Submitted: $date<br>\n";
if ( $FORM{'intro'} ){
print GUEST "Story Introduction: $FORM{'intro'}<p>\n";
}
print GUEST "<b>Story:</b><br>\n";
$story=$FORM{'story'};
$story =~s/\n/<br>/gi;
print GUEST "$story\n";
print GUEST "<hr>\n\n";
if ($entry_order eq '0') {
print GUEST "<!--begin-->\n";
}
}
else {
print GUEST $_;
}
}
close (GUEST);
# Log The Entry
if ($uselog eq '1') {
&log('entry');
}
#########
# Options
# Mail Option
if ($mail eq '1') {
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: $FORM{'username'}\n";
print MAIL "From: $FORM{'username'}\n";
print MAIL "Subject: New Story Submission\n\n";
print MAIL "$FORM{'realname'} from email address $FORM{'username'} has posted a story to the web site.\n\n";
print MAIL "Name: $FORM{'realname'}\n";
print MAIL "Name of Story: $FORM{'storyname'}\n";
print MAIL "Introduction to Story: $FORM{'intro'}\n";
print MAIL "Story:\n";
print MAIL "$FORM{'story'}\n\n";
print MAIL "-$date\n";
print MAIL "------------------------------------------------------\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: $fromaddress\n";
print MAIL "Subject: New Story Submission\n\n";
print MAIL "You are receiving this email because you submitted a story to the website.\n";
print MAIL "Below is what you submitted.\n\n";
print MAIL "Name: $FORM{'realname'}\n";
print MAIL "Email Address: $FORM{'username'}\n";
print MAIL "Name of Story: $FORM{'storyname'}\n";
print MAIL "Story:\n";
print MAIL "$FORM{'story'}\n\n";
print MAIL "-$date\n";
close (MAIL);
}
# Print Out Initial Output Location Heading
if ($redirection eq '1') {
print "Location: $guestbookurl\n\n";
}
else {
&no_redirection;
}
# Log the Entry or Error
sub log {
$log_type = $_[0];
open (LOG, ">>$guestlog");
if ($log_type eq 'entry') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]<br>\n";
}
elsif ($log_type eq 'no_name') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No Name<br>\n";
}
elsif ($log_type eq 'no_comments') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No ";
print LOG "Comments<br>\n";
}
}
# Redirection Option
sub no_redirection {
# Print Beginning of HTML
print "Content-Type: text/html\n\n";
print "<html><head><title><center>Thank you.</center></title></head>\n";
print "<body bgcolor=\"ece4dd\">\n";
print "<body><h1><center>Thank you for submitting your story.</h1></center>\n";
print "<body><Center>A copy of your story has been sent to your email address.</center>\n";
print "<body><Center>Click <a href=\"/stories.htm\">HERE</a> to return to the stories page.</center>\n";
print "<body><center>You may have to refresh the page to see your story.\n";
# Print End of HTML
print "<hr>\n";
print "</body></html>\n";
exit;
}