]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Exclude private IP addresses since GeoIP2::Reader doesn't support them
authorNeil Gierman <neilgierman@users.noreply.github.com>
Thu, 30 Aug 2018 03:10:44 +0000 (22:10 -0500)
committerNeil Gierman <neilgierman@users.noreply.github.com>
Thu, 30 Aug 2018 03:10:44 +0000 (22:10 -0500)
wwwroot/cgi-bin/plugins/geoip2.pm
wwwroot/cgi-bin/plugins/geoip2_city.pm

index 2bd2d99aa747673febf93c51256909a8d881a48a..92a71069a71fca4567ced6e50bfe46ef7f2065d8 100644 (file)
@@ -52,6 +52,7 @@ my %TmpDomainLookup;
 use vars qw/
 $reader
 /;
+use Data::Validate::IP 0.25 qw( is_private_ip );
 # ----->
 
 
@@ -199,11 +200,13 @@ sub ShowInfoHost_geoip2 {
             $address = inet_ntoa(inet_aton($param));
             if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2 $param resolved to $address",5); }
             # Now do the same lookup from the IP
+            # GeoIP2::Reader doesn't support private IP addresses
+            if (!is_private_ip($address)){
                if (!$res){$res=lc($reader->country( ip => $address )->country()->iso_code()) if $reader;}
                if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2 for $param: [$res]",5); }
                    if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
-               }
+               }}
                print "</td>";
        }
        else {
index 0591f71a49aa95b98f902e1c64a2a353017cb14c..715f991f6de29e275669190051af3a4644df6ab8 100644 (file)
@@ -55,6 +55,7 @@ $geoip2_city
 %_city_l
 $MAXNBOFSECTIONGIR
 /;
+use Data::Validate::IP 0.25 qw( is_private_ip );
 # ----->
 
 
@@ -305,11 +306,13 @@ sub ShowInfoHost_geoip2_city {
                 $address = inet_ntoa(inet_aton($param));
                 if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2_city $param resolved to $address",5); }
                 # Now do the same lookup from the IP
+                # GeoIP2::Reader doesn't support lookups for Private IPs
+                if (!is_private_ip($address)){
                        $record=$geoip2_city->city(ip=>$address) if $geoip2_city;
                        if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2_city for $param: [$record]",5); }
                    $country=$record->country()->iso_code() if $record;
                    $city=$record->city()->name() if $record;
-                       }
+                       }}
 #                      print "<td>";
 #                  if ($country) { print $DomainsHashIDLib{$country}?$DomainsHashIDLib{$country}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
 #                  else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }