#!/usr/bin/perl use Time::Local; use CGI::Carp qw(fatalsToBrowser); use vars qw(%config %form %02d); local %config; $font = ''; $file = './weblog.log'; $root = 'nixnut.nz'; $config{'nztime'} = '12'; require "./seconds.cfg"; require "./howmany.cfg"; local %form = &get_form_data; print "Cache-control: no-cache\nPragma: no-cache\nContent-type: text/html\n\n"; if ($form{'action'} eq '') { &display; } elsif ($form{'action'} eq 'seconds') { &seconds; } elsif ($form{'action'} eq 'howmany') { &howmany; } else { &display; } ########## this below has no effect use File::ReadBackwards ; # Object interface $bw = File::ReadBackwards->new( '$file' ) or die "can't read '$file' $!" ; while( defined( $log_line = $bw->readline ) ) { print $log_line ; } # ... or the alternative way of reading until ( $bw->eof ) { print $bw->readline ; } # Tied Handle Interface tie *BW, 'File::ReadBackwards', '$file' or die "can't read '$file' $!" ; while( ) { print ; } ########## ########## sub display { @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); @months = ('January','February','March','April','May','June','July','August','September','October','November','December'); ($sec,$min,$hour,$mday,$mon,$year,$wday) = (gmtime(time + $config{'nztime'}*3600))[0,1,2,3,4,5,6]; $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec); $year += 1900; if ($hour eq "12") { $hour = "12"; $pm = "y"; } if ($hour eq "13") { $hour = "1"; $pm = "y"; } if ($hour eq "14") { $hour = "2"; $pm = "y"; } if ($hour eq "15") { $hour = "3"; $pm = "y"; }if ($hour eq "16") { $hour = "4"; $pm = "y"; } if ($hour eq "17") { $hour = "5"; $pm = "y"; } if ($hour eq "18") { $hour = "6"; $pm = "y"; } if ($hour eq "19") { $hour = "7"; $pm = "y"; } if ($hour eq "20") { $hour = "8"; $pm = "y"; } if ($hour eq "21") { $hour = "9"; $pm = "y"; } if ($hour eq "22") { $hour = "10"; $pm = "y"; } if ($hour eq "23") { $hour = "11"; $pm = "y"; } if ($hour eq "24") { $hour = "12"; $pm = "n"; } $time = sprintf("%02d:%02d",$hour,$min); $tdate = "$days[$wday], $months[$mon] $mday, $year"; $mon = $mon + 1; if ($pm eq "y") { $tm = "am"; # pm swapped to allow gmt in script (not needed anyway) } else { $tm = "pm"; # am swapped to allow gmt in script (not needed anyway) } &oops('cant open seconds') unless (open(SECONDS, "seconds.cfg")); ($form{'seconds'}) = ; close SECONDS; &oops('cant open howmany') unless (open(HOWMANY, "howmany.cfg")); ($form{'howmany'}) = ; close HOWMANY; print "Tracking for $root"; print "\n\n$tdate
\n"; open (FILE, "tail -$form{'howmany'} $file | tail -$form{'howmany'} |") or die "Opening $file: $!"; while () { chomp; s/^\"//; s/\"$//; my ($date, $user, $host, $page, $browser) = split(' ', $_); print "\n"; } close (FILE); print "
$font Time$font User$font Host$font Page $font Browser
$font $date$font $user$font $host$font $page $font $browser
"; print ""; print ""; print ""; print ""; print ""; print ""; print "
$font Last refresh: $time
$fontRefresh rate:
$font\# of entries:
"; print ""; exit; } #-##################### Sub: change refresh sub seconds { $form{'seconds'} = $seconds if !($form{'seconds'}); &oops('cant open file.') unless (open SECONDS, ">seconds.cfg"); print SECONDS "$form{'seconds'}"; close SECONDS; &display; } #-##################### Sub: change howmany sub howmany { $form{'howmany'} = $howmany if !($form{'howmany'}); &oops('cant open file.') unless (open HOWMANY, ">howmany.cfg"); print HOWMANY "$form{'howmany'}"; close HOWMANY; &display; } #-##################### Sub: Get Form Data This gets data from a post. sub get_form_data { my $temp; my $buffer; my @data; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); foreach $temp (split(/&|=/,$buffer)) { $temp =~ tr/+/ /; $temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; $temp =~ s/[\r\n]/ /g; push @data, $temp; } foreach $temp (split(/&|=/,$ENV{'QUERY_STRING'})) { $temp =~ tr/+/ /; $temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; $temp =~ s/[\r\n]/ /g; push @data, $temp; } return @data; }