#!/usr/bin/perl my $TITLE = "Page me on ICQ!"; my $BGCOLOR = "#FFCC00"; my $TEXT_COLOR_NORMAL = "#000000"; my $REQUIRED_TEXT_COLOR = "Black"; my $BACKGROUND_URL = ""; my $CGI_DIR = "http://diabcam.braenet.com.au/cgi-bin"; $SHOW_OPTIONAL_FIELDS = 0; my $sendmail = "/usr/sbin/sendmail"; my $destination_email = "8539769\@pager.icq.com"; &print_header; &get_form_data; if (!$FORM_DATA{'mail'}) { &print_html_form; } else { $error = 0; &check_form_data; if (!$error) { &send_mail; &reply_to_user; } } exit(0); sub print_header { print ("Content-type: text/html\n\n"); print ("\n\n$TITLE\n\n"); print ("\n"); }#print_header sub get_form_data { $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $form_info = $ENV{'QUERY_STRING'}; } else { $size_of_form_information = $ENV{'CONTENT_LENGTH'}; read (STDIN, $form_info, $size_of_form_information); } @key_value_pairs = split (/&/, $form_info); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($FORM_DATA{$key})) { $FORM_DATA{$key} = join (", ", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } } #get_form_data sub print_html_form { print <<__END_OF_HTML_CODE__;
__END_OF_HTML_CODE__ if ($SHOW_OPTIONAL_FIELDS) { print ("
All required "); print ("information is bolded in this color.\n"); print ("Everything else is just for my own curiosity.
"); } print <<__END_OF_HTML_CODE__;
__END_OF_HTML_CODE__ if ($SHOW_OPTIONAL_FIELDS) { print ("\n"); print ("\n"); print ("\n"); print ("\n"); } print <<__END_OF_HTML_CODE__;
Your name:
Your email:

__END_OF_HTML_CODE__ if ($SHOW_OPTIONAL_FIELDS) { print <<__END_OF_HTML_CODE__;
Your country of residence:

Your home State/Province: If inside the U.S.:
If outside the U.S.:

__END_OF_HTML_CODE__ } print <<__END_OF_HTML_CODE__; Please enter your message below:

Please note that your are limited to 450 characters.


__END_OF_HTML_CODE__ } #print_html_form sub check_form_data { my %error_codes = ( "1" => "You need to enter your email address.", "2" => "You seemed to have forgotten to enter the email message you wish to send.", "3" => "For security reasons, you cannot have any of the following characters in your email or subject fields: [ ; < > & \* ` \| ] " ); if ($FORM_DATA{'users_email'} !~ /\@/ && $FORM_DATA{'users_email'} !~ /\w/) { $error = 1; } elsif ($FORM_DATA{'message'} !~ /\w/) { $error = 2; } if (($FORM_DATA{"subject"} =~ /[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/) || ($FORM_DATA{"to"} =~ /[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/) || ($FORM_DATA{"users_email"} =~ /[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/)) { $error = 3; } if ($error) { print ("

\n"); print ("Sorry! Your message could not be sent for the "); print ("following reasons:
\n"); print ("
$error_codes{$error}\n
\n
"); print ("Please hit the back button in your browser to "); print ("correct this. Thank you!\n"); print ("

\n\n\n"); } if ($FORM_DATA{'to'} ne "") { $destination_email = $FORM_DATA{'to'}; } } #check_form_data sub send_mail { open (MESSAGE, "| $sendmail -t -oi "); print MESSAGE <<__END_OF_MESSAGE__; To: $destination_email From: $FORM_DATA{"users_email"} __END_OF_MESSAGE__ if ($FORM_DATA{'users_name'} ne "") { print MESSAGE ("$FORM_DATA{'users_name'} - "); } print MESSAGE ("$FORM_DATA{'users_email'} paged you on ICQ "); print MESSAGE ("from your website.\n"); if ($FORM_DATA{'users_country'} ne "") { print MESSAGE ("They are in the country of: $FORM_DATA{'users_country'}\n"); } if ($FORM_DATA{'state_usa'} =~ /^USA$/i) { print MESSAGE ("They are writing from the state of: $FORM_DATA{'state_address1'}\n\n"); } elsif ($FORM_DATA{'state_usa'} =~ /^NOT_USA$/i) { print MESSAGE ("They are writing from the province of: $FORM_DATA{'state_address2'}\n\n"); } print MESSAGE ("The follow is what they had to say:\n\n"); print MESSAGE ("$FORM_DATA{'message'}\n"); close (MESSAGE); if ($FORM_DATA{'keep_copy'}) { open (MESSAGE, "| $sendmail -t -oi "); print MESSAGE <<__END_OF_MESSAGE__; To: $FORM_DATA{"users_email"} __END_OF_MESSAGE__ print MESSAGE ("The following is what you wrote from the "); print MESSAGE ("$TITLE webpage...:\n\n"); print MESSAGE ("$FORM_DATA{'message'}\n"); close (MESSAGE); } } #send_mail sub reply_to_user { print ("Thank you for paging me on ICQ

\n"); print ("Below is a copy of the information you sent me:
\n"); print ("
\n"); if ($FORM_DATA{'users_name'} ne "") { print ("
Your name:\n
$FORM_DATA{'users_name'}

\n"); } print ("
Your email:\n
$FORM_DATA{'users_email'}

\n"); if ($FORM_DATA{'users_country'} ne "") { print ("
Your country:\n
$FORM_DATA{'users_country'}

\n"); } if ($FORM_DATA{'state_address1'} ne "" && $FORM_DATA{'state_usa'} =~ /^USA$/i) { print ("
Your state:\n
$FORM_DATA{'state_address1'}

\n"); } elsif ($FORM_DATA{'state_address2'} ne "" && $FORM_DATA{'state_usa'} =~ /^NOT_USA$/i) { print ("
Your state:\n
$FORM_DATA{'state_address2'}

\n") if ($FORM_DATA{'state_address2'} ne ""); } print ("
Your message:\n
$FORM_DATA{'message'}

\n"); print ("
\n"); print ("\n\n"); } #reply_to_user #FILE: icq.pl