SpamDetector/Sendmail.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 63 CC 4 SCAR 15.9
CC
4
Cov
0%
parse_logs
12.0
preconfig
6.0
config_prefix
2.0
CRAP 4.9
1  
2 package SyslogScan::Daemon::SpamDetector::Sendmail;
3  
4 use strict;
5 use warnings;
6 use SyslogScan::Daemon::SpamDetector::Plugin;
7 use Plugins::SimpleConfig;
8 our(@ISA) = qw(SyslogScan::Daemon::SpamDetector::Plugin);
9  
10 my %defaults = (
11 rx_extra => '.',
12 rx_month => '(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)',
13 rx_date => '',
14 logfile => '/var/log/mail.log',
15 debug => 0,
16 );
17  
18 sub config_prefix { 'sdsendmail_' }
19  
20 sub parse_config_line { simple_config_line(\%defaults, @_); }
21  
22 sub new { simple_new(\%defaults, @_); }
23  
24 our $Mon;
25 our $Date;
26 our $iprx;
27  
28 sub preconfig
29 {
30 my $self = shift;
31 $self->{Mon} = qr/$self->{rx_month}/;
32 $self->{Date} = $self->{rx_date} ? qr/$self->{rx_date}/ : qr/$self->{Mon} [ 1-3][0-9] \d\d:\d\d:\d\d/;
33 $self->{Extra} = qr/$self->{rx_extra}/;
34 }
35  
36 sub get_logs
37 {
38 my $self = shift;
39 my $Date = $self->{Date};
40 return (
41 $self->{logfile} => [
42 # Oct 20 00:00:12 idiom sm-mta[16655]: k9K6xf1f016655: from=<declarator@embrace.org.uk>, size=771, class=0, nrcpts=1, msgid=<46600514770495.39A8A178A2@SLDS5JHS>, proto=ESMTP, daemon=Daemon0, relay=pool-151-205-120-16.ny325.east.verizon.net [151.205.120.16]
43 qr{^$Date (\S+) sm-mta\[\d+\]: \w+: from=<(.*?)>, size=\d+, class=\d+, nrcpts=\d+, msgid=<(.*?)>, proto=\S+, daemon=\S+, relay=(?:(\S+) )?\[([\d\.]{8,40})\]},
44  
45 ],
46 );
47 }
48  
49 sub parse_logs
50 {
51 my ($self, $logfile, $rx) = @_;
52 my $debug = $self->{debug};
53 my $logline = $_;
54 my ($host, $from, $id, $relayname, $relayip) = ($1, $2, $3, $4, $5);
55 return () if $self->{Extra} && ! /$self->{Extra}/;
56 print "SPAMDETECT $id => $relayip\n" if $self->{debug};
57 my %info = (
58 id => $id,
59 ip => $relayip,
60 from => $from,
61 relayname => $relayname,
62 status => 'idmap',
63 match => 'Sendmail',
64 host => $host,
65 );
66 return %info;
67 }
68  
69 1;
70  
71 =head1 NAME
72  
73 SyslogScan::Daemon::SpamDetector::Sendmail - record incomming messages
74  
75 =head1 SYNOPSIS
76  
77 plugin SyslogScan::Daemon::SpamDetector as sd_
78  
79 sd_plugin SyslogScan::Daemon::SpamDetector::Sendmail
80 debug 0
81 logfile /var/log/mail.info
82 rx_extra 'ingore_lines_without_this_string'
83  
84 =head1 DESCRIPTION
85  
86 SyslogScan::Daemon::SpamDetector::Sendmail watches the mail log file and
87 notices which Message-IDs came from which IP address.
88  
89 =head1 CONFIGURATION PARAMETERS
90  
91 The following configuration parameters are supported:
92  
93 =over 4
94  
95 =item debug
96  
97 Debugging on (1) or off (0).
98  
99 =item logfile
100  
101 Which logfile to watch (default: C</var/log/mail.log>).
102  
103 =item rx_extra
104  
105 Ignore log lines that don't match a regular expression.
106  
107 =back
108  
109 =head1 SEE ALSO
110  
111 L<SyslogScan::Daemon::SpamDetector>
112 L<SyslogScan::Daemon::SpamDetector::Sendmail>
113  
114 =head1 THANK THE AUTHOR
115  
116 If you need high-speed internet services (T1, T3, OC3 etc), please
117 send me your request-for-quote. I have access to very good pricing:
118 you'll save money and get a great service.
119  
120 =head1 LICENSE
121  
122 Copyright(C) 2006 David Muir Sharnoff <muir@idiom.com>.
123 This module may be used and distributed on the same terms
124 as Perl itself.
125