#!/usr/bin/perl # ********* change to /usr/bin/perl for Tiger Tech ********** # Generic mailform.pl by Jacques Delsemme, UC Santa Cruz - CATS # 12 March 1996 # # Modified by tra@ucolick.org for UCO/Lick use 03-26-96 # Modified by ted@ucolick.org with more options 11-26-01 # Modified by ted@ucolick.org for use at cantrall.net 02-05-03 # # The following field is required: # mailform-notify e-mail address to send form # at line 153, $notify is hard-coded to "webmaster@cantrall.net" # # The following fields are optional: # mailform-title Title string for # mailform-h1 Primary heading for

#* mailform-h3 Lesser heading for

# mailform-reply Reply sent to user # mailform-required List of required fields # mailform-wrapmargin List of textarea fields to be wrapped #* mailform-append1 Field to append to "Title" in email Subject line #* mailform-append2 Field to append to "append1" in email Subject line #* mailform-append3 Field to append to "append2" in email Subject line #* mailform-email 1=at least one of 3 email fields is required #* mailform-tab 0 to 3, tab style to use in mailed data #* mailform-xml 0=standard style; 1=mail data in XML style # # Any fieldname beginning with mailform- is assumed to be internal to # the mailform program, and will not be mailed. # #* XMLtag- Used in pairs, such as XMLtag- XMLtag- # # Any fieldname beginning with XMLtag- is not mailed but the value becomes an XML tag # (such as surrounding an address) which is mailed. ##### Define programs ################################################## $mailprog = "/usr/lib/sendmail"; $fmtprog = "/usr/ucb/fmt -60"; $catprog = "/usr/bin/cat"; $tmpfile = "/tmp/mailform$$"; $bad = 0; $mailfrom = "none given"; ##### Read and parse input ############################################# &ReadParse; ##### Define default values for some fields ############################ $title = "Reply form"; $title = $in{'mailform-title'} if (defined ($in{'mailform-title'})); $h1 = $title; $h1 = $in{'mailform-h1'} if (defined ($in{'mailform-h1'})); $h3 = ""; $h3 = $in{'mailform-h3'} if (defined ($in{'mailform-h3'})); $reply = "The form has been sent.\n"; $reply = $in{'mailform-reply'} if (defined ($in{'mailform-reply'})); $append1 = ""; if (defined ($in{'mailform-append1'})){ $append1 = "=$in{$in{'mailform-append1'}}"; } $append2 = ""; if (defined ($in{'mailform-append2'})){ $append2 = "$in{$in{'mailform-append2'}}"; } $append3 = ""; if (defined ($in{'mailform-append3'})){ $append3 = "$in{$in{'mailform-append3'}}"; } #* to have the data returned to $notify in XML format. # $xml = "0"; $xml = $in{'mailform-xml'} if (defined ($in{'mailform-xml'})); #* to have fields returned to user as a web page table. # enter 'seeall' mode if e-mail1 says 'seeall' $seealltest = $in{'E-mail1'}; ## line 84 if ($seealltest eq "seeall") { $seeall="1"; } #* to have even empty fields returned to $notify. # $nulval = "0"; $nulval = $in{'mailform-nulval'} if (defined ($in{'mailform-nulval'})); # values to put tabs before and/or after each data item # $tab value # 0=no tabs # 1=tab before only # 2=tab after only # 3=tab before and after # anything else is the same as a "1" $tab = "1"; # default value - tab before data $tab = $in{'mailform-tab'} if (defined($in{'mailform-tab'}) && $in{'mailform-tab'} ne ""); if ($tab eq "0") {$tb = ""; $ta = ""; } else {if ($tab eq "1") {$tb = "\t"; $ta = ""; } else {if ($tab eq "2") {$tb = ""; $ta = "\t"; } else {if ($tab eq "3") {$tb = "\t"; $ta = "\t"; } else {$tb = "\t"; $ta = ""; } } } } # If 'mailform-email' is set, at least one of 3 email fields is required $mail = "0"; $mail = $in{'mailform-email'} if (defined ($in{'mailform-email'})); $email = "none"; $email = $in{'E-mail'} if (defined ($in{'E-mail'}) && $in{'E-mail'} ne ""); $email1 = "none1"; $email1 = $in{'E-mail1'} if (defined ($in{'E-mail1'}) && $in{'E-mail1'} ne ""); $email2 = "none2"; $email2 = $in{'E-mail2'} if (defined ($in{'E-mail2'}) && $in{'E-mail2'} ne ""); #* to include date and time in the data returned to $notify, put the following in the form. # # # ($sc, $mn, $hr, $dy, $mo, $yr, $wd, $yd, $ds) = localtime; #* adjust to cancel out DST, make month start at 1, make year 4 digit $hr=$hr-$ds; $mo = $mo + 1; $yr = $yr + 1900; #* convert all 1 digit data into 2 digit data if ( $mo < 10 ) { $mo="0$mo"; } if ( $dy < 10 ) { $dy="0$dy"; } if ( $hr < 10 ) { $hr="0$hr"; } if ( $mn < 10 ) { $mn="0$mn"; } if ( $sc < 10 ) { $sc="0$sc"; } #* indicate the time is always in PST format $time = "$hr:$mn:$sc (PST)"; $date = "$yr/$mo/$dy"; #* insert date and time into data stream in place of "value=1" if (defined ($in{'Submit-date'}) && $in{'Submit-date'} ne "") {$in{'Submit-date'} = $date;} if (defined ($in{'Submit-time'}) && $in{'Submit-time'} ne "") {$in{'Submit-time'} = $time;} if (defined ($in{'PerlUpdated'}) && $in{'PerlUpdated'} ne "") {$in{'PerlUpdated'} = "2002/05/16";} ##### Print header ##################################################### print "Content-type: text/html\n\n"; print "\n"; print "$title feedback form\n"; print "\n"; print "

$h1

\n\n"; ##### Check notify field ############################ $notify = $in{'mailform-notify'}; $notify = "webmaster\@cantrall.net"; if ( !defined ($notify) || $notify eq "" ) { print "

Form error, notify webmaster (no mailform-notify field).\n"; print "The form failed to go through.\n"; $bad = 1; } #*### Check if there is at least one email address given ############### if ( defined($mail) && $mail ne "0" ){ if ( $email eq "none" && $email1 eq "none1" && $email2 eq "none2" ){ print "

There must be an email address given.\n"; print "The form will not be accepted without one.

\n"; $bad = 1; } } ##### Check required field ############################ $required = $in{'mailform-required'}; if ( defined($required) && $required ne "") { foreach $key (split(' ', $required)) { $value = $in{$key}; if (!defined ($value) || $value eq "" || $value eq "..." ) { print "

You did not fill-in the $key field!\n"; $bad = 1; } } } ##### Check wrapmargin field ############################ $wrapmargin = $in{'mailform-wrapmargin'}; $wrapmargin = $in{'mailform-textarea'} if ($in{'mailform-textarea'}); if ( defined($wrapmargin) && $wrapmargin ne "") { foreach $key (split(' ', $wrapmargin)) { $value = $in{$key}; if (defined ($value) && $value ne "") { open(OUT, "|$fmtprog >$tmpfile"); print OUT $value; close OUT; $in{$key} = `$catprog $tmpfile`; #* remove the 'newline' at the end of the field chop($in{$key}); unlink($tmpfile); } } } ##### process form ##################################################### ##### process form ##################################################### ##### process form ##################################################### if ( $bad == 1 ) { print "

Press the Back button in your "; print "browser to return to the form to correct it, and resubmit it.\n"; } else { #*## use one of the email addresses given. (prefering "$email" over the others.) if ( $email2 ne "none2") {$mailfrom = $email2;} if ( $email1 ne "none1") {$mailfrom = $email1;} if ( $email ne "none" ) {$mailfrom = $email;} if ( open (OUT, "|$mailprog -f$email $notify") != 0 ) { print OUT "From: $mailfrom\n"; if ($append1 ne ""){ print OUT "Subject: $title$append1$append2$append3.xml\n" } else { print OUT "Subject: (WWW) $title\n"; } print OUT "To: $notify\n"; print OUT "\n"; if ($seeall=="1"){print "\n";} foreach $var (@in) { ($key, $value) = split('=', $var); $value = $in{$key}; # email even empty variables back to me as data fields if ($nulval eq "1" && $value eq ""){ $value = "\t"; } if ($seeall=="1"){print "\n";} if ($key !~ /^mailform-/ && $value ne "" ) { ### line 227 ### $value =~ s/\n/\n\t/g; if ( $xml != "0" ){ if ($key !~ /^XMLtag-/ && $value ne ""){ #*## return XML formatted data ############# print OUT "<$key>$tb$value$ta\n"; } else { print OUT "$value\n"; } } else { if ($key !~ /^XMLtag-/ && $value ne ""){ #*## return unformatted data ############# print OUT "$key$tb$value$ta\n"; } } } } if ($seeall=="1"){print "
KeyValue
$key$value
";} close (OUT); #*### Print out sub-heading if it exists if ( defined($h3) && $h3 ne "" ) { print "

$h3

\n\n"; } print "

$reply\n"; } else { print "

$mailprog error: $!\n"; print "

Your form failed to go through.\n"; } } ##### Print footer ##################################################### print "


\n
\n"; print "webmaster\@cantrall.net
\n"; ### created Feb 05 2003 ### print "Last revised on Feb 10 2003
\n"; print "
\n\n\n"; exit (0); ######################################################################## # Perl Routines to Manipulate CGI input # S.E.Brenner@bioc.cam.ac.uk # $Header: /people/seb1005/http/cgi-bin/RCS/cgi-lib.pl,v 1.2 1994/01/10 15:05:40 seb1005 Exp $ # # Copyright 1993 Steven E. Brenner # Unpublished work. # Permission granted to use and modify this library so long as the # copyright above is maintained, modifications are documented, and # credit is given for any use of the library. # ReadParse # Reads in GET or POST data, converts it to unescaped text, and puts # one key=value in each member of the list "@in" # Also creates key/value pairs in %in, using '\0' to separate multiple # selections # If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse, # information is stored there, rather than in $in, @in, and %in. sub ReadParse { if (@_) { local (*in) = @_; } local ($i, $loc, $key, $val); # Read in text if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) { $in .= getc; } } @in = split(/&/,$in); foreach $i (0 .. $#in) { # Convert plus's to spaces $in[$i] =~ s/\+/ /g; # Convert %XX from hex numbers to alphanumeric $in[$i] =~ s/%(..)/pack("c",hex($1))/ge; # Split into key and value. $loc = index($in[$i],"="); $key = substr($in[$i],0,$loc); $val = substr($in[$i],$loc+1); $in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator $in{$key} .= $val; } return 1; # just for fun }