| 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 <ot@w3.org> 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | require Exporter; | |||||||||||||||||||
| 13 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 14 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||||||||
| 15 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 16 | 1 | our @EXPORT = qw(); | |||||||||||||||||||
| 17 | 1 | our $VERSION = sprintf "%d.%03d",q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | our $config_filename; | |||||||||||||||||||
| 20 | 1 | our %conf; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | ########################### | ||||||||||||||||||||
| 23 | # usual package interface # | ||||||||||||||||||||
| 24 | ########################### | ||||||||||||||||||||
| 25 | sub new | ||||||||||||||||||||
| 26 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 27 | 0 | my $self = {}; | |||||||||||||||||||
| 28 | 0 | my $proto = shift; | |||||||||||||||||||
| 29 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $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 | ▶ | if (@_) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
configure: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 58 | 0 | return %conf; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub config_default | ||||||||||||||||||||
| 62 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
config_default: not called CC=11 SCAR=47.1
Pod
documented
| |||||||||||||||||||||
| 63 | 1 | ▶ | use Sys::Hostname qw(hostname); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||
| 65 | # setting default values for LogProcessor | ||||||||||||||||||||
| 66 | 0 | ▶ | if (!exists $conf{LogProcessor}{DirectoryIndex}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | { | ||||||||||||||||||||
| 68 | 0 | $conf{LogProcessor}{DirectoryIndex}=("index.html index.htm index"); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 0 | ▶ | if (!exists $conf{LogProcessor}{MaxInvalid}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | { | ||||||||||||||||||||
| 72 | 0 | $conf{LogProcessor}{MaxInvalid}=10; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | ▶ | if (!exists $conf{LogProcessor}{ServerName}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | { | ||||||||||||||||||||
| 76 | 0 | $conf{LogProcessor}{ServerName}=hostname(); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | 0 | ▶ | if (!exists $conf{LogProcessor}{DocumentRoot}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | { | ||||||||||||||||||||
| 80 | 0 | $conf{LogProcessor}{DocumentRoot}="/var/www/"; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | ▶ | if (!exists $conf{LogProcessor}{LogFiles}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | { | ||||||||||||||||||||
| 84 | 0 | push @{$conf{LogProcessor}{LogFiles}}, "/var/log/apache/access.log"; | |||||||||||||||||||
| 85 | 0 | $conf{LogProcessor}{LogType}{"/var/log/apache/access.log"}="common"; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | 0 | ▶ | if (!exists $conf{LogProcessor}{RefererMatch}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | { | ||||||||||||||||||||
| 89 | 0 | $conf{LogProcessor}{RefererMatch} =".*"; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | if (!exists $conf{LogProcessor}{UseValidationModule}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | { | ||||||||||||||||||||
| 94 | #adding modules and options for the modules | ||||||||||||||||||||
| 95 | 0 | push @{$conf{LogProcessor}{UseValidationModule}}, "W3C::LogValidator::HTMLValidator"; | |||||||||||||||||||
| 96 | 0 | push @{$conf{LogProcessor}{UseValidationModule}}, "W3C::LogValidator::Basic"; | |||||||||||||||||||
| 97 | 0 | $conf{"W3C::LogValidator::HTMLValidator"}{max_invalid}=10; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | # adding default limit - useful for very (too) big logfiles | ||||||||||||||||||||
| 100 | 0 | ▶ | if (!exists $conf{LogProcessor}{EntriesPerLogfile}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | { | ||||||||||||||||||||
| 102 | 0 | $conf{LogProcessor}{EntriesPerLogfile}=100000; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | # adding default handling of URIs with query strings | ||||||||||||||||||||
| 105 | 0 | ▶ | if (!exists $conf{LogProcessor}{ExcludeCGI}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | { | ||||||||||||||||||||
| 107 | 0 | $conf{LogProcessor}{ExcludeCGI}=1; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | # parameter muting the final report if nothing interesting to say | ||||||||||||||||||||
| 110 | 0 | ▶ | if (!exists $conf{LogProcessor}{QuietIfNoReport}) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | { | ||||||||||||||||||||
| 112 | 0 | $conf{LogProcessor}{QuietIfNoReport}=0; # not muted by default | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | sub config_file | ||||||||||||||||||||
| 119 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
config_file: not called CC=8 SCAR=40.7
Pod
documented
| |||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||
| 121 | 1 | ▶ | use Config::General; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 122 | 0 | ▶ | my $config_read = new Config::General(-ConfigFile => "$config_filename") | ||||||||||||||||||
|
Condition0%0/2
'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename") || die("could not load config $W3C::LogValidator::Config::config_filename : $!")
MC/DC0%0/1
'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename") || die("could not load config $W3C::LogValidator::Config::config_filename : $!")
'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename")
Truth table0%0/2
A
A= 'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::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 | ▶ | if (exists($tmpconf{Module})) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 155 | { | ||||||||||||||||||||
| 156 | 0 | %conf = %{$tmpconf{Module}}; | |||||||||||||||||||
| 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; | |||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | # specific action is needed for "CustomLog" | ||||||||||||||||||||
| 164 | 0 | ▶ | if (exists($tmpconf{CustomLog})) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | { | ||||||||||||||||||||
| 166 | # if there are several log files, $tmpconf{CustomLog} is an array | ||||||||||||||||||||
| 167 | 0 | ▶ | if (ref($tmpconf{CustomLog}) eq 'ARRAY') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 168 | { | ||||||||||||||||||||
| 169 | 0 | foreach my $customlog (@{ $tmpconf{CustomLog} }) | |||||||||||||||||||
| 170 | { | ||||||||||||||||||||
| 171 | 0 | $_ = $customlog; | |||||||||||||||||||
| 172 | 0 | ▶ | if (/^(.*) (.*)$/) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 173 | { | ||||||||||||||||||||
| 174 | # only supported (so far) is the syntax: | ||||||||||||||||||||
| 175 | # CustomLog path/file nickname | ||||||||||||||||||||
| 176 | 0 | push @{$conf{LogProcessor}{LogFiles}}, $1; | |||||||||||||||||||
| 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 | ▶ | if (/^(.*) (.*)$/) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 186 | { | ||||||||||||||||||||
| 187 | 0 | push @{$conf{LogProcessor}{LogFiles}}, $1; | |||||||||||||||||||
| 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 | 1; | |||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | __END__ | ||||||||||||||||||||