#!/usr/local/bin/perl -- -*-perl-*- # Program allows users of a www system to send comments to an email # address that is selected on a pull-down form box. # Adapted from form-mail.pl # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu). # For more information see: # http://www.chem.vt.edu/chem-ed/CHP/scripts/perl/response.html. # Program and concept by Ron Earp and Brian Tissue. # Copyright 1996 by Ronald L. Earp and Brian M. Tissue, all rights reserved. # This should match the mail program on your system. $mailprog = '/usr/lib/sendmail'; # The following should be changed to match your server $site = "the VT Chemistry WWW server"; $copysubject = "Copy of comments to VT Chemistry WWW server"; $homepage = "vt-chem-home.html"; $pagename = "VT WWW Homepage"; # Print out a content-type for HTTP/1.0 compatibility print "Content-type: text/html\n\n"; # Print a title and initial heading print "Thank you"; print "

Thank you for your comments!

"; # 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; } # This line assigns the recipient to the value selected on the FORM $recipient = "$FORM{'receiver'}"; # If the comments are blank, then give a "blank form" response &blank_response unless $FORM{'comments'}; # Now send mail to $recipient open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; print MAIL "$FORM{'username'} ($FORM{'realname'}) sent the following\n"; print MAIL "comment from the $ENV{'HTTP_REFERER'} page :\n\n"; print MAIL "------------------------------------------------------------\n"; print MAIL "$FORM{'comments'}"; print MAIL "\n------------------------------------------------------------\n"; print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n"; print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n"; print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n"; close (MAIL); # Now copy comments to the person writing them if they request if ($FORM{'copy'} ne "") { $recipient = "$FORM{'username'}"; open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; print MAIL "You sent the following comment\n"; print MAIL "from the $ENV{'HTTP_REFERER'} page.\n"; print MAIL "------------------------------------------------------------\n"; print MAIL "$FORM{'comments'}"; print MAIL "\n-----------------------------------------------------------\n"; print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n"; print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n"; print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n"; close (MAIL); } # Make the person feel good for writing to us print "The following information was sent:

"; print "Your Name: $FORM{'realname'}

"; print "Your email: $FORM{'username'}

"; print "Subject: $FORM{'subject'}

"; print "Comments: $FORM{'comments'}

"; print "


"; print "Return to $pagename

"; print "


"; # ------------------------------------------------------------ # subroutine blank_response sub blank_response { print "Your comments appear to be blank, and thus were not sent "; print "to our webmasters. Please re-enter your comments, or "; print "return to our home page, if you want.

"; exit; }