From: eldy <>
Date: Wed, 27 Oct 2004 20:56:49 +0000 (+0000)
Subject: Add city and region inside host chart if geoip_city and geoip_region plugins are...
X-Git-Tag: AWSTATS_6_3_RELEASE~76
X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ba112a6ff9c47c9b73036634be35da1eba4a209;p=thirdparty%2FAWStats.git
Add city and region inside host chart if geoip_city and geoip_region plugins are loaded.
---
diff --git a/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm b/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
index 6e6441aa..cb8d7838 100755
--- a/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
+++ b/wwwroot/cgi-bin/plugins/geoip_city_maxmind.pm
@@ -26,7 +26,7 @@ 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="AddHTMLMenuLink SectionInitHashArray SectionProcessIp SectionReadHistory SectionWriteHistory";
+my $PluginHooksFunctions="AddHTMLMenuLink AddHTMLGraph ShowInfoHost SectionInitHashArray SectionProcessIp SectionReadHistory SectionWriteHistory";
# ----->
# <-----
@@ -142,14 +142,14 @@ sub Init_geoip_city_maxmind {
# <-----
# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
debug(" Plugin geoip_city_maxmind: InitParams=$InitParams",1);
- if ($UpdateStats) {
+# 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");
@@ -276,6 +276,58 @@ sub AddHTMLGraph_geoip_city_maxmind {
}
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: ShowInfoHost_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to add additionnal columns to the Hosts report.
+# This function is called when building rows of the report (One call for each
+# row). So it allows you to add a column in report, for example with code :
+# print "
This is a new cell for $param | ";
+# Parameters: Host name or ip
+#-----------------------------------------------------------------------------
+sub ShowInfoHost_geoip_city_maxmind {
+ my $param="$_[0]";
+ # <-----
+ if ($param eq '__title__') {
+ print "GeoIP City | ";
+ }
+ elsif ($param) {
+ my $ip=0;
+ my $key;
+ if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
+ $ip=4;
+ $key=$param;
+ }
+ elsif ($param =~ /^[0-9A-F]*:/i) { # IPv6 address
+ $ip=6;
+ $key=$param;
+ }
+ print "";
+ 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;
+ if ($city) { print "$city"; }
+ else { print "$Message[0]"; }
+ }
+ if ($key && $ip==6) {
+ print "$Message[0]";
+ }
+ if (! $key) {
+ print "$Message[0]";
+ }
+ print " | ";
+ }
+ else {
+ print " | ";
+ }
+ return 1;
+ # ----->
+}
+
+
#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionInitHashArray_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
diff --git a/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm b/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm
index 3089bd32..5825e290 100755
--- a/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm
+++ b/wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm
@@ -27,7 +27,7 @@ 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="AddHTMLMenuLink SectionInitHashArray SectionProcessIp SectionProcessHostname SectionReadHistory SectionWriteHistory";
+my $PluginHooksFunctions="AddHTMLMenuLink AddHTMLGraph ShowInfoHost SectionInitHashArray SectionProcessIp SectionProcessHostname SectionReadHistory SectionWriteHistory";
# ----->
# <-----
@@ -41,7 +41,8 @@ $geoip_region_maxmind
$MAXNBOFSECTIONGIR
%region
/;
-my %countrylib=('ca'=>'Canadian Regions','us'=>'US regions');
+my %countrylib=('ca'=>'Canada','us'=>'USA');
+my %countryregionlib=('ca'=>'Canadian Regions','us'=>'US regions');
my %regca=(
'AB',"Alberta",
'BC',"British Columbia",
@@ -139,14 +140,14 @@ sub Init_geoip_region_maxmind {
# <-----
# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
debug(" Plugin geoip_region_maxmind: InitParams=$InitParams",1);
- if ($UpdateStats) {
+# 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");
@@ -206,7 +207,7 @@ sub AddHTMLGraph_geoip_region_maxmind {
# Group by country
my @countrylist=('ca','us');
foreach my $country (@countrylist) {
- print "| ".$countrylib{$country}." | ";
+ print "
| ".$countryregionlib{$country}." | ";
if ($ShowRegions =~ /P/i) { print " | "; }
if ($ShowRegions =~ /P/i) { print " | "; }
if ($ShowRegions =~ /H/i) { print " | "; }
@@ -268,6 +269,70 @@ sub AddHTMLGraph_geoip_region_maxmind {
}
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: ShowInfoHost_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to add additionnal columns to the Hosts report.
+# This function is called when building rows of the report (One call for each
+# row). So it allows you to add a column in report, for example with code :
+# print "This is a new cell for $param | ";
+# Parameters: Host name or ip
+#-----------------------------------------------------------------------------
+sub ShowInfoHost_geoip_region_maxmind {
+ my $param="$_[0]";
+ # <-----
+ if ($param eq '__title__') {
+ print "GeoIP Region | ";
+ }
+ elsif ($param) {
+ my $ip=0;
+ my $key;
+ if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
+ $ip=4;
+ $key=$param;
+ }
+ elsif ($param =~ /^[0-9A-F]*:/i) { # IPv6 address
+ $ip=6;
+ $key=$param;
+ }
+ print "";
+ if ($key && $ip==4) {
+ 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 ($res1 =~ /\w\w/) { print $countrylib{lc($res1)}||uc($res1); }
+ else { print "$Message[0]"; }
+ if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
+ print " (";
+ print $region{lc($res1)}{uc($res2)};
+ print ")";
+ }
+ }
+ if ($key && $ip==6) {
+ print "$Message[0]";
+ }
+ if (! $key) {
+ 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 ($res1 =~ /\w\w/) { print $countrylib{lc($res1)}||uc($res1); }
+ else { print "$Message[0]"; }
+ if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
+ print " (";
+ print $region{lc($res1)}{uc($res2)};
+ print ")";
+ }
+ }
+ print " | ";
+ }
+ else {
+ print " | ";
+ }
+ return 1;
+ # ----->
+}
+
+
#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionInitHashArray_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
diff --git a/wwwroot/cgi-bin/plugins/hostinfo.pm b/wwwroot/cgi-bin/plugins/hostinfo.pm
index 7c266573..0e260be8 100644
--- a/wwwroot/cgi-bin/plugins/hostinfo.pm
+++ b/wwwroot/cgi-bin/plugins/hostinfo.pm
@@ -98,7 +98,7 @@ sub ShowInfoHost_hostinfo {
my $param="$_[0]";
# <-----
if ($param eq '__title__') {
- print "$Message[114] | ";
+ print "$Message[114] | ";
}
elsif ($param) {
my $keyforwhois;
|---|