]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Fixed bug with override when using GeoIP C library
authormanolamancha <>
Tue, 11 May 2010 18:27:13 +0000 (18:27 +0000)
committermanolamancha <>
Tue, 11 May 2010 18:27:13 +0000 (18:27 +0000)
wwwroot/cgi-bin/plugins/geoip.pm
wwwroot/cgi-bin/plugins/geoip_asn_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_isp_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_org_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm

index 8c3156470ff8f9bc30989f771902a2618c0d1a7c..342083fdf67a82b69c232b7a05afd3be04b7deed 100644 (file)
@@ -98,8 +98,7 @@ sub GetCountryCodeByAddr_geoip {
     my $param="$_[0]";
        # <-----
        if (! $param) { return ''; }
-       if (!$LoadedOverride){&LoadOverrideFile_geoip();}
-       my $res=$TmpDomainLookup{$param}||'';
+       my $res= TmpLookup_geoip($param);
        if (! $res) {
                $res=lc($gi->country_code_by_addr($param)) || 'unknown';
                $TmpDomainLookup{$param}=$res;
@@ -120,8 +119,7 @@ sub GetCountryCodeByName_geoip {
     my $param="$_[0]";
        # <-----
        if (! $param) { return ''; }
-       if (!$LoadedOverride){&LoadOverrideFile_geoip();}
-       my $res=$TmpDomainLookup{$param}||'';
+       my $res = TmpLookup_geoip($param);
        if (! $res) {
                $res=lc($gi->country_code_by_name($param)) || 'unknown';
                $TmpDomainLookup{$param}=$res;
@@ -165,8 +163,6 @@ sub ShowInfoHost_geoip {
         print "</th>";
        }
        elsif ($param) {
-               # try loading our override file if we haven't yet
-               if (!$LoadedOverride){&LoadOverrideFile_geoip();}
         my $ip=0;
                my $key;
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
@@ -179,9 +175,7 @@ sub ShowInfoHost_geoip {
                }
                print "<td>";
                if ($key && $ip==4) {
-                       my $res;
-                       if ($gi){ $res = $TmpDomainLookup{$gi->get_ip_address($param)}||''; }
-                       else { $res = $TmpDomainLookup{$param}||''; }
+                       my $res = TmpLookup_geoip($param);
                if (!$res){$res=lc($gi->country_code_by_addr($param)) if $gi;}
                if ($Debug) { debug("  Plugin $PluginName: GetCountryByIp for $param: [$res]",5); }
                    if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
@@ -191,9 +185,7 @@ sub ShowInfoHost_geoip {
                    print "<span style=\"color: #$color_other\">$Message[0]</span>";
                }
                if (! $key) {
-                       my $res;
-                       if ($gi){ $res = $TmpDomainLookup{$gi->get_ip_address($param)}||''; }
-                       else { $res = $TmpDomainLookup{$param}||''; }
+                       my $res = TmpLookup_geoip($param);
                if (!$res){$res=lc($gi->country_code_by_addr($param)) if $gi;}
                if ($Debug) { debug("  Plugin $PluginName: GetCountryByHostname for $param: [$res]",5); }
                    if ($res) { print $DomainsHashIDLib{$res}?$DomainsHashIDLib{$res}:"<span style=\"color: #$color_other\">$Message[0]</span>"; }
@@ -243,4 +235,22 @@ sub LoadOverrideFile_geoip{
        debug(" Plugin $PluginName: Overload file loaded: ".(scalar keys %TmpDomainLookup)." entries found.");
 }
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: TmpLookup
+# Searches the temporary hash for the parameter value and returns the corresponding
+# GEOIP entry
+#-----------------------------------------------------------------------------
+sub TmpLookup_geoip(){
+       $param = shift;
+       if (!$LoadedOverride){&LoadOverrideFile_geoip();}
+       my $val;
+       if ($gi &&
+       (($type eq 'geoip' && $gi->VERSION >= 1.30) || 
+         $type eq 'geoippureperl' && $gi->VERSION >= 1.17)){
+               $val = $TmpDomainLookup{$gi->get_ip_address($param)};
+       }
+    else {$val = $TmpDomainLookup{$param};}
+    return $val || '';
+}
+
 1;     # Do not remove this line
index 77dbef0b9f7b209e14c5444e9a40fa71615eee6f..2c32d6e1fa01c47815a253044384f4eb13c4bc7b 100644 (file)
@@ -258,8 +258,6 @@ sub ShowInfoHost_geoip_asn_maxmind {
         print "</th>";
        }
        elsif ($param) {
-               # try loading our override file if we haven't yet
-               if (!$LoadedOverride){&LoadOverrideFile_geoip_asn_maxmind();}
         my $ip=0;
                my $key;
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
@@ -273,8 +271,7 @@ sub ShowInfoHost_geoip_asn_maxmind {
                print "<td>";
                my $asn = 0;
                if ($key && $ip==4) {
-               if ($geoip_asn_maxmind){$asn = $TmpLookup{$geoip_asn_maxmind->get_ip_address($param)};}
-               else {$asn = $TmpLookup{$param};}
+               $asn = TmpLookup_geoip_asn_maxmind($param);
                if (!$asn && $type eq 'geoippureperl')
                        {
                        # Function org_by_addr does not exists in PurePerl but org_by_name do same
@@ -290,8 +287,7 @@ sub ShowInfoHost_geoip_asn_maxmind {
                    debug("  Plugin $PluginName: IPv6 not supported by MaxMind Free DBs: $key",3);
                }
                if (! $key) {
-               if ($geoip_asn_maxmind){$asn = $TmpLookup{$geoip_asn_maxmind->get_ip_address($param)};}
-               else {$asn = $TmpLookup{$param};}
+               $asn = TmpLookup_geoip_asn_maxmind($param);
                if (!$asn && $type eq 'geoippureperl')
                        {
                        $asn=$geoip_asn_maxmind->org_by_name($param) if $geoip_asn_maxmind;
@@ -350,10 +346,7 @@ sub SectionInitHashArray_geoip_asn_maxmind {
 sub SectionProcessIp_geoip_asn_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       my $asn = 0;
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_asn_maxmind();}
-       if ($geoip_asn_maxmind){$asn = $TmpLookup{$geoip_asn_maxmind->get_ip_address($param)};}
-               else {$asn = $TmpLookup{$param};}
+       my $asn = TmpLookup_geoip_asn_maxmind($param);
        if (!$asn && $type eq 'geoippureperl')
        {
                # Function org_by_addr does not exists in PurePerl but org_by_name do same
@@ -383,9 +376,7 @@ sub SectionProcessIp_geoip_asn_maxmind {
 sub SectionProcessHostname_geoip_asn_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       my $asn=0;
-       if ($geoip_asn_maxmind){$asn = $TmpLookup{$geoip_asn_maxmind->get_ip_address($param)};}
-    else {$asn = $TmpLookup{$param};}
+       my $asn = TmpLookup_geoip_asn_maxmind($param);
        if (!$asn && $type eq 'geoippureperl')
        {
                $asn=$geoip_asn_maxmind->org_by_name($param) if $geoip_asn_maxmind;
@@ -518,4 +509,23 @@ sub trim($)
        return $string;
 }
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: TmpLookup
+# Searches the temporary hash for the parameter value and returns the corresponding
+# GEOIP entry
+#-----------------------------------------------------------------------------
+sub TmpLookup_geoip_asn_maxmind(){
+       $param = shift;
+       if (!$LoadedOverride){&LoadOverrideFile_geoip_asn_maxmind();}
+       my $val;
+       if ($geoip_asn_maxmind && 
+       (($type eq 'geoip' && $geoip_asn_maxmind->VERSION >= 1.30) || 
+         $type eq 'geoippureperl' && $geoip_asn_maxmind->VERSION >= 1.17)){
+               $val = $TmpLookup{$geoip_asn_maxmind->get_ip_address($param)};
+       }
+    else {$val = $TmpLookup{$param};}
+    return $val || '';
+}
+
+
 1;     # Do not remove this line
index 5c52a13d88884b1947ea550dff3c1bee880da369..626914269618d2d26c6699e5480b63bc09b42c59 100755 (executable)
@@ -4452,8 +4452,7 @@ sub AddHTMLGraph_geoip_city_maxmind {
 sub GetCountryCodeByAddr_geoip_city_maxmind {
     my $param="$_[0]";
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_city_maxmind();}
-       my $res=$TmpDomainLookup{$param}||'';
+       my $res = TmpLookup_geoip_city_maxmind($param);
        if ($type eq 'geoippureperl') {
                if (! $res) {
                        my @record = ();
@@ -4493,8 +4492,7 @@ sub GetCountryCodeByAddr_geoip_city_maxmind {
 sub GetCountryCodeByName_geoip_city_maxmind {
     my $param="$_[0]";
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_city_maxmind();}
-       my $res=$TmpDomainLookup{$param}||'';
+       my $res = TmpLookup_geoip_city_maxmind($param);
        if ($type eq 'geoippureperl') {
                if (! $res) {
                        my @record = ();
@@ -4564,7 +4562,6 @@ sub ShowInfoHost_geoip_city_maxmind {
        elsif ($param)
        {
                # try loading our override file if we haven't yet
-               if (!$LoadedOverride){&LoadOverrideFile_geoip_city_maxmind();}
         my $ip=0;
                my $key;
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
@@ -4578,9 +4575,10 @@ sub ShowInfoHost_geoip_city_maxmind {
                if ($key && $ip==4) {
                my $country;
                my $city;
-               my @res;
-               if ($geoip_city_maxmind){@res = @{$TmpDomainLookup{$geoip_city_maxmind->get_ip_address($param)}};}
-               else {@res = @{$TmpDomainLookup{$param}};}
+               my @res = TmpLookup_geoip_city_maxmind($param);
+                       if (!@res){
+                               @res=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+                       }
                if (@res){
                        $country = $res[0];
                        $city = $res[4];
@@ -4619,9 +4617,10 @@ sub ShowInfoHost_geoip_city_maxmind {
                if (! $key) {
                my $country;
                my $city;
-               my @res;
-               if ($geoip_city_maxmind){@res = @{$TmpDomainLookup{$geoip_city_maxmind->get_ip_address($param)}};}
-               else {@res = @{$TmpDomainLookup{$param}};}
+               my @res = TmpLookup_geoip_city_maxmind($param);
+                       if (!@res){
+                               @res=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+                       }
                if (@res){
                        $country = $res[0];
                        $city = $res[4];
@@ -4680,13 +4679,9 @@ sub SectionInitHashArray_geoip_city_maxmind {
 sub SectionProcessIp_geoip_city_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_city_maxmind();}
        if ($type eq 'geoippureperl') {
-               my @record = ();
-               my @res;
-        if ($geoip_city_maxmind){@res = @{$TmpDomainLookup{$geoip_city_maxmind->get_ip_address($param)}};}
-        else {@res = @{$TmpDomainLookup{$param}};}
-               if (!@res){
+               my @record = TmpLookup_geoip_city_maxmind($param);
+               if (!@record){
                        @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
                }
                if ($Debug) { debug("  Plugin $PluginName: GetCityByName for $param: [@record]",5); }
@@ -4707,19 +4702,27 @@ sub SectionProcessIp_geoip_city_maxmind {
        else
        {
                my $record=();
-               if ($TmpDomainLookup{$param}){
-                       @record = $TmpDomainLookup{$param};
+               my $city, $countrycity, $region;
+               my @rec = TmpLookup_geoip_city_maxmind($param);
+               if (@rec){
+                       $city = $rec[4];
+                       $countrycity = $rec[3];
+                       $region = $rec[0];
                }else{
                        $record=$geoip_city_maxmind->record_by_addr($param) if $geoip_city_maxmind;
+                       if ($record){
+                               $city = $record->city;
+                               $countrycity = $record->country_code;
+                               $region = $record->region;
+                       }
                }
-               if ($Debug) { debug("  Plugin $PluginName: GetCityByIp for $param: [$record]",5); }
-           if ($record) {
-               my $city=$record->city;
+               if ($Debug) { debug("  Plugin $PluginName: GetCityByIp for $param: [$city]",5); }
+           if ($city) {
        #       if ($PageBool) { $_city_p{$city}++; }
                if ($city) {
-                   my $countrycity=($record->country_code).'_'.$city;
+                   my $countrycity=$countrycity.'_'.$city;
                    $countrycity=~s/ /%20/g;
-                   if ($record->region) { $countrycity.='_'.$record->region; }
+                   if ($region) { $countrycity.='_'.$region; }
                    $_city_h{lc($countrycity)}++;
                } else {
                    $_city_h{'unknown'}++;
@@ -4740,16 +4743,9 @@ sub SectionProcessIp_geoip_city_maxmind {
 #-----------------------------------------------------------------------------
 sub SectionProcessHostname_geoip_city_maxmind {
     my $param="$_[0]";      # Param must be an IP
-       # <-----
-       # if the record is already in our temp array, then return
-       #if ($TmpDomainLookup{$param}){ return; }
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_city_maxmind();}
        if ($type eq 'geoippureperl') {
-               my @record = ();
-               my @res;
-        if ($geoip_city_maxmind){@res = @{$TmpDomainLookup{$geoip_city_maxmind->get_ip_address($param)}};}
-        else {@res = @{$TmpDomainLookup{$param}};}
-               if (!@res){
+               my @record = TmpLookup_geoip_city_maxmind($param);
+               if (!@record){
                        @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
                }
                if ($Debug) { debug("  Plugin $PluginName: GetCityByName for $param: [@record]",5); }
@@ -4770,8 +4766,11 @@ sub SectionProcessHostname_geoip_city_maxmind {
        else
        {
                my $record=();
-               if ($TmpDomainLookup{$param}){
-                       @record = $TmpDomainLookup{$param};
+               my @rec = TmpLookup_geoip_city_maxmind($param);
+               if (@rec){
+                       $record->city = $rec[4];
+                       $record->region = $rec[3];
+                       $record->country_code = $rec[0];
                }else{
                        $record=$geoip_city_maxmind->record_by_name($param) if $geoip_city_maxmind;
                }
@@ -4912,4 +4911,23 @@ sub LoadOverrideFile_geoip_city_maxmind{
        return;
 }
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: TmpLookup
+# Searches the temporary hash for the parameter value and returns the corresponding
+# GEOIP entry
+#-----------------------------------------------------------------------------
+sub TmpLookup_geoip_city_maxmind(){
+       $param = shift;
+       if (!$LoadedOverride){&LoadOverrideFile_geoip_city_maxmind();}
+       my @val = ();
+       if ($geoip_city_maxmind &&
+       (($type eq 'geoip' && $geoip_city_maxmind->VERSION >= 1.30) || 
+         $type eq 'geoippureperl' && $geoip_city_maxmind->VERSION >= 1.17)){
+               @val = @{$TmpDomainLookup{$geoip_city_maxmind->get_ip_address($param)}};
+       }
+    else {@val = @{$TmpDomainLookup{$param};}}
+    return @val;
+}
+
+
 1;     # Do not remove this line
index b6256eb60dd29025b4060b6b2f35d6750f51eea9..398fe151ad569a13b3707f31e8ce941ad20c9eb1 100644 (file)
@@ -235,8 +235,6 @@ sub ShowInfoHost_geoip_isp_maxmind {
         print "</th>";
        }
        elsif ($param) {
-               # try loading our override file if we haven't yet
-               if (!$LoadedOverride){&LoadOverrideFile_geoip_isp_maxmind();}
         my $ip=0;
                my $key;
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
@@ -249,9 +247,7 @@ sub ShowInfoHost_geoip_isp_maxmind {
                }
                print "<td>";
                if ($key && $ip==4) {
-               my $isp;
-               if ($geoip_isp_maxmind){$isp = $TmpDomainLookup{$geoip_isp_maxmind->get_ip_address($param)};}
-               else {$isp = $TmpDomainLookup{$param};}
+               my $isp = TmpLookup_geoip_isp_maxmind($param);
                if (!$isp && $type eq 'geoippureperl')
                        {
                        # Function isp_by_addr does not exists in PurePerl but isp_by_name do same
@@ -277,9 +273,7 @@ sub ShowInfoHost_geoip_isp_maxmind {
                    print "<span style=\"color: #$color_other\">$Message[0]</span>";
                }
                if (! $key) {
-               my $isp;
-               if ($geoip_isp_maxmind){$isp = $TmpDomainLookup{$geoip_isp_maxmind->get_ip_address($param)};}
-               else {$isp = $TmpDomainLookup{$param};}
+               my $isp = TmpLookup_geoip_isp_maxmind($param);
                if (!$isp && $type eq 'geoippureperl')
                        {
                        $isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
@@ -330,10 +324,7 @@ sub SectionInitHashArray_geoip_isp_maxmind {
 sub SectionProcessIp_geoip_isp_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_isp_maxmind();}
-       my $isp;
-    if ($geoip_isp_maxmind){$isp = $TmpDomainLookup{$geoip_isp_maxmind->get_ip_address($param)};}
-    else {$isp = $TmpDomainLookup{$param};}
+       my $isp = TmpLookup_geoip_isp_maxmind($param);
        if (!$isp && $type eq 'geoippureperl')
        {
                # Function isp_by_addr does not exists in PurePerl but isp_by_name do same
@@ -364,10 +355,7 @@ sub SectionProcessIp_geoip_isp_maxmind {
 sub SectionProcessHostname_geoip_isp_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_isp_maxmind();}
-       my $isp;
-    if ($geoip_isp_maxmind){$isp = $TmpDomainLookup{$geoip_isp_maxmind->get_ip_address($param)};}
-    else {$isp = $TmpDomainLookup{$param};}
+       my $isp = TmpLookup_geoip_isp_maxmind($param);
        if (!$isp && $type eq 'geoippureperl')
        {
                $isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
@@ -493,4 +481,22 @@ sub LoadOverrideFile_geoip_isp_maxmind{
        return;
 }
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: TmpLookup
+# Searches the temporary hash for the parameter value and returns the corresponding
+# GEOIP entry
+#-----------------------------------------------------------------------------
+sub TmpLookup_geoip_isp_maxmind(){
+       $param = shift;
+       if (!$LoadedOverride){&LoadOverrideFile_geoip_isp_maxmind();}
+       my $val;
+       if ($geoip_isp_maxmind &&
+       (($type eq 'geoip' && $geoip_isp_maxmind->VERSION >= 1.30) || 
+         $type eq 'geoippureperl' && $geoip_isp_maxmind->VERSION >= 1.17)){
+               $val = $TmpDomainLookup{$geoip_isp_maxmind->get_ip_address($param)};
+       }
+    else {$val = $TmpDomainLookup{$param};}
+    return $val || '';
+}
+
 1;     # Do not remove this line
index b09626c7dab60ddec5905fb1c5d87c9325fd5a58..6f49862e30d16cb5432108946c7a7822736129f9 100644 (file)
@@ -235,7 +235,6 @@ sub ShowInfoHost_geoip_org_maxmind {
         print "</th>";
        }
        elsif ($param) {
-               if (!$LoadedOverride){&LoadOverrideFile_geoip_org_maxmind();}
         my $ip=0;
                my $key;
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
@@ -248,9 +247,7 @@ sub ShowInfoHost_geoip_org_maxmind {
                }
                print "<td>";
                if ($key && $ip==4) {
-                       my $org;
-               if ($geoip_org_maxmind){$org = $TmpDomainLookup{$geoip_org_maxmind->get_ip_address($param)};}
-               else {$org = $TmpDomainLookup{$param};}
+                       my $org = TmpLookup_geoip_org_maxmind($param);
                if (!$org && $type eq 'geoippureperl')
                        {
                        # Function org_by_addr does not exists in PurePerl but org_by_name do same
@@ -275,9 +272,7 @@ sub ShowInfoHost_geoip_org_maxmind {
                    print "<span style=\"color: #$color_other\">$Message[0]</span>";
                }
                if (! $key) {
-               my $org;
-               if ($geoip_org_maxmind){$org = $TmpDomainLookup{$geoip_org_maxmind->get_ip_address($param)};}
-               else {$org = $TmpDomainLookup{$param};}
+               my $org = TmpLookup_geoip_org_maxmind($param);
                if (!$org && $type eq 'geoippureperl')
                        {
                        $org=$geoip_org_maxmind->org_by_name($param) if $geoip_org_maxmind;
@@ -328,10 +323,7 @@ sub SectionInitHashArray_geoip_org_maxmind {
 sub SectionProcessIp_geoip_org_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_org_maxmind();}
-       my $org;
-    if ($geoip_org_maxmind){$org = $TmpDomainLookup{$geoip_org_maxmind->get_ip_address($param)};}
-    else {$org = $TmpDomainLookup{$param};}
+       my $org = TmpLookup_geoip_org_maxmind($param);
        if (!$org && $type eq 'geoippureperl')
        {
                # Function org_by_addr does not exists in PurePerl but org_by_name do same
@@ -361,10 +353,7 @@ sub SectionProcessIp_geoip_org_maxmind {
 sub SectionProcessHostname_geoip_org_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_org_maxmind();}
-       my $org;
-    if ($geoip_org_maxmind){$org = $TmpDomainLookup{$geoip_org_maxmind->get_ip_address($param)};}
-    else {$org = $TmpDomainLookup{$param};}
+       my $org = TmpLookup_geoip_org_maxmind($param);
        if (!$org && $type eq 'geoippureperl')
        {
                $org=$geoip_org_maxmind->org_by_name($param) if $geoip_org_maxmind;
@@ -490,4 +479,22 @@ sub LoadOverrideFile_geoip_org_maxmind{
        return;
 }
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: TmpLookup
+# Searches the temporary hash for the parameter value and returns the corresponding
+# GEOIP entry
+#-----------------------------------------------------------------------------
+sub TmpLookup_geoip_org_maxmind(){
+       $param = shift;
+       if (!$LoadedOverride){&LoadOverrideFile_geoip_org_maxmind();}
+       my $val;
+       if ($geoip_org_maxmind && 
+       (($type eq 'geoip' && $geoip_org_maxmind->VERSION >= 1.30) || 
+         $type eq 'geoippureperl' && $geoip_org_maxmind->VERSION >= 1.17)){
+               $val = $TmpDomainLookup{$geoip_org_maxmind->get_ip_address($param)};
+       }
+    else {$val = $TmpDomainLookup{$param};}
+    return $val || '';
+}
+
 1;     # Do not remove this line
index 5b1e3be8f50fe76780ebc5109c8e602c0b0bad9f..6e07b2c492ce5782a4db9a954f6f8e8225f76747 100755 (executable)
@@ -393,9 +393,7 @@ sub ShowInfoHost_geoip_region_maxmind {
                print "<td>";
                if ($key && $ip==4) {
                my ($res1,$res2,$countryregion)=();
-               my @res;
-               if ($geoip_region_maxmind){@res = @{$TmpDomainLookup{$geoip_region_maxmind->get_ip_address($param)}};}
-               else {@res = @{$TmpDomainLookup{$param}};}
+               my @res = TmpLookup_geoip_region_maxmind($param);
                if (@res){
                        $res1 = $res[0];
                        $res2 = $res[1];
@@ -427,9 +425,7 @@ sub ShowInfoHost_geoip_region_maxmind {
         }
                if (! $key) {
                my ($res1,$res2,$countryregion)=();
-               my @res;
-               if ($geoip_region_maxmind){@res = @{$TmpDomainLookup{$geoip_region_maxmind->get_ip_address($param)}};}
-               else {@res = @{$TmpDomainLookup{$param}};}
+               my @res = TmpLookup_geoip_region_maxmind($param);
                if (@res){
                        $res1 = $res[0];
                        $res2 = $res[1];
@@ -487,11 +483,8 @@ sub SectionInitHashArray_geoip_region_maxmind {
 sub SectionProcessIp_geoip_region_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_region_maxmind();}
        my ($res1,$res2,$countryregion)=();
-       my @res;
-    if ($geoip_region_maxmind){@res = @{$TmpDomainLookup{$geoip_region_maxmind->get_ip_address($param)}};}
-    else {@res = @{$TmpDomainLookup{$param}};}
+       my @res = TmpLookup_geoip_region_maxmind($param);
     if (@res){
        $res1 = $res[0];
                $res2 = $res[1];
@@ -515,11 +508,8 @@ sub SectionProcessIp_geoip_region_maxmind {
 sub SectionProcessHostname_geoip_region_maxmind {
     my $param="$_[0]";      # Param must be a hostname
        # <-----
-       if (!$LoadedOverride){&LoadOverrideFile_geoip_region_maxmind();}
        my ($res1,$res2,$countryregion)=();
-       my @res;
-    if ($geoip_region_maxmind){@res = @{$TmpDomainLookup{$geoip_region_maxmind->get_ip_address($param)}};}
-    else {@res = @{$TmpDomainLookup{$param}};}
+       my @res = TmpLookup_geoip_region_maxmind($param);
     if (@res){
        $res1 = $res[0];
                $res2 = $res[1];
@@ -645,4 +635,22 @@ sub LoadOverrideFile_geoip_region_maxmind{
        return;
 }
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: TmpLookup
+# Searches the temporary hash for the parameter value and returns the corresponding
+# GEOIP entry
+#-----------------------------------------------------------------------------
+sub TmpLookup_geoip_region_maxmind(){
+       $param = shift;
+       if (!$LoadedOverride){&LoadOverrideFile_geoip_region_maxmind();}
+       my @val = ();
+       if ($geoip_region_maxmind &&
+       (($type eq 'geoip' && $geoip_region_maxmind->VERSION >= 1.30) || 
+         $type eq 'geoippureperl' && $geoip_region_maxmind->VERSION >= 1.17)){
+               @val = @{$TmpDomainLookup{$geoip_region_maxmind->get_ip_address($param)}};
+       }
+    else {@val = @{$TmpDomainLookup{$param};}}
+    return @val;
+}
+
 1;     # Do not remove this line