#!/usr/bin/perl ############################################## ############################################## # SCRIPT NAME: Page_Web_Log_Reader.cgi # FUNCTION: summarize the web log ############################################## # MINE: Molecular INformation Explorer # Copyright 2000 Dawn Field. All rights reserved. # The CGI-PERL scripts belonging to MINE # may be used and modified freely, but I do # request that this copyright notice remain attached # to this file/source code. If you make modifications # please do not distribute unless # you fully document the modifications. use CGI; require "CGI-MINE.pl"; ################# # START EACH MINE CGI SCRIPT ################# # this redirects the error messages to the user's screen # and is useful for debugging CGI scripts! open (STDERR, ">&STDOUT"); # print errors to screen $| = 1; # flush the print buffer continuously # make a new query object using CGI.pm module $query = new CGI; # print the required header and start the web page print $query->header; print $query->start_html('MINE'); # Each time a script is invoked for the first time (or $action undef), # log the visit in the custom MINE server log (see CGI-MINE.pl) # (put this after the header incase an error message is printed) # check value of $action $action = $query->param('action'); if ($action eq undef) {&log();} END { &table_bottom(); } ####### # START THE WEBPAGE ####### # print the MINE menu &menu; # start the basic gray table used for formatting MINE pages &table_top(); # put the main title of your page here print "Usage Summary
"; print "This is a sample utility script to show how you could use PERL to summarize the information logged in the MINE web log (log_archive_file).
";
# initialize some variables
%seen_script = (); # a hash to keep track of each script
%seen_user = (); # a hash to keep track of each IP-machine name
%seen_domain = (); # a hash to keep track of domain at the end of each machine name (e.g. .edu)
# read the contents of the web log (made by &log() function in CGI-MINE.pl
open (IN, "log_archive_file");
while ($line = ";
# PRINT SCRIPT USAGE HASH
print "Script Usage Summary: _____________ $total_seen";
undef($total_seen);
undef($counter);
print " User Log Summary:
";
++$seen_script{$script};
++$seen_user{"$ip $machine"};
$machine =~/(\.)(\w+)$/;
$domain = ($2);
# sometime the machine name is the IP, and we want to skip those
if ($domain =~ /[0-9]/) { undef ($domain);}
# print "Domain: $domain
";
if ($domain) {++$seen_domain{"$domain"};}
}
# start a table
print "
";
print "";
# PRINT DOMAIN HASH
print " ";
undef($counter);
foreach $motif_type (sort keys %seen_domain) {
$counter++;
print "Distribution by Domain Accessed $counter $motif_type $seen_domain{$motif_type} ";
$total_seen = $total_seen + "$seen_domain{$motif_type}";
}
print "
";
undef($counter);
undef($total_seen);
foreach $motif_type (sort keys %seen_script) {
$counter++;
print "$counter. $motif_type accessed $seen_script{$motif_type} times
";
$total_seen = $total_seen + "$seen_script{$motif_type}";
}
# PRINT USER HASH
print "
";
foreach $motif_type (sort keys %seen_user) {
$counter++;
print "$counter. $motif_type visited $seen_user{$motif_type} times
";
}
# finish the table formatting
&table_bottom();
# PRINT BOTTOM OF EACH WEB PAGE
# if $show_source is set to 1 show a link
# at the bottom of each script to the source
# code - pass the name of this script to the
# function in CGI-MINE.pl
if ($show_source) {
$script_name = $query->script_name();
&source ($script_name);
} # ATTACH the MINE copywrite
&mine_cp;
print $query->end_html;
#################
# END WEBPAGE
#################