From: Neil Gierman Date: Thu, 19 Apr 2018 15:22:14 +0000 (-0500) Subject: Fix issue with ShowHost section when address is resolved. X-Git-Tag: AWSTATS_7_8~22^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07cf98676a9009a5cac1fde0f371c1e0f9b3707f;p=thirdparty%2FAWStats.git Fix issue with ShowHost section when address is resolved. --- diff --git a/wwwroot/cgi-bin/plugins/geoip2.pm b/wwwroot/cgi-bin/plugins/geoip2.pm index 91037028..24d5aa3d 100644 --- a/wwwroot/cgi-bin/plugins/geoip2.pm +++ b/wwwroot/cgi-bin/plugins/geoip2.pm @@ -97,6 +97,7 @@ sub GetCountryCodeByAddr_geoip2 { if (! $param) { return ''; } my $res= TmpLookup_geoip2($param); if (! $res) { + if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param",5); } $res=lc($reader->country( ip => $param )->country()->iso_code()) || 'unknown'; $TmpDomainLookup{$param}=$res; if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByAddr for $param: [$res]",5); } @@ -120,6 +121,7 @@ sub GetCountryCodeByName_geoip2 { if (! $res) { # First resolve the name to an IP $address = inet_ntoa(inet_aton($param)); + if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName $param resolved to $address",5); } # Now do the same lookup from the IP $res=lc($reader->country( ip => $address )->country()->iso_code()) || 'unknown'; $TmpDomainLookup{$param}=$res; @@ -175,6 +177,7 @@ sub ShowInfoHost_geoip2 { } print ""; if ($key && $ip==4) { + if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); } my $res = TmpLookup_geoip2($param); if (!$res){$res=lc($reader->country( ip => $param )->country()->iso_code()) if $reader;} if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param: [$res]",5); } @@ -182,6 +185,7 @@ sub ShowInfoHost_geoip2 { else { print "$Message[0]"; } } if ($key && $ip==6) { # GeoIP2 supports both IPv4 and IPv6 + if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); } my $res = TmpLookup_geoip2($param); if (!$res){$res=lc($reader->country( ip => $param )->country()->iso_code()) if $reader;} if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param: [$res]",5); } @@ -189,8 +193,13 @@ sub ShowInfoHost_geoip2 { else { print "$Message[0]"; } } if (! $key) { + if ($Debug) { debug(" Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); } my $res = TmpLookup_geoip2($param); - if (!$res){$res=lc($reader->country( ip => $param )->country()->iso_code()) if $reader;} + # First resolve the name to an IP + $address = inet_ntoa(inet_aton($param)); + if ($Debug) { debug(" Plugin $PluginName: GetCountryCodeByName $param resolved to $address",5); } + # Now do the same lookup from the IP + if (!$res){$res=lc($reader->country( ip => $address )->country()->iso_code()) if $reader;} if ($Debug) { debug(" Plugin $PluginName: GetCountryByHostname for $param: [$res]",5); } if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"$Message[0]"; } else { print "$Message[0]"; }