#!/usr/bin/perl require 5.8.2; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI::apacheSSI (autotie => 'STDOUT', '_enable_exec_cmd' => 1); use Time::HiRes qw(time); use POSIX qw(strftime); use Email::Valid; #################################################################### ### ### ### FormMail++ v1.21 Oct 05, 2020 ### ### DOCUMENTATION => http://www.johnwoodruff.com/FormMail++ ### ### ### #################################################################### $TEMPLATE = ''; $BASE_TAG = "_self"; &initialize; &parse_stdin; &send_mail; &return_html; exit; ######################################################################################################### sub initialize {my($i, $template, @error, @files); #--------------------------------------------------------------------------------------------------- # GLOBAL DECLARATIONS #--------------------------------------------------------------------------------------------------- %Data = (); %Mail = (); @Lines = (); @Sequence = (); $Runtime = time(); $VERSION = 'FormMail++ 1.21'; $DATETIME = strftime("%a, %d %b %Y %H:%M:%S %Z", localtime); #i.e. Tue, 3 Jun 2014 00:10:14 EDT $PLSCRIPT = substr($ENV{SCRIPT_FILENAME}, rindex($ENV{SCRIPT_FILENAME}, "/") + 1); #--------------------------------------------------------------------------------------------------- # PERFORM SOME CONFIGURATION CHECKS #--------------------------------------------------------------------------------------------------- if ($ENV{REQUEST_METHOD} ne 'POST') {if ($ENV{CONTENT_LENGTH} =~ /^\s*$/gm && $ENV{QUERY_STRING} =~ /^\s*$/gm) {&about; exit;} else {push(@error,'Invalid method. Data must be submitted via POST');} } elsif ($ENV{REQUEST_METHOD} eq 'POST') {if (!$ENV{HTTP_REFERER}) {push(@error,'The referrer page must be identified');} elsif ($ENV{HTTP_REFERER} !~ /$ENV{SERVER_NAME}/i) {push(@error,'Data cannot be submitted from a remote server');} } else {die;} if (scalar(@error) > 0) {&about(@error); exit;} #--------------------------------------------------------------------------------------------------- # CONSTRUCT TEMPLATE -f=file -r=readable -x=executable -T=text-only -d=directory -c=system file #--------------------------------------------------------------------------------------------------- chdir($ENV{DOCUMENT_ROOT}); if (!$BASE_TAG) {$BASE_TAG = substr($ENV{HTTP_REFERER}, 0, rindex($ENV{HTTP_REFERER}, '/')+1 )} if (!$TEMPLATE) {opendir(SCRIPTDIR, $ENV{DOCUMENT_ROOT}); @files = readdir(SCRIPTDIR); closedir(SCRIPTDIR); $template = substr($PLSCRIPT, 0, index($PLSCRIPT, ".")); foreach $i (@files) {if ($i =~ /^$template\.s?html?$/) {$template = $i; last;} } } else {$template = $TEMPLATE;} if ((-f $template) && ((-r $template) || (-x $template)) && (-T $template) && !(-c $template) && !(-d $template)) {open(TEMPLATE, "<", "$template") or &about("Cannot open template - $!"); @Lines =