]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Now geoip plugins works both with GeoIP C API or GeoIP PurePerl API.
authoreldy <>
Thu, 23 Mar 2006 12:36:32 +0000 (12:36 +0000)
committereldy <>
Thu, 23 Mar 2006 12:36:32 +0000 (12:36 +0000)
wwwroot/cgi-bin/plugins/geoip.pm
wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm

index 6dea75e0bf2da56e4fab8c9d91067639504ea3c9..497dac81ad7155533812728eea99c2795566f4cc 100644 (file)
@@ -69,12 +69,13 @@ sub Init_geoip {
                else { $mode=Geo::IP::GEOIP_STANDARD(); }
        }
        %TmpDomainLookup=();
-       debug(" Plugin geoip: GeoIP initialized in mode $type $mode",1);
+       debug(" Plugin geoip: GeoIP initialized type=$type mode=$mode",1);
        if ($type eq 'geoippureperl') {
                $gi = Geo::IP::PurePerl->open($datafile, $mode);
        } else {
                $gi = Geo::IP->open($datafile, $mode);
        }
+       debug(" Plugin geoip: GeoIP initialized database_info=".$gi->database_info());
        # ----->
 
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
index 50e9a7da9c9da2d59b21ebfadc7301573bf8b81b..051c6680703e0e1cfe6f0b5829dbaa0400f094d9 100755 (executable)
@@ -4,15 +4,24 @@
 # This plugin allow you to add a city report.
 # Need the licensed city database from Maxmind.
 #-----------------------------------------------------------------------------
-# Perl Required Modules: Geo::IP (Geo::IP::PurePerl is not yet supported)
+# Perl Required Modules: Geo::IP or Geo::IP::PurePerl
 #-----------------------------------------------------------------------------
 # $Revision$ - $Author$ - $Date$
 
 
 # <-----
 # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
-if (!eval ('require "Geo/IP.pm";'))    {
-    return $@?"Error: $@":"Error: Need Perl module Geo::IP (Geo::IP::PurePerl is not yet supported)";
+use vars qw/ $type /;
+$type='geoip';
+if (!eval ('require "Geo/IP.pm";')) {
+       $error1=$@;
+       $type='geoippureperl';
+       if (!eval ('require "Geo/IP/PurePerl.pm";')) {
+               $error2=$@;
+               $ret=($error1||$error2)?"Error:\n$error1$error2":"";
+               $ret.="Error: Need Perl module Geo::IP or Geo::IP::PurePerl";
+               return $ret;
+       }
 }
 # ----->
 use strict;no strict "refs";
@@ -25,13 +34,14 @@ use strict;no strict "refs";
 # <-----
 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
-my $PluginNeedAWStatsVersion="6.2";
+my $PluginNeedAWStatsVersion="6.5";
 my $PluginHooksFunctions="AddHTMLMenuLink AddHTMLGraph ShowInfoHost SectionInitHashArray SectionProcessIp SectionProcessHostname SectionReadHistory SectionWriteHistory";
 # ----->
 
 # <-----
 # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
 use vars qw/
+%TmpDomainLookup
 $geoip_city_maxmind
 %_city_p
 %_city_h
@@ -4263,14 +4273,23 @@ sub Init_geoip_city_maxmind {
        # <-----
        # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
        debug(" Plugin geoip_city_maxmind: InitParams=$InitParams",1);
-#    if ($UpdateStats) {
-       my ($mode,$datafile)=split(/\s+/,$InitParams,2);
-       if (! $datafile) { $datafile="GeoIPCity.dat"; }
-       if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE')  { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
-       else { $mode=Geo::IP::GEOIP_STANDARD(); }
-       debug(" Plugin geoip_city_maxmind: GeoIP initialized in mode $mode",1);
-        $geoip_city_maxmind = Geo::IP->open($datafile, $mode);
-#    }
+       my ($mode,$datafile)=split(/\s+/,$InitParams,2);
+       if (! $datafile) { $datafile="GeoIPCity.dat"; }
+       if ($type eq 'geoippureperl') {
+               if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE')  { $mode=Geo::IP::PurePerl::GEOIP_MEMORY_CACHE(); }
+               else { $mode=Geo::IP::PurePerl::GEOIP_STANDARD(); }
+       } else {
+               if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE')  { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
+               else { $mode=Geo::IP::GEOIP_STANDARD(); }
+       }
+       %TmpDomainLookup=();
+       debug(" Plugin geoip_city_maxmind: GeoIP initialized type=$type mode=$mode",1);
+       if ($type eq 'geoippureperl') {
+               $geoip_city_maxmind = Geo::IP::PurePerl->open($datafile, $mode);
+       } else {
+               $geoip_city_maxmind = Geo::IP->open($datafile, $mode);
+       }
+       debug(" Plugin geoip_city_maxmind: GeoIP initialized database_info=".$gi->database_info());
        # ----->
 
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
@@ -4402,6 +4421,86 @@ sub AddHTMLGraph_geoip_city_maxmind {
 }
 
 
+#-----------------------------------------------------------------------------
+# 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_geoip_city_maxmind {
+    my $param="$_[0]";
+       # <-----
+       my $res=$TmpDomainLookup{$param}||'';
+       if ($type eq 'geoippureperl') {
+               if (! $res) {
+                       my @record = ();
+                       @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+               my $country;
+               $country=$record[0] if @record;
+               $res=lc($country) || 'unknown';
+                       $TmpDomainLookup{$param}=$res;
+               if ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByAddr for $param: [$res]",5); }
+               }
+               elsif ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
+       }
+       else
+       {
+               if (! $res) {
+               my $record=();
+               $record=$geoip_city_maxmind->record_by_addr($param) if $geoip_city_maxmind;
+               my $country;
+               $country=$record->country if $record;
+               $res=lc($country) || 'unknown';
+                       $TmpDomainLookup{$param}=$res;
+               if ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByAddr for $param: [$res]",5); }
+               }
+               elsif ($Debug) { debug("  Plugin geoip_region_maxmind: 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_geoip_city_maxmind {
+    my $param="$_[0]";
+       # <-----
+       my $res=$TmpDomainLookup{$param}||'';
+       if ($type eq 'geoippureperl') {
+               if (! $res) {
+                       my @record = ();
+                       @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+               my $country;
+               $country=$record[0] if @record;
+               $res=lc($country) || 'unknown';
+                       $TmpDomainLookup{$param}=$res;
+               if ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByName for $param: [$res]",5); }
+               }
+               elsif ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
+       }
+       else
+       {
+               if (! $res) {
+               my $record=();
+               $record=$geoip_city_maxmind->record_by_name($param) if $geoip_city_maxmind;
+               my $country;
+               $country=$record->country if $record;
+               $res=lc($country) || 'unknown';
+                       $TmpDomainLookup{$param}=$res;
+               if ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByName for $param: [$res]",5); }
+               }
+               elsif ($Debug) { debug("  Plugin geoip_region_maxmind: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
+       }
+       # ----->
+       return $res;
+}
+
+
 #-----------------------------------------------------------------------------
 # PLUGIN FUNCTION: ShowInfoHost_pluginname
 # UNIQUE: NO (Several plugins using this function can be loaded)
@@ -4430,6 +4529,9 @@ sub ShowInfoHost_geoip_city_maxmind {
        $NewLinkParams =~ s/^&amp;//; $NewLinkParams =~ s/&amp;$//;
        if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
 
+#              print "<th width=\"80\">";
+#        print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=plugin_geoip_city_maxmind&amp;suboutput=country"):"$PROG$StaticLinks.plugin_geoip_city_maxmind.country.$StaticExt")."\"$NewLinkTarget>GeoIP<br/>Country</a>";
+#        print "</th>";
                print "<th width=\"80\">";
         print "<a href=\"".($ENV{'GATEWAY_INTERFACE'} || !$StaticLinks?XMLEncode("$AWScript?${NewLinkParams}output=plugin_geoip_city_maxmind"):"$PROG$StaticLinks.plugin_geoip_city_maxmind.$StaticExt")."\"$NewLinkTarget>GeoIP<br/>City</a>";
         print "</th>";
@@ -4445,32 +4547,74 @@ sub ShowInfoHost_geoip_city_maxmind {
                    $ip=6;
                        $key=$param;
                }
-               print "<td>";
                if ($key && $ip==4) {
-               my $record=();
-               $record=$geoip_city_maxmind->record_by_addr($param) if $geoip_city_maxmind;
-               if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByIp for $param: [$record]",5); }
-            my $city;
-            $city=$record->city if $record;
+               my $country;
+               my $city;
+                       if ($type eq 'geoippureperl')
+                       {
+                               my @record = ();
+                               @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+                       if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByIp for $param: [@record]",5); }
+                   $country=$record[0] if @record;
+                   $city=$record[4] if @record;
+                       }
+                       else
+                       {
+                       my $record=();
+                       $record=$geoip_city_maxmind->record_by_addr($param) if $geoip_city_maxmind;
+                       if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByIp for $param: [$record]",5); }
+                   $country=$record->country_code if $record;
+                   $city=$record->city 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>"; }
+#                  print "</td>";
+                       print "<td>";
                    if ($city) { print "$city"; }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
+                   print "</td>";
                }
                if ($key && $ip==6) {
+#                      print "<td>";
+#                  print "<span style=\"color: #$color_other\">$Message[0]</span>";
+#                      print "</td>";
+                       print "<td>";
                    print "<span style=\"color: #$color_other\">$Message[0]</span>";
+                       print "</td>";
                }
                if (! $key) {
-               my $record=();
-               $record=$geoip_city_maxmind->record_by_name($param) if $geoip_city_maxmind;
-               if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByHostname for $param: [$record]",5); }
-            my $city;
-            $city=$record->city if $record;
+               my $country;
+               my $city;
+                       if ($type eq 'geoippureperl')
+                       {
+                               my @record = ();
+                               @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+                       if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByHostname for $param: [@record]",5); }
+                   $country=$record[0] if @record;
+                   $city=$record[4] if @record;
+                       }
+                       else
+                       {
+                       my $record=();
+                       $record=$geoip_city_maxmind->record_by_name($param) if $geoip_city_maxmind;
+                       if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByHostname for $param: [$record]",5); }
+                   $country=$record->country_code if $record;
+                   $city=$record->city 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>"; }
+                   print "</td>";
+                       print "<td>";
                    if ($city) { print "$city"; }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
+                       print "</td>";
                }
-               print "</td>";
        }
        else {
                print "<td>&nbsp;</td>";
+               print "<td>&nbsp;</td>";
        }
        return 1;
        # ----->
@@ -4498,24 +4642,45 @@ sub SectionInitHashArray_geoip_city_maxmind {
 sub SectionProcessIp_geoip_city_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       my $record=();
-       $record=$geoip_city_maxmind->record_by_addr($param) if $geoip_city_maxmind;
-       if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByIp for $param: [$record]",5); }
-    if ($record) {
-        my $city=$record->city;
-#      if ($PageBool) { $_city_p{$city}++; }
-        if ($city) {
-            my $countrycity=($record->country_code).'_'.$city;
-            $countrycity=~s/ /%20/g;
-            if ($record->region) { $countrycity.='_'.$record->region; }
-            $_city_h{lc($countrycity)}++;
-        } else {
-            $_city_h{'unknown'}++;
-        }
-#      if ($timerecord > $_city_l{$city}) { $_city_l{$city}=$timerecord; }
-    } else {
-        $_city_h{'unknown'}++;
-    }
+       if ($type eq 'geoippureperl') {
+               my @record = ();
+               @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+               if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByName for $param: [@record]",5); }
+           if (@record) {
+                       my $city=$record[4];
+                       if ($city) {
+                   my $countrycity=$record[0].'_'.$city;
+                   $countrycity=~s/ /%20/g;
+                   if ($record[3]) { $countrycity.='_'.$record[3]; }
+                   $_city_h{lc($countrycity)}++;
+               } else {
+                   $_city_h{'unknown'}++;
+               }
+           } else {
+               $_city_h{'unknown'}++;
+           }
+       }
+       else
+       {
+               my $record=();
+               $record=$geoip_city_maxmind->record_by_addr($param) if $geoip_city_maxmind;
+               if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByIp for $param: [$record]",5); }
+           if ($record) {
+               my $city=$record->city;
+       #       if ($PageBool) { $_city_p{$city}++; }
+               if ($city) {
+                   my $countrycity=($record->country_code).'_'.$city;
+                   $countrycity=~s/ /%20/g;
+                   if ($record->region) { $countrycity.='_'.$record->region; }
+                   $_city_h{lc($countrycity)}++;
+               } else {
+                   $_city_h{'unknown'}++;
+               }
+       #       if ($timerecord > $_city_l{$city}) { $_city_l{$city}=$timerecord; }
+           } else {
+               $_city_h{'unknown'}++;
+           }
+       }
        # ----->
        return;
 }
@@ -4528,24 +4693,45 @@ sub SectionProcessIp_geoip_city_maxmind {
 sub SectionProcessHostname_geoip_city_maxmind {
     my $param="$_[0]";      # Param must be an IP
        # <-----
-       my $record=();
-       $record=$geoip_city_maxmind->record_by_name($param) if $geoip_city_maxmind;
-       if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByName for $param: [$record]",5); }
-    if ($record) {
-        my $city=$record->city;
-#          if ($PageBool) { $_city_p{$city}++; }
-        if ($city) {
-            my $countrycity=($record->country_code).'_'.$city;
-            $countrycity=~s/ /%20/g;
-            if ($record->region) { $countrycity.='_'.$record->region; }
-            $_city_h{lc($countrycity)}++;
-        } else {
-            $_city_h{'unknown'}++;
-        }
-#          if ($timerecord > $_city_l{$city}) { $_city_l{$city}=$timerecord; }
-    } else {
-        $_city_h{'unknown'}++;
-    }
+       if ($type eq 'geoippureperl') {
+               my @record = ();
+               @record=$geoip_city_maxmind->get_city_record($param) if $geoip_city_maxmind;
+               if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByName for $param: [@record]",5); }
+           if (@record) {
+                       my $city=$record[4];
+                       if ($city) {
+                   my $countrycity=$record[0].'_'.$city;
+                   $countrycity=~s/ /%20/g;
+                   if ($record[3]) { $countrycity.='_'.$record[3]; }
+                   $_city_h{lc($countrycity)}++;
+               } else {
+                   $_city_h{'unknown'}++;
+               }
+           } else {
+               $_city_h{'unknown'}++;
+           }
+       }
+       else
+       {
+               my $record=();
+               $record=$geoip_city_maxmind->record_by_name($param) if $geoip_city_maxmind;
+               if ($Debug) { debug("  Plugin geoip_city_maxmind: GetCityByName for $param: [$record]",5); }
+           if ($record) {
+               my $city=$record->city;
+       #           if ($PageBool) { $_city_p{$city}++; }
+               if ($city) {
+                   my $countrycity=($record->country_code).'_'.$city;
+                   $countrycity=~s/ /%20/g;
+                   if ($record->region) { $countrycity.='_'.$record->region; }
+                   $_city_h{lc($countrycity)}++;
+               } else {
+                   $_city_h{'unknown'}++;
+               }
+       #           if ($timerecord > $_city_l{$city}) { $_city_l{$city}=$timerecord; }
+           } else {
+               $_city_h{'unknown'}++;
+           }
+       }
        # ----->
        return;
 }
index 2f5619a804ee83c5da48ad2663deace7dedd6554..b9f2288e719e6b86cfa72f36631e20c87498d770 100755 (executable)
@@ -5,7 +5,7 @@
 # from a Geographical database (US and Canada).
 # Need the licensed region database from Maxmind.
 #-----------------------------------------------------------------------------
-# Perl Required Modules: Geo::IP (Geo::IP::PurePerl is not yet supported)
+# Perl Required Modules: Geo::IP or Geo::IP::PurePerl
 #-----------------------------------------------------------------------------
 # $Revision$ - $Author$ - $Date$
 
@@ -35,8 +35,8 @@ use strict;no strict "refs";
 # <-----
 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
-my $PluginNeedAWStatsVersion="6.2";
-my $PluginHooksFunctions="GetCountryCodeByAddr GetCountryCodeByName AddHTMLMenuLink AddHTMLGraph ShowInfoHost SectionInitHashArray SectionProcessIp SectionProcessHostname SectionReadHistory SectionWriteHistory";
+my $PluginNeedAWStatsVersion="6.5";
+my $PluginHooksFunctions="AddHTMLMenuLink AddHTMLGraph ShowInfoHost SectionInitHashArray SectionProcessIp SectionProcessHostname SectionReadHistory SectionWriteHistory";
 # ----->
 
 # <-----
@@ -149,7 +149,7 @@ sub Init_geoip_region_maxmind {
     
        # <-----
        # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
-       debug(" Plugin geoip: InitParams=$InitParams",1);
+       debug(" Plugin geoip_region_maxmind: InitParams=$InitParams",1);
        my ($mode,$datafile)=split(/\s+/,$InitParams,2);
        if (! $datafile) { $datafile="GeoIPRegion.dat"; }
        if ($type eq 'geoippureperl') {
@@ -160,13 +160,14 @@ sub Init_geoip_region_maxmind {
                else { $mode=Geo::IP::GEOIP_STANDARD(); }
        }
        %TmpDomainLookup=();
-       debug(" Plugin geoip: GeoIP initialized in mode $type $mode",1);
+       debug(" Plugin geoip_region_maxmind: GeoIP initialized type=$type mode=$mode",1);
        if ($type eq 'geoippureperl') {
                $geoip_region_maxmind = Geo::IP::PurePerl->open($datafile, $mode);
        } else {
                $geoip_region_maxmind = Geo::IP->open($datafile, $mode);
        }
-       # ----->
+       debug(" Plugin geoip_region_maxmind: GeoIP initialized database_info=".$gi->database_info());
+       # ----->
 
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
 }
@@ -184,7 +185,7 @@ sub AddHTMLMenuLink_geoip_region_maxmind {
        # <-----
        if ($Debug) { debug(" Plugin geoip_region_maxmind: AddHTMLMenuLink"); }
     if ($categ eq 'who') {
-        $menu->{'plugin_geoip_region_maxmind'}=2.1;               # Pos
+        $menu->{'plugin_geoip_region_maxmind'}=2.1;             # Pos
         $menulink->{'plugin_geoip_region_maxmind'}=2;           # Type of link
         $menutext->{'plugin_geoip_region_maxmind'}="Regions";   # Text
     }
@@ -292,6 +293,7 @@ sub AddHTMLGraph_geoip_region_maxmind {
 # 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_geoip_region_maxmind {
     my $param="$_[0]";
        # <-----
@@ -314,6 +316,7 @@ sub GetCountryCodeByAddr_geoip_region_maxmind {
 # 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_geoip_region_maxmind {
     my $param="$_[0]";
        # <-----
@@ -476,7 +479,7 @@ sub SectionProcessHostname_geoip_region_maxmind {
        # <-----
        my ($res1,$res2,$countryregion)=();
        ($res1,$res2)=$geoip_region_maxmind->region_by_name($param) if $geoip_region_maxmind;
-       if ($Debug) { debug("  Plugin geoip_region_maxmind: GetRegionByName for $param: [{$res1}_{$res2}]",5); }
+       if ($Debug) { debug("  Plugin geoip_region_maxmind: GetRegionByName for $param: [${res1}_${res2}]",5); }
     if ($res2 =~ /\w\w/) { $countryregion=lc("${res1}_${res2}"); }
     else { $countryregion='unknown'; }
 #      if ($PageBool) { $_region_p{$countryregion}++; }