diff options
Diffstat (limited to 'iceaccessd')
-rw-r--r-- | iceaccessd | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/iceaccessd b/iceaccessd new file mode 100644 index 0000000..b47e3db --- /dev/null +++ b/iceaccessd @@ -0,0 +1,82 @@ +#!/usr/bin/perl -w +# +# Copyright (c) 2002 Ivan Kohler +# All rights reserved. +# This program is free software; you can redistribute it and/or modify it under +# the same terms as Perl itself. +# +# ivan-icelog@420.am + +use strict; +use vars qw($eof); +#use Date::Parse; +use Time::Local; + +my $c = 0; +my %mon = + map { ( $_ => $c++ ) } qw( jan feb mar apr may jun jul aug sep oct nov dec ); + +$|=1; +$eof=0; + +my( $file, $pos ) = @ARGV; +open(FILE,"<$file") or die "Can't open $file: $!"; +seek(FILE,$pos,0) or die "Can't seek: $!"; + +$SIG{'HUP'} = sub { print "EOF\n"; exit; }; +#$SIG{'HUP'} = sub { $eof=time; }; # set an alarm + +while (1) { + + while (<FILE>) { + next if /^$/; + #rootwood.haze.st - - [24/Dec/2001:15:33:50 -0800] "GET / HTTP/1.0" 200 1388544 "-" "xmms/1.2.5" 89 + /^ + ([\w\-\.]+)\ -\ -\ #hostname + \[(\d{2})\/(\w{3})\/(\d{4}):(\d{2}):(\d{2}):(\d{2})\ -(\d{4})\]\ #date + "GET\ ([\/\w\-\.]+)\ HTTP\/\d\.\d"\ # request string + (\d{3})\ #staus resonse + (\d+)\ #bytes + "([^"]*)"\ #referer + "([^"]*)"\ #user agent + (\d+) #seconds connected + $/xo or do { + die "unparsable line: $_"; + next; + }; + + #warn "ok: $_"; + + my $hostname = $1; + my( $mday, $mon, $year, $hours, $min, $sec, $zone ) = + ( $2, $3, $4, $5, $6, $7, $8 ); + + my $mountpoint = $9; + my $status = $10; + my $bytes = $11; + my $referer = $12; + my $useragent = $13; + my $seconds = $14; + + $SIG{HUP} = sub { $eof=1 }; + print join("\t", + tell FILE, + hostname => $hostname, + start => timelocal($sec, $min, $hours, $mday, $mon{lc($mon)}, $year), + mountpoint => $mountpoint, + bytes => $bytes, + useragent => $useragent, + seconds => $seconds, + ), "\n"; + $SIG{'HUP'} = sub { print "EOF\n"; exit; }; + if ( $eof ) { + print "EOF\n"; + exit; + } + + } + + sleep 1; + seek(FILE,0,1); +} + |