#!/usr/local/bin/perl ##################################################################### # Filename : mailform.cgi # Copyright : 1997 Brian Chu http://www.cs.siena.edu # Purpose : To provide a generic form that people can use on their # webpages to use for comments. This tends to work more # effectively than mailto: links, as people often don't # set their machines up properly. ##################################################################### # This script may be used and modified free of charge by anyone so # long as this copyright notice and the comments above remain intact. By # using this this code you agree to indemnify Brian Chu and Siena College # from any liability that might arise from it's use. # # Selling the code for this program without prior written consent is # expressly forbidden. In other words, please ask first before you try and # make money off of my program. # # Obtain permission before redistributing this software over the Internet or # in any other medium. In all cases copyright and header must remain intact. $| = 1; print "Content-type: text/html\n\n"; require "cgi-lib.pl"; require "mail-lib.pl"; @required_fields = ("email","comments"); ##################################################### # Main Program # ##################################################### ReadParse(*in); OnlySiena(); check_required_fields(); get_date(); send_email(); thanks_HTML(); ##################################################### # SUBPROGRAMS # ##################################################### ################ OnlySiena subroutine ############### sub OnlySiena { $REFERER = $ENV{'HTTP_REFERER'}; if($REFERER =~ /siena\.edu/i) { return 1; } else { print < Sorry, Unauthorized User!

Unauthorized User!

Sorry, you are not authorized to use a this script on your site. This script is registered only for members of the Siena Community. If you would like a copy of this script for your own use, contact the web\@ares.cs.siena.edu.


Return to Siena

END_ONLY exit; } } ##### OnlySiena ######### check_required_fields subroutine ########## sub check_required_fields { @hidden_fields = ("owner_email","owner","X-URL","home_URL"); foreach $hidden (@hidden_fields) { if ($in{$hidden} eq "") { &error("Admin configuration error", "The owner of this mailform did not set it up properly."); } } foreach $field (@required_fields) { if ($in{$field} eq "") { &error("Missing required field data", "It appears that you have omitted some important information."); } } } ######## end sub check_required_fields. ########## ############### get_date subroutine ################ sub get_date { @DAYS=('Sunday','Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday'); @MONTHS=('January','February','March','April','May','June', 'July','August','September','October','November','December'); ($sec,$min,$mil_hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $DAY_NAME=$DAYS[$wday]; $MONTH_NAME=$MONTHS[$mon]; $date = "$DAY_NAME, $mday $MONTH_NAME"; } ############ end sub get_date ############# ############### send_email subroutine ############## sub send_email { $email_body = "E-Mail: <$in{'email'}>\n"; if ($in{'name'} ne "") { $email_body .= "Name: $in{'name'}\n"; } if (($in{'URL'} ne "") && ($in{'URL'} ne "http://")) { $email_body .= "URL: $in{'URL'}\n";} if ($in{'subject'} eq "") { $email_subject = "[WEBMAIL] "; } else { $email_subject = "[WEBMAIL] $in{'subject'}"; } $email_body .= "Date: $date\n"; $email_body .= "Comments: $in{'comments'}\n"; &send_mail("$in{'email'}", "$in{'owner_email'}", "$email_subject","$email_body"); } ############ end sub send_email ########### ################ thanks_HTML subroutine ############ sub thanks_HTML { $comments = $in{'comments'}; $comments =~ s/\n/\n
/g; &header("Thanks for sending E-Mail!!"); print "Your comments were as follows:
\n"; print "
\n"; print "E-Mail: $in{'email'}
\n"; if ($in{'name'} ne "") { print "Name: $in{'name'}
\n"; } if (($in{'URL'} ne "") && ($in{'URL'} ne "http://")) { print "URL: $in{'URL'}
\n"; } if ($in{'subject'} eq "") { print "Subject: <No Subject>
\n"; } else { print "Subject: $in{'subject'}
\n"; } print "Comments: $comments
\n"; print "
\n"; $IP=$ENV{'REMOTE_ADDR'}; if ($IP =~ /^204\.168\.(145)|(126)|(127)/) { print "
\n"; print <how to create your own mailform. END_SIENA ; } &footer; } ########### end sub thanks_HTML ############ ################ error subroutine ################## sub error { local ($title, $body) = @_; $form_URL=$in{'X-URL'}; &header($title); print <
$body
Go back to the Mail Form.
END_ERROR ; &footer; exit; } ############# end sub error ############# ################ header subroutine ################## sub header { local ($title) = @_; print < $title

$title

END_HEAD ; } ############# end sub header ############# ############### footer subroutine ################### sub footer { $owner="$in{'owner'}\'s"; $URL=$in{'home_URL'}; print <
Return to $owner Homepage.
Mail script created by Brian Chu.

Return to Siena

END_FOOT ; } ############# end sub footer ############# 1;