#!/usr/bin/perl
$mailprog = '/usr/lib/sendmail';
$recipient = 'ldrel\@spectranet.ca';
#$recipient = 'kasra\@ezenet.com';
print "Content-type: text/html\n\n";
print "<Head><Title>Thank you</Title></Head>";
print "<Body><H1>Thank you</H1>";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
}
    print "<BODY BGCOLOR=#FFFFFF TEXT=#000000>";

# If the comments are blank, then give a "blank form" response
&blank_response unless $FORM{'fn'};
&blank_response unless $FORM{'ln'};
&blank_response unless $FORM{'add'};
&blank_response unless $FORM{'tel'};
&blank_response unless $FORM{'email'};
# Now send mail to $recipient
#		open (LOGFILE, ">>ldreg.dat");
#		print LOGFILE "$FORM{'realname'}\n";
#		close (LOGFILE);
$name = $FORM{'fn'};
print "$name $FORM{'S1'}<BR>\n";
print "First name is: $FORM{'fn'}<BR>\n";
print "Last name is: $FORM{'ln'}<BR>\n";
print "Address is: $FORM{'add'}<BR>\n";
print "Phone number is: $FORM{'tel'}<BR>\n";
print "Email is: $FORM{'email'}<BR>\n";
print "$name requires $FORM{'S2'}<BR>\n";
print "Time frame within: $FORM{'S3'}<BR>\n";
print "Purchasing Requirements: ";
if(length($FORM{'S5'})==0){
	print "$FORM{'S4'}<BR>\n";
}else{
	print "$FORM{'S5'}<BR>\n";
}
print "Rental Price Range: ";
if(length($FORM{'S6'})==0){
	print "$FORM{'S5'}<BR>\n";
}else{
	print "$FORM{'S6'}<BR>\n";
}
print "Purchase Price Range: ";
if(length($FORM{'S8'})==0){
	print "$FORM{'S7'}<BR>\n";
}else{
	print "$FORM{'S8'}<BR>\n";
}
print "Location: ";
if(length($FORM{'S10'})==0){
	print "$FORM{'S9'}<BR>\n";
}else{
	print "$FORM{'S10'}<BR>\n";
}
print "To know us from: ";
if(length($FORM{'S12'})==0){
	print "$FORM{'S11'}<BR>\n";
}else{
	print "$FORM{'S12'}<BR>\n";
}
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "From: EZENET\n";
print MAIL "Subject: email from your form\n\n";
print MAIL "$name $FORM{'S1'}\n";
print MAIL "First name is: $FORM{'fn'}\n";
print MAIL "Last name is: $FORM{'ln'}\n";
print MAIL "Address is: $FORM{'add'}\n";
print MAIL "Phone number is: $FORM{'tel'}\n";
print MAIL "Email is: $FORM{'email'}\n";
print MAIL "$name requires $FORM{'S2'}\n";
print MAIL "Time frame within: $FORM{'S3'}\n";
print MAIL "Purchasing Requirements: ";
if(length($FORM{'S5'})==0){
	print MAIL "$FORM{'S4'}\n";
}else{
	print MAIL "$FORM{'S5'}\n";
}
print MAIL "Rental Price Range: ";
if(length($FORM{'S6'})==0){
	print MAIL "$FORM{'S5'}\n";
}else{
	print MAIL "$FORM{'S6'}\n";
}
print MAIL "Purchase Price Range: ";
if(length($FORM{'S8'})==0){
	print MAIL "$FORM{'S7'}\n";
}else{
	print MAIL "$FORM{'S8'}\n";
}
print MAIL "Location: ";
if(length($FORM{'S10'})==0){
	print MAIL "$FORM{'S9'}\n";
}else{
	print MAIL "$FORM{'S10'}\n";
}
print MAIL "To know us from: ";
if(length($FORM{'S12'})==0){
	print MAIL "$FORM{'S11'}\n";
}else{
	print MAIL "$FORM{'S12'}\n";
}
print MAIL "\n------------------------------------------------------------\n";
print MAIL "Compiled by FORM-ldrel Generator.... Copyright EZENET INC 1997\n";
print MAIL "\n------------------------------------------------------------\n";
close (MAIL);
open (MAIL, ">>/var/spool/news/htdocs/ldrel/reg.log");
print MAIL "$name $FORM{'S1'}\n";
print MAIL "First name is: $FORM{'fn'}\n";
print MAIL "Last name is: $FORM{'ln'}\n";
print MAIL "Address is: $FORM{'add'}\n";
print MAIL "Phone number is: $FORM{'tel'}\n";
print MAIL "Email is: $FORM{'email'}\n";
print MAIL "$name requires $FORM{'S2'}\n";
print MAIL "Time frame within: $FORM{'S3'}\n";
print MAIL "Purchasing Requirements: ";
if(length($FORM{'S5'})==0){
	print MAIL "$FORM{'S4'}\n";
}else{
	print MAIL "$FORM{'S5'}\n";
}
print MAIL "Rental Price Range: ";
if(length($FORM{'S6'})==0){
	print MAIL "$FORM{'S5'}\n";
}else{
	print MAIL "$FORM{'S6'}\n";
}
print MAIL "Purchase Price Range: ";
if(length($FORM{'S8'})==0){
	print MAIL "$FORM{'S7'}\n";
}else{
	print MAIL "$FORM{'S8'}\n";
}
print MAIL "Location: ";
if(length($FORM{'S10'})==0){
	print MAIL "$FORM{'S9'}\n";
}else{
	print MAIL "$FORM{'S10'}\n";
}
print MAIL "To know us from: ";
if(length($FORM{'S12'})==0){
	print MAIL "$FORM{'S11'}\n";
}else{
	print MAIL "$FORM{'S12'}\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 sending comments to <I>The Tech</I>!<P>";
print "Return to our <A HREF=\"/\">home page</A>, if you want.<P>";

# ------------------------------------------------------------
# subroutine blank_response
sub blank_response
{
    print "Something missing please go back";
    print "return to our <A HREF=\"/\">home page</A>, if you want.<P>";
    exit;
}
