| 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 = '2.01'; # 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
Condition66%2/3
$self->match eq "gt" and $score < $threshold
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
| |||||||||||||||||||||||||||||||||||||
| 30 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 31 | ▶ | } elsif( $self->match eq 'lt' && $score > $threshold ) { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->match eq "lt" and $score > $threshold
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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 39 | 1 | my $ip = $r->attr('client_address'); | |||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | if( defined $ip ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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 | __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 2.01 | ||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||