| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (c) 2002-2005 the World Wide Web Consortium : |
|
2
|
|
|
|
|
|
|
# Keio University, |
|
3
|
|
|
|
|
|
|
# European Research Consortium for Informatics and Mathematics |
|
4
|
|
|
|
|
|
|
# Massachusetts Institute of Technology. |
|
5
|
|
|
|
|
|
|
# written by Olivier Thereaux for W3C |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# $Id: Config.pm,v 1.13 2008/11/14 15:17:20 ot Exp $ |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package W3C::LogValidator::Config; |
|
10
|
1
|
|
|
1
|
|
9
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
317
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ); |
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
16
|
|
|
|
|
|
|
our @EXPORT = qw(); |
|
17
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%03d",q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $config_filename; |
|
20
|
|
|
|
|
|
|
our %conf; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
########################### |
|
23
|
|
|
|
|
|
|
# usual package interface # |
|
24
|
|
|
|
|
|
|
########################### |
|
25
|
|
|
|
|
|
|
sub new |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
0
|
|
|
0
|
1
|
|
my $self = {}; |
|
28
|
0
|
|
|
|
|
|
my $proto = shift; |
|
29
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
30
|
0
|
|
|
|
|
|
$self->{NAME} = undef; |
|
31
|
0
|
|
|
|
|
|
$self->{SERVERADMIN} = undef; |
|
32
|
0
|
|
|
|
|
|
$self->{DOCUMENTROOT} = undef; |
|
33
|
0
|
|
|
|
|
|
$self->{LOGFILES} = undef; |
|
34
|
0
|
|
|
|
|
|
$self->{LOGFORMAT} = undef; |
|
35
|
0
|
|
|
|
|
|
$self->{LOGTYPE} = undef; |
|
36
|
0
|
|
|
|
|
|
$self->{MODULES} = undef; |
|
37
|
0
|
|
|
|
|
|
$self->{MAX_INVALID} = undef; |
|
38
|
0
|
|
|
|
|
|
$self->{DIRECTORYINDEX} = undef; |
|
39
|
0
|
|
|
|
|
|
bless($self, $class); |
|
40
|
|
|
|
|
|
|
# default values |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# did we get a config file as an argument? |
|
43
|
0
|
0
|
|
|
|
|
if (@_) |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
0
|
|
|
|
|
|
$config_filename = shift; |
|
46
|
0
|
|
|
|
|
|
$self->config_file; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
else |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
0
|
|
|
|
|
|
$self->config_default; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
# $self->give_config; # debug |
|
53
|
0
|
|
|
|
|
|
return $self; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub configure |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
0
|
|
|
0
|
1
|
|
return %conf; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub config_default |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
1
|
|
|
1
|
|
299
|
use Sys::Hostname qw(hostname); |
|
|
1
|
|
|
|
|
1031
|
|
|
|
1
|
|
|
|
|
390
|
|
|
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
65
|
|
|
|
|
|
|
# setting default values for LogProcessor |
|
66
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{DirectoryIndex}) |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
|
|
|
|
|
$conf{LogProcessor}{DirectoryIndex}=("index.html index.htm index"); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{MaxInvalid}) |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
0
|
|
|
|
|
|
$conf{LogProcessor}{MaxInvalid}=10; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{ServerName}) |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
0
|
|
|
|
|
|
$conf{LogProcessor}{ServerName}=hostname(); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{DocumentRoot}) |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
0
|
|
|
|
|
|
$conf{LogProcessor}{DocumentRoot}="/var/www/"; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{LogFiles}) |
|
83
|
|
|
|
|
|
|
{ |
|
84
|
0
|
|
|
|
|
|
push @{$conf{LogProcessor}{LogFiles}}, "/var/log/apache/access.log"; |
|
|
0
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$conf{LogProcessor}{LogType}{"/var/log/apache/access.log"}="common"; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{RefererMatch}) |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
|
|
|
$conf{LogProcessor}{RefererMatch} =".*"; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{UseValidationModule}) |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
|
|
|
|
|
|
#adding modules and options for the modules |
|
95
|
0
|
|
|
|
|
|
push @{$conf{LogProcessor}{UseValidationModule}}, "W3C::LogValidator::HTMLValidator"; |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
push @{$conf{LogProcessor}{UseValidationModule}}, "W3C::LogValidator::Basic"; |
|
|
0
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$conf{"W3C::LogValidator::HTMLValidator"}{max_invalid}=10; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
# adding default limit - useful for very (too) big logfiles |
|
100
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{EntriesPerLogfile}) |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
0
|
|
|
|
|
|
$conf{LogProcessor}{EntriesPerLogfile}=100000; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
# adding default handling of URIs with query strings |
|
105
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{ExcludeCGI}) |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
0
|
|
|
|
|
|
$conf{LogProcessor}{ExcludeCGI}=1; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
# parameter muting the final report if nothing interesting to say |
|
110
|
0
|
0
|
|
|
|
|
if (!exists $conf{LogProcessor}{QuietIfNoReport}) |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
|
|
|
|
|
$conf{LogProcessor}{QuietIfNoReport}=0; # not muted by default |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub config_file |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
121
|
1
|
|
|
1
|
|
564
|
use Config::General; |
|
|
1
|
|
|
|
|
23496
|
|
|
|
1
|
|
|
|
|
373
|
|
|
122
|
0
|
|
0
|
|
|
|
my $config_read = new Config::General(-ConfigFile => "$config_filename") |
|
123
|
|
|
|
|
|
|
|| die "could not load config $config_filename : $!"; |
|
124
|
|
|
|
|
|
|
# using C::General to read logfile |
|
125
|
0
|
|
|
|
|
|
my %tmpconf = $config_read->getall; |
|
126
|
|
|
|
|
|
|
# extracting modules config |
|
127
|
|
|
|
|
|
|
# Config::General will give the hash this structure |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# HASH { |
|
130
|
|
|
|
|
|
|
# foo -> valfoo |
|
131
|
|
|
|
|
|
|
# bar -> valbar |
|
132
|
|
|
|
|
|
|
# Module { |
|
133
|
|
|
|
|
|
|
# module1 { |
|
134
|
|
|
|
|
|
|
# ga -> valga |
|
135
|
|
|
|
|
|
|
# } |
|
136
|
|
|
|
|
|
|
# } |
|
137
|
|
|
|
|
|
|
# } |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# and we want |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# HASH { |
|
143
|
|
|
|
|
|
|
# LogProcessor { |
|
144
|
|
|
|
|
|
|
# foo -> valfoo |
|
145
|
|
|
|
|
|
|
# bar -> valbar |
|
146
|
|
|
|
|
|
|
# } |
|
147
|
|
|
|
|
|
|
# module1 { |
|
148
|
|
|
|
|
|
|
# ga -> valga |
|
149
|
|
|
|
|
|
|
# } |
|
150
|
|
|
|
|
|
|
# } |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# so First we extract what's in the Module subhash |
|
154
|
0
|
0
|
|
|
|
|
if (exists($tmpconf{Module})) |
|
155
|
|
|
|
|
|
|
{ |
|
156
|
0
|
|
|
|
|
|
%conf = %{$tmpconf{Module}}; |
|
|
0
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
# remove it |
|
159
|
0
|
|
|
|
|
|
delete $tmpconf{Module}; |
|
160
|
|
|
|
|
|
|
# and merging with the global values we put in the LogProcessor subhash |
|
161
|
0
|
|
|
|
|
|
%{$conf{LogProcessor}} = %tmpconf; |
|
|
0
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# specific action is needed for "CustomLog" |
|
164
|
0
|
0
|
|
|
|
|
if (exists($tmpconf{CustomLog})) |
|
165
|
|
|
|
|
|
|
{ |
|
166
|
|
|
|
|
|
|
# if there are several log files, $tmpconf{CustomLog} is an array |
|
167
|
0
|
0
|
|
|
|
|
if (ref($tmpconf{CustomLog}) eq 'ARRAY') |
|
168
|
|
|
|
|
|
|
{ |
|
169
|
0
|
|
|
|
|
|
foreach my $customlog (@{ $tmpconf{CustomLog} }) |
|
|
0
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
{ |
|
171
|
0
|
|
|
|
|
|
$_ = $customlog; |
|
172
|
0
|
0
|
|
|
|
|
if (/^(.*) (.*)$/) |
|
173
|
|
|
|
|
|
|
{ |
|
174
|
|
|
|
|
|
|
# only supported (so far) is the syntax: |
|
175
|
|
|
|
|
|
|
# CustomLog path/file nickname |
|
176
|
0
|
|
|
|
|
|
push @{$conf{LogProcessor}{LogFiles}}, $1; |
|
|
0
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
$conf{LogProcessor}{LogType}{$1}=$2; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
else # one log file, $tmpconf{CustomLog} is not an array |
|
183
|
|
|
|
|
|
|
{ |
|
184
|
0
|
|
|
|
|
|
$_ = $tmpconf{CustomLog}; |
|
185
|
0
|
0
|
|
|
|
|
if (/^(.*) (.*)$/) |
|
186
|
|
|
|
|
|
|
{ |
|
187
|
0
|
|
|
|
|
|
push @{$conf{LogProcessor}{LogFiles}}, $1; |
|
|
0
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$conf{LogProcessor}{LogType}{$1}=$2; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
} |
|
191
|
0
|
|
|
|
|
|
delete $conf{LogProcessor}{CustomLog}; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# add default values for variables not included in the config file |
|
195
|
0
|
|
|
|
|
|
$self->config_default(); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
package W3C::LogValidator::Config; |
|
199
|
|
|
|
|
|
|
1; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
__END__ |