#!/usr/bin/perl -w ############################################################################## # Check the rouchrumble log file # Author: Chris Rouch # Date: 30/09/2003 # Changelog: # Copyright (c) Chris Rouch 2003 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or see http://www.gnu.org/licenses/gpl.txt ############################################################################## use strict; use Getopt::Long; use File::Find (); use Date::Format; # constants use constant OK => 1; use constant TOP=>"/a/www/master"; use constant CFG=>"$ENV{HOME}/.rumble"; use constant SITE=>"www.rouchrumble.org"; use constant LOGDIR=>"/logs"; use constant LOGFILE=>"www.rouchrumble.org.log"; use constant LOCALDIR=>"/tmp"; use constant LOCALFILE=>LOCALDIR . '/'. LOGFILE; use constant HOURSECS=> 60 * 60; use constant DAYSECS=> 24 * HOURSECS; # general global variables use vars qw ($PROG $USAGE $OPTIONS %goodfiles %accessed); # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; # command line variables my $top=TOP; # top dir my $verbose; # make some noise # command line switch my %opts= ( "t|top=s" => \$top, "v|verbose" => \$verbose, ); ($PROG=$0) =~ s!.*/!!; SetUsage(\%opts,\$OPTIONS); $USAGE="Usage: $PROG $OPTIONS"; die "$USAGE\n" unless GetOptions(%opts); # program begins here File::Find::find(\&GetFiles,$top); FetchLog(); GetAccessed(); Compare(); ############### end of main ############# sub FetchLog { # fetch the http log file my ($cmd,$ret); $cmd=sprintf("ncftpget -f %s %s %s/%s",CFG,LOCALDIR,LOGDIR,LOGFILE); $ret=system($cmd); die "$cmd failed - $!\n" unless ($ret == 0); } sub GetFiles { my ($dev,$ino,$mode,$nlink,$uid,$gid,$short); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)); ($short=$name) =~ s!$top!!; $goodfiles{$short}=1 if (-f _); } sub GetAccessed { my ($yesterday,$inc,$url); $yesterday = time2str("%e/%b/%Y",time - DAYSECS); open(L,LOCALFILE) or die "Can't read @{[LOCALFILE]} - $!\n"; while () { chomp; next unless (m!\[$yesterday:!); next unless (m!"GET\s+!); next if (m!GET\s+/\s+!); # ignore requests for top dir ($url=$_) =~ s!^.*"GET\s+(.*)\s+HTTP.*$!$1!; if ($url =~m!/thumbs.php\?title=(.*)\&subtitle=(.*)!) { $inc="/$1-$2.inc"; $accessed{$inc} =1; } $url=~s!.php\?.*$!.php!; # zap any other parameters $accessed{$url} =$_; } } sub Compare { foreach my $file (keys %accessed) { if (!$goodfiles{$file}) { print "Missing $file:\n"; print "\t$accessed{$file}\n\n"; } } } sub SetUsage { my ($ropts,$rstr) = @_; foreach my $key (keys %$ropts) { if ($key =~ /\|/) { $key=~ s!^.*\|!!; } if ($key =~ /=/) { $key =~ s!=.*$! value!; } $key = '-' . $key; $$rstr .= '[' . $key . '] '; } } ############### end of file #############