| 1 | package Mail::Abuse::Incident::Log; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | require 5.005_62; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use NetAddr::IP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Date::Parse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use base 'Mail::Abuse::Incident'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # The code below should be in a single line | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | our $VERSION = do { my @r = (q$Revision: 1.24 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r }; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | Mail::Abuse::Incident::Log - Parses generic logs into Mail::Abuse::Reports | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | use Mail::Abuse::Report; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | use Mail::Abuse::Incident::Log; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | my $i = new Mail::Abuse::Incident::Log; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | my $report = new Mail::Abuse::Report (incidents => [$i] ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | This class parses generic logs that include a timestamp and an IP | ||||||||||||||||||||||||||||||||||||||||||
| 34 | address in the same group of lines. Various configuration keys can | ||||||||||||||||||||||||||||||||||||||||||
| 35 | influence the way this module works, as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =item B<log lines> | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | Controls how many consecutive lines to attempt a match on. More lines | ||||||||||||||||||||||||||||||||||||||||||
| 42 | generally means more incidents parsed, but might lead to false | ||||||||||||||||||||||||||||||||||||||||||
| 43 | matches. Its default value is 5 lines, which seems to work well | ||||||||||||||||||||||||||||||||||||||||||
| 44 | enough. This should vary widely by site. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | use constant LINES => 'log lines'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =item B<debug log> | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | When set to a true value, produces some debugging information sent | ||||||||||||||||||||||||||||||||||||||||||
| 55 | through C<warn()>. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | ▶ | use constant DEBUG => 'debug log'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | The following functions are provided for the customization of the | ||||||||||||||||||||||||||||||||||||||||||
| 66 | behavior of the class. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =item C<parse($report)> | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | Pushes all instances of log incidents into the given report, based | ||||||||||||||||||||||||||||||||||||||||||
| 75 | on parsing of the text in the report itself. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | Returns a list of objects of the same class, with the incident data | ||||||||||||||||||||||||||||||||||||||||||
| 78 | (IP address, timestamp and other information) filled. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | The IP address and timestamp searching is done in a consecutive number | ||||||||||||||||||||||||||||||||||||||||||
| 81 | of lines. This number can be set with the C<log lines> variable, and | ||||||||||||||||||||||||||||||||||||||||||
| 82 | defaults to 5 lines. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | This module tends to get a significant number of, potentially false, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | incidents out of reports. Adjust the number of lines carefully based | ||||||||||||||||||||||||||||||||||||||||||
| 86 | on the types of complaints that your site receives. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub _push ($$$$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_push: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $rep = shift; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $ip = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $date = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $subtype = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $ret = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $i = $self->new(); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $i->ip($ip); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $i->time($date); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $i->type("log/$subtype"); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $i->data($data || 'no data'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$data || 'no data'
MC/DC0%0/1
$data || 'no data'
$data
Truth table0%0/2
A
A= $data
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | return | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if grep { $i->ip eq $_->ip | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$i->ip eq $_->ip && $i->time == $_->time && $i->type eq $_->type
$i->ip eq $_->ip and $i->time == $_->time
MC/DC0%0/3
$i->ip eq $_->ip && $i->time == $_->time && $i->type eq $_->type
$i->ip eq $_->ip
$i->time == $_->time
$i->type eq $_->type
Truth table0%0/4
A and B && C
A= $i->ip eq $_->ipB= $i->time == $_->timeC= $i->type eq $_->type
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | and $i->time == $_->time | ||||||||||||||||||||||||||||||||||||||||||
| 109 | and $i->type eq $_->type } @$ret; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | push @$ret, $i; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # warn "_push $ip $date, ret=", scalar @$ret, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $i; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | sub _add_ip ($$) | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_ip: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $ip = new NetAddr::IP $_[1] or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | for (@{$_[0]}) | |||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return if $_ == $ip; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | push @{$_[0]}, $ip; | |||||||||||||||||||||||||||||||||||||||||
| 127 | # warn "# _add_ip $_[1], ret=", scalar @{$_[0]}, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | sub _add_time ($$) | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_time: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | for (@{$_[0]}) | |||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return if $_ == $_[1]->[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | push @{$_[0]}, $_[1]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | sub parse | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=63 SCAR=83.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $rep = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my @ret = (); # Default return | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $text = undef; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $lines = ($rep->config ? $rep->config->{&LINES} : '') || 5; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
($rep->config ? $rep->config->{&LINES} : '') || 5
MC/DC0%0/1
($rep->config ? $rep->config->{&LINES} : '') || 5
($rep->config ? $rep->config->{&LINES} : '')
Truth table0%0/2
A
A= ($rep->config ? $rep->config->{&LINES} : '')
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $debug = ($rep->config ? $rep->config->{&DEBUG} : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $lines --; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $subtype; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($rep->normalized) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $text = $rep->body; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | else | ||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # Skip the report headers and focus | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # on the offender's | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ($ {$rep->text} =~ m!^\s*\n(.*)!xms) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $t = $1; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $text = \$t; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | else | ||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $text = $rep->text; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return unless $$text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | # Attempt to guess a type of log by | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # searching for keywords performing | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # score-based identification | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my %rules = ( | |||||||||||||||||||||||||||||||||||||||||
| 182 | 'copyright' => qr(copyright\W+infringement | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |rights|media|kazaa|edonkey|DMCA|BSA | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |MPAA|RIAA|copyrighted\W+material | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |(anti-?)?piracy)ix, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 'virus' => qr(virus|worm)ix, | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 'proxy' => qr(proxy|socks|squid)ix, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 'network' => qr(scan|ids|intrusion|firewall | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |portscan|connection)ix, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 'spam' => qr(spam|uce|ube|unsolicited|mass | ||||||||||||||||||||||||||||||||||||||||||
| 191 | x-virus-|e?smtp)ix, | ||||||||||||||||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my %scores = map { $_ => 0 } keys %rules; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $scores{$subtype = '*'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | for my $r (keys %rules) | |||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $re = $rules{$r}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $scores{$r} ++ while $$text =~ m/\W($re)\W/ixg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $scores{$r} ++ while $$text =~ m/^($re)\W/ixg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $scores{$r} ++ while $$text =~ m/\W($re)$/ixg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $scores{$r} ++ while $$text =~ m/^($re)$/ixg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | foreach (keys %scores) | |||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $subtype = $_ if $scores{$_} > $scores{$subtype}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | warn "M::A::I::Log: subtype is $subtype due to scoring\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my @time; # List of timestamps | |||||||||||||||||||||||||||||||||||||||||
| 215 | my @addr; # List of IP addresses | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | for my $skip (0..$lines-1) | |||||||||||||||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $$text =~ m!^!g; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $$text =~ m!(([^\n]*\n){$skip,$skip})!g; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | while ($$text =~ m!^(([^\n]*\n)(([^\n]*\n){0,$lines})?)!mg) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | @time = (); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | @addr = (); | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | # Get candidate timestamps here first | ||||||||||||||||||||||||||||||||||||||||||
| 229 | # to get rid of false matches | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my @candidates = (); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my @passed = (); | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | _add_ip \@addr, $1 while $line =~ m/(\d+\.\d+\.\d+\.\d+)/g; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | while ($line =~ m/(\d+[:-]\d+[:-]\d+T[\d:\.]+)/g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | warn "M::A::I::Log: matched [1] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | while ($line =~ m/((\w{3},\s+)?\d+\s+\w+\s+\d+\s+[\d:]+(\s[-+]?[A-Z0-9]+)?)/g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | warn "M::A::I::Log: matched [2] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | while ($line =~ m!(\d+[/-]\d+[/-]\d+\s+\d+:\d+:\d+)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | warn "M::A::I::Log: matched [3] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | while ($line =~ m!(\d+[/-]\w+[/-]\d+[:\s]+\d+:\d+:\d+)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | warn "M::A::I::Log: matched [4] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | while ($line =~ m!(\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\w+\s+\d+)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | warn "M::A::I::Log: matched [5] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | while ($line =~ m!((\w{3}\s)?\w{3}\s+\d+\s\d+:\d+:\d+(\s\d+)?)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | warn "M::A::I::Log: matched [6] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | while ($line =~ m/(\w+,?\s+\d+\s+\d+\s+\d+:\d+(:\d+)?\s*((AM|PM)?\s*[-+]?[A-Z0-9]+)?)/g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | warn "M::A::I::Log: matched [7] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | while ($line =~ m!(\d+/\d+)-(\d+:\d+:\d+)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | my $p = str2time("$1 $2", $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time("$1 $2", $rep->tz) || (next)
MC/DC0%0/1
str2time("$1 $2", $rep->tz) || (next)
str2time("$1 $2", $rep->tz)
Truth table0%0/2
A
A= str2time("$1 $2", $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | warn "M::A::I::Log: matched [8] date $1 $2 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | push @candidates, [ "$1 $2", $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | while ($line =~ m!Date: (\d+-\d+-\d+), Time: (\d+:\d+:\d+)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my $p = str2time("$1 $2", $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time("$1 $2", $rep->tz) || (next)
MC/DC0%0/1
str2time("$1 $2", $rep->tz) || (next)
str2time("$1 $2", $rep->tz)
Truth table0%0/2
A
A= str2time("$1 $2", $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | warn "M::A::I::Log: matched [9] date $1 $2 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | push @candidates, [ "$1 $2", $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | while ($line =~ m/(\d{2}\s+\w{3}\s+\d{4}\s+\d+:\d\d:\d\d(\s+[-+]?[A-Z0-9]+)?)/g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | warn "M::A::I::Log: matched [10] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | while ($line =~ m!(\d+/\w+/\d+)[:/](\d+:\d+:\d+(\s+[-+]?[\d\w]+)?)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | my $p = str2time("$1 $2", $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time("$1 $2", $rep->tz) || (next)
MC/DC0%0/1
str2time("$1 $2", $rep->tz) || (next)
str2time("$1 $2", $rep->tz)
Truth table0%0/2
A
A= str2time("$1 $2", $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | warn "M::A::I::Log: matched [11] date $1 $2(" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | push @candidates, [ "$1 $2", $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | # Mar 02 2004 15:21:35 | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | while ($line =~ m!(\w+ \d+ \d+ \d+:\d+:\d+)!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $p = str2time($1, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($1, $rep->tz) || (next)
MC/DC0%0/1
str2time($1, $rep->tz) || (next)
str2time($1, $rep->tz)
Truth table0%0/2
A
A= str2time($1, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | warn "M::A::I::Log: matched [12] date $1 (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | push @candidates, [ $1, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | # 4Mar2004 3:30:50 | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | while ($line =~ m!((\d+)(\w{3})(\d+)\s+(\d+:\d+:\d+))!g) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $date = "$2 $3 $4 $5"; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $p = str2time($date, $rep->tz) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
str2time($date, $rep->tz) || (next)
MC/DC0%0/1
str2time($date, $rep->tz) || (next)
str2time($date, $rep->tz)
Truth table0%0/2
A
A= str2time($date, $rep->tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | warn "M::A::I::Log: matched [13] date $date (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | scalar localtime($p) . ")\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | push @candidates, [ $date, $p ]; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | # @candidates contain all proto-timestamps | ||||||||||||||||||||||||||||||||||||||||||
| 348 | # Partial matches are possible, so we must | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # choose only the longest | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | # warn "passed (before)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 352 | # warn "-> $_\n" for @candidates; | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | for my $t (sort { length $a->[0] <=> length $b->[0] } @candidates) | |||||||||||||||||||||||||||||||||||||||||
| 355 | { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | @passed = grep { index($t, $_->[0]) < 0; } @passed; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | push @passed, $t | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | # warn "passed (after)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | # warn "-> $_\n" for @passed; | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | _add_time \@time, $_ for @passed; | |||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | # if (@time and @addr) | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | # warn "M::A::I::Log: Matches for block [$line] follows:\n" | ||||||||||||||||||||||||||||||||||||||||||
| 368 | # if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | for my $time (@time) | |||||||||||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | for my $a (@addr) | |||||||||||||||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $p = $self->_push($rep, $a, $time, | |||||||||||||||||||||||||||||||||||||||||
| 376 | $line, $subtype, \@ret); | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | warn "M::A::I::Log: add incident $a, ", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p and $debug
MC/DC0%0/2
$p and $debug
$p
$debug
Truth table0%0/3
A and B
A= $pB= $debug
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | scalar localtime $time, "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 379 | if $p and $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return @ret; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | __END__ | ||||||||||||||||||||||||||||||||||||||||||