#!/usr/bin/perl
######################
# General Mail Form To Work With Any Fields
# Created 6/9/95 Last Modified 11/13/2003
# Version 1.5
# Modified by Emil Briggs, Charles Brabec, Burtland Jones, Mark Skogsberg
# Define Variables
$mailprog = '/bin/sendmail';
######################
# A date for those with no /bin/date
#
@junk = localtime(time);
$date = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$junk[4]];
$junk[5] += 1900;
$date .= "-" . $junk[3] . "-" . $junk[5];
$date .= " " . $junk[2] . ":" . $junk[1] . " EST";
$datafile = '/etc/hosts';
######################
# Necessary Fields in HTML Form: (Read the README file for more info)
# recipient = specifies who mail is sent to
# username = specifies the remote users email address for replies
# realname = specifies the remote users real identity
# subject = specifies what you want the subject of your mail to be
########################
# A subroutine to die gracefully under html
########################
sub safe_die {
print "Content-type: text/html\n\n";
print @_,"
\n";
exit(0);
}
######################
# Read in posted data
######################
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
############################################
# Capture referring URL for security checks
############################################
$finddomain = $ENV{'HTTP_REFERER'};
############################################
# die if Script is called directly
############################################
if ($finddomain eq "") {
&safe_die("Please do not call this interface directly");
}
############################################
# Clean the $finddomain variable and get the URI portion, if any
############################################
$finddomain = lc($finddomain);
$finddomain =~ s/^http:\/\/|^https:\/\///;
$finddomain =~ s/^www\.//;
if($finddomain =~ /\//) {
($finddomain, $uri_path) = split(/\//, $finddomain, 2);
}
else {
$uri_path = "";
}
&check_exists($finddomain);
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
####################################
# drop the case of the email address to make pattern matching easier
####################################
$FORM{'recipient'} = lc($FORM{'recipient'});
##############################################
# verify that referrer is valid local file
##############################################
$isvalid = &file_verify($uri_path);
if($isvalid == 0) {
&safe_die("Referring file is not a valid form");
}
# clean up the recipient address, to avoid hackers
$whoto = $FORM{'recipient'};
if ($whoto eq "") {
&safe_die("No Recipient Given!\n");
}
if ($FORM{'username'} eq "") {
$FORM{'username'} = "No-Email-Given\@nowhere.none";
}
# Open The Mail
open (MAIL, "|$mailprog -t") || &safe_die("Can't open $mailprog!\n");
print MAIL "From: $FORM{'username'}\n";
print MAIL "Reply-To: $FORM{'username'}\n";
print MAIL "To: $whoto\n";
print MAIL "Subject: $FORM{'subject'}\n\n";
print MAIL "Below is the information submitted on $date\n";
print MAIL "----------------------------------------------------------------------------------------\n\n";
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
if (($name eq "recipient")||
($name eq "subject") ||
($name eq "Senden") ||
($name eq "Send") ||
($name eq "thankurl")) {
print MAIL "";
}
else {
# Print the MAIL for each name value pair
print MAIL "$name: $value\n";
}}
close (MAIL);
if ($FORM{thankurl} eq "no") {
print "Content-type: text/html\n\n";
print "
\n";
}}
print "";
}
else
{
print "Location: $FORM{'thankurl'}\n\n";
}
sub check_exists {
$chkdomain = shift;
$found = 0;
open(DB, "<$datafile") || &safe_die("Cannot open data file");
while ($lin =