use strict; use warnings; use Date::Manip; use CGI qw/:standard/; # Make sure security is not compromised by calling unpathed programs. $ENV{PATH} = "/bin:/usr/bin:/usr/local/bin:"; $ENV{IFS}=""; # Use CGI to print the header print header; # Make variables local only my %referers = (); my $row = 0; my $counter = 0; # Retrieve and security-check parameters my $site = param('site'); my $hour = param('hour'); my $minute = param('minute'); if ($hour !~ /^\d\d?$/) { die('Invalid hour'); } if ($minute !~ /^\d\d?$/) { die('Invalid minute'); } # Get date object for the checkpoint my $check_date = ParseDate("${hour}hours ${minute}minutes ago"); # Select the server log - current 12/19/02 my $data = ''; if ($site eq 'star') {$data = 'indystar/access_log'} elsif ($site eq 'topics') {$data = 'topics/access_log'} else {$data = 'noblesville/access_log'} # Create headline for web page print "

Referrers in the past $hour hours and $minute minutes

"; # File handling, one line at a time; if can't open, say why open(FH,"$data") || die('Could not open $data: $1'); while (defined(my $line = ) ) { next if ($line !~ /^\S+ \S \S \[(\S+) \S+\] "[^"]+" \d+ \d+ "([^"]+)"/); my $line_date = ParseDate($1); # Check to see if the line date is in the range we're after next unless Date_Cmp($line_date, $check_date)>0; # If the referer is new, set to 1 entry, otherwise increment if (not exists $referers{$2}) { $referers{$2}=1; } else { $referers{$2}++; } } close(FH); # Sort and print for (sort {$referers{$b} <=> $referers{$a}} keys %referers) { if ($counter <= 10) { open (FILE, ">storage1.txt") || die('Could not open $storage1.txt: $1'); print "$_ - $referers{$_}

"; print FILE "$_ - $referers{$_}

"; ++$counter; } elsif ($counter > 10 && $counter <= 20) { if ($counter == 11) { print "

        Next
"; print FILE "

        Next
"; open (FILE2, ">storage2.txt") || die('Could not open $storage2.txt: $1'); print FILE2 "$_ - $referers{$_}

"; ++$counter; } } elsif ($counter > 20 && $counter <= 30) { if ($counter == 21) { print "

a href=\"storage2.txt\">Previous        Next
"; open (FILE3, ">storage3.txt") || die('Could not open $storage3.txt: $1'); print FILE3 "$_ - $referers{$_}

"; ++$counter; } } elsif ($counter > 30 && $counter <= 40) { if ($counter == 31) { print "

a href=\"storage3.txt\">Previous
"; open (FILE4, ">storage4.txt") || die('Could not open $storage4.txt: $1'); print FILE4 "$_ - $referers{$_}

"; } } } close FILE; close FILE2; close FILE3; close FILE4;