]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Fix logging and resolving
authorNeil Gierman <neilgierman@users.noreply.github.com>
Sun, 22 Apr 2018 02:01:22 +0000 (21:01 -0500)
committerNeil Gierman <neilgierman@users.noreply.github.com>
Sun, 22 Apr 2018 02:01:22 +0000 (21:01 -0500)
wwwroot/cgi-bin/plugins/geoip2.pm
wwwroot/cgi-bin/plugins/geoip2_city.pm

index 24d5aa3d1f977a15a53395c40032cee5106f0b4b..2bd2d99aa747673febf93c51256909a8d881a48a 100644 (file)
@@ -97,12 +97,12 @@ sub GetCountryCodeByAddr_geoip2 {
        if (! $param) { return ''; }
        my $res= TmpLookup_geoip2($param);
        if (! $res) {
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr for $param",5); }
+               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr_geoip2 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); }
+               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr_geoip2 for $param: [$res]",5); }
        }
-       elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
+       elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr_geoip2 for $param: Already resolved to [$res]",5); }
        # ----->
        return $res;
 }
@@ -121,13 +121,13 @@ 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); }
+               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName_geoip2 $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;
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName for $param: [$res]",5); }
+               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName_geoip2 for $param: [$res]",5); }
        }
-       elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
+       elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName_geoip2 for $param: Already resolved to [$res]",5); }
        # ----->
        return $res;
 }
@@ -177,30 +177,30 @@ sub ShowInfoHost_geoip2 {
                }
                print "<td>";
                if ($key && $ip==4) {
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); }
+               if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2 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); }
+               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>"; }
                }
                if ($key && $ip==6) {                              # GeoIP2 supports both IPv4 and IPv6
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); }
+               if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2 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); }
+               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>"; }
                }
                if (! $key) {
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryByIp for $param key=$key ip=$ip",5); }
+               if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2 for $param key=$key ip=$ip",5); }
                        my $res = TmpLookup_geoip2($param);
             # First resolve the name to an IP
             $address = inet_ntoa(inet_aton($param));
-            if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName $param resolved to $address",5); }
+            if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2 $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 ($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>"; }
                }
index 92d0bbcf003079b1c2ee2376d36c4fc6acc39f42..262ba135c29933fcfc2b0ae8f26008ba96ad3327 100644 (file)
@@ -4436,72 +4436,6 @@ sub AddHTMLGraph_geoip2_city {
        return 0;
 }
 
-
-#-----------------------------------------------------------------------------
-# PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
-# UNIQUE: YES (Only one plugin using this function can be loaded)
-# GetCountryCodeByAddr is called to translate an ip into a country code in lower case.
-#-----------------------------------------------------------------------------
-# Rem: not used
-sub GetCountryCodeByAddr_geoip2_city {
-    my $param="$_[0]";
-       # <-----
-       my $res = TmpLookup_geoip2_city($param);
-    if (! $res) {
-        my $record=();
-        $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
-        my $country;
-        $country=$record->country()->iso_code() if $record;
-        $res=lc($country) || 'unknown';
-        $TmpDomainLookup{$param}=$res;
-        if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr for $param: [$res]",5); }
-    }
-    elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
-       # ----->
-       return $res;
-}
-
-
-#-----------------------------------------------------------------------------
-# PLUGIN FUNCTION: GetCountryCodeByName_pluginname
-# UNIQUE: YES (Only one plugin using this function can be loaded)
-# GetCountryCodeByName is called to translate a host name into a country code in lower case.
-#-----------------------------------------------------------------------------
-# Rem: not used
-sub GetCountryCodeByName_geoip2_city {
-    my $param="$_[0]";
-       # <-----
-       my $res = TmpLookup_geoip2_city($param);
-       if ($type eq 'geoippureperl') {
-               if (! $res) {
-                       my @record = ();
-                       @record=$geoip2_city->get_city_record($param) if $geoip2_city;
-               my $country;
-               $country=$record[0] if @record;
-               $res=lc($country) || 'unknown';
-                       $TmpDomainLookup{$param}=$res;
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName for $param: [$res]",5); }
-               }
-               elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
-       }
-       else
-       {
-               if (! $res) {
-               my $record=();
-               $record=$geoip2_city->record_by_name($param) if $geoip2_city;
-               my $country;
-               $country=$record->country if $record;
-               $res=lc($country) || 'unknown';
-                       $TmpDomainLookup{$param}=$res;
-               if ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName for $param: [$res]",5); }
-               }
-               elsif ($Debug) { debug("  Plugin $PluginName: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
-       }
-       # ----->
-       return $res;
-}
-
-
 #-----------------------------------------------------------------------------
 # PLUGIN FUNCTION: ShowInfoHost_pluginname
 # UNIQUE: NO (Several plugins using this function can be loaded)
@@ -4562,8 +4496,9 @@ sub ShowInfoHost_geoip2_city {
                        else
                        {
                        my $record=();
+                       if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2_city for $param",5); }
                        $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
-                       if ($Debug) { debug("  Plugin $PluginName: GetCityByIp for $param: [".$record->city()->name()."]",5); }
+                       if ($Debug) { debug("  Plugin $PluginName: ShowInfoHost_geoip2_city for $param: [".$record->city()->name()."]",5); }
                    $country=$record->country()->iso_code() if $record;
                    $city=$record->city()->name() if $record;
                        }
@@ -4587,8 +4522,12 @@ sub ShowInfoHost_geoip2_city {
                        else
                        {
                        my $record=();
-                       $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
-                       if ($Debug) { debug("  Plugin $PluginName: GetCityByHostname for $param: [$record]",5); }
+                # First resolve the name to an IP
+                $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
+                       $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;
                        }
@@ -4637,6 +4576,7 @@ sub SectionProcessIp_geoip2_city {
         $record->region = $rec[0];
         $record->country_code = $rec[3];
     }else{
+        if ($Debug) { debug("  Plugin $PluginName: SectionProcessIp_geoip2_city for $param",5); }
         $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
     }
     if ($Debug) { debug("  Plugin $PluginName: GetCityByIp for $param: [".$record->city()->name()."]",5); }
@@ -4673,7 +4613,11 @@ sub SectionProcessHostname_geoip2_city {
         $record->region = $rec[3];
         $record->country_code = $rec[0];
     }else{
-        $record=$geoip2_city->city(ip=>$param) if $geoip2_city;
+        # First resolve the name to an IP
+        $address = inet_ntoa(inet_aton($param));
+               if ($Debug) { debug("  Plugin $PluginName: SectionProcessHostname_geoip2_city $param resolved to $address",5); }
+        # Now do the same lookup from the IP
+        $record=$geoip2_city->city(ip=>$address) if $geoip2_city;
     }
     if ($Debug) { debug("  Plugin $PluginName: GetCityByName for $param: [$record]",5); }
     if ($record) {