MtPolicyd/Plugin/ScoreAction.pm

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