Merge pull request #167 from jaredj/prefer-geoip1

Prefer Geo::IP over GeoIP2
This commit is contained in:
Matt Simerson 2014-12-18 11:32:08 -08:00
commit 63d423c896
2 changed files with 8 additions and 5 deletions

View File

@ -146,8 +146,8 @@ sub register {
sub load_geoip { sub load_geoip {
my ( $self ) = @_; my ( $self ) = @_;
$self->load_geoip2() and return 1;
$self->load_geoip1() and return 1; $self->load_geoip1() and return 1;
$self->load_geoip2() and return 1;
return 0; return 0;
} }
@ -182,7 +182,8 @@ sub load_geoip2 {
return; return;
} }
$self->log(LOGINFO, "GeoIP2 loaded"); warn "Using GeoIP2."
. " ASN data is not currently available using the GeoIP2 module!\n";
eval { eval {
$self->{_geoip2_city} = GeoIP2::Database::Reader->new( $self->{_geoip2_city} = GeoIP2::Database::Reader->new(
@ -308,22 +309,27 @@ sub open_geoip_db {
next if !-f "$db_dir/$db.dat"; next if !-f "$db_dir/$db.dat";
$self->log(LOGINFO, "using db $db"); $self->log(LOGINFO, "using db $db");
$self->{_geoip_city} = Geo::IP->open("$db_dir/$db.dat"); $self->{_geoip_city} = Geo::IP->open("$db_dir/$db.dat");
last if $self->{_geoip_city};
} }
warn "Missing GeoIP City data!\n" if ! $self->{_geoip_city};
if (-f "$db_dir/GeoIPASNum.dat") { if (-f "$db_dir/GeoIPASNum.dat") {
$self->log(LOGINFO, "using GeoIPASNum"); $self->log(LOGINFO, "using GeoIPASNum");
$self->{GeoIPASNum} = Geo::IP->open("$db_dir/GeoIPASNum.dat"); $self->{GeoIPASNum} = Geo::IP->open("$db_dir/GeoIPASNum.dat");
} }
warn "Missing GeoIP ASN data!\n" if ! $self->{GeoIPASNum};
if (-f "$db_dir/GeoIPASNumv6.dat") { if (-f "$db_dir/GeoIPASNumv6.dat") {
$self->log(LOGINFO, "using GeoIPASNumv6"); $self->log(LOGINFO, "using GeoIPASNumv6");
$self->{GeoIPASNumv6} = Geo::IP->open("$db_dir/GeoIPASNumv6.dat"); $self->{GeoIPASNumv6} = Geo::IP->open("$db_dir/GeoIPASNumv6.dat");
warn "Missing GeoIP ASN IPV6 data!\n" if ! $self->{GeoIPASNum};
} }
# can't think of a good reason to load country if city data is present # can't think of a good reason to load country if city data is present
if (!$self->{_geoip_city}) { if (!$self->{_geoip_city}) {
$self->log(LOGDEBUG, "using default db"); $self->log(LOGDEBUG, "using default db");
$self->{_geoip} = Geo::IP->new(); # loads default Country DB $self->{_geoip} = Geo::IP->new(); # loads default Country DB
warn "Missing GeoIP Country data!\n" if ! $self->{_geoip};
} }
} }

View File

@ -11,14 +11,11 @@ sub register_tests {
eval 'use GeoIP2::Database::Reader'; eval 'use GeoIP2::Database::Reader';
if ( !$@ ) { if ( !$@ ) {
warn "using GeoIP2\n";
$self->register_test('test_geoip2_lookup'); $self->register_test('test_geoip2_lookup');
} }
eval 'use Geo::IP'; eval 'use Geo::IP';
if ( !$@ ) { if ( !$@ ) {
warn "loaded Geo::IP\n";
$self->register_test('test_geoip_lookup'); $self->register_test('test_geoip_lookup');
$self->register_test('test_geoip_load_db'); $self->register_test('test_geoip_load_db');
$self->register_test('test_geoip_init_cc'); $self->register_test('test_geoip_init_cc');