#!/usr/bin/perl -w # # Web front end for ExtractEmail (Extract emails from sendmail logs) # Todd A. Lyons # Rev 0 -- 03/13/06 # License: GPLv2 use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $parameters; # # Returns text string of header html. # sub genHeader { my ($username) = @_; my $body; $body .= CGI::header . "\n"; $body .= CGI::start_html(-title => "Searching Email Logs") . "\n"; my $intro = ''; if ( $username ) { # Do some funky stuff to make the title appear properly. $intro = "for "; } $body .= "

  Searching Email Logs " . $intro . $username . "

"; return $body; } # # Returns text string of javascript code. # sub genJavascript { my $body; $body = " "; return $body; } # # # sub genSearchHeader { my $body = "
Patience! It normally takes a little over a minute to search through a full week's logs.
"; return $body; } # # Returns text string of search results. # sub genSearchResults { my ($username,$age) = @_; my $cliopts = ''; if ( $parameters->{today} ) { $cliopts .= " --date=today"; $age = "maillog"; } if ( $parameters->{yesterday} ) { $cliopts .= " --date=yesterday"; $age = "maillog"; } my $results = `/usr/bin/nice /usr/local/bin/extractemail.pl $cliopts --email=$username --logfile=/disk1/log/$age`; my $body = "
 
                " . CGI::escapeHTML($results) . "
                
"; return $body; } # # Returns text string of main body html form. # sub genForm { my ($username) = @_; my $formhref = CGI::url(-absolute=>1); my $body; $body = "
 
Recipient Email Address:
How long ago:
This week
Last week
2 weeks ago
3 weeks ago
4 weeks ago
5 weeks ago
6 weeks ago
Show only today
Show only yesterday

        Clear form
 
"; return $body; } # # Returns footer html. # sub genFooter { my $body; $body = CGI::end_html; return $body; } foreach my $param ( param() ) { $parameters->{$param} = param($param); } my $username = $parameters->{username} || ''; print genHeader($username); print genJavascript(); # If user didn't select how long ago, but did check today or yesterday, # set the age manually. if ( ! $parameters->{age} and ( $parameters->{today} or $parameters->{yesterday} ) ) { $parameters->{age} = "maillog"; } if ( $parameters->{send} and $parameters->{age} and $username ) { print genSearchHeader(); print genSearchResults($username,$parameters->{age}); print genForm($username); } else { print genForm($username); } print genFooter();