#!/opt/bin/perl
# -- -*-perl-*-

# Modified for return to any url by James Judd for ENS 950911

# ------------------------------------------------------------
# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
#
#Last Updated: March 14, 1994
#
# Form-mail provides a mechanism by which users of a World-
# Wide Web browser mat submit comments to the webmasters
# (or anyone else) at a site.  It should be compatible with
# any CGI-compatible HTTP server.
#
#Please read the README file that came with this distribution
# for further details.
# -----------------------------------------------------------

# -----------------------------------------------------------
# This package is Copyright 1994 by The Tech.
# -----------------------------------------------------------

# Define fairly-constants

# This should match the mail program on your system.
$mailprog = '/usr/lib/sendmail';

# This should be set to the username or alias that runs your
# WWW server
$recipient = 'britttb\@mail.auburn.edu';

# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
# Print a title and initial heading
print "<HEAD><Title>Thank You</Title></HEAD>";
print "<BODY><H1>$FORM{'head'}</H1>";

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

   $FORM{$name} = $value;
}



{
# Now send mail to the $recipient

open (MAIL, "|$mailprog -f $FORM{'e-mail'} $recipient") || die "Can't 
open $mailprog!\n";
print MAIL "From: $FORM{'name'} who is reachable at: $FORM{'e-mail'}\n";
print MAIL "\n";
print MAIL "My web-page address is: $FORM{'url'}\n";
print MAIL "\n";
print MAIL "The team I dislike the most is: $FORM{'dislike'}\n";
print MAIL "\n";
print MAIL "I give the content of the site a rating of: $FORM{'rate1'}\n";
print MAIL "\n";
print MAIL "I give the organization of the site a rating of: $FORM{'rate2'}\n";
print MAIL "\n";
print MAIL "My modem speed is: $FORM{'modem'}\n";
print MAIL "\n";
print MAIL "Comments: $FORM{'comments'}\n";
print MAIL "\n";
close (MAIL);

# Make the person feel good for writing to you
print "<p>Your comments have been submitted.";
print "<p>Thank You for your input.";

$FORM{'retdesc'} =~ tr/_/ /;

if ($FORM{'returl'} ne "")
  {
    print "<A HREF=\"$FORM{'returl'}\"> $FORM{'retdesc'}</A>.</p>";
  }
else
  {
    print "<A HREF=\"/usewrs/$username\"> go back.<.A></p>";
  }
}

# -------------------------------------------------------
