line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Logfile::Apache; |
2
|
|
|
|
|
|
|
require Logfile::Base; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
@ISA = qw ( Logfile::Base ) ; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub next { |
7
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
8
|
2
|
|
|
|
|
5
|
my $fh = $self->{Fh}; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
|
|
4
|
my ($line,$host,$user,$pass,$rest, |
11
|
|
|
|
|
|
|
$date,$req,$code,$bytes,$file,$proto,$hour); |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
|
|
16
|
while (defined ($line = <$fh>)) { |
14
|
2
|
|
|
|
|
25
|
($host,$user,$date,$rest) = |
15
|
|
|
|
|
|
|
$line =~ m,^([^\s]+)\s+-\s+([^ ]+)\s+\[(.*?)\]\s+(.*),; |
16
|
2
|
50
|
|
|
|
25
|
next unless $rest; |
17
|
2
|
|
|
|
|
10
|
$rest =~ s/\"//g; |
18
|
2
|
|
|
|
|
8
|
($req, $file, $proto, $code, $bytes) = split ' ', $rest; |
19
|
2
|
50
|
|
|
|
6
|
last if $date; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
5
|
return undef unless $date; |
23
|
2
|
|
|
|
|
6
|
$user =~ s/\s+//g; |
24
|
2
|
50
|
33
|
|
|
17
|
$bytes = 0 unless $bytes ne '-' and $bytes>0; |
25
|
2
|
|
|
|
|
18
|
Logfile::Base::Record->new(Host => $host, |
26
|
|
|
|
|
|
|
Date => $date, |
27
|
|
|
|
|
|
|
File => $file, |
28
|
|
|
|
|
|
|
Bytes => $bytes, |
29
|
|
|
|
|
|
|
User => $user, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub norm { |
34
|
0
|
|
|
0
|
0
|
|
my ($self, $key, $val) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if ($key eq File) { |
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$val =~ s/\?.*//; # remove that !!! |
38
|
0
|
0
|
|
|
|
|
$val = '/' unless $val; |
39
|
0
|
|
|
|
|
|
$val =~ s/\.\w+$//; |
40
|
0
|
|
|
|
|
|
$val =~ s!%([\da-f][\da-f])!chr(hex($1))!eig; |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$val =~ s!~(\w+)/.*!~$1!; |
42
|
|
|
|
|
|
|
# proxy |
43
|
0
|
|
|
|
|
|
$val =~ s!^((http|ftp|wais)://[^/]+)/.*!$1!; |
44
|
|
|
|
|
|
|
# confine to depth 3 |
45
|
0
|
|
|
|
|
|
my @val = split /\//, $val; |
46
|
0
|
0
|
|
|
|
|
$#val = 2 if $#val > 2; |
47
|
|
|
|
|
|
|
#printf STDERR "$val => %s\n", join('/', @val) || '/'; |
48
|
0
|
0
|
|
|
|
|
join('/', @val) || '/'; |
49
|
|
|
|
|
|
|
} elsif ($key eq Bytes) { |
50
|
0
|
|
|
|
|
|
$val =~ s/\D.*//; |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
|
$val; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |