#!/usr/local/bin/perl # QNDstat - quick and dirty access log daily summariser, (c) John Blackburne, johnb@hk.super.net, 1995 # version 1.2, 1 Oct 1995 # See http://www.hk.super.nwt/~johnb/qndstat.html for docs $log = "/hk/httpd/httpd_access_log"; # log file to be processed $passwd = "/etc/passwd"; # unix password file $html_dir = "/u4/bwijoh00/johnb/public_html/"; # directory in which stats pages will be created $daily_file = 'daily_hits.html'; # name of file for daily stats $monthly_file = 'monthly_hits.html'; # name of file for monthly stats $saved_records = "/u4/bwijoh00/johnb/progs/rec_save"; # (any old) file used to save cumulative monthly totals $server_name = "Supernet"; # the name of the server or service provider # comment out the next two lines if graphs not desired. $daily_bar = "/~johnb/icons/bar1.gif"; # The bars for the graphs. Can be absolute or relative URLs or just file names of files $monthly_bar = "/~johnb/icons/bar2.gif"; # ...files in the same directory as the html pages produced. Just about any graphics will do. ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time - (18 * 3600)); ($mname) = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")[$mon]; ($dname) = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")[$wday]; $ss = "$mday/".(substr ($mname, 0, 3)); ($ss =~ /^\d\//) && ($ss = '0'.$ss); open (LOG, $log) || die "Can't open httpd log file"; print $ss /\[$ss.*\/(%7E|~)([a-zA-Z0-9_+\-.]*)\/[\/\w]*(|.html?)\s.*\s\d+$/o && $u{$2}++ while ; #isn't perl fun ! close LOG; if ($mday != 1 && -e $saved_records) { open (SAVED, $saved_records) || die "Can't open archive file to read from"; @temp = split(/:/,); $old_month = shift(@temp) if ($temp[0] =~ /hits\.html$/); %m = @temp; close SAVED; } if ($mday == 1) { $old_month = "$mname${year}hits.html"; rename("$html_dir$monthly_file","$html_dir$old_month"); } foreach $w (keys %u) { $m{$w} += $u{$w}; } open (SAVED, ">$saved_records") || die "Can't open archive file to write to"; @temp = %m; unshift (@temp,$old_month) if defined ($old_month); print SAVED join (':',@temp); close SAVED; open (PASSWD, $passwd) || die "Cant open password file"; while () { ($id, $id2, $uid, $gid, $fname) = split (/:/); if (defined $m{$id}) { $fname =~ s/,.*//; $n{$id} = $fname; $n{$id} = substr($n{$id},0,25).' ...' if (length ($n{$id}) > 29); } } $old_str = defined($old_month) ? ", or click here to see last months stats" : ''; open (HTML, ">$html_dir$monthly_file") || die "Can't create the monthly access count"; print HTML <<"EOM"; $server_name Hits Count for $mname 19$year

$server_name Hits Count

  This page tracks the number of hits on all $server_name users' Web pages, sorted by the number of hits logged, so far during $mname. There is also a page tracking hits day by day$old_str. EOM print HTML ((defined($monthly_bar)) ? "\n" : "
    \n"); foreach $w (reverse sort byval keys %m) { if (defined($monthly_bar)) { $monthly_max = $m{$w} if ! defined ($monthly_max); $width = int(250 * $m{$w} / $monthly_max); print HTML "
\n" if defined $n{$w}; } else { print HTML "
  • $n{$w} ($w)   $m{$w}\n" if defined $n{$w}; } } print HTML ((defined($monthly_bar)) ? "
  •   $n{$w} ($w)   $m{$w}
    \n" : "\n"); &html_tail; close HTML; open (HTML, ">$html_dir$daily_file") || die "Can't create the daily access count"; print HTML <<"EOM"; $server_name Hits Count for $mname $mday 19$year

    $server_name Hits Count

      This page tracks the number of hits on all $server_name users' Web pages, sorted by the number of hits logged, on $dname, $mname $mday 19$year. There is also a page recording hits during the whole of $mname to date. EOM print HTML ((defined($daily_bar)) ? "\n" : "
      \n"); foreach $w (reverse sort byval2 keys %u) { if (defined($daily_bar)) { $daily_max = $u{$w} if ! defined ($daily_max); $width = int(250 * $u{$w} / $daily_max); print HTML "
    \n" if defined $n{$w}; } else { print HTML "
  • $n{$w} ($w)   $u{$w}\n" if defined $n{$w}; } } print HTML ((defined($daily_bar)) ? "
  •   $n{$w} ($w)   $u{$w}
    \n" : "\n"); &html_tail; close HTML; exit; sub byval { $m{$a} <=> $m{$b}; } sub byval2 { $u{$a} <=> $u{$b}; } sub html_tail { print HTML <<"EOM";
      Note: the links will not work if a user does not have an accessible home/index page.
    Page created by QNDstat. EOM }