line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Plugin::GeoIP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
973
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: plugin to lookup geoip database |
6
|
|
|
|
|
|
|
our $VERSION = '1.5'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::Plugin'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'address_fields' => ( is => 'ro', isa => 'Str', default => 'client_ip' ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has '_address_fields' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, |
13
|
|
|
|
|
|
|
default => sub { |
14
|
|
|
|
|
|
|
my $self = shift; |
15
|
|
|
|
|
|
|
return( [ split(/\s*,\s*/, $self->address_fields) ] ); |
16
|
|
|
|
|
|
|
}, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5203
|
use Geo::IP; |
|
1
|
|
|
|
|
34203
|
|
|
1
|
|
|
|
|
353
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub process { |
22
|
0
|
|
|
0
|
1
|
|
my ( $self, $stash ) = @_; |
23
|
0
|
|
|
|
|
|
my $addr; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
foreach my $field ( @{$self->_address_fields} ) { |
|
0
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if( defined $stash->{$field} ) { |
27
|
0
|
|
|
|
|
|
$addr = $stash->{'client_ip'}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
if( ! defined $addr ) { |
32
|
0
|
|
|
|
|
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $cc = $self->_geoip->country_code_by_addr( $addr ); |
36
|
0
|
0
|
|
|
|
|
if( defined $cc ) { |
37
|
0
|
|
|
|
|
|
$stash->{'geoip_cc'} = $cc; |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
|
$stash->{'geoip_cc'} = 'unknown'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'database' => ( is => 'ro', isa => 'Str', default => '/usr/share/GeoIP/GeoIP.dat' ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has '_geoip' => ( |
48
|
|
|
|
|
|
|
is => 'ro', isa => 'Geo::IP', lazy => 1, |
49
|
|
|
|
|
|
|
default => sub { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
return Geo::IP->open( $self->database, GEOIP_STANDARD ); |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=encoding UTF-8 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Log::Saftpresse::Plugin::GeoIP - plugin to lookup geoip database |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 VERSION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
version 1.5 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is free software, licensed under: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |