garymgordon
Programmer
I have this very basic email parsing script that works fine when I have -w added to the shebang line. But, when I change it to have -wT (for tainting) instead of just the -w, I get an INTERNAL SERVER ERROR returned. (Error included: The server encountered an internal error or misconfiguration and was unable to complete your request.)
Evidently there is something wrong in the code, but being that I am quite new to Perl, I can't figure it out.
If you can, please let me know what part of this code needs to be changed in order to stop any and all errors from occuring. (And any other suggestions you'd like to make are always welcome.)
Thanks ... and here's the code:
#!/usr/local/bin/perl -wT
&get_form_data();
&send_email;
&print_thankyou_page;
sub get_form_data
{
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
# Split the name-value pairs
@pairs = split (/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}
}
sub send_email
{
$to = "webmaster\@garymgordon.com";
$mailprog = '/usr/lib/sendmail';
open(MAIL,"|$mailprog -t"
;
print MAIL "From: $FORM{'email'}\n";
print MAIL "To: $to\n";
print MAIL "Subject: General Email Contact Form.\n\n";
print MAIL "First Name: \t$FORM{'first_name'} \n\n";
print MAIL "Last Name: \t$FORM{'last_name'} \n\n";
print MAIL "E-mail Address: \t$FORM{'email'} \n\n";
print MAIL "Status: \t$FORM{'status'} \n\n";
print MAIL "Other \(if other is selected for Status\): \t$FORM{'other'} \n\n";
print MAIL "Comments: \t$FORM{'comments'} \n\n";
print MAIL " \n";
close(MAIL);
}
sub print_thankyou_page
{
print "Content-type: text/html\n\n";
print "<HTML>\n<HEAD>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\">\n";
print "<H3>THANK YOU SUBMITTING YOUR INFORMATION.</H3>\n\n";
print "<P>\n";
print "We have received your comments and will forward this to the appropriate person.<BR><BR><BR>\n";
print "Click below to return back:<BR>\n";
print "<B><A HREF=\" TARGET=\"\_top\">Gary M. Gordon, Web Developer</A></B><BR><BR>\n\n\n";
print "</BODY>\n</HTML>";
}
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
Evidently there is something wrong in the code, but being that I am quite new to Perl, I can't figure it out.
If you can, please let me know what part of this code needs to be changed in order to stop any and all errors from occuring. (And any other suggestions you'd like to make are always welcome.)
Thanks ... and here's the code:
#!/usr/local/bin/perl -wT
&get_form_data();
&send_email;
&print_thankyou_page;
sub get_form_data
{
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
# Split the name-value pairs
@pairs = split (/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}
}
sub send_email
{
$to = "webmaster\@garymgordon.com";
$mailprog = '/usr/lib/sendmail';
open(MAIL,"|$mailprog -t"
print MAIL "From: $FORM{'email'}\n";
print MAIL "To: $to\n";
print MAIL "Subject: General Email Contact Form.\n\n";
print MAIL "First Name: \t$FORM{'first_name'} \n\n";
print MAIL "Last Name: \t$FORM{'last_name'} \n\n";
print MAIL "E-mail Address: \t$FORM{'email'} \n\n";
print MAIL "Status: \t$FORM{'status'} \n\n";
print MAIL "Other \(if other is selected for Status\): \t$FORM{'other'} \n\n";
print MAIL "Comments: \t$FORM{'comments'} \n\n";
print MAIL " \n";
close(MAIL);
}
sub print_thankyou_page
{
print "Content-type: text/html\n\n";
print "<HTML>\n<HEAD>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\">\n";
print "<H3>THANK YOU SUBMITTING YOUR INFORMATION.</H3>\n\n";
print "<P>\n";
print "We have received your comments and will forward this to the appropriate person.<BR><BR><BR>\n";
print "Click below to return back:<BR>\n";
print "<B><A HREF=\" TARGET=\"\_top\">Gary M. Gordon, Web Developer</A></B><BR><BR>\n\n\n";
print "</BODY>\n</HTML>";
}
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer