#!/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><H3>REGISTERING WITH VULCAN SOFTWARE LIMITED</H3><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{'details'};
# Now send mail to $recipient
#-------------------------------------------------------------------------------------
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "This person wants to Register with Vulcan Software Limited.\n\n";
print MAIL  "------------------------------------------------------------\n";
print MAIL "$FORM{'details'}";
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 Registering and supporting the Amiga<br><hr>";
print "Your personal ID Number and all of Vulcans newsletters with order forms for our MiniSeries Amiga range will be sent to you shortly.<br><hr>";
print "<A HREF=\"/\">Main Vulcan Page</A><br>";

# ------------------------------------------------------------
# subroutine blank_response
sub blank_response
{
    print "None of your details were filled in and nothing was sent to Vulcan.<br><hr>";
    print "<A HREF=\"/\">Main Vulcan Page</A><br>";
    exit;
}
