#!/usr/bin/perl

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

print "Content-type: text/html\n\n";
print "<Head><Title>MSG is sent</Title></Head>";
print "<Body><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/pinkfloyd/pinklist.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 ">>>> <font color=green>Email:</font><font color=blue>$FORM{'to'}</font> ";
close (LOGFILE);

$recipient = 'thewall@pinkfloyd.com';
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "From: $FORM{'to'}\n";
print MAIL "Subject: wall\n\n";
print MAIL  "------------------------------------------------------------\n";

close (MAIL);



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

print "$ENV{'REMOTE_HOST'}--";
print "<font color=lightgreen>$t</font>-------<font color=green>Name:</font><font color=red>$FORM{'comments'}</font>";
print "<font color=green>Email:</font><font color=blue>$FORM{'to'}</font> ";
print "BACK <A HREF=\"/index.html\">Main Page</A>";

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