Here is the entire script. I believe I just need to add a (hopefully) small bit to be able to include my user name and password and have it work with the Net/SMTP.pm module:
#!/usr/bin/perl
#First released with snap 10
$port = 25; #SMTP PORT NUMBER
$smtpServer = 'smtp.ipower.com';
$domain = 'mydomain.biz';
$sWebMaster='myemail@mydomain.biz';
$sReturnURL='http://mydomain.biz';
$sReturnText='Submit';
use Socket;
use URI::Escape;
$SIG{'INT'} = 'dokill';
sub dokill {
kill 9,$child if $child;
}
($name,$aliases,$proto) = getprotobyname('tcp');
($name,$aliases,$port) = getservbyname($port,'tcp')
unless $port =~ /^\d+$/;;
($name,$aliases,$type,$len,$thataddr) = gethostbyname($smtpServer);
my $iaddr = inet_aton($smtpServer);
$that = sockaddr_in($port, $iaddr);
read(STDIN , $buffer , $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/ , $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /; #Translate + to <space>
$value =~ s/%0D/ /g;
$value =~ s/%0A/ /g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #C
+onvert Hex values
$value =~ s/~!/ ~!/g;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #Do
+ the same for the names
$name =~ s/~!/ ~!/g;
$FORM{$name} .= ';' if (defined($FORM{$name})); #Seperate multi
+ values with ;
$FORM{$name} .= $value; #Add the value to the contr
+ol name key
}
if($FORM{':COOKIE:'})
{
if($ENV{'HTTP_COOKIE'} =~ /\QSURVEY=$FORM{':SURVEY:'}/) {
print "Content-type:text/html\n\n";
print "\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Data Received</TITLE></HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\">\n";
print "<FONT FACE=ARIAL>\n";
print "<CENTER><H2>Repeat Submission</H2>\n";
print "<P>You have already submitted data to this surve
+y.Only one submission is allowed.\n";
print "<P><a href=\"$sReturnURL\">$sReturnText</a>\n";
print "</CENTER>\n";
print "</FONT></BODY></HTML>\n";
exit;
}
}
$recipient = $FORM{':EMAIL:'}; #Get address from hidden
+ Email control
#Check for malicous use of recipient
if ($recipient =~ />|<|;|\\|\// ) {
#Change this message to change the page returned when the email addres
+s cannot be used
print "Content-type:text/html\n\n";
print "\n\n";
print "<HEAD><TITLE>Invalid Email Address</TITLE></HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\">\n";
print "<CENTER><H2>The system is unable to process the</H2><BR
+><BR>\n";
print "<CENTER><H2>email address in this form.</H2><BR><BR>\n";
print "Please report this error to $sWebMaster.</center>\n";
print "</BODY>\n";
exit;
}
if($FORM{':RECEIPT:'})
{
$theQ = $FORM{':RECEIPT:'};
$sender = $FORM{$theQ}; #Get address from hidden Em
+ail control
#Check for malicous use of sender email
if(length($sender)==0)
{
print "\n\n";
print "<HEAD><TITLE>No Email Address</TITLE></HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#
+0000ff\" VLINK=\"0000ff\">\n";
if($FORM{':RECEIPTLBL:'})
{
print "<CENTER><H2>You have not given a contact email in $
+FORM{':RECEIPTLBL:'}.</H2><BR><BR>\n";
}
else
{
print "<CENTER><H2>You have not given a contact email.
+</H2><BR><BR>\n";
}
print "<CENTER><H2>The address must be given so a receipt can
+be sent</H2><BR><BR>\n";
print "Please use the back button on your browser to retur
+n to the questionnaire and enter an address.</center>\n";
print "</BODY>\n";
exit;
}
}
if (!socket(S, PF_INET, SOCK_STREAM, $proto)) {
die $!;
}
if (!connect(S,$that)) {
die $!;
}
select (S);
$|=1; # flush
select (STDOUT);
$|=1; # flush
#set up ESMTP session here
$stat = <S>;
die("500 fatal: bad message on connect: $stat") if ($stat !~ /^2/);
print S "HELO $domain\r\n";
$stat = <S>;
die("500 fatal: bad message on HELO: $stat") if ($stat !~ /^2/);
print S "MAIL FROM:<surveyScript\@$domain>\r\n";
$stat = <S>;
die("500 fatal: bad message on MAIL FROM: $stat") if ($stat !~ /^2/);
print S "RCPT TO:<$FORM{':EMAIL:'}>";
print S "\r\n";
$stat = <S>;
die("500 fatal: bad message on RCPT TO: $stat") if ($stat !~ /^2/);
print S "DATA\r\n";
$stat= <S>;
print S "To: $FORM{':EMAIL:'} \n";
print S"Subject: Internet submission of $FORM{':SURVEY:'} data\n\n";
print S "***START SURVEY DATA***\n";
my $doEscape = $FORM{':MSGENCODE:'} ? 1 : 0;
if ($doEscape)
{
$FORM{':MSGENCODE:'} = "2";
}
foreach $key (keys(%FORM))
{
if ($key !~ /^:OKPAGE:$/)
{
my $val = $FORM{$key};
if ($doEscape)
{
$val = uri_escape($val, "^A-Za-z0-9\-_.!~*'()\x20@");
}
print S "$key=$val\n";
}
}
print S "***END SURVEY DATA***\n";
print S "\r\n.\r\n";
$stat= <S>;
die("500 fatal: bad message on DATA END: $stat") if ($stat !~ /^2/);
print S "QUIT\r\n";
#close socket here
close(S);
if($FORM{':COOKIE:'})
{
print "Set-Cookie: SURVEY=$FORM{':SURVEY:'} ; expires=$FORM{':COOK
+IE:'}\n";
}
if($FORM{':OKPAGE:'})
{
print "Location: $FORM{':OKPAGE:'}\n\n";
}else{
print "Content-type:text/html\n\n";
print "<HEAD><TITLE>Thank-you</TITLE></HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\">\n";
print "<center>\n";
print "<h2>Thank You</h2>\n";
print "Thank you for taking the time to answer this survey.<p>\n";
print "Your response has been submitted succesfully to $FORM{':EMA
+IL:'}.<p>\n";
print "<a href=\"$sReturnURL\">$sReturnText</a></center>\n";
print "</body>\n";
}
|