MtPolicyd/Plugin/RBL.pm

filter: Statementstmt 69.2% 36 / 52 Branchbran 14.2% 2 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 54.1% 46 / 85 CC 10 SCAR 26.7
CC
10
Cov
53%
run
25.3
_get_reject_action
12.0
BEGIN
1.0
CRAP 14.4
« MtPolicyd/Client/Request.pm ↑ Summary MtPolicyd/Plugin/ScoreAction.pm »
1 package Mail::MtPolicyd::Plugin::RBL;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.11'; # VERSION
7 # ABSTRACT: mtpolicyd plugin for checking the client-address against an RBL
8  
9  
10 2 extends 'Mail::MtPolicyd::Plugin';
11 2 with 'Mail::MtPolicyd::Plugin::Role::Scoring';
12 2 with 'Mail::MtPolicyd::Plugin::Role::UserConfig' => {
13 'uc_attributes' => [ 'enabled' ],
14 };
15  
16 2 ▶use Mail::MtPolicyd::Plugin::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Mail::RBL;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 2 has 'domain' => ( is => 'rw', isa => 'Str', required => 1 );
22 2 has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' );
23  
24 2 has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject' );
25  
26 2 has 'reject_message' => (
27 is => 'ro', isa => 'Str', default => 'delivery from %IP% rejected %INFO%',
28 );
29  
30 2 has 'score' => ( is => 'rw', isa => 'Maybe[Num]' );
31  
32 has '_rbl' => (
33 is => 'ro', isa => 'Mail::RBL', lazy => 1,
34 default => sub {
35 1 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
36 1 Mail::RBL->new($self->domain)
37 },
38 2 );
39  
40 sub run {
41 2 ▶ my ( $self, $r ) = @_;
Subroutine run: called CC=8 SCAR=32.3
Pod documented
42 2 my $ip = $r->attr('client_address');
43 2 my $session = $r->session;
44  
45 2 my $enabled = $self->get_uc( $session, 'enabled' );
46 2 ▶ if( $enabled eq 'off' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enabled eq "off") 0 2 2
47 0 return;
48 }
49
50 my ( $ip_result, $info ) = $r->do_cached('rbl-'.$self->name.'-result',
51 2 ▶ sub { $self->_rbl->check( $ip ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
52  
53 2 ▶ if( ! defined $ip_result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip_result) 2 0 2
54 2 $self->log($r, 'ip '.$ip.' not on '.$self->domain.' blacklist');
55 2 return; # host is not on the list
56 }
57 0 ▶ $self->log($r, 'ip '.$ip.' on '.$self->domain.' blacklist'.( defined $info ? ' ('.$info.')' : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $info ? : 0 0 0
58 0 ▶ if( defined $self->score && ! $r->is_already_done('rbl-'.$self->name.'-score') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')) 0 0 0
Condition0%0/3
defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')
defined $self->score not $r->is_already_done('rbl-' . $self->name . '-score')
Truth table0%0/3
A and not(B)
A= defined $self->scoreB= not $r->is_already_done('rbl-' . $self->name . '-score')
ABresult
0X0
100
111
59 0 $self->add_score($r, $self->name => $self->score);
60 }
61  
62 0 ▶ if( $self->mode eq 'reject' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode eq "reject") 0 0 0
63 0 return Mail::MtPolicyd::Plugin::Result->new(
64 action => $self->_get_reject_action($ip, $info),
65 abort => 1,
66 );
67 }
68 0 ▶ if( $self->mode eq 'accept' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode eq "accept") 0 0 0
69 0 return Mail::MtPolicyd::Plugin::Result->new_dunno;
70 }
71  
72 0 return;
73 }
74  
75 sub _get_reject_action {
76 0 ▶ my ( $self, $ip, $info ) = @_;
Subroutine _get_reject_action: not called CC=3 SCAR=24.8
77 0 my $message = $self->reject_message;
78 0 $message =~ s/%IP%/$ip/;
79 0 ▶ if( defined $info && $info ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info and $info ne '') { } 0 0 0
Condition0%0/3
defined $info and $info ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $info and $info ne ""
defined $info $info ne ""
Truth table0%0/3
A and B
A= defined $infoB= $info ne ""
ABresult
0X0
100
111
80 0 $message =~ s/%INFO%/($info)/;
81 } else {
82 0 $message =~ s/%INFO%//;
83 }
84 0 return('reject '.$message);
85 }
86  
87 2 __PACKAGE__->meta->make_immutable;
88  
89 2 1;
90  
91  
92 __END__
93 =pod
94  
95 =head1 NAME
96  
97 Mail::MtPolicyd::Plugin::RBL - mtpolicyd plugin for checking the client-address against an RBL
98  
99 =head1 VERSION
100  
101 version 1.11
102  
103 =head1 DESCRIPTION
104  
105 This plugin queries a DNS black/white list.
106  
107 =head1 PARAMETERS
108  
109 =over
110  
111 =item domain (required)
112  
113 The domain of the blacklist to query.
114  
115 =item (uc_)enabled (default: on)
116  
117 Enable/disable this check.
118  
119 =item mode (default: reject)
120  
121 =over
122  
123 =item reject
124  
125 Reject the message. (reject)
126  
127 =item accept
128  
129 Stop processing an accept this message. (dunno)
130  
131 =item passive
132  
133 Only apply the score if one is given.
134  
135 =back
136  
137 =item reject_message (default: delivery from %IP% rejected %INFO%)
138  
139 A pattern for the reject message if mode is set to 'reject'.
140  
141 =item score (default: empty)
142  
143 Apply this score if the check matched.
144  
145 =back
146  
147 =head1 EXAMPLE DNS BLACKLIST
148  
149 <Plugin sorbs.net>
150 module = "RBL"
151 mode = "passive"
152 domain="dnsbl.sorbs.net"
153 score = 5
154 </Plugin>
155  
156 =head1 EXAMPLE DNS WHITELIST
157  
158 <Plugin dnswl.org>
159 module = "RBL"
160 mode = "accept" # will stop here
161 domain="list.dnswl.org"
162 </Plugin>
163  
164 =head1 AUTHOR
165  
166 Markus Benning <ich@markusbenning.de>
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
171  
172 This is free software, licensed under:
173  
174 The GNU General Public License, Version 2, June 1991
175  
176 =cut
177  
« MtPolicyd/Client/Request.pm ↑ Summary MtPolicyd/Plugin/ScoreAction.pm »