8
8
#-----------------------------------------------------------------------------
9
9
# Perl Required Modules: Geo::IP or Geo::IP::PurePerl
10
10
#-----------------------------------------------------------------------------
11
# $Revision: 1.21 $ - $Author: eldy $ - $Date: 2005/08/23 20:14:06 $
11
# $Revision: 1.24 $ - $Author: eldy $ - $Date: 2006/05/06 02:51:34 $
15
15
# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
16
16
use vars qw/ $type /;
18
if (!eval ('require "Geo/IP.pm";')) {
18
if (!eval ('require "Geo/IP.pm";')) {
19
20
$type='geoippureperl';
20
if (!eval ('require "Geo/IP/PurePerl.pm";')) { return $@?"Error: $@":"Error: Need Perl module Geo::IP or Geo::IP::PurePerl"; }
21
if (!eval ('require "Geo/IP/PurePerl.pm";')) {
23
$ret=($error1||$error2)?"Error:\n$error1$error2":"";
24
$ret.="Error: Need Perl module Geo::IP or Geo::IP::PurePerl";
23
29
use strict;no strict "refs";
63
69
else { $mode=Geo::IP::GEOIP_STANDARD(); }
65
71
%TmpDomainLookup=();
66
debug(" Plugin geoip: GeoIP initialized in mode $type $mode",1);
72
debug(" Plugin geoip: GeoIP initialized type=$type mode=$mode",1);
67
73
if ($type eq 'geoippureperl') {
68
74
$gi = Geo::IP::PurePerl->open($datafile, $mode);
70
76
$gi = Geo::IP->open($datafile, $mode);
78
# Fails on some GeoIP version
79
# debug(" Plugin geoip: GeoIP initialized database_info=".$gi->database_info());
74
82
return ($checkversion?$checkversion:"$PluginHooksFunctions");
78
86
#-----------------------------------------------------------------------------
87
# PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
88
# UNIQUE: YES (Only one plugin using this function can be loaded)
89
# GetCountryCodeByAddr is called to translate an ip into a country code in lower case.
90
#-----------------------------------------------------------------------------
91
sub GetCountryCodeByAddr_geoip {
94
my $res=$TmpDomainLookup{$param}||'';
96
$res=lc($gi->country_code_by_addr($param)) || 'unknown';
97
$TmpDomainLookup{$param}=$res;
98
if ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: [$res]",5); }
100
elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
106
#-----------------------------------------------------------------------------
79
107
# PLUGIN FUNCTION: GetCountryCodeByName_pluginname
80
108
# UNIQUE: YES (Only one plugin using this function can be loaded)
81
# GetCountryCodeByName is called to translate a host name into a country name.
109
# GetCountryCodeByName is called to translate a host name into a country code in lower case.
82
110
#-----------------------------------------------------------------------------
83
111
sub GetCountryCodeByName_geoip {
84
112
my $param="$_[0]";
86
114
my $res=$TmpDomainLookup{$param}||'';
88
$res=lc($gi->country_code_by_name($param));
89
$TmpDomainLookup{$param}=$res || 'unknown';
116
$res=lc($gi->country_code_by_name($param)) || 'unknown';
117
$TmpDomainLookup{$param}=$res;
90
118
if ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: [$res]",5); }
92
elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: Already resolved to $res",5); }
97
#-----------------------------------------------------------------------------
98
# PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
99
# UNIQUE: YES (Only one plugin using this function can be loaded)
100
# GetCountryCodeByAddr is called to translate an ip into a country name.
101
#-----------------------------------------------------------------------------
102
sub GetCountryCodeByAddr_geoip {
105
my $res=$TmpDomainLookup{$param}||'';
107
$res=lc($gi->country_code_by_addr($param));
108
$TmpDomainLookup{$param}=$res || 'unknown';
109
if ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: $res",5); }
111
elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to $res",5); }
120
elsif ($Debug) { debug(" Plugin geoip: GetCountryCodeByName for $param: Already resolved to [$res]",5); }