#! /usr/local/bin/perl # # # # Set Variables $server = "http://science.widener.edu/"; $emailurl = "/~svanbram/chem465/comments.html"; $emailreal = "/~svanbram/chem465/comments.html"; $emaillog = "/~svanbram/emaillog.html"; $cgiurl = "/~svanbram/chem465/email_b.cgi"; # Set Your Options: $mail = 1; # 1 = Yes; 0 = No $uselog = 0; # 1 = Yes; 0 = No $linkmail = 0; # 1 = Yes; 0 = No $separator = 1; # 1 =
; 0 =

$redirection = 0; # 1 = Yes; 0 = No ############## # If you answered 1 to $mail you will need to fill out these variables below: $mailprog = '/usr/lib/sendmail'; $recipient = 'svanbram@science.widener.edu'; # Get the Date for Entry $date = `date +"%a, %h %d, 19%y at %T"`; chop($date); $shortdate = `date +"%D %T"`; 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; # Stop people from using subshells to execute commands # Not a big deal when using sendmail, but very important # when using UCB mail (aka mailx). $value =~ s/~!/ ~!/g; # Uncomment for debugging purposes # print "Setting $name to $value

"; $FORM{$name} = $value; } # Print the Blank Response Subroutines &no_comments unless $FORM{'comments'}; ############## # Sub Routines sub no_comments { print "Content-type: text/html\n\n"; print "No Message\n"; print "

Your Message appears to be blank.

\n"; print "The message section in the form appears to be blank and therefore the message was not sent. Please enter your message below.

\n"; print "

\n"; print "Your message:
\n"; print "

\n"; print " or


\n"; print "Return to the Email form.\n"; print "\n"; # Log The Error if ($uselog eq '1') { open (LOG, ">>$emaillog"); print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] ERR - No Comments
\n"; close (LOG); } exit; } sub no_name { print "Content-type: text/html\n\n"; print "No Name\n"; print "

Your name or Email address appears to be blank

\n"; print "The name or Email address sections in the form appear to be blank and therefore your message was not sent. Please add your name and Email address below.

\n"; print "

\n"; print "Your Name:
\n"; print "E-Mail:

\n"; print "Your message has been retained.

\n"; print "\n"; print " or


\n"; print "Return to the Email form.\n"; print "\n"; # Log The Error if ($uselog eq '1') { open (LOG, ">>$emaillog"); print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] ERR - No Name
\n"; close (LOG); } exit; } ######### # Options # Mail Option if ($mail eq '1') { open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "Reply-to: anonymous chem 465"; print MAIL "From: anonymous, chem 465"; print MAIL "Subject: Web Email from: chem 465 anonymous"; print MAIL "Email Message:\n\n"; print MAIL "$FORM{'comments'}\n"; print MAIL "\n"; print MAIL "Message from:\n"; print MAIL "chem 465 anonymous"; if ( $FORM{'username'} ){ print MAIL " ($FORM{'username'})"; } print MAIL "\n"; print MAIL "$date\n"; close (MAIL); } # Print Out Initial Output Location Heading if ($redirection eq '1') { print "Location: $server$emailurl\n\n"; } else { &redirection } # Redirection Option sub redirection { # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "Message Received\n"; print "

Your message has been received.

\n"; # Print Response print "Your message will be sent to $recipient.
\n"; print "Here is what you submitted:

\n"; print "from anonymous chem 465"; print "
\n"; print "

\n";
print "$FORM{'comments'}
\n"; print "
\n"; print "$date

\n"; # Print End of HTML print "


\n"; print "Go back.\n"; print "\n"; exit; }