#!/usr/local/bin/perl # The Complete Web Master - CGI - Doug Steinwand # October 28, 1997 - CGI Version of Access Summary # # Parses a server log and displays a bar chart # showing the number of requests from each host name # # Note: Bar chart works in newer browsers only. # (Netscape 3+ and MSIE 3+) # # path and name to your web server's log file: $logfile="access_log"; # color for the bar chart: $bclr="#ff0000"; # read the access log, putting each # host name into a hash open F, $logfile or die "Cannot open $logfile: $!\n"; while () { # remove \n from end chomp; # find the host name ($h,$junk)=split(/\s/,$_,2); # skip blanks next unless length $h; # count it $hosts{$h}++; # find top-level domain $h=~/^.+\.(.+?)$/; # store unless it's an IP address $domains{$1}++ unless $1 > 0; } close F; # print the header print "Content-type: text/html\n\n"; # display the domain chart bar_chart("Access By Top-Level Domain", \%domains); # display full host name bar_chart("Access By Individual Hosts", \%hosts); exit 0; # displays a bar chart with a title sub bar_chart { my($title, $hash)=@_; my($max,$bar,$bbb); # find the maximum $max=1; foreach (values %$hash) { $max=$_ if $max < $_; } # display the bar chart print "

$title

"; foreach (sort keys %$hash) { # calculate bar width $bar=int(100*$$hash{$_}/$max); $bbb=100-$bar; print < EOT } print "
$_ $$hash{$_}
   
"; }