#!/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 $value =~ s/%0D/ /g; $value =~ s/%0A/ /g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #Convert 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 control name key } if($FORM{':COOKIE:'}) { if($ENV{'HTTP_COOKIE'} =~ /\QSURVEY=$FORM{':SURVEY:'}/) { print "Content-type:text/html\n\n"; print "\n\n"; print "\n"; print "Data Received\n"; print "\n"; print "\n"; print "

Repeat Submission

\n"; print "

You have already submitted data to this survey.Only one submission is allowed.\n"; print "

$sReturnText\n"; print "

\n"; print "
\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 address cannot be used print "Content-type:text/html\n\n"; print "\n\n"; print "Invalid Email Address\n"; print "\n"; print "

The system is unable to process the



\n"; print "

email address in this form.



\n"; print "Please report this error to $sWebMaster.
\n"; print "\n"; exit; } if($FORM{':RECEIPT:'}) { $theQ = $FORM{':RECEIPT:'}; $sender = $FORM{$theQ}; #Get address from hidden Email control #Check for malicous use of sender email if(length($sender)==0) { print "\n\n"; print "No Email Address\n"; print "\n"; if($FORM{':RECEIPTLBL:'}) { print "

You have not given a contact email in $FORM{':RECEIPTLBL:'}.



\n"; } else { print "

You have not given a contact email.



\n"; } print "

The address must be given so a receipt can be sent



\n"; print "Please use the back button on your browser to return to the questionnaire and enter an address.
\n"; print "\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 = ; die("500 fatal: bad message on connect: $stat") if ($stat !~ /^2/); print S "HELO $domain\r\n"; $stat = ; die("500 fatal: bad message on HELO: $stat") if ($stat !~ /^2/); print S "MAIL FROM:\r\n"; $stat = ; die("500 fatal: bad message on MAIL FROM: $stat") if ($stat !~ /^2/); print S "RCPT TO:<$FORM{':EMAIL:'}>"; print S "\r\n"; $stat = ; die("500 fatal: bad message on RCPT TO: $stat") if ($stat !~ /^2/); print S "DATA\r\n"; $stat= ; 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= ; 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{':COOKIE:'}\n"; } if($FORM{':OKPAGE:'}) { print "Location: $FORM{':OKPAGE:'}\n\n"; }else{ print "Content-type:text/html\n\n"; print "Thank-you\n"; print "\n"; print "
\n"; print "

Thank You

\n"; print "Thank you for taking the time to answer this survey.

\n"; print "Your response has been submitted succesfully to $FORM{':EMAIL:'}.

\n"; print "$sReturnText

\n"; print "\n"; }