line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Plugin::RBLAction; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3100
|
use Moose; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
16
|
|
4
|
2
|
|
|
2
|
|
13301
|
use namespace::autoclean; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: mtpolicyd plugin for checking the client-address against an RBL |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Mail::MtPolicyd::Plugin'; |
11
|
|
|
|
|
|
|
with 'Mail::MtPolicyd::Plugin::Role::Scoring'; |
12
|
|
|
|
|
|
|
with 'Mail::MtPolicyd::Plugin::Role::UserConfig' => { |
13
|
|
|
|
|
|
|
'uc_attributes' => [ 'enabled', 'mode' ], |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
248
|
use Mail::MtPolicyd::Plugin::Result; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
11
|
use Mail::RBL; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1209
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'result_from' => ( is => 'rw', isa => 'Str', required => 1 ); |
22
|
|
|
|
|
|
|
has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' ); |
23
|
|
|
|
|
|
|
has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject' ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 're_match' => ( is => 'rw', isa => 'Str', required => 1 ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'reject_message' => ( |
28
|
|
|
|
|
|
|
is => 'ro', isa => 'Str', default => 'delivery from %IP% rejected %INFO%', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'score' => ( is => 'rw', isa => 'Maybe[Num]' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub run { |
34
|
2
|
|
|
2
|
1
|
86
|
my ( $self, $r ) = @_; |
35
|
2
|
|
|
|
|
166
|
my $ip = $r->attr('client_address'); |
36
|
2
|
|
|
|
|
103
|
my $session = $r->session; |
37
|
2
|
|
|
|
|
15
|
my $mode = $self->get_uc( $session, 'mode' ); |
38
|
2
|
|
|
|
|
14
|
my $enabled = $self->get_uc( $session, 'enabled' ); |
39
|
|
|
|
|
|
|
|
40
|
2
|
50
|
|
|
|
8
|
if( $enabled eq 'off' ) { |
41
|
0
|
|
|
|
|
0
|
return; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
106
|
my $result_key = 'rbl-'.$self->result_from.'-result'; |
45
|
2
|
50
|
33
|
|
|
22
|
if( ! defined $session->{$result_key} || ref( $session->{$result_key} ) ne 'ARRAY' ) { |
46
|
0
|
|
|
|
|
0
|
$self->log( $r, 'no RBL check result for '.$self->name.' found!'); |
47
|
0
|
|
|
|
|
0
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
2
|
|
|
|
|
5
|
my ( $ip_result, $info ) = @{$session->{$result_key}}; |
|
2
|
|
|
|
|
9
|
|
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
20
|
if( ! defined $ip_result ) { |
52
|
0
|
|
|
|
|
0
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
116
|
my $regex = $self->re_match; |
56
|
2
|
100
|
|
|
|
24
|
if( $ip_result->addr !~ m/$regex/ ) { |
57
|
1
|
|
|
|
|
277
|
$self->log( $r, $ip_result->addr.' did not match regex '.$regex); |
58
|
1
|
|
|
|
|
9
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
177
|
$self->log( $r, $ip_result->addr.' match regex '.$regex); |
62
|
1
|
50
|
33
|
|
|
61
|
if( defined $self->score && ! $r->is_already_done('rbl-'.$self->name.'-score') ) { |
63
|
1
|
|
|
|
|
47
|
$self->add_score($r, $self->name => $self->score); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
|
|
|
5
|
if( $mode eq 'reject' ) { |
67
|
1
|
|
|
|
|
5
|
return Mail::MtPolicyd::Plugin::Result->new( |
68
|
|
|
|
|
|
|
action => $self->_get_reject_action($ip, $info), |
69
|
|
|
|
|
|
|
abort => 1, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
|
|
|
0
|
if( $mode eq 'accept' ) { |
73
|
0
|
|
|
|
|
0
|
return Mail::MtPolicyd::Plugin::Result->new_dunno; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _get_reject_action { |
80
|
1
|
|
|
1
|
|
2
|
my ( $self, $ip, $info ) = @_; |
81
|
1
|
|
|
|
|
43
|
my $message = $self->reject_message; |
82
|
1
|
|
|
|
|
5
|
$message =~ s/%IP%/$ip/; |
83
|
1
|
50
|
33
|
|
|
8
|
if( defined $info && $info ne '' ) { |
84
|
1
|
|
|
|
|
10
|
$message =~ s/%INFO%/($info)/; |
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
0
|
$message =~ s/%INFO%//; |
87
|
|
|
|
|
|
|
} |
88
|
1
|
|
|
|
|
49
|
return('reject '.$message); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=pod |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=encoding UTF-8 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Mail::MtPolicyd::Plugin::RBLAction - mtpolicyd plugin for checking the client-address against an RBL |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 VERSION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
version 1.23 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 DESCRIPTION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This plugin can be used when a more complex evaluation of an RBL result is needed that just match/not-match. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
With this plugin you can take the same actions as with the RBL plugin, but it can match the result with a regular expression. This allows one to take action based on the category in combined blacklists. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 PARAMETERS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=over |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item result_from (required) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Use the query result of this RBL check. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item (uc_)enabled (default: on) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Enable/disable this check. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item (uc_)mode (default: reject) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item reject |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Reject the message. (reject) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item accept |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Stop processing an accept this message. (dunno) |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item passive |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Only apply the score if one is given. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item re_match (required) |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
An regular expression to check the RBL result. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item reject_message (default: delivery from %IP% rejected %INFO%) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
A pattern for the reject message if mode is set to 'reject'. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item score (default: empty) |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Apply this score if the check matched. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 EXAMPLE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
<Plugin spamhaus-rbl> |
162
|
|
|
|
|
|
|
module = "RBL" |
163
|
|
|
|
|
|
|
mode = "passive" |
164
|
|
|
|
|
|
|
domain="zen.spamhaus.org" |
165
|
|
|
|
|
|
|
</Plugin> |
166
|
|
|
|
|
|
|
<Plugin spamhaus-rbl-sbl> |
167
|
|
|
|
|
|
|
module = "RBLAction" |
168
|
|
|
|
|
|
|
result_from = "spamhaus-rbl" |
169
|
|
|
|
|
|
|
mode = "passive" |
170
|
|
|
|
|
|
|
re_match = "^127\.0\.0\.[23]$" |
171
|
|
|
|
|
|
|
score = 5 |
172
|
|
|
|
|
|
|
</Plugin> |
173
|
|
|
|
|
|
|
<Plugin spamhaus-rbl-xbl> |
174
|
|
|
|
|
|
|
module = "RBLAction" |
175
|
|
|
|
|
|
|
result_from = "spamhaus-rbl" |
176
|
|
|
|
|
|
|
mode = "passive" |
177
|
|
|
|
|
|
|
re_match = "^127\.0\.0\.[4-7]$" |
178
|
|
|
|
|
|
|
score = 5 |
179
|
|
|
|
|
|
|
</Plugin> |
180
|
|
|
|
|
|
|
<Plugin spamhaus-rbl-pbl> |
181
|
|
|
|
|
|
|
module = "RBLAction" |
182
|
|
|
|
|
|
|
result_from = "spamhaus-rbl" |
183
|
|
|
|
|
|
|
mode = "passive" |
184
|
|
|
|
|
|
|
re_match = "^127\.0\.0\.1[01]$" |
185
|
|
|
|
|
|
|
score = 3 |
186
|
|
|
|
|
|
|
</Plugin> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This is free software, licensed under: |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |