#!/usr/bin/perl # File name: form_handler.cgi # send e-mail containing user's input to a form # remember to put your handle on the front of this file name &setup; &main; sub main { # here we check for malicious hackery $bad_input = ""; foreach $item (values %in) { if ($item =~ /[<>\*`\|]/) { $bad_input = "yes"; } } if ($bad_input eq "yes") { &html_header; print "

Please use only standard characters in this input.

"; &html_footer; } else { # here we ccheck the input for problems if ($in{'name'} eq "") { &html_header; print "

Sorry but you need to supply your name.

Return

\n"; &html_footer; } if ($in{'email'} eq "" | $in{'email'} =~ / /) { &html_header; print "

Sorry but you need to supply your e-mail address.

Return

\n"; &html_footer; } if ($in{'number'} eq "" | $in{'number'} =~ / /) { &html_header; print "

Sorry but you need to specify how many will be in your tour group.

Return

\n"; &html_footer; } if ($in{'start_date'} eq "" | $in{'start_date'} =~ / /) { &html_header; print "

Sorry but you need to specify what date you want your tour to start.

Return

\n"; &html_footer; } if ($in{'end_date'} eq "" | $in{'end_date'} =~ / /) { &html_header; print "

Sorry but you need to specify what date you want your tour to end.

Return

\n"; &html_footer; } else { &send_email; &show_message; } } } sub setup { print "Content-type: text/html\r\n"; print "\r\n"; require '../../../../cgi-bin/cgi-lib.pl'; # this links to cgi-bin.pl on David Mc's account &ReadParse; $cgi_name = "form_handler.cgi"; # change this to the file name based on your handle $my_email = $in{'my_email'}; $start_day = (localtime) [3]; $start_month = (localtime) [4] + 1; $start_year = (localtime) [5] + 1900; $received_date = "$start_month/$start_day/$start_year"; } sub send_email { print "\n"; $to = $in{'my_email'}; open (MAIL, "| /usr/sbin/sendmail -t") || die "error: can't start mail program"; print MAIL "To: $to \n"; print MAIL "From: Texas Tours <$my_email> \n"; print MAIL "Subject: Request for tour received $received_date \n\n"; print MAIL "We have just received this tour request:\n\n"; print MAIL "Name: $in{'name'} \n"; print MAIL "E-mail: $in{'email'} \n"; print MAIL "Group number: $in{'tour_group'} \n"; print MAIL "Start date: $in{'start_date'} \n"; print MAIL "End date: $in{'end_date'} \n"; close MAIL; } sub show_message { # show student okay web page &html_header; print "
\n"; print "

Okay, a potential customer filled out the questionnaire on $received_date.

\n"; print "

Here is the information we received:

\n"; print "

Name: $in{'name'}
\n"; print "E-mail: $in{'email'}
\n"; print "Group number: $in{'number'}
\n"; print "Start date: $in{'start_date'}
\n"; print "End date: $in{'end_date'}
\n"; &html_footer; } sub html_header { print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "Texas Tours \n"; print " \n"; print " \n"; print "

Texas Tours

"; } sub html_footer { print $signature; print ""; print ""; }