#!/usr/bin/perl
$scriptname = "MailPage";
$version = "2.0";
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("$ENV{'HTTP_USER_AGENT'}");
use CGI::
Carp qw(fatalsToBrowser
);
# Provides you with fatal error message if they occur.
my $email = 'info@your_site.com'; #THIS WILL BE THE SENDER'S ADDRESS
main: {
&getinput;
&GetCookies;
if (lc $FORM{'action'} eq
"send") { &getbase
($FORM{'url'}); &send;
} elsif (lc $FORM{'action'} eq
"privacy") {&privacy;
} else { &moreinfo }
}
sub moreinfo {
$FORM{'url'} = $ENV{'HTTP_REFERER'} unless $FORM{'url'};
if ($FORM{'url'} !~
m/^http/
) { $FORM{'url'} =
$ENV{'HTTP_REFERER'};
}
print "Content-type: text/html\n\n";
&pageheader("Email Hits");
foreach $line (@temptoken) {
if ($line =~
m/
$token/i
) { <form action="$ENV{'SCRIPT_NAME'}" method="post">
<input type="hidden" name="action" value="send">
<input type="hidden" name="url" value="$FORM{'url'}">
<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 >
<TR>
<TD>Recipient's Email address<input type="text" name="recipientemail"></TD>
<td><INPUT TYPE="submit" VALUE="SEND"></td>
</TR>
</TABLE>
</BLOCKQUOTE>
</form>
~;
}
print "$line";
}
&powered_by("nologout");
exit;
}
sub send {
&check_email($FORM{'senderemail'});
&send_body;
print "Content-type: text/html\n\n";
&pageheader("Send!");
foreach $line (@temptoken) {
if ($line =~ m/$token/i) {
print qq~
<h2>Sent!</h2>
The email has been sent to $FORM{'recipient'}. Please click the back button below to return to the page you were before.<p>
<center><FORM><INPUT type="button" value="Back" onClick="history.go(-2)"></FORM></center>
~;
}
print "$line";
}
&powered_by("nologout");
$JUMP_TO = $ENV{'HTTP_REFERER'};
exit;
}
sub send_body {
$req = new HTTP::Request 'GET' => $FORM{'url'};
$res = $ua->request($req);
if ($res->is_success) {
#print "Content-type: image/gif\n\n";
#print $res->content;
open MAIL, "$mailprog" || die "Cannot open $mailprog so I cannot send email";
print MAIL "To: $FORM{'recipientemail'}\n";
print MAIL "From: $email\n";
print MAIL "Subject: Info Centres Advertisement Stats\n";
print MAIL "Content-type: text/html\n\n";
foreach $line ($res->content) {
if ($line =~ /\<body/ig) { $line =~ s/<body(.*?)\>/\<body $1\>$header/ig;}
if ($line =~ /\<head/ig) { $line =~ s/<head>/<head><base href=\"$base\">/ig;}
print MAIL $line;
}
close MAIL;
}
else {
&send_plain;
}
}
sub privacy {
print "Content-type: text/html\n\n";
&pageheader("Privacy Policy");
foreach $line (@temptoken) {
if ($line =~ m/$token/i) {
print qq~
<h2>Privacy Policy</h2>
~;
open FILE, $privacy_file || die "Cannot open $privacy_file";
flock(FILE, 2) if $use_flock;
@lines = <FILE>;
flock(FILE, 8) if $use_flock;
close FILE;
print @lines;
}
print "$line";
}
&powered_by("nologout");
}
sub getbase {
local($baseurl) = @_;
if ($baseurl =~ /\.html?$/i) {
@items = split(/\//,$baseurl);
$n = scalar @items;
$n--;
for($i=0;$i<$n;$i++) {
$base .= @items[$i] . "/";
}
}
else { $base = $baseurl; }
}
sub errors {
local($errors) = @_;
&expires_header("now");
print "Content-type: text/html\n\n";
&pageheader('An error occured');
foreach $line (@temptoken) {
if ($line =~ m/$token/i) {
if ($errors eq 'with the email address you gave') {
print qq~
<h2>Invalid email address</h2>
The following email address is invalid: $invalidmail<br>
Please press the back button and try again.
~;
}
# If the error type was not found:
else {
print qq~
Error Undefined! Please contact <a href="mailto:$email?subject=Error_Undefined">$webmasteremail</a> and be detailed in what you did what caused the error.
~;
}
# Back button:
print qq~
<center><FORM><INPUT type="button" value="Back" onClick="history.go(-1)"></FORM></center>
~;
}
print "$line";
}
&powered_by("nologout");
$JUMP_TO = $ENV{'HTTP_REFERER'};
exit; # Exit the script when an error occured.
}