| 1 | package Mail::Abuse::Incident::MyNetWatchman; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | require 5.005_62; | |||||||||||
| 4 | |||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use NetAddr::IP; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | ▶ | use Date::Parse; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | ▶ | 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 | 2 | our $VERSION = do { my @r = (q$Revision: 1.3 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r }; | |||||||||||
| 16 | |||||||||||||
| 17 | =pod | ||||||||||||
| 18 | |||||||||||||
| 19 | =head1 NAME | ||||||||||||
| 20 | |||||||||||||
| 21 | Mail::Abuse::Incident::MyNetWatchman - Parses MyNetWatchman reports into Mail::Abuse::Reports | ||||||||||||
| 22 | |||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||
| 24 | |||||||||||||
| 25 | use Mail::Abuse::Report; | ||||||||||||
| 26 | use Mail::Abuse::Incident::MyNetWatchman; | ||||||||||||
| 27 | |||||||||||||
| 28 | my $i = new Mail::Abuse::Incident::MyNetWatchman; | ||||||||||||
| 29 | my $report = new Mail::Abuse::Report (incidents => [$i] ); | ||||||||||||
| 30 | |||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||
| 32 | |||||||||||||
| 33 | This class parses MyNetWatchman incidents. See | ||||||||||||
| 34 | http://www.MyNetWatchman.com/ for more information regarding their | ||||||||||||
| 35 | excellent service. | ||||||||||||
| 36 | |||||||||||||
| 37 | The following functions are provided for the customization of the | ||||||||||||
| 38 | behavior of the class. | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | =over | ||||||||||||
| 43 | |||||||||||||
| 44 | =item C<parse($report)> | ||||||||||||
| 45 | |||||||||||||
| 46 | Pushes all instances of MyNetWatchman incidents into the given report, based | ||||||||||||
| 47 | on parsing of the text in the report itself. | ||||||||||||
| 48 | |||||||||||||
| 49 | Returns a list of objects of the same class, with the incident data | ||||||||||||
| 50 | (IP address, timestamp and other information) filled. | ||||||||||||
| 51 | |||||||||||||
| 52 | =cut | ||||||||||||
| 53 | |||||||||||||
| 54 | sub parse | ||||||||||||
| 55 | 4 | ▶ | { | ||||||||||
|
Subroutine
parse: called CC=12 SCAR=25.3
Pod
documented
| |||||||||||||
| 56 | 4 | my $self = shift; | |||||||||||
| 57 | 4 | my $rep = shift; | |||||||||||
| 58 | |||||||||||||
| 59 | 4 | my @ret = (); # Default return | |||||||||||
| 60 | 4 | my $count = 0; | |||||||||||
| 61 | |||||||||||||
| 62 | 4 | my $text = undef; | |||||||||||
| 63 | |||||||||||||
| 64 | 4 | ▶ | if ($rep->normalized) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | { | ||||||||||||
| 66 | 2 | $text = $rep->body; | |||||||||||
| 67 | 2 | ▶ | return unless defined $rep->header->get('Subject'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 2 | ▶ | return unless $rep->header->get('Subject') =~ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | m!myNetWatchman Incident!; | ||||||||||||
| 70 | } | ||||||||||||
| 71 | else | ||||||||||||
| 72 | { | ||||||||||||
| 73 | 2 | $text = $rep->text; | |||||||||||
| 74 | 2 | ▶ | return unless $$text =~ m!^Subject: myNetWatchman Incident!m; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | 4 | ▶ | return unless $$text =~ m!myNetWatchman Incident \[\d+\] Src:!m; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | |||||||||||||
| 79 | # Better guess at the timezone | ||||||||||||
| 80 | |||||||||||||
| 81 | 4 | my $source = ''; | |||||||||||
| 82 | |||||||||||||
| 83 | 4 | ▶ | $$text =~ m!Time Zone: ([-+\d\w]+)! | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | and $rep->tz($1); | ||||||||||||
| 85 | 4 | ▶ | $$text =~ m!Source IP: (\d+\.\d+\.\d+\.\d+)! | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | and $source = new NetAddr::IP $1; | ||||||||||||
| 87 | |||||||||||||
| 88 | 4 | ▶ | return unless $source; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | |||||||||||||
| 90 | 4 | ▶ | while ($$text =~ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | m!^(([^\n,]+, )?([^\n,]+), [^\n,]+, [^\n,]+, [^\n,]+, ([^\n,]+), [^\n,]+, [^\n,]+)$!gm) | ||||||||||||
| 92 | { | ||||||||||||
| 93 | 68 | my $data = $1; | |||||||||||
| 94 | 68 | my $type = $4; | |||||||||||
| 95 | 68 | my $date = str2time($3, $rep->tz); | |||||||||||
| 96 | |||||||||||||
| 97 | 68 | ▶ | next unless defined $date; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | |||||||||||||
| 99 | 64 | my $i = $self->new(); | |||||||||||
| 100 | 64 | $i->ip($source); | |||||||||||
| 101 | 64 | $i->time($date); | |||||||||||
| 102 | 64 | $i->type("mynetwatchman/$type"); | |||||||||||
| 103 | 64 | ▶ | $i->data($data || 'no data'); | ||||||||||
|
Condition50%1/2
$data || 'no data'
MC/DC0%0/1
$data || 'no data'
$data
Truth table50%1/2
A
A= $data
| |||||||||||||
| 104 | 64 | push @ret, $i; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 4 | return @ret; | |||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | __END__ | ||||||||||||