line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Plugin::GeoIPAction; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1512
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
6612
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: mtpolicyd plugin for checking geo information of an ip |
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
|
1
|
|
|
1
|
|
120
|
use Mail::MtPolicyd::Plugin::Result; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
656
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'result_from' => ( is => 'rw', isa => 'Str', required => 1 ); |
19
|
|
|
|
|
|
|
has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' ); |
20
|
|
|
|
|
|
|
has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'country_codes' => ( is => 'rw', isa => 'Str', required => 1 ); |
23
|
|
|
|
|
|
|
has '_country_codes' => ( |
24
|
|
|
|
|
|
|
is => 'ro', isa => 'ArrayRef', lazy => 1, |
25
|
|
|
|
|
|
|
default => sub { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
return [ split(/\s*,\s*/, $self->country_codes) ]; |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub is_in_country_codes { |
32
|
0
|
|
|
0
|
0
|
|
my ( $self, $cc ) = @_; |
33
|
0
|
0
|
|
|
|
|
if ( grep { $_ eq $cc } @{$self->_country_codes} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return(1); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
return(0); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has 'reject_message' => ( |
40
|
|
|
|
|
|
|
is => 'ro', isa => 'Str', default => 'delivery from %CC% (%IP%) rejected', |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'score' => ( is => 'rw', isa => 'Maybe[Num]' ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub run { |
46
|
0
|
|
|
0
|
1
|
|
my ( $self, $r ) = @_; |
47
|
0
|
|
|
|
|
|
my $ip = $r->attr('client_address'); |
48
|
0
|
|
|
|
|
|
my $session = $r->session; |
49
|
0
|
|
|
|
|
|
my $mode = $self->get_uc( $session, 'mode' ); |
50
|
0
|
|
|
|
|
|
my $enabled = $self->get_uc( $session, 'enabled' ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if( $enabled eq 'off' ) { |
53
|
0
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $result_key = 'geoip-'.$self->result_from.'-result'; |
57
|
0
|
0
|
|
|
|
|
if( ! defined $session->{$result_key} ) { |
58
|
0
|
|
|
|
|
|
$self->log( $r, 'no GeoIP check result for '.$self->name.' found!'); |
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
my ( $country_code ) = @{$session->{$result_key}}; |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if( ! $self->is_in_country_codes( $country_code ) ) { |
64
|
0
|
|
|
|
|
|
$self->log( $r, 'country_code '.$country_code.' of IP not in country_code list'.$self->name); |
65
|
0
|
|
|
|
|
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->log( $r, 'country code '.$country_code.' on list'.$self->name ); |
69
|
0
|
0
|
0
|
|
|
|
if( defined $self->score && ! $r->is_already_done('geoip-'.$self->name.'-score') ) { |
70
|
0
|
|
|
|
|
|
$self->add_score($r, $self->name => $self->score); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if( $mode eq 'reject' ) { |
74
|
0
|
|
|
|
|
|
return Mail::MtPolicyd::Plugin::Result->new( |
75
|
|
|
|
|
|
|
action => $self->_get_reject_action($ip, $country_code ), |
76
|
|
|
|
|
|
|
abort => 1, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
0
|
0
|
0
|
|
|
|
if( $mode eq 'accept' || $mode eq 'dunno' ) { |
80
|
0
|
|
|
|
|
|
return Mail::MtPolicyd::Plugin::Result->new_dunno; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _get_reject_action { |
87
|
0
|
|
|
0
|
|
|
my ( $self, $ip, $cc ) = @_; |
88
|
0
|
|
|
|
|
|
my $message = $self->reject_message; |
89
|
0
|
|
|
|
|
|
$message =~ s/%IP%/$ip/; |
90
|
0
|
|
|
|
|
|
$message =~ s/%CC%/$cc/; |
91
|
0
|
|
|
|
|
|
return('reject '.$message); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Mail::MtPolicyd::Plugin::GeoIPAction - mtpolicyd plugin for checking geo information of an ip |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 1.23 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This plugin will execute an action or score based on a previous lookup |
115
|
|
|
|
|
|
|
done with GeoIPLookup plugin. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 PARAMETERS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item result_from (required) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Take the GeoIP information from the result of this plugin. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The plugin in must be executed before this plugin. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item (uc_)enabled (default: on) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Enable/disable this plugin. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item country_codes (required) |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
A comma separated list of 2 letter country codes to match. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item (uc_)mode (default: reject) |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
If set to 'passive' no action will be returned. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item reject_message (default: 'delivery from %CC% (%IP%) rejected) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Could be used to specify an custom reject message. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item score (default: empty) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
A score to apply to the message. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This is free software, licensed under: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |