summaryrefslogtreecommitdiff
path: root/iceaccessd
blob: 4fd4e1fad57d367d225709d36674c2353c34161b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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
      ([\w\-]+)\  #identd!! 
      ([\w\-]+)\  #authname
      \[(\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 ) =
      (    $4,   $5,    $6,     $7,   $8,   $9,   $10 );

    my $mountpoint = $11;
    my $status = $12;
    my $bytes = $13;
    my $referer = $14;
    my $useragent = $15;
    my $seconds = $16;

    $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);
}