MtPolicyd/Plugin/RBL.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 71.4% 10 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 83.7% 72 / 86 CC 10 SCAR 15.8
CC
10
Cov
86%
run
8.3
_get_reject_action
3.3
BEGIN
1.0
CRAP 4.9
« MtPolicyd/Plugin/Quota.pm ↑ Summary MtPolicyd/Plugin/Proxy.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 = '2.01'; # 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', 'mode' ],
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 5 ▶ my ( $self, $r ) = @_;
Subroutine run: called CC=8 SCAR=21.2
Pod documented
42 5 my $ip = $r->attr('client_address');
43 5 my $session = $r->session;
44 5 my $mode = $self->get_uc( $session, 'mode' );
45 5 my $enabled = $self->get_uc( $session, 'enabled' );
46  
47 5 ▶ if( $enabled eq 'off' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enabled eq "off") 1 4 5
48 1 return;
49 }
50
51 my ( $ip_result, $info ) = $r->do_cached('rbl-'.$self->name.'-result',
52 4 ▶ sub { $self->_rbl->check( $ip ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
53  
54 4 ▶ if( ! defined $ip_result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip_result) 1 3 4
55 1 $self->log($r, 'ip '.$ip.' not on '.$self->domain.' blacklist');
56 1 return; # host is not on the list
57 }
58 3 ▶ $self->log($r, 'ip '.$ip.' on '.$self->domain.' blacklist'.( defined $info ? ' ('.$info.')' : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $info ? : 3 0 3
59 3 ▶ 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')) 3 0 3
Condition33%1/3
defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')
!ll&&!rl&&r
003
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 table33%1/3
A and not(B)
A= defined $self->scoreB= not $r->is_already_done('rbl-' . $self->name . '-score')
ABresult
0X0
100
111
60 3 $self->add_score($r, $self->name => $self->score);
61 }
62  
63 3 ▶ if( $mode eq 'reject' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "reject") 2 1 3
64 2 return Mail::MtPolicyd::Plugin::Result->new(
65 action => $self->_get_reject_action($ip, $info),
66 abort => 1,
67 );
68 }
69 1 ▶ if( $mode eq 'accept' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "accept") 0 1 1
70 0 return Mail::MtPolicyd::Plugin::Result->new_dunno;
71 }
72  
73 1 return;
74 }
75  
76 sub _get_reject_action {
77 2 ▶ my ( $self, $ip, $info ) = @_;
Subroutine _get_reject_action: called CC=3 SCAR=12.0
78 2 my $message = $self->reject_message;
79 2 $message =~ s/%IP%/$ip/;
80 2 ▶ if( defined $info && $info ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info and $info ne '') { } 2 0 2
Condition33%1/3
defined $info and $info ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $info and $info ne ""
defined $info $info ne ""
Truth table33%1/3
A and B
A= defined $infoB= $info ne ""
ABresult
0X0
100
111
81 2 $message =~ s/%INFO%/($info)/;
82 } else {
83 0 $message =~ s/%INFO%//;
84 }
85 2 return('reject '.$message);
86 }
87  
88 2 __PACKAGE__->meta->make_immutable;
89  
90 2 1;
91  
92 __END__
93  
94 =pod
95  
96 =encoding UTF-8
97  
98 =head1 NAME
99  
100 Mail::MtPolicyd::Plugin::RBL - mtpolicyd plugin for checking the client-address against an RBL
101  
102 =head1 VERSION
103  
104 version 2.01
105  
106 =head1 DESCRIPTION
107  
108 This plugin queries a DNS black/white list.
109  
110 =head1 PARAMETERS
111  
112 =over
113  
114 =item domain (required)
115  
116 The domain of the blacklist to query.
117  
118 =item (uc_)enabled (default: on)
119  
120 Enable/disable this check.
121  
122 =item (uc_)mode (default: reject)
123  
124 =over
125  
126 =item reject
127  
128 Reject the message. (reject)
129  
130 =item accept
131  
132 Stop processing an accept this message. (dunno)
133  
134 =item passive
135  
136 Only apply the score if one is given.
137  
138 =back
139  
140 =item reject_message (default: delivery from %IP% rejected %INFO%)
141  
142 A pattern for the reject message if mode is set to 'reject'.
143  
144 =item score (default: empty)
145  
146 Apply this score if the check matched.
147  
148 =back
149  
150 =head1 EXAMPLE DNS BLACKLIST
151  
152 <Plugin sorbs.net>
153 module = "RBL"
154 mode = "passive"
155 domain="dnsbl.sorbs.net"
156 score = 5
157 </Plugin>
158  
159 =head1 EXAMPLE DNS WHITELIST
160  
161 <Plugin dnswl.org>
162 module = "RBL"
163 mode = "accept" # will stop here
164 domain="list.dnswl.org"
165 </Plugin>
166  
167 =head1 AUTHOR
168  
169 Markus Benning <ich@markusbenning.de>
170  
171 =head1 COPYRIGHT AND LICENSE
172  
173 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
174  
175 This is free software, licensed under:
176  
177 The GNU General Public License, Version 2, June 1991
178  
179 =cut
« MtPolicyd/Plugin/Quota.pm ↑ Summary MtPolicyd/Plugin/Proxy.pm »