| 1 | package Mail::MtPolicyd::Plugin::RBLAction; | ||||||||||||||||||||||||||||
| 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 'result_from' => ( is => 'rw', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 22 | 2 | has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' ); | |||||||||||||||||||||||||||
| 23 | 2 | has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject' ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | has 're_match' => ( is => 'rw', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | has 'reject_message' => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', isa => 'Str', default => 'delivery from %IP% rejected %INFO%', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | has 'score' => ( is => 'rw', isa => 'Maybe[Num]' ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub run { | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | my ( $self, $r ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=27.5
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 2 | my $ip = $r->attr('client_address'); | |||||||||||||||||||||||||||
| 36 | 2 | my $session = $r->session; | |||||||||||||||||||||||||||
| 37 | 2 | my $mode = $self->get_uc( $session, 'mode' ); | |||||||||||||||||||||||||||
| 38 | 2 | my $enabled = $self->get_uc( $session, 'enabled' ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | if( $enabled eq 'off' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | return; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | my $result_key = 'rbl-'.$self->result_from.'-result'; | |||||||||||||||||||||||||||
| 45 | 2 | ▶ | if( ! defined $session->{$result_key} || ref( $session->{$result_key} ) ne 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $session->{$result_key} or ref $session->{$result_key} ne "ARRAY"
MC/DC0%0/2
not defined $session->{$result_key} or ref $session->{$result_key} ne "ARRAY"
not defined $session->{$result_key}
ref $session->{$result_key} ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not defined $session->{$result_key}B= ref $session->{$result_key} ne "ARRAY"
| |||||||||||||||||||||||||||||
| 46 | 0 | $self->log( $r, 'no RBL check result for '.$self->name.' found!'); | |||||||||||||||||||||||||||
| 47 | 0 | return; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 2 | my ( $ip_result, $info ) = @{$session->{$result_key}}; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | if( ! defined $ip_result ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | my $regex = $self->re_match; | |||||||||||||||||||||||||||
| 56 | 2 | ▶ | if( $ip_result->addr !~ m/$regex/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | $self->log( $r, $ip_result->addr.' did not match regex '.$regex); | |||||||||||||||||||||||||||
| 58 | 1 | return; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | $self->log( $r, $ip_result->addr.' match regex '.$regex); | |||||||||||||||||||||||||||
| 62 | 1 | ▶ | if( defined $self->score && ! $r->is_already_done('rbl-'.$self->name.'-score') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')
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')
| |||||||||||||||||||||||||||||
| 63 | 1 | $self->add_score($r, $self->name => $self->score); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | if( $mode eq 'reject' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 1 | return Mail::MtPolicyd::Plugin::Result->new( | |||||||||||||||||||||||||||
| 68 | action => $self->_get_reject_action($ip, $info), | ||||||||||||||||||||||||||||
| 69 | abort => 1, | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if( $mode eq 'accept' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | return Mail::MtPolicyd::Plugin::Result->new_dunno; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | return; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub _get_reject_action { | ||||||||||||||||||||||||||||
| 80 | 1 | ▶ | my ( $self, $ip, $info ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_reject_action: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 81 | 1 | my $message = $self->reject_message; | |||||||||||||||||||||||||||
| 82 | 1 | $message =~ s/%IP%/$ip/; | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | if( defined $info && $info ne '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $info and $info ne ""
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 ""
| |||||||||||||||||||||||||||||
| 84 | 1 | $message =~ s/%INFO%/($info)/; | |||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 0 | $message =~ s/%INFO%//; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 1 | return('reject '.$message); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | 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 2.01 | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||