#!/usr/bin/perl
#
# Developed by Daniel Lafraia (lafraia@iron.com.br)
# Made in Brazil
# -- Super Form v1.1 (Sep 5th 1997)
# -- Super Form v1.2 (Dec 9th 1997)

$mailer = "/usr/lib/sendmail";
$version = "1.2";

$recebidas = $ENV{'QUERY_STRING'};
@partes = split(/&/, $recebidas);
foreach $parte (@partes)
{
    ($var, $str) = split(/=/, $parte);
    $str =~ tr/+/ /;
    $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $in{$var} = $str;
    $variaveis++;
    if ($var ne "\lreceiver" and $var ne "\lsubject" and $var ne "\lconfirm_page") { $string[$variaveis] = "${var}: $str"; }
}

if ($in{receiver} eq "") { &blankfield; }
if ($in{confirm_page} eq "") { &blankfield; }
if ($in{subject} eq "") { &blankfield; }

open (OUT, "|$mailer -oi -t");
print OUT "From: Super Form <lafraia\@iron.com.br>\n";
print OUT "To: $in{receiver}\n";
print OUT "Subject: $in{subject}\n\n";
print OUT "-------------------------------------------------\n";
for ($i = 0; $i < $variaveis + 1; $i++)
{
 if ($string[$i] ne "") { print OUT " -> $string[$i]\n" };
}
print OUT "-------------------------------------------------\n";
print OUT " Security Environment:\n";
print OUT "  That connection came from $ENV{'REMOTE_HOST'}\n";
print OUT "  Address: $ENV{'REMOTE_ADDR'}\n";
print OUT "  Real IP Address: $ENV{'HTTP_X_FORWARDED_FOR'}\n" if ($ENV{'HTTP_X_FORWARDED_FOR'});
print OUT "-------------------------------------------------\n";
print OUT "Message sent by Super Form v$version - MADE IN BRAZIL!\n";
print OUT "Developed by Daniel Lafraia (lafraia\@iron.com.br)\n";
print OUT "-------------------------------------------------\n";
close (OUT);

print "Location: $in{confirm_page}\n\n";

sub blankfield {
print <<EOF;
Content-type: text/html


<HTML>
<HEAD>
<TITLE>Super Form - Error Report</TITLE>
</HEAD>
<!-- Developed with Perl by Daniel Lafraia (lafraia\@iron.com.br) --!>
<BODY BACKGROUND="/images/atualfundo.gif">
<CENTER>
<HR WIDTH=90%>
<font color=red size=5>
Required variables are not being definied.<br>
Vari&aacute;veis necessarias n&atilde;o est&atilde;o sendo definidas.<br>
</font>
<HR WIDTH=90%>
Questions? Suggestions? E-Mail the <a href="mailto:lafraia\@iron.com.br">author</a>!
</CENTER>
</BODY>
</HTML>
EOF
exit;
}
