#!/usr/local/bin/perl

require "/afs/unc/proj/wwwc-f95/lib/cgi-lib.pl";

print &PrintHeader;
print "<H2>JBS WWW Access Report</H2>\n";
print "<hr>\n";

print "<h3>Access Counts</h3>\n";
print "<DL>\n";
dbmopen(%counters, "/afs/unc/home/jbs/public_html/counts/counters", 0777);
while (($key, $value) = each(%counters)) {
print "<DT>$key<DD>$value\n";
}
print "</DL>\n";
dbmclose(%counters);

print "<hr><h3>Access Locations</h3>\n";
open(LOGFILE, "<../counts/logfile");
while (<LOGFILE>) {
chop;
($file, $host, $date) = split(/\;/, $_);
@parts = split(/\./, $host);
$net_host = pack('C4', @parts);
@net_info = gethostbyaddr($net_host,'1');
$host = $net_info[0];
$line = "$file\;$host\;$date"; 
push (@table, $line);
}

@sorted_table = sort(@table);

  # process first item
$line = @sorted_table[0];
($file, $host, $date) = split(/\;/, $line);
$last_file = $file;
$last_host = $host;
print "<OL>\n";  # start file list
print "<LI>$file\n";
print "<OL>\n";  # start host list
print "<LI>$host\n";
print "<OL>\n";  # start date list
print "<LI>$date\n";

  # Process rest of date
for ($i = 1; $i <= $#sorted_table; $i++) {
$line = $sorted_table[$i];
($file, $host, $date) = split(/\;/, $line);

if ($file ne $last_file) {  # new file
	$last_file =  $file;
	print "</OL>\n";  # end of date list
	print "</OL>\n";  # end of host list
	print "<LI>$file\n";
	print "<OL>\n";   # new host list
	print "<LI>$host\n";
	print "<OL>\n";   # new date list
	print "<LI>$date\n";
	}
	
	else {  # same file
		if ($host ne $last_host) {  # new host
			$last_host = $host;
	 	        print "</OL>\n";  # end date list
			print "<LI>$host\n";
			print "<OL>\n";   # new date list
			print "<LI>$date\n";
			}

		else {  # same host
			print "<LI>$date\n";
			}
		} # end same file
} # end $i loop

print "</OL>\n";  # end date list
print "</OL>\n";  # end host list
print "</OL>\n";  # end file list

close(LOGFILE);

