#!/usr/bin/perl 


$path = $0;
$path =~ s#/[^/]*$##;

require "$path/config.ph";

    # Print this out no matter what
    print "Content-type: text/html\n\n";

    if ($ENV{'REQUEST_METHOD'} eq 'POST')
    {
      # How many bytes are we supposed to receive?
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

      @field = split(/&/, $buffer);

      foreach $next_field (@field)
      {
          ($name, $value) = split(/=/, $next_field);
          $value =~ tr/+/ /;
          $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
          $value =~ s/~!/ ~!/g;   # Stops people using subshells apparently

          $USER_INPUT{$name} = $value;
      }

    }

$time_n_date = `date`;
chop $time_n_date;

open(MAILTO,"| /usr/ucb/mail -s WWW_Comments $who_to_mail");
print MAILTO "On $time_n_date,\n";
print MAILTO "$USER_INPUT{name} ($USER_INPUT{email})\n";
print MAILTO "****from $ENV{'REMOTE_HOST'} ($ENV{'REMOTE_ADDR'})*****\n";
print MAILTO "wrote..\n\n";
print MAILTO "$USER_INPUT{comments}\n";
close(MAILTO);

print "<h2>Thank you `$USER_INPUT{name}` for your comments<p>I will get back to you as soon as I can.<hr><h2>\n";


