#!/usr/bin/perl use Socket; ############ SPECIAL FORM VARIABLES############## #required: comma delimited list of required entry fields #data_order: comma delimited list indicating what fields to actually # print and in what order. #outputfile: the name of the file to save the data in if using a file. # the file will automatically be named ending with .bout #emailfile: the name of the file to hold only the sender e-mail address # the file will automatically be named ending with .bemf #ok_url: URL to go to if successful #not_ok_url URL to go to if unsuccessful #submit_to: email address of person to input receive data by mail # this can be a comma seperated list of e-mail addresses #cc_to: email address of Cc Recipient # this can be a comma seperated list of e-mail addresses #submit_by: email address of person completing form #autorespond: NO LONGER USED AS OF JAN 31, 2000 #automessage: text to print for autoconfirmation e-mail # the file will automatically be named ending with .baut #form_id: name of form for e-mail subject #countfile: name of file for serial number counter # the file will automatically be named ending with .bcnt #okaydomains: prevents calling the script from other sites, # without restricting e-mail addresses. # replaces $SECURE_NAME from earlier versions. # use only lower case letters. #SMTP_SERVER: the full host name of the server providing e-mail # gateway service ################################################################## ## MAIN ########################################################## # uncomment the line below and # name if you wish to make is so the script can only be called # from your site. @okaydomains=("http://xxxxx.com", "http://www.xxxxx.com"); #SMTP_SERVER: indicates the name of the host acting as the e-mail # gateway. "localhost" should work on most systems. $smtp_path = "mail.xxxxxx.com"; $SMTP_SERVER="smtp.mail.xxxxxxxx.com"; #$SMTP_SERVER="localhost"; $defaultSender = "xxxxxx@xxxxxxx.com"; $SMTP_PORT="587"; $SSL="OFF"; $SMTP_Auth="true"; $Set_From="xxxxx@xxxxxx.com"; $auth_username="xxxxx@xxxxxx.com"; $auth_password="xxxxxxxxxxxx"; #OR IF SMTP IS UNAVAILABLE TO YOU, USE SEND_MAIL- # BUT NOT BOTH! #$SEND_MAIL="/usr/lib/sendmail -t"; #$host = "smtp.mail.xxxxxxx.com"; #$SMTP_PORT="587"; #$SSL="OFF"; #$SMTP_Debug="0"; #$SMTP_Auth="true"; #$Set_From="xxxxx\@xxxxxx.com"; #$auth_username="xxxxx@xxxxxx.com"; #$auth_password="xxxxxxxxxxx"; $lockfile="/tmp/bnbform.lck"; $SD=&sys_date; $ST=&sys_time; &decode_vars; &valid_page; if ($fields{'countfile'} ne "") { &get_number; } &valid_data; &write_data; if ($fields{'automessage'} ne "") { &answer_back; } if ($fields{'ok_url'} ne ""){ print "Location: $fields{'ok_url'}\n\n"; exit; } else { &thank_you; } ################################################################## sub write_data { if ($fields{'submit_by'} ne "") { if (&valid_address == 0) { &bad_email; exit; } } if ($fields{'submit_by'} ne "" && $fields{'emailfile'} ne "") { open (EMF,">>$fields{'emailfile'}"); print EMF "$fields{'submit_by'}\n"; close (EMF); } if ($fields{'submit_to'} ne "") { $msgtext=""; $msgtext .= "On $SD at $ST,\n"; $msgtext .= "The following information was submitted:\n"; $msgtext .= "From Host: $ENV{'REMOTE_ADDR'}\n"; } if ($fields{'outputfile'} ne "") { &get_the_lock; open(OUT_FILE,">>$fields{'outputfile'}"); } foreach $to_print (@sortlist) { if ($fields{'outputfile'} ne "") { print OUT_FILE "$fields{$to_print}\|"; } if ($fields{'submit_to'} ne "") { $msgtext .= "$to_print = $fields{$to_print}\n"; } } if ($fields{'outputfile'} ne "") { print OUT_FILE "$SD\|$ST\|\n"; close(OUT_FILE); &drop_the_lock; } foreach $to_get (@recipients) { $mailresult=&sendmail($fields{submit_by}, $fields{submit_by}, $to_get, $SMTP_SERVER, $fields {form_id}, $msgtext); if ($mailresult ne "1") { print "Content-type: text/html\n\n"; print "MAIL NOT SENT. SMTP ERROR: $mailcodes{'$mailresult'}\n"; exit } } foreach $to_cc (@cc_tos) { $mailresult=&sendmail($fields{submit_by}, $fields{submit_by}, $to_cc, $SMTP_SERVER, $fields {form_id}, $msgtext); if ($mailresult ne "1") { print "Content-type: text/html\n\n"; print "MAIL NOT SENT. SMTP ERROR: $mailcodes{'$mailresult'}\n"; exit } } } ################################################################## sub decode_vars { $i=0; read(STDIN,$temp,$ENV{'CONTENT_LENGTH'}); @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)=split(/=/,$item,2); $content=~tr/+/ /; $content=~s/%(..)/pack("c",hex($1))/ge; $content=~s/\t/ /g; $fields{$key}=$content; if ($key eq "data_order") { $content=~s/\012//g; $content=~s/\015//g; $content=~s/ //g; $content=~s/ //g; @sortlist=split(/,/,$content); } if ($key eq "required") { $content=~s/\012//g; $content=~s/\015//g; $content=~s/ //g; @mandatory=split(/,/,$content); } if ($key eq "submit_to") { $content=~s/\012//g; $content=~s/\015//g; $content=~s/ //g; @recipients=split(/,/,$content); } if ($key eq "cc_to") { $content=~s/\012//g; $content=~s/\015//g; $content=~s/ //g; @cc_tos=split(/,/,$content); } } if ( ( ($fields{automessage}=~ /^([-\/\w.]+)$/ || $fields{automessage} eq "") && ($fields{countfile}=~ /^([-\/\w.]+)$/ || $fields{countfile} eq "") && ($fields{emailfile}=~ /^([-\/\w.]+)$/ || $fields{emailfile} eq "") && ($fields{outputfile}=~ /^([-\/\w.]+)$/ || $fields{outputfile} eq "") ) ) {$donothing=0;} else { print "Content-type: text/html\n\n sorry, invalid characters...\n"; exit; } if ($fields{automessage} ne "") {$fields{automessage} .= ".baut";} if ($fields{countfile} ne "") {$fields{countfile} .= ".bcnt";} if ($fields{emailfile} ne "") {$fields{emailfile} .= ".bemf";} if ($fields{outputfile} ne "") {$fields{outputfile} .= ".bout";} } ################################################################## sub valid_data { if ($fields{'data_order'} eq "") #make sure we have work to do! { print "Content-type: text/html\n\n"; print <<__W1__;
Thank you!Your information has been sent and I will be in touch with you as soon as I canHere is the information you provided:
__W2__
foreach $itm (@sortlist) {
print <<__W2A__;
$itm: $fields{$itm}
|
__W3__
exit;
}
##################################################################
sub answer_back
{
$subject = "Thank you";
$msgtext="";
if ($fields{'automessage'} ne "") {
open (AM,"< $fields{'automessage'}");
while (