#!/usr/bin/perl
# todo: file upload. If someone can do that, we'll appreciate it!
# Name: A+ Forms, Release: 1.0
# This script is copyrighted by A+.
# Coded by Pedro Cruz (a.k.a "Peter", a.k.a "JediMaster").
# This software is free to use *only* by customers of Sanders Hosting.
# Customers have the right to modify it as they wish.
# If you make improvements and want to make them available
# to everyone else, let us know at tech@sandershosting.com.
# We'll take a look at your code and will consider implementing
# it to the original source file.
# Please read the following instructions.
# If you wish to limit this CGI to only forms on your domain, set
# $referrer_limitation to "1". If you don't, *anyone* on the Internet
# can use this CGI to send data from forms through *your* website.
# Leaving it at "0" is not recommended.
$referrer_limitation = 0;
# If you set $referrer_limitation to 1, set $yourdomainname below
# to your domain's name. Example: "sandershosting.com". No "www.",
# no "http://", etc. Just the domain name and its extension.
$yourdomainname = "sandershosting.com";
# THERE IS NOTHING ELSE TO MODIFY BEYOND THIS LINE!
# If you do know Perl + CGI, then feel free to modify the code below.
if ($referrer_limitation == 1)
{
$page_with_form = $ENV{'HTTP_REFERER'};
if ($page_with_form !~ m/$yourdomainname/)
{
print "Content-type: text/html\n\n";
print "
You are not allowed to submit data to this CGI
$yourdomainame";
exit;
}
}
read (STDIN , $info , $ENV{'CONTENT_LENGTH'});
@submissiondata = split (/\&/ , $info);
foreach $line (@submissiondata)
{
($key , $content) = split (/=/ , $line);
$content =~ tr/+/ /;
$content =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($array{$key})
{
$array{$key} = $array{$key} . "\;$content";
}
else
{
$array{$key} = $content;
}
}
if ($array{necessaryfields})
{
@necessaryfields = split (/\,/ , $array{necessaryfields});
undef (@missingfields);
foreach $field (@necessaryfields)
{
if (!($array{$field}))
{
print "Location: $array{redirectonerror}\n\n" if ($array{redirectonerror});
push (@missingfields , $field);
}
}
if ($array{template_missing_fields})
{
undef ($tempstring);
if ($array{template_missing_fields} =~ m/[[fields]]/)
{
if (!($array{html_code_to_list_missing_fields}))
{
print "Content-type: text/html\n\n";
print "Warning! You did not specified the field \"html_code_to_list_missing_fields\"!";
exit;
}
if ($array{html_code_to_list_missing_fields} =~ m/\[\[missingfieldname\]\]/)
{
if (!($array{necessaryfieldnames}))
{
print "Content-type: text/html\n\n";
print "Warning! You did not specified the field \"necessaryfieldnames\"!";
exit;
}
@missingfieldnamepairs = split (/\;/ , $array{necessaryfieldnames});
foreach $pairs (@missingfieldnamepairs)
{
($key , $value) = split (/\,/ , $pairs);
$array2{$key} = $value;
}
}
$temp = $array{html_code_to_list_missing_fields};
foreach $field (@missingfields)
{
$temp =~ s/\[\[missingfield\]\]/$field/g;
$temp =~ s/\[\[missingfieldname\]\]/$array2{$field}/g;
$tempstring .= $temp;
$temp = $array{html_code_to_list_missing_fields};
}
}
$array{template_missing_fields} =~ s/\[\[fields\]\]/$tempstring/g;
print "Content-type: text/html\n\n";
print $array{template_missing_fields};
exit;
}
print "Content-type: text/html\n\n";
print "Warning! You did not specified what to do when a necessary field is missing!";
exit;
}
foreach $arraykey (keys %array)
{
$array{template} =~ s/\[\[$arraykey\]\]/$array{$arraykey}/g;
$array{subject} =~ s/\[\[$arraykey\]\]/$array{$arraykey}/g;
if (($array{template} =~ m/\[\[random/) || ($array{subject} =~ m/\[\[random/))
{
if (!($array{randomdigits}))
{
print "Content-type: text/html\n\n";
print "Warning! You did not specified the field \"randomdigits\"!";
exit;
}
$digits = $array{randomdigits};
$randomnumber = rand(9999999);
$randomnumber =~ s/\.//g;
$randomnumber = substr ($randomnumber , 0 , $digits);
$array{template} =~ s/\[\[random\]\]/$randomnumber/g;
$array{subject} =~ s/\[\[random\]\]/$randomnumber/g;
}
}
open (mail , "|/usr/sbin/sendmail -t");
print mail "To: $array{emailreceiver}\n";
print mail "From: $array{emailfrom}\n";
print mail "Subject: $array{subject}\n\n";
print mail "$array{template}\n\n";
close (mail);
print "Location: $array{redirect}\n\n";