#!/usr/bin/perl # Modified to handle multiple pages: Adam J. Griff, Ph.D. (griff@comptuer.org) # This is a companion program to the "counter.xbm" script. # When invoked, it responds with some HTML that it builds on # the fly that give usage statistics. # This script was written by Michael Morse (mmorse@nsf.gov) at # the National Science Foundation. Feel free to modify and use # it any way you wish. You will certainly have to modify # initialize(), since most of the NSF-specific stuff is there. # Also, createHTML() has some more NSF-specific stuff (like my # address!), that you'll want to change. # REQUIRED CHANGES # Modified by Griff to handle multiple pages. # Just call the counter followed by a ?unique_page_name. # Change the directory path for $serverRoot in the init procedure to the # path on your server # for example $serverRoot = "/home/www/htdocs" use POSIX; use NDBM_File; &initialize; &getDate; &getNumbers; &createHTML; exit(0); sub initialize { $serverRoot = "/home/www/www.griffmonster.com/htdocs"; $port = $ENV{SERVER_PORT}; $pagename = $ENV{QUERY_STRING}; $forString = $pagename; $theString = $pagename; $logFiles = "$serverRoot/logs/counter"; $dbmFile = "$serverRoot/logs/hosts"; $counterFile = "$logFiles.$pagename.txt"; $hostsFile = "$logFiles.$pagename.hosts.txt"; } sub createHTML { print<Usage Statistics for $forString

Usage Statistics for $forString


Numbers That May Interest You

As of now ($date)
The odometer counter was adapted and enhanced by Adam J. Griff, Ph.D. from a similar program used at NASA Langley Research Center. EOMEOM print "

Unique visitors

"; print "\n"; } untie(%HOSTS); print "
", $key, "", $HOSTS{$key} , "
\n"; } sub sortNumAlpha { if ($HOSTS{$b} eq $HOSTS{$a}) { $a cmp $b; } else { $HOSTS{$b} <=> $HOSTS{$a}; } } sub getNumbers { open(COUNTERFILE,"<$counterFile") || die "$0: can\'t open $counterFile: $!\n"; $count = ; chop $count; close(COUNTERFILE); open(COUNTERFILE,"<$hostsFile") || die "$0: can\'t open $hostsFile: $!\n"; $hosts = ; chop $hosts; close(COUNTERFILE); $host_addr = $ENV{REMOTE_ADDR}; if (defined $ENV{REMOTE_HOST}) { $host = $ENV{REMOTE_HOST}; } else { open(TEMP, "/usr/bin/host $host_addr 2>&1|"); while ((!defined $host) && ($temp = )) { if ($temp =~ /domain name pointer\s*(\S*)\./) { $host = $1; } } close (TEMP); } ($host = $host_addr) if (!defined $host); tie(%HOSTS, 'NDBM_File', "$dbmFile.$pagename", 1, 0); $you = $HOSTS{$host}; untie(%HOSTS); $count =~ s/^0+//; $hosts =~ s/^0+//; $you =~ s/^0+//; } sub getDate{ @month_names = ("January","February","March","April","May","June", "July","August","September","October","November","December"); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $date = sprintf("%s $mday, %04d, $hour:%02d",$month_names[$mon],($year+1900),$min); }