line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Plugin::GeoIPLookup; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1376
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
4835
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.02'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: mtpolicyd plugin for checking geo information of an client_address |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Mail::MtPolicyd::Plugin'; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
146
|
use Mail::MtPolicyd::Plugin::Result; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1219
|
use Geo::IP; |
|
1
|
|
|
|
|
22566
|
|
|
1
|
|
|
|
|
345
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '_geoip' => ( |
17
|
|
|
|
|
|
|
is => 'ro', isa => 'Geo::IP', lazy => 1, |
18
|
|
|
|
|
|
|
default => sub { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
Geo::IP->open( $self->database, GEOIP_STANDARD ); |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'database' => ( is => 'rw', isa => 'Str', default => '/usr/share/GeoIP/GeoIP.dat'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub run { |
27
|
0
|
|
|
0
|
1
|
|
my ( $self, $r ) = @_; |
28
|
0
|
|
|
|
|
|
my $ip = $r->attr('client_address'); |
29
|
0
|
|
|
|
|
|
my $session = $r->session; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my ( $result ) = $r->do_cached('geoip-'.$self->name.'-result', |
32
|
0
|
|
|
0
|
|
|
sub { $self->_geoip->country_code_by_addr( $ip ) } ); |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if( ! defined $result ) { |
35
|
0
|
|
|
|
|
|
$self->log($r, 'no GeoIP record for '.$ip.' found'); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=encoding UTF-8 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Mail::MtPolicyd::Plugin::GeoIPLookup - mtpolicyd plugin for checking geo information of an client_address |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 2.02 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This plugin queries a GeoIP for the country code of the client_address. |
62
|
|
|
|
|
|
|
The plugin is divided in this plugin which does the Lookup and the GeoIPAction |
63
|
|
|
|
|
|
|
plugin which can be used to take actions based on country code. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 PARAMETERS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item database (default: /usr/share/GeoIP/GeoIP.dat) |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The path to the geoip country database. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=back |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 MAXMIND GEOIP COUNTRY DATABASE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
On a debian system you can install the country database with the geoip-database package. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
You also download it directly from Maxmind: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
http://dev.maxmind.com/geoip/geoip2/geolite2/ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
(choose "GeoLite2 Country/DB") |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This is free software, licensed under: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |