#!/usr/bin/perl ############################################################################## # COPYRIGHT NOTICE - EmailIt! Version 1.01 Jan 2000 # # # # Copyright 1999 Ben Hare http://cgi.upws.com/ # # # # EmailIt! may be used and modified free of charge by anyone so long as this # # copyright notice and copyright notices displayed in all HTML output of the # # program remain intact. This program uses # # several modified routines from Matt Wright's FormMail program - See # # copyright notice for FormMail at end of page. # # By using this code you agree to indemnify Ben Hare from any liability that # # might arise from its use. # ############################################################################## #Although you are free to edit this file, no editing is required. All set-up should be done #in variables.pl. Please do not remove any copyright notices within the script. require 'variables.pl'; $version = "1.01"; print "Content-type:text/html\n\n"; if (!$ENV{'HTTP_REFERER'}) { print "EmailIt 1.0\n"; print "\n"; print "This script cannot be accessed directly.\n"; print "To run the script you need to create a link to it on a web page, then access\n"; print "it via the link. That page will be the page the script sends.\n\n"; print "If you are trying to configure this script, view the\n"; print "README information.\n\n"; print "\n"; exit; } if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { print "Bad request method\n"; } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; if ($FORM{$name} && $value) { $FORM{$name} = "$FORM{$name}, $value"; } elsif ($value) { $FORM{$name} = $value; } } if ($FORM{'action'} eq "sendit") { &check_url; &sendit; &returnhtml; } elsif ($FORM{'action'} eq "refer") { &check_url; &main; } elsif ($FORM{'action'} eq "README") { &readme; } else { &check_url; &main; } sub main { if ($FORM{'url'} eq "") { $sendpage = $ENV{'HTTP_REFERER'}; } else { $sendpage = $FORM{'url'}; } print < $sitename: Email It! EOF ; if ($useheader) { &header; } else { print < EOF ; } print <EmailIt!
EOF ; if ($allowuseredit) { print < EOF ; } else { print < EOF ; } print <
Fill out the form below to email the page you requested
( $sendpage ) to a friend!


Your Friend's Name:
Your Friend's Email Address:
Your Name:
Your Email Address:
Message Subject:
Message:
Message Subject: $FORM{'title'}
Message: Thought you might be interested in reading this article from the Web site of the Committee to Protect Journalists: $sendpage
 
 
EmailIt! $version by UPWS © 2000.
EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; exit; } sub sendit { if (($FORM{'tomail'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) || ($FORM{'tomail'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) || ($FORM{'frommail'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) || ($FORM{'frommail'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) || ($FORM{'toname'} eq "") || ($FORM{'fromname'} eq "") || ($FORM{'message'} eq "") ) { print < $sitename: Email It! : Error EOF ; if ($useheader) { &header; } else { print < EOF ; } print <Email It! : Error
EOF ; if ($allowuseredit) { print < EOF ; } else { print < EOF ; } print <
Missing fields or bad email address(es) detected. Please fix the problem:

Your Friend's Name:
Your Friend's Email Address:
Your Name:
Your Email Address:
Message Subject:
Message:
Message Subject: $FORM{'subject'}
Message: $FORM{'message'}
 
 
EmailIt! $version by UPWS © 2000.
EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; exit; } else { # Open The Mail Program open(MAIL,"|$mailprog -t"); print MAIL "To: $FORM{'tomail'}\n"; print MAIL "From: $FORM{'frommail'} ($FORM{'fromname'})\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; print MAIL "To: $FORM{'toname'}\n\n"; print MAIL $FORM{'message'}; print MAIL "\n\n"; print MAIL "Regards,\n\n"; print MAIL "$FORM{'fromname'}\n\n"; close (MAIL); } if ($sendthankyou) { open(MAIL2,"|$mailprog -t"); print MAIL2 "To: $FORM{'frommail'}\n"; print MAIL2 "From: $adminmail ($adminname)\n"; print MAIL2 "Subject: Thanks for recommending $sitename!\n\n"; if ($customthankyou) { open(LIST,"$path/thankyou.txt"); @thankyou = ; close(LIST); foreach $line(@thankyou) { print MAIL2 "$line"; } print MAIL2 "\n\n"; } else { print MAIL2 "To: $FORM{'fromname'}\n\n"; print MAIL2 "Thanks for forwarding our article.\n\n"; print MAIL2 "Best Regards,\n\n"; print MAIL2 "$adminname\n"; print MAIL2 "$sitename\n"; print MAIL2 "$siteURL\n\n"; } close (MAIL2); } if ($notifyadmin) { open(MAIL3,"|$mailprog -t"); print MAIL3 "To: $adminmail\n"; print MAIL3 "From: $adminmail (EmailIt!)\n"; print MAIL3 "Subject: New Recommendation!\n\n"; print MAIL3 "To $adminname,\n\n"; print MAIL3 "$FORM{'fromname'} ( $FORM{'frommail'} ) has just recommended the page\n\n"; print MAIL3 "$FORM{'url'}\n\n"; print MAIL3 "to $FORM{'toname'} ( $FORM{'tomail'} )\n\n"; print MAIL3 "Yours sincerely,\n\n"; print MAIL3 "EmailIt!\n\n"; close (MAIL3); } } sub returnhtml { #Then print out response page if ($noredirect) { print < $sitename: Email It! : Message Sent! EOF ; if ($useheader) { &header; } else { print < EOF ; } print <Email It! : Message Sent!

Thanks $FORM{'fromname'}! Your message has been sent to $FORM{'toname'}. Click here to return to our homepage.

 

 

EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; } else { print < $sitename: Email It! : Message Sent!

Email It! : Message Sent!

Thanks $FORM{'fromname'}! Your message has been sent to $FORM{'toname'}. Now forwarding you back to the page you emailed...

 

 

EOF ; } exit; } #the following check_referer routine written by Matt Wright. #see copyright notice below. sub check_url { # Localize the check_referer flag which determines if user is valid. # local($check_referer) = 0; # If a referring URL was specified, for each valid referer, make sure # # that a valid referring URL was passed to FormMail. # if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) { $check_referer = 1; last; } } } else { $check_referer = 1; } # If the HTTP_REFERER was invalid, send back an error. # if ($check_referer != 1) { print < $sitename: Email It! : Bad Referer EOF ; if ($useheader) { &header; } else { print < EOF ; } print <Email It! : Bad Referer

The page attempting to access this program resides at $ENV{'HTTP_REFERER'}, which is not allowed to access this program. Any page linking to this program must reside at $ENV{'SERVER_NAME'}.

If you are trying to configure this program to run on your server, view the README file.


EmailIt! $version by UPWS © 2000.
EOF ; if ($usefooter) { &footer; } else { print < 

 

EOF ; } print < EOF ; exit; } } sub readme { print < EmailIt! $version README: EmailIt!
================
Version: $version

Note:
Currently, EmailIt! has only been tested and will only run on Unix systems. EmailIt! will not run on NT (due to the fact that it's email functions currently require sendmail and smtp is not currently supported).

Set-Up:

To set-up the program you only need to edit one file: variables.pl.
Open variables.pl in a text editor and set each variable to suit your webserver environment.
It is commented all the way through so should be self-explanatory..!

Script must be executable: set emailit.cgi to 755, variables.pl and thankyou.txt should all be fine at 644.

If you set \$customthankyou to 1, you need to enter your custom thankyou message for the program to use in the file "thankyou.txt" and upload that to the same directory as the script.
This is the path you specified in variables.pl.
The script will then send your thankyou message instead of the default (provided \$sendthanks is also set to 1!).

To run the program you *must* link to it and access the program via the link. The program is not designed to be accessed directly as the program is based on taking information from a specific page you wish to be sent to it (more secure).

Linking:

Create a link on the pages on your website that you want people to be able to refer to their friends using EmailIt! The link *must* be in the following format:

Whatever

In the above example, replace "/path/to/" with the actual path to EmailIt! on your webserver and replace "Title Of Page To Send" with the title of the page you want to send (strangely enough!).

This is all that's required to link to the program - when a user clicks on that link, the program will get the URL to send and title the message with whatever you have specified in "title".

NOTE:

If you use frames on your site you should not use the above linking method. In the above method, the URL of the page to send is taken from the HTTP_REFERER environment variable. If the link is on a page within a frame, there is no way for it to realize it's within a frame so it will send the wrong URL (the URL of just *one* of the frames).
To get around this, when using frames you should link to the program as follows:

Whatever

In the above example, you specify the URL of the page (which should be the frameset itself) so that the program will send the correct URL.

EOF ; exit; } sub header { if (-e "$path/header.txt") { open(HEAD,"$path/header.txt") || &error("can't open $path/header.txt for reading"); @header = ; close(HEAD); foreach $line(@header) { print "$line"; } } else { &error("header.txt does not exist"); } } sub footer { if (-e "$path/footer.txt") { open(FOOT,"$path/footer.txt") || &error("can't open footer.txt for reading"); @footer = ; close(FOOT); foreach $line(@footer) { print "$line"; } } else { &error("footer.txt does not exist"); } } sub error { my $error_msg = shift; print <
$error_msg EOF ; exit; } #Contains elements adapted from FormMail by Matt Wright ############################################################################## # FormMail Version 1.6 # # Copyright 1995-1997 Matt Wright mattw@worldwidemart.com # # Created 06/09/95 Last Modified 05/02/97 # # Matt's Script Archive, Inc.: http://www.worldwidemart.com/scripts/ # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1995-1997 Matthew M. Wright All Rights Reserved. # # # # FormMail 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 # # code you agree to indemnify Matthew M. Wright from any liability that # # might arise from its 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 # ##############################################################################