eldy / AWStats

AWStats Log Analyzer project (official sources)
https://www.awstats.org
369 stars 120 forks source link

GeoIP2 fails to determine IPv6 addresses #122

Closed Rehtael closed 5 years ago

Rehtael commented 5 years ago

The IP address you provided (xxxx:xxx:xxxx:xxxx::x) is not a public IP address when calling GeoIP2::Database::Reader::country on GeoIP2::Database::Reader

Trace begun at /usr/lib/perl5/site_perl/5.18.2/GeoIP2/Database/Reader.pm line 81 GeoIP2::Database::Reader::_model_for_address('GeoIP2::Database::Reader=HASH(0x2f40430)', 'Country', 'type_check', 'Regexp=REGEXP(0x4dd0790)', 'ip', 'xxxx:xxx:xxxx:xxxx::x') called at /usr/lib/perl5/site_perl/5.18.2/GeoIP2/Database/Reader.pm line 133 GeoIP2::Database::Reader::country('GeoIP2::Database::Reader=HASH(0x2f40430)', 'ip', 'xxxx:xxx:xxxx:xxxx::x') called at geoip2.pm line 102 main::GetCountryCodeByAddr_geoip2('xxxx:xxx:xxxx:xxxx::x') called at /usr/local/awstats/wwwroot/cgi-bin/awstats.pl line 19426

m-cameron commented 5 years ago

What is the IPv6 address that causing the issue?

Rehtael commented 5 years ago

Its in the private fd9d range, but shouldn't matter as I've only got the geoip2 plugin enabled (both country and city) so shouldn't even try to do a lookup... there is an overall fault with the GeoIP2 perl modules in that it throws on lookup failure instead of gracefully exiting

Rehtael commented 5 years ago

This is the hack I shoved in to get around the problem (the "if ($AtLeastOneSectionPlugin" is a terrible workaround, but works for now):

Line 19,423

# Resolve Domain
if ($ip)
{    # If we have ip, we use it in priority instead of hostname
    if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip6'} && $ip == 6 ) {
        $Domain = GetCountryCodeByAddr_geoip6($Host);
    }
    elsif ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} && $ip == 4 ) {
        $Domain = GetCountryCodeByAddr_geoip($Host);
    }

#               elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($Host); }
#               elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($Host); }
    elsif (
        $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} && $ip == 4 )
    {
        $Domain = GetCountryCodeByAddr_geoipfree($Host);
    }
    elsif (
        $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip2'} && $ip == 4 )
    {
        $Domain = GetCountryCodeByAddr_geoip2($Host);
    }
    elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
    if ($AtLeastOneSectionPlugin && $ip == 4) {
        foreach my $pluginname (
            keys %{ $PluginsLoaded{'SectionProcessIp'} } )
        {
            my $function = "SectionProcessIp_$pluginname";
            if ($Debug) {
                debug( "  Call to plugin function $function",
                    5 );
            }
            &$function($Host);
        }
    }
}
Rehtael commented 5 years ago

Actually, I wonder if this plugin might be better: https://github.com/maxmind/GeoIP2-perl/issues/65