#!/usr/bin/perl # script to count accesses to top level directory # and then redirect to a known place in the web tree # data is stored in a dbm file keyed by path and number of # accesses. use strict; use Fcntl; use NDBM_File; my $dbm = "/mount/www/logs/eventaccess"; my $dbmlock = "/mount/www/logs/eventaccess.lock"; exit(0) unless(defined($ENV{SCRIPT_NAME}) and defined($ENV{SERVER_NAME})); my $path = $ENV{SCRIPT_NAME}; $path =~ s,/+,/,g; $path =~ s/\/index.html$//; # the toplevel name in the path is assumed to be the # conference name. my @pathlist = split /\//,$path; my $event = $pathlist[0]; # the path may start with / $event = $pathlist[1] if ($event eq ""); my $server = $ENV{SERVER_NAME}; my $http = "http"; if ($server =~ m/db.usenix.org/) { $http = "https"; } # lock things sysopen LOCKF, $dbmlock,&O_CREAT|&O_RDWR, 0664; flock LOCKF, 0x2; my %db; tie %db, 'NDBM_File', $dbm, &O_RDWR|&O_CREAT, 0777; my $ti = time(); my @line = (); # line is count:starttime:thistime if (defined($db{$path})) { @line = split /:/, $db{$path}; $line[0]++; $line[2] = $ti; } else { $line[0] = 1; $line[1] = $ti; $line[2] = $ti; } $db{$path} = join(":", @line); untie %db; flock LOCKF, 0x8; close LOCKF; print "Location: $http://$server/events/$event/index.html\n\n"; exit 0;