line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Plugin::ScoreAction; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2500
|
use Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
19
|
|
4
|
2
|
|
|
2
|
|
13378
|
use namespace::autoclean; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
21
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: mtpolicyd plugin for running an action based on the score |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Mail::MtPolicyd::Plugin'; |
10
|
|
|
|
|
|
|
with 'Mail::MtPolicyd::Plugin::Role::Scoring'; |
11
|
|
|
|
|
|
|
with 'Mail::MtPolicyd::Plugin::Role::UserConfig' => { |
12
|
|
|
|
|
|
|
'uc_attributes' => [ 'threshold' ], |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
with 'Mail::MtPolicyd::Plugin::Role::PluginChain'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
256
|
use Mail::MtPolicyd::Plugin::Result; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
891
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'threshold' => ( is => 'ro', isa => 'Num', required => 1 ); |
21
|
|
|
|
|
|
|
has 'match' => ( is => 'rw', isa => 'Str', default => 'gt' ); |
22
|
|
|
|
|
|
|
has 'action' => ( is => 'ro', isa => 'Maybe[Str]' ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub run { |
25
|
2
|
|
|
2
|
1
|
552
|
my ( $self, $r ) = @_; |
26
|
2
|
|
|
|
|
9
|
my $score = $self->_get_score($r); |
27
|
2
|
|
|
|
|
10
|
my $score_detail = $self->_get_score_detail($r); |
28
|
2
|
|
|
|
|
70
|
my $threshold = $self->get_uc( $r->session, 'threshold' ); |
29
|
2
|
100
|
66
|
|
|
80
|
if( $self->match eq 'gt' && $score < $threshold ) { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
30
|
1
|
|
|
|
|
5
|
return; |
31
|
|
|
|
|
|
|
} elsif( $self->match eq 'lt' && $score > $threshold ) { |
32
|
0
|
|
|
|
|
0
|
return; |
33
|
|
|
|
|
|
|
} elsif( $self->match !~ m/^[lg]t$/) { |
34
|
0
|
|
|
|
|
0
|
die('unknown value for parameter match.'); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
43
|
my $action = $self->action; |
38
|
1
|
50
|
|
|
|
5
|
if( defined $action ) { |
39
|
1
|
|
|
|
|
48
|
my $ip = $r->attr('client_address'); |
40
|
1
|
50
|
|
|
|
4
|
if( defined $ip ) { |
41
|
1
|
|
|
|
|
5
|
$action =~ s/%IP%/$ip/; |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
0
|
$action =~ s/%IP%/unknown/; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
4
|
$action =~ s/%SCORE%/$score/; |
47
|
1
|
50
|
|
|
|
3
|
if( defined $score_detail ) { |
48
|
1
|
|
|
|
|
7
|
$action =~ s/%SCORE_DETAIL%/, $score_detail/; |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
0
|
$action =~ s/%SCORE_DETAIL%//; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
47
|
return Mail::MtPolicyd::Plugin::Result->new( |
54
|
|
|
|
|
|
|
action => $action, |
55
|
|
|
|
|
|
|
abort => 1, |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if( defined $self->chain ) { |
60
|
0
|
|
|
|
|
|
my $chain_result = $self->chain->run( $r ); |
61
|
0
|
|
|
|
|
|
return( @{$chain_result->plugin_results} ); |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=encoding UTF-8 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Mail::MtPolicyd::Plugin::ScoreAction - mtpolicyd plugin for running an action based on the score |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 VERSION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
version 1.23 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Returns a action based on the score. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 PARAMETERS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item threshold (required) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
If the score is higher than this value the action will be executed. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item match (default: gt) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
If it should match if the score if >= or <= the threshold. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Possible values: gt, lt |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item uc_threshold (default: undef) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
If set the value for threshold will be fetched from this |
106
|
|
|
|
|
|
|
user-config value if defined. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item score_field (default: score) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Specifies the name of the field the score is stored in. |
111
|
|
|
|
|
|
|
Could be set if you need multiple scores. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item action (default: empty) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The action to be executed. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The following patterns in the string will be replaced: |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
%IP%, %SCORE%, %SCORE_DETAIL% |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item Plugin (default: empty) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Execute this plugins when the condition matched. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 EXAMPLE |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Reject everything with a score >= 15. and do greylisting for the remaining request with a score >=5. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
<Plugin ScoreReject> |
132
|
|
|
|
|
|
|
module = "ScoreAction" |
133
|
|
|
|
|
|
|
threshold = 15 |
134
|
|
|
|
|
|
|
action = "reject sender ip %IP% is blocked (score=%SCORE%%SCORE_DETAIL%)" |
135
|
|
|
|
|
|
|
</Plugin> |
136
|
|
|
|
|
|
|
<Plugin ScoreGreylist> |
137
|
|
|
|
|
|
|
module = "ScoreAction" |
138
|
|
|
|
|
|
|
threshold = 5 |
139
|
|
|
|
|
|
|
<Plugin greylist> |
140
|
|
|
|
|
|
|
module = "Greylist" |
141
|
|
|
|
|
|
|
score = -5 |
142
|
|
|
|
|
|
|
mode = "passive" |
143
|
|
|
|
|
|
|
</Plugin> |
144
|
|
|
|
|
|
|
</Plugin> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This is free software, licensed under: |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |