From: eldy <>
Date: Sun, 24 Oct 2004 17:27:23 +0000 (+0000)
Subject: New: Add the geoip_region_maxmind and the geoip_city_maxmind plugin.
X-Git-Tag: AWSTATS_6_3_RELEASE~82
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f088c60c4e76961ef316dd18fe4dc05c54eac22e;p=thirdparty%2FAWStats.git
New: Add the geoip_region_maxmind and the geoip_city_maxmind plugin.
---
diff --git a/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm b/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
new file mode 100755
index 00000000..6e6441aa
--- /dev/null
+++ b/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
@@ -0,0 +1,388 @@
+#!/usr/bin/perl
+#-----------------------------------------------------------------------------
+# GeoIp_City_Maxmind AWStats plugin
+# 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)
+#-----------------------------------------------------------------------------
+# $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 strict;no strict "refs";
+
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN VARIABLES
+#-----------------------------------------------------------------------------
+# <-----
+# 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="AddHTMLMenuLink SectionInitHashArray SectionProcessIp SectionReadHistory SectionWriteHistory";
+# ----->
+
+# <-----
+# IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
+use vars qw/
+$geoip_city_maxmind
+%_city_p
+%_city_h
+%_city_k
+%_city_l
+%_region_p
+%_region_h
+%_region_k
+%_region_l
+$MAXNBOFSECTIONGIR
+%region
+/;
+my %countrylib=('ca'=>'Canadian Regions','us'=>'US regions');
+my %regca=(
+'AB',"Alberta",
+'BC',"British Columbia",
+'MB',"Manitoba",
+'NB',"New Brunswick",
+'NF',"Newfoundland",
+'NS',"Nova Scotia",
+'NU',"Nunavut",
+'ON',"Ontario",
+'PE',"Prince Edward Island",
+'QC',"Quebec",
+'SK',"Saskatchewan",
+'NT',"Northwest Territories",
+'YT',"Yukon Territory"
+);
+my %regus=(
+'AA',"Armed Forces Americas",
+'AE',"Armed Forces Europe, Middle East, & Canada",
+'AK',"Alaska",
+'AL',"Alabama",
+'AP',"Armed Forces Pacific",
+'AR',"Arkansas",
+'AS',"American Samoa",
+'AZ',"Arizona",
+'CA',"California",
+'CO',"Colorado",
+'CT',"Connecticut",
+'DC',"District of Columbia",
+'DE',"Delaware",
+'FL',"Florida",
+'FM',"Federated States of Micronesia",
+'GA',"Georgia",
+'GU',"Guam",
+'HI',"Hawaii",
+'IA',"Iowa",
+'ID',"Idaho",
+'IL',"Illinois",
+'IN',"Indiana",
+'KS',"Kansas",
+'KY',"Kentucky",
+'LA',"Louisiana",
+'MA',"Massachusetts",
+'MD',"Maryland",
+'ME',"Maine",
+'MH',"Marshall Islands",
+'MI',"Michigan",
+'MN',"Minnesota",
+'MO',"Missouri",
+'MP',"Northern Mariana Islands",
+'MS',"Mississippi",
+'MT',"Montana",
+'NC',"North Carolina",
+'ND',"North Dakota",
+'NE',"Nebraska",
+'NH',"New Hampshire",
+'NJ',"New Jersey",
+'NM',"New Mexico",
+'NV',"Nevada",
+'NY',"New York",
+'OH',"Ohio",
+'OK',"Oklahoma",
+'OR',"Oregon",
+'PA',"Pennsylvania",
+'PR',"Puerto Rico",
+'PW',"Palau",
+'RI',"Rhode Island",
+'SC',"South Carolina",
+'SD',"South Dakota",
+'TN',"Tennessee",
+'TX',"Texas",
+'UT',"Utah",
+'VA',"Virginia",
+'VI',"Virgin Islands",
+'VT',"Vermont",
+'WA',"Washington",
+'WV',"West Virginia",
+'WI',"Wisconsin",
+'WY',"Wyoming"
+);
+my %region=(
+'ca'=>\%regca,
+'us'=>\%regus
+);
+# ----->
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: Init_pluginname
+#-----------------------------------------------------------------------------
+sub Init_geoip_city_maxmind {
+ my $InitParams=shift;
+ my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
+ $MAXNBOFSECTIONGIR=10;
+
+ # <-----
+ # 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);
+ }
+ # ----->
+
+ return ($checkversion?$checkversion:"$PluginHooksFunctions");
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLMenuLink_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub AddHTMLMenuLink_geoip_city_maxmind {
+ my $categ=$_[0];
+ my $menu=$_[1];
+ my $menulink=$_[2];
+ my $menutext=$_[3];
+ # <-----
+ if ($Debug) { debug(" Plugin geoip_city_maxmind: AddHTMLMenuLink"); }
+ if ($categ eq 'who') {
+ $menu->{'plugin_geoip_city_maxmind'}=1; # Pos
+ $menulink->{'plugin_geoip_city_maxmind'}=2; # Type of link
+ $menutext->{'plugin_geoip_city_maxmind'}="Cities"; # Text
+ }
+ # ----->
+ return 0;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLGraph_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub AddHTMLGraph_geoip_city_maxmind {
+ my $categ=$_[0];
+ my $menu=$_[1];
+ my $menulink=$_[2];
+ my $menutext=$_[3];
+ # <-----
+ my $ShowCities='H';
+ $MinHit{'Cities'}=1;
+ my $total_p; my $total_h; my $total_k;
+ my $rest_p; my $rest_h; my $rest_k;
+
+ if ($Debug) { debug(" Plugin geoip_city_maxmind: AddHTMLGraph $categ $menu $menulink $menutext"); }
+ my $title='Cities';
+ &tab_head("$title",19,0,'cities');
+ print "
| Cities : ".((scalar keys %_city_h)-($_city_h{'unknown'}?1:0))." | ";
+ if ($ShowCities =~ /P/i) { print "$Message[56] | "; }
+ if ($ShowCities =~ /P/i) { print "$Message[15] | "; }
+ if ($ShowCities =~ /H/i) { print "$Message[57] | "; }
+ if ($ShowCities =~ /H/i) { print "$Message[15] | "; }
+ if ($ShowCities =~ /B/i) { print "$Message[75] | "; }
+ if ($ShowCities =~ /L/i) { print "$Message[9] | "; }
+ print "
\n";
+ $total_p=$total_h=$total_k=0;
+ my $count=0;
+ &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Cities'},\%_city_h,\%_city_h);
+ # Group by country
+# my @countrylist=('ca','us');
+# foreach my $country (@countrylist) {
+# print "";
+# print "| ".$countrylib{$country}." | ";
+# if ($ShowCities =~ /P/i) { print " | "; }
+# if ($ShowCities =~ /P/i) { print " | "; }
+# if ($ShowCities =~ /H/i) { print " | "; }
+# if ($ShowCities =~ /H/i) { print " | "; }
+# if ($ShowCities =~ /B/i) { print " | "; }
+# if ($ShowCities =~ /L/i) { print " | "; }
+# print "
\n";
+ foreach my $key (@keylist) {
+ if ($key eq 'unknown') { next; }
+ my ($countrycode,$city)=split('_',$key);
+# if ($countrycode ne $country) { next; }
+ my $p_p; my $p_h;
+ if ($TotalPages) { $p_p=int($_city_p{$key}/$TotalPages*1000)/10; }
+ if ($TotalHits) { $p_h=int($_city_h{$key}/$TotalHits*1000)/10; }
+ print "";
+ print "| ".$DomainsHashIDLib{$countrycode}." | ";
+ print "".ucfirst($city)." | ";
+ if ($ShowCities =~ /P/i) { print "".($_city_p{$key}?$_city_p{$key}:" ")." | "; }
+ if ($ShowCities =~ /P/i) { print "".($_city_p{$key}?"$p_p %":' ')." | "; }
+ if ($ShowCities =~ /H/i) { print "".($_city_h{$key}?$_city_h{$key}:" ")." | "; }
+ if ($ShowCities =~ /H/i) { print "".($_city_h{$key}?"$p_h %":' ')." | "; }
+ if ($ShowCities =~ /B/i) { print "".Format_Bytes($_city_k{$key})." | "; }
+ if ($ShowCities =~ /L/i) { print "".($_city_p{$key}?Format_Date($_city_l{$key},1):'-')." | "; }
+ print "
\n";
+ $total_p += $_city_p{$key}||0;
+ $total_h += $_city_h{$key};
+ $total_k += $_city_k{$key}||0;
+ $count++;
+ }
+# }
+ if ($Debug) { debug("Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",2); }
+ $rest_p=0;
+ $rest_h=$TotalHits-$total_h;
+ $rest_k=0;
+ if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other cities
+# print "";
+# print "| | ";
+# if ($ShowCities =~ /P/i) { print " | "; }
+# if ($ShowCities =~ /P/i) { print " | "; }
+# if ($ShowCities =~ /H/i) { print " | "; }
+# if ($ShowCities =~ /H/i) { print " | "; }
+# if ($ShowCities =~ /B/i) { print " | "; }
+# if ($ShowCities =~ /L/i) { print " | "; }
+# print "
\n";
+
+ my $p_p; my $p_h;
+ if ($TotalPages) { $p_p=int($rest_p/$TotalPages*1000)/10; }
+ if ($TotalHits) { $p_h=int($rest_h/$TotalHits*1000)/10; }
+ print "";
+ print "| $Message[2]/$Message[0] | ";
+ if ($ShowCities =~ /P/i) { print "".($rest_p?$rest_p:" ")." | "; }
+ if ($ShowCities =~ /P/i) { print "".($rest_p?"$p_p %":' ')." | "; }
+ if ($ShowCities =~ /H/i) { print "".($rest_h?$rest_h:" ")." | "; }
+ if ($ShowCities =~ /H/i) { print "".($rest_h?"$p_h %":' ')." | "; }
+ if ($ShowCities =~ /B/i) { print "".Format_Bytes($rest_k)." | "; }
+ if ($ShowCities =~ /L/i) { print " | "; }
+ print "
\n";
+ }
+ &tab_end();
+
+ # ----->
+ return 0;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionInitHashArray_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionInitHashArray_geoip_city_maxmind {
+ my $param="$_[0]";
+ # <-----
+ if ($Debug) { debug(" Plugin geoip_city_maxmind: Init_HashArray"); }
+ %_city_p = %_city_h = %_city_k = %_city_l =();
+ # ----->
+ return 0;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionProcessIP_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+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); }
+ my $city=$record->city;
+# if ($PageBool) { $_city_p{$city}++; }
+ if ($city) {
+ my $countrycity=lc(($record->country_code)."_".$city);
+ $countrycity=~tr/ /_/;
+ $_city_h{$countrycity}++;
+ } else {
+ $_city_h{'unknown'}++;
+ }
+# if ($timerecord > $_city_l{$city}) { $_city_l{$city}=$timerecord; }
+ # ----->
+ return;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionReadHistory_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionReadHistory_geoip_city_maxmind {
+ my $issectiontoload=shift;
+ my $xmlold=shift;
+ my $xmleb=shift;
+ my $countlines=shift;
+ # <-----
+ if ($Debug) { debug(" Plugin geoip_city_maxmind: Begin of PLUGIN_geoip_city_maxmind section"); }
+ my @field=();
+ my $count=0;my $countloaded=0;
+ do {
+ if ($field[0]) {
+ $count++;
+ if ($issectiontoload) {
+ $countloaded++;
+ if ($field[2]) { $_city_h{$field[0]}+=$field[2]; }
+ }
+ }
+ $_=;
+ chomp $_; s/\r//;
+ @field=split(/\s+/,($xmlold?CleanFromTags($_):$_));
+ $countlines++;
+ }
+ until ($field[0] eq 'END_PLUGIN_geoip_city_maxmind' || $field[0] eq "${xmleb}END_PLUGIN_geoip_city_maxmind" || ! $_);
+ if ($field[0] ne 'END_PLUGIN_geoip_city_maxmind' && $field[0] ne "${xmleb}END_PLUGIN_geoip_city_maxmind") { error("History file is corrupted (End of section PLUGIN not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
+ if ($Debug) { debug(" Plugin geoip_city_maxmind: End of PLUGIN_geoip_city_maxmind section ($count entries, $countloaded loaded)"); }
+ # ----->
+ return 0;
+}
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionWriteHistory_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionWriteHistory_geoip_city_maxmind {
+ my ($xml,$xmlbb,$xmlbs,$xmlbe,$xmlrb,$xmlrs,$xmlre,$xmleb,$xmlee)=(shift,shift,shift,shift,shift,shift,shift,shift,shift);
+ if ($Debug) { debug(" Plugin geoip_city_maxmind: SectionWriteHistory_geoip_city_maxmind start - ".(scalar keys %_city_h)); }
+ # <-----
+ print HISTORYTMP "\n";
+ if ($xml) { print HISTORYTMP "$MAXNBOFSECTIONGIR\n"; }
+ print HISTORYTMP "# Plugin key - Pages - Hits - Bandwidth - Last access\n";
+ #print HISTORYTMP "# The $MaxNbOfExtra[$extranum] first number of hits are first\n";
+ $ValueInFile{'plugin_geoip_city_maxmind'}=tell HISTORYTMP;
+ print HISTORYTMP "${xmlbb}BEGIN_PLUGIN_geoip_city_maxmind${xmlbs}".(scalar keys %_city_h)."${xmlbe}\n";
+ &BuildKeyList($MAXNBOFSECTIONGIR,1,\%_city_h,\%_city_h);
+ my %keysinkeylist=();
+ foreach (@keylist) {
+ $keysinkeylist{$_}=1;
+ #my $page=$_city_p{$_}||0;
+ #my $bytes=$_city_k{$_}||0;
+ #my $lastaccess=$_city_l{$_}||'';
+ print HISTORYTMP "${xmlrb}$_${xmlrs}0${xmlrs}", $_city_h{$_}, "${xmlrs}0${xmlrs}0${xmlre}\n"; next;
+ }
+ foreach (keys %_city_h) {
+ if ($keysinkeylist{$_}) { next; }
+ #my $page=$_city_p{$_}||0;
+ #my $bytes=$_city_k{$_}||0;
+ #my $lastaccess=$_city_l{$_}||'';
+ print HISTORYTMP "${xmlrb}$_${xmlrs}0${xmlrs}", $_city_h{$_}, "${xmlrs}0${xmlrs}0${xmlre}\n"; next;
+ }
+ print HISTORYTMP "${xmleb}END_PLUGIN_geoip_city_maxmind${xmlee}\n";
+ # ----->
+ return 0;
+}
+
+
+
+1; # Do not remove this line
diff --git a/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm b/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm
new file mode 100755
index 00000000..3089bd32
--- /dev/null
+++ b/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm
@@ -0,0 +1,394 @@
+#!/usr/bin/perl
+#-----------------------------------------------------------------------------
+# GeoIp_Region_Maxmind AWStats plugin
+# This plugin allow you to add a region report with regions detected
+# 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)
+#-----------------------------------------------------------------------------
+# $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 strict;no strict "refs";
+
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN VARIABLES
+#-----------------------------------------------------------------------------
+# <-----
+# 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="AddHTMLMenuLink SectionInitHashArray SectionProcessIp SectionProcessHostname SectionReadHistory SectionWriteHistory";
+# ----->
+
+# <-----
+# IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
+use vars qw/
+$geoip_region_maxmind
+%_region_p
+%_region_h
+%_region_k
+%_region_l
+$MAXNBOFSECTIONGIR
+%region
+/;
+my %countrylib=('ca'=>'Canadian Regions','us'=>'US regions');
+my %regca=(
+'AB',"Alberta",
+'BC',"British Columbia",
+'MB',"Manitoba",
+'NB',"New Brunswick",
+'NF',"Newfoundland",
+'NS',"Nova Scotia",
+'NU',"Nunavut",
+'ON',"Ontario",
+'PE',"Prince Edward Island",
+'QC',"Quebec",
+'SK',"Saskatchewan",
+'NT',"Northwest Territories",
+'YT',"Yukon Territory"
+);
+my %regus=(
+'AA',"Armed Forces Americas",
+'AE',"Armed Forces Europe, Middle East, & Canada",
+'AK',"Alaska",
+'AL',"Alabama",
+'AP',"Armed Forces Pacific",
+'AR',"Arkansas",
+'AS',"American Samoa",
+'AZ',"Arizona",
+'CA',"California",
+'CO',"Colorado",
+'CT',"Connecticut",
+'DC',"District of Columbia",
+'DE',"Delaware",
+'FL',"Florida",
+'FM',"Federated States of Micronesia",
+'GA',"Georgia",
+'GU',"Guam",
+'HI',"Hawaii",
+'IA',"Iowa",
+'ID',"Idaho",
+'IL',"Illinois",
+'IN',"Indiana",
+'KS',"Kansas",
+'KY',"Kentucky",
+'LA',"Louisiana",
+'MA',"Massachusetts",
+'MD',"Maryland",
+'ME',"Maine",
+'MH',"Marshall Islands",
+'MI',"Michigan",
+'MN',"Minnesota",
+'MO',"Missouri",
+'MP',"Northern Mariana Islands",
+'MS',"Mississippi",
+'MT',"Montana",
+'NC',"North Carolina",
+'ND',"North Dakota",
+'NE',"Nebraska",
+'NH',"New Hampshire",
+'NJ',"New Jersey",
+'NM',"New Mexico",
+'NV',"Nevada",
+'NY',"New York",
+'OH',"Ohio",
+'OK',"Oklahoma",
+'OR',"Oregon",
+'PA',"Pennsylvania",
+'PR',"Puerto Rico",
+'PW',"Palau",
+'RI',"Rhode Island",
+'SC',"South Carolina",
+'SD',"South Dakota",
+'TN',"Tennessee",
+'TX',"Texas",
+'UT',"Utah",
+'VA',"Virginia",
+'VI',"Virgin Islands",
+'VT',"Vermont",
+'WA',"Washington",
+'WV',"West Virginia",
+'WI',"Wisconsin",
+'WY',"Wyoming"
+);
+my %region=(
+'ca'=>\%regca,
+'us'=>\%regus
+);
+# ----->
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: Init_pluginname
+#-----------------------------------------------------------------------------
+sub Init_geoip_region_maxmind {
+ my $InitParams=shift;
+ my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
+ $MAXNBOFSECTIONGIR=10;
+
+ # <-----
+ # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
+ debug(" Plugin geoip_region_maxmind: InitParams=$InitParams",1);
+ if ($UpdateStats) {
+ my ($mode,$datafile)=split(/\s+/,$InitParams,2);
+ if (! $datafile) { $datafile="GeoIPRegion.dat"; }
+ if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE') { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
+ else { $mode=Geo::IP::GEOIP_STANDARD(); }
+ debug(" Plugin geoip_region_maxmind: GeoIP initialized in mode $mode",1);
+ $geoip_region_maxmind = Geo::IP->open($datafile, $mode);
+ }
+ # ----->
+
+ return ($checkversion?$checkversion:"$PluginHooksFunctions");
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLMenuLink_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub AddHTMLMenuLink_geoip_region_maxmind {
+ my $categ=$_[0];
+ my $menu=$_[1];
+ my $menulink=$_[2];
+ my $menutext=$_[3];
+ # <-----
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: AddHTMLMenuLink"); }
+ if ($categ eq 'who') {
+ $menu->{'plugin_geoip_region_maxmind'}=1; # Pos
+ $menulink->{'plugin_geoip_region_maxmind'}=2; # Type of link
+ $menutext->{'plugin_geoip_region_maxmind'}="Regions"; # Text
+ }
+ # ----->
+ return 0;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLGraph_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub AddHTMLGraph_geoip_region_maxmind {
+ my $categ=$_[0];
+ my $menu=$_[1];
+ my $menulink=$_[2];
+ my $menutext=$_[3];
+ # <-----
+ my $ShowRegions='H';
+ $MinHit{'Regions'}=1;
+ my $total_p; my $total_h; my $total_k;
+ my $rest_p; my $rest_h; my $rest_k;
+
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: AddHTMLGraph"); }
+ my $title='Regions';
+ &tab_head("$title",19,0,'regions');
+ print "| US and CA Regions : ".((scalar keys %_region_h)-($_region_h{'unknown'}?1:0))." | ";
+ if ($ShowRegions =~ /P/i) { print "$Message[56] | "; }
+ if ($ShowRegions =~ /P/i) { print "$Message[15] | "; }
+ if ($ShowRegions =~ /H/i) { print "$Message[57] | "; }
+ if ($ShowRegions =~ /H/i) { print "$Message[15] | "; }
+ if ($ShowRegions =~ /B/i) { print "$Message[75] | "; }
+ if ($ShowRegions =~ /L/i) { print "$Message[9] | "; }
+ print "
\n";
+ $total_p=$total_h=$total_k=0;
+ my $count=0;
+ &BuildKeyList($MaxRowsInHTMLOutput,$MinHit{'Regions'},\%_region_h,\%_region_h);
+ # Group by country
+ my @countrylist=('ca','us');
+ foreach my $country (@countrylist) {
+ print "| ".$countrylib{$country}." | ";
+ if ($ShowRegions =~ /P/i) { print " | "; }
+ if ($ShowRegions =~ /P/i) { print " | "; }
+ if ($ShowRegions =~ /H/i) { print " | "; }
+ if ($ShowRegions =~ /H/i) { print " | "; }
+ if ($ShowRegions =~ /B/i) { print " | "; }
+ if ($ShowRegions =~ /L/i) { print " | "; }
+ print "
\n";
+ foreach my $key (@keylist) {
+ if ($key eq 'unknown') { next; }
+ my ($countrycode,$regioncode)=split('_',$key);
+ if ($countrycode ne $country) { next; }
+ my $p_p; my $p_h;
+ if ($TotalPages) { $p_p=int($_region_p{$key}/$TotalPages*1000)/10; }
+ if ($TotalHits) { $p_h=int($_region_h{$key}/$TotalHits*1000)/10; }
+ print "| ".$region{$countrycode}{uc($regioncode)}." ($regioncode) | ";
+ if ($ShowRegions =~ /P/i) { print "".($_region_p{$key}?$_region_p{$key}:" ")." | "; }
+ if ($ShowRegions =~ /P/i) { print "".($_region_p{$key}?"$p_p %":' ')." | "; }
+ if ($ShowRegions =~ /H/i) { print "".($_region_h{$key}?$_region_h{$key}:" ")." | "; }
+ if ($ShowRegions =~ /H/i) { print "".($_region_h{$key}?"$p_h %":' ')." | "; }
+ if ($ShowRegions =~ /B/i) { print "".Format_Bytes($_region_k{$key})." | "; }
+ if ($ShowRegions =~ /L/i) { print "".($_region_p{$key}?Format_Date($_region_l{$key},1):'-')." | "; }
+ print "
\n";
+ $total_p += $_region_p{$key}||0;
+ $total_h += $_region_h{$key};
+ $total_k += $_region_k{$key}||0;
+ $count++;
+ }
+ }
+ if ($Debug) { debug("Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",2); }
+ $rest_p=0;
+ $rest_h=$TotalHits-$total_h;
+ $rest_k=0;
+ if ($rest_p > 0 || $rest_h > 0 || $rest_k > 0) { # All other regions
+ print "| | ";
+ if ($ShowRegions =~ /P/i) { print " | "; }
+ if ($ShowRegions =~ /P/i) { print " | "; }
+ if ($ShowRegions =~ /H/i) { print " | "; }
+ if ($ShowRegions =~ /H/i) { print " | "; }
+ if ($ShowRegions =~ /B/i) { print " | "; }
+ if ($ShowRegions =~ /L/i) { print " | "; }
+ print "
\n";
+
+ my $p_p; my $p_h;
+ if ($TotalPages) { $p_p=int($rest_p/$TotalPages*1000)/10; }
+ if ($TotalHits) { $p_h=int($rest_h/$TotalHits*1000)/10; }
+ print "| $Message[2]/$Message[0] | ";
+ if ($ShowRegions =~ /P/i) { print "".($rest_p?$rest_p:" ")." | "; }
+ if ($ShowRegions =~ /P/i) { print "".($rest_p?"$p_p %":' ')." | "; }
+ if ($ShowRegions =~ /H/i) { print "".($rest_h?$rest_h:" ")." | "; }
+ if ($ShowRegions =~ /H/i) { print "".($rest_h?"$p_h %":' ')." | "; }
+ if ($ShowRegions =~ /B/i) { print "".Format_Bytes($rest_k)." | "; }
+ if ($ShowRegions =~ /L/i) { print " | "; }
+ print "
\n";
+ }
+ &tab_end();
+
+ # ----->
+ return 0;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionInitHashArray_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionInitHashArray_geoip_region_maxmind {
+ my $param="$_[0]";
+ # <-----
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: Init_HashArray"); }
+ %_region_p = %_region_h = %_region_k = %_region_l =();
+ # ----->
+ return 0;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionProcessHostname_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionProcessIp_geoip_region_maxmind {
+ my $param="$_[0]"; # Param must be an IP
+ # <-----
+ my ($res1,$res2,$countryregion)=();
+ ($res1,$res2)=$geoip_region_maxmind->region_by_name($param) if $geoip_region_maxmind;
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: GetRegionByIp for $param: [${res1}_${res2}]",5); }
+ if ($res2 =~ /\w\w/) { $countryregion=lc("${res1}_${res2}"); }
+ else { $countryregion='unknown'; }
+# if ($PageBool) { $_region_p{$countryregion}++; }
+ $_region_h{$countryregion}++;
+# if ($timerecord > $_region_l{$countryregion}) { $_region_l{$countryregion}=$timerecord; }
+ # ----->
+ return;
+}
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionProcessHostname_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionProcessHostname_geoip_region_maxmind {
+ my $param="$_[0]"; # Param must be a hostname
+ # <-----
+ 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 ($res2 =~ /\w\w/) { $countryregion=lc("${res1}_${res2}"); }
+ else { $countryregion='unknown'; }
+# if ($PageBool) { $_region_p{$countryregion}++; }
+ $_region_h{$countryregion}++;
+# if ($timerecord > $_region_l{$countryregion}) { $_region_l{$countryregion}=$timerecord; }
+ # ----->
+ return;
+}
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionReadHistory_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionReadHistory_geoip_region_maxmind {
+ my $issectiontoload=shift;
+ my $xmlold=shift;
+ my $xmleb=shift;
+ my $countlines=shift;
+ # <-----
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: Begin of PLUGIN_geoip_region_maxmind section"); }
+ my @field=();
+ my $count=0;my $countloaded=0;
+ do {
+ if ($field[0]) {
+ $count++;
+ if ($issectiontoload) {
+ $countloaded++;
+ if ($field[2]) { $_region_h{$field[0]}+=$field[2]; }
+ }
+ }
+ $_=;
+ chomp $_; s/\r//;
+ @field=split(/\s+/,($xmlold?CleanFromTags($_):$_));
+ $countlines++;
+ }
+ until ($field[0] eq 'END_PLUGIN_geoip_region_maxmind' || $field[0] eq "${xmleb}END_PLUGIN_geoip_region_maxmind" || ! $_);
+ if ($field[0] ne 'END_PLUGIN_geoip_region_maxmind' && $field[0] ne "${xmleb}END_PLUGIN_geoip_region_maxmind") { error("History file is corrupted (End of section PLUGIN not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: End of PLUGIN_geoip_region_maxmind section ($count entries, $countloaded loaded)"); }
+ # ----->
+ return 0;
+}
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: SectionWriteHistory_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+#-----------------------------------------------------------------------------
+sub SectionWriteHistory_geoip_region_maxmind {
+ my ($xml,$xmlbb,$xmlbs,$xmlbe,$xmlrb,$xmlrs,$xmlre,$xmleb,$xmlee)=(shift,shift,shift,shift,shift,shift,shift,shift,shift);
+ if ($Debug) { debug(" Plugin geoip_region_maxmind: SectionWriteHistory_geoip_region_maxmind start - ".(scalar keys %_region_h)); }
+ # <-----
+ print HISTORYTMP "\n";
+ if ($xml) { print HISTORYTMP "$MAXNBOFSECTIONGIR\n"; }
+ print HISTORYTMP "# Plugin key - Pages - Hits - Bandwidth - Last access\n";
+ #print HISTORYTMP "# The $MaxNbOfExtra[$extranum] first number of hits are first\n";
+ $ValueInFile{'plugin_geoip_region_maxmind'}=tell HISTORYTMP;
+ print HISTORYTMP "${xmlbb}BEGIN_PLUGIN_geoip_region_maxmind${xmlbs}".(scalar keys %_region_h)."${xmlbe}\n";
+ &BuildKeyList($MAXNBOFSECTIONGIR,1,\%_region_h,\%_region_h);
+ my %keysinkeylist=();
+ foreach (@keylist) {
+ $keysinkeylist{$_}=1;
+ #my $page=$_region_p{$_}||0;
+ #my $bytes=$_region_k{$_}||0;
+ #my $lastaccess=$_region_l{$_}||'';
+ print HISTORYTMP "${xmlrb}$_${xmlrs}0${xmlrs}", $_region_h{$_}, "${xmlrs}0${xmlrs}0${xmlre}\n"; next;
+ }
+ foreach (keys %_region_h) {
+ if ($keysinkeylist{$_}) { next; }
+ #my $page=$_region_p{$_}||0;
+ #my $bytes=$_region_k{$_}||0;
+ #my $lastaccess=$_region_l{$_}||'';
+ print HISTORYTMP "${xmlrb}$_${xmlrs}0${xmlrs}", $_region_h{$_}, "${xmlrs}0${xmlrs}0${xmlre}\n"; next;
+ }
+ print HISTORYTMP "${xmleb}END_PLUGIN_geoip_region_maxmind${xmlee}\n";
+ # ----->
+ return 0;
+}
+
+
+
+1; # Do not remove this line