#!/usr/bin/perl

$mailprog = '/usr/lib/sendmail';

print "Content-type: text/html\n\n";
print "<Head><Title>MSG is sent</Title></Head>";
print "<Body bgcolor=white text=black><font face=arial size=2><center><H1>Thank you</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;
}

# If the comments are blank, then give a "blank form" response
&blank_response unless $FORM{'comments'};

# Now send mail to $recipient

$scheck = $FORM{'to'};
$scc = '@';
if($scheck =~/$scc/){
}else{
        print "Sorry you put the wrong e-mail format";
        exit;
}

open (LOGFILE, ">>/usr/local/etc/httpd/htdocs/ins/junior.html");
 

 
#$t = localtime(time);
#print LOGFILE "$ENV{'REMOTE_HOST'}--";
#print LOGFILE "<font color=lightgreen>$t</font>-------<font color=green>Name:</font><font color=red>$FORM{'comments'}</font>";
print LOGFILE "$FORM{'to'}\n";
close (LOGFILE);

$recipient = 'brian@ezenet.com';
#$recipient = 'kasra@ezenet.com';
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";

print MAIL "Name: $FORM{'comments'}\n";
print MAIL "Email: $FORM{'to'}\n";
print MAIL "Subject: subscribe to candianjunior.com\n\n";


print MAIL "==========================================\n\n";
print MAIL "Name: $FORM{'comments'}\n";
print MAIL "Email: $FORM{'to'}\n";
print MAIL "Subject: subscribe to candianjunior.com\n\n";



close (MAIL);








# Make the person feel good for writing to us
print "Thank you $FORM{'comments'} <P>";
print "Your email <font color=red>$FORM{'to'}</font> has been added to the list! <P>";
print "For security reasons, we will keep this log from your entry! <P>";

print "<font color=red>IP Address:</font> <font color=green>$ENV{'REMOTE_HOST'}</font><br>";
print "<font color=red>Date/Time Stamp</font> <font color=green>$t</font><br><font color=red>Name:</font> <font color=green>$FORM{'comments'}</font><br>";
print "<font color=red>Email:</font> <font color=green>$FORM{'to'}</font><p>";
print "<h2><A HREF=\"http://www.canadianjunior.com/index.html\">BACK</a></h2>";

# ------------------------------------------------------------
# subroutine blank_response
sub blank_response
{
    print "Your name appears to be blank, and thus was not sent.<br> ";
    print "Go BACK and Please re-enter your email,";
    print "Click here to go<A HREF=\"/brian/junior.html\"> BACK</A> NOW.<P>";
    exit;
}
