#!/bin/perl -- -*-perl-*-

# Define fairly-constants
$mailprog = '/usr/lib/sendmail';
#--------------------------------------------
$recipient = 'Paul@vul-soft.demon.co.uk';
#--------------------------------------------
print "Content-type: text/html\n\n";
print "<Head><Title>Thank you</Title></Head>";
#---------------------------------------------------------------------------------
print "<Body><CENTER><H4>REQUESTING TO BE ADDED TO THE VULCAN PUBLIC INTERNET NEWS SERVICE</H4><br><hr>";
#--------------------------------------------------------------------------------
# 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;
}
# If the comments are blank, then give a "blank form" response
&blank_response unless $FORM{'email'};
# Now send mail to $recipient
#-------------------------------------------------------------------------------------
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "This User Wants to be added to the Public Internet News Service!\n\n";
print MAIL  "------------------------------------------------------------\n";
print MAIL "Identification: $FORM{'email'}\n";
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 "Thank you for your request<br><hr>";
print "Your Email address will be added.<br><hr>";
print "<A HREF=\"/\">Main Vulcan Page</A><br>";

# ------------------------------------------------------------
# subroutine blank_response
sub blank_response
{
    print "The Box was blank and no request was sent to Vulcan.<br><hr>";
    print "<A HREF=\"/\">Main Vulcan Page</A><br>";
    exit;
}
