#!/usr/bin/perl ############################################################################### ## ## The URL Access Notifier ## ## This CGI will send an e-mail when it will be accessed ## It is good to be called like an image from inside a web page this way: ## ## ## ## ## ## Distributed under the terms of the GPL as found at ## ## http://www.gnu.org/licenses/gpl.txt ## ## ## This software home page: ## ## http://avi.alkalay.net/software/notify/ ## ## ## ## Copyright (C) 2001 by Avi Alkalay ## ## Avi Alkalay ## ## 19 Aug 2001 ## Made in Brazil ## ## ## Changelog ## ## * Sat Sep 22 06:18:01 BRST 2001 Avi Alkalay ## - 1.91 ## - Added 'redirect' support ## * Sun Aug 19 2001 Avi Alkalay ## - 1.9 ## - First public clean release ## use strict; use CGI qw(:push :standard :cgi); $|=1; my $defaultTo="aviram\@yahoo.com"; #my $defaultTo="aviram\@br.ibm.com"; my $defaultFrom="notifier\@alkalay.net"; my $signature="URL Access Notifier"; my $version="1.91"; my $home="http://avi.alkalay.net/software/notify/"; ############################################################################### ## ## getCGIContext ## ## Uses the CGI.pm library to get parameters passed via the form or URL. ## Returns a hash containing the values needed by the program. ## ############################################################################### sub getCGIContext { my $query=new CGI; my %input; $input{time}=localtime(); $input{remoteHost}=$query->remote_host(); $input{virtualHost}=$query->virtual_host(); #$input{referer}=$query->referer(); $input{referer}=$query->param('referer'); $input{userAgent}=$query->http('User-agent'); $input{identifier}=$query->param('id'); $input{to}=$query->param('to'); $input{from}=$query->param('from'); $input{redir}=$query->param('redir'); if ($input{referer} eq "") { $input{referer}=$query->referer(); } if ($input{referer} eq "") { $input{referer}="Direct Access"; } if ($input{identifier} eq "") { $input{identifier}=join(" ",@ARGV); } if ($input{to} eq "") { $input{to}=$defaultTo; } if ($input{from} eq "") { $input{from}=$defaultFrom; } # Calculate a very simple hash to get the cookie $input{hash}=$input{identifier}; $input{hash}=~s/[ \.]//g; $input{times}=$query->cookie(-name=>"notify.$input{hash}"); if ($input{identifier}) { $input{times}+=1; $input{cookie}=$query->cookie(-name=>"notify.$input{hash}", -value=>$input{times}, -domain=>$input{virtualHost}, -expires=>'+3y', -path=>"/"); } return %input; } ############################################################################### ## ## sendMIMEEmail ## ## Build and send a MIME message ## ############################################################################### sub sendMIMEEmail { my (%cgiContext)=@_; my $SENDMAIL="/usr/sbin/sendmail -t"; #my $SENDMAIL="/tmp/log -t"; my $boundary="____________________" . rand(); $boundary=~s/\.//g; open(MAIL,"| $SENDMAIL -f \"$cgiContext{from}\""); print MAIL <$nameSize); } foreach $var (sort(keys(%ENV))) { #$tempOut=" " x $nameSize-length($var),"$var=$ENV{$var}\n"; $output=join("",$output," " x ($nameSize-length($var)),"$var=$ENV{$var}\n"); } $output=join("",$output,< $home EOF return $output; } ############################################################################### ## ## genHTMLOutput ## ## Creates the report in HTML format ## ############################################################################### sub genHTMLOutput { my (%cgiContext)=@_; my $output; my $tempOut; my $var; $output=< Notify URL Access Notify


The resource identified by "$cgiContext{identifier}" was accessed.

Access information:
Access time: $cgiContext{time}
User Remote Host: $cgiContext{remoteHost}
Times this user
accessed this resource:
$cgiContext{times}
User Agent signature: $cgiContext{userAgent}
User came from: $cgiContext{referer}
User redirected to: $cgiContext{redir}
Virtual Host: $cgiContext{virtualHost}


Other HTTP Session environment variables:
EOF foreach $var (sort(keys(%ENV))) { $tempOut=< EOF $output=join("",$output,$tempOut); } $output=join("",$output,<
$var = $ENV{$var}

$signature $version by Avi Alkalay <avi at alkalay.net>
$home
EOF return $output; } ############################################################################### ## ## Main block ## ## Just call above functions in a special order. ## ############################################################################### # Get the parameters pre-processed by CGI.pm my %cgiContext=getCGIContext(); if ($cgiContext{redir} eq "") { print header(-type=>"image/gif",-cookie=>$cgiContext{cookie},-size=>0); } else { print redirect($cgiContext{redir}); } sendMIMEEmail(%cgiContext); close(STDOUT);