Monks,
I have a CGI program that is used to produce custom reports from our firewall logs. These reports sometimes take 30-60 min to produce. I configured Apache so the browser won't timeout while creating the report. This program also uses some system utilities to create the report so it's not all Perl based. I would like a way to let the user know the status of the report being generated. I have read Merlyn's Webtechnique
article, but I'm having a hard time trying to implement this into my program. I was thinking about trying to guess how long the script will take from the users values and keep refreshing this number. Does anyone have any suggestions? Here is a summary of the action script:
#!/usr/bin/perl -w
use strict;
# 'taint' in the import list is currently a no-op. See the documentat
+ion
use CGI::Carp 'fatalsToBrowser';
use CGI::Safe qw/:standard taint/;
use Mail::Sender;
my $summary = param( 'summary' ) || '';
my $num_sites = param( 'websites' ) || '';
my $ip = param( 'ip' ) || '';
...
my (@days,$string,$result,$sender,$src,$direct);
my $dir = "/var/tmp";
my $header = "$dir/header";
my $output = "$dir/output";
# Delete the output file if it exist
unlink $output;
# Run the subroutines
&check_email();
&display_page();
# Delete the output file once we are done
unlink $output;
exit;
sub check_email {
# Make sure the user enters a company email address.
if ($email =~ /([.\w]+)(\@acme+\.com$)/) {
&do_work();
} else {
die "$email is not a valid email address. Please try again.\n";
}
}
sub do_work {
# Copy the 1st line from the log files which is necessary for fwlog
+sum
open (IN,"$header") or die "can't open file $header: $!";
open (OUT,">$output") or die "can't open file $output: $!";
while (<IN>) {
print OUT $_;
}
# Add each day to an array
$string = "$month1" . "$year";
@days = ($day1 .. $day2);
@days = map {$_ .= "$string"} @days; # add the month and year to ea
+ch day
if ($summary eq 'yes') {
if ($direction eq 'inbound') {
...
}
}
elsif ($direction eq 'outbound') {
....
}
}
elsif ($summary eq 'no') {
...
}
elsif ($direction eq 'outbound') {
...
}
close (IN);
close (OUT);
my $fwlogsum = "/usr/local/bin/fwlogsum -ra -w -sc -bo -T -l $outpu
+t -o /exported/web-usage/$report.html";
my $fwlogsum_sum = "/usr/local/bin/fwlogsum -ra -w -sc -bo -T -S -P
+ $num_sites -l $output -o /exported/web-usage/$report.html";
my $fwlogsum_sum_dns = "/usr/local/bin/fwlogsum -ra -w -sc -bo -C -
+T -R -S -P $num_sites -l $output -o /exported/web-usage/$report.html"
+;
my $fwlogsum_dns = "/usr/local/bin/fwlogsum -ra -w -sc -bo -C -T -R
+ -l $output -o /exported/web-usage/$report.html";
if ($dns eq 'yes' && $summary eq 'yes') {
$result = `$fwlogsum_sum_dns`;
} elsif ($dns eq 'yes' && $summary eq 'no'){
$result = `$fwlogsum_dns`;
} elsif ($dns eq 'no' && $summary eq 'yes'){
$result = `$fwlogsum_sum`;
} else {
$result = `$fwlogsum`;
} #end else
mail();
}
sub mail {
...
}
sub display_page {
my $message = shift;
print
header,
start_html( "-title" => "Results Page"),
p(" "),
p( strong("Mail Sent Ok") ),
end_html;
}
Thanks,
Dru
Another satisfied monk.