(file) Return to geoip.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / awstats-6.3 / wwwroot / cgi-bin / plugins

  1 rizwank 1.1 #!/usr/bin/perl
  2             #-----------------------------------------------------------------------------
  3             # GeoIp Maxmind AWStats plugin
  4             # This plugin allow you to get country report with countries detected
  5             # from a Geographical database (GeoIP internal database) instead of domain
  6             # hostname suffix.
  7             # Need the country database from Maxmind (free).
  8             #-----------------------------------------------------------------------------
  9             # Perl Required Modules: Geo::IP or Geo::IP::PurePerl
 10             #-----------------------------------------------------------------------------
 11             # $Revision: 1.14 $ - $Author: eldy $ - $Date: 2005/01/22 16:39:53 $
 12             
 13             
 14             # <-----
 15             # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
 16             use vars qw/ $type /;
 17             $type='geoip';
 18             if (!eval ('require "Geo/IP.pm";')) 	{
 19             	$type='geoippureperl';
 20             	if (!eval ('require "Geo/IP/PurePerl.pm";')) { return $@?"Error: $@":"Error: Need Perl module Geo::IP or Geo::IP::PurePerl"; }
 21             }
 22 rizwank 1.1 # ----->
 23             use strict;no strict "refs";
 24             
 25             
 26             
 27             #-----------------------------------------------------------------------------
 28             # PLUGIN VARIABLES
 29             #-----------------------------------------------------------------------------
 30             # <-----
 31             # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 32             # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
 33             my $PluginNeedAWStatsVersion="5.4";
 34             my $PluginHooksFunctions="GetCountryCodeByAddr GetCountryCodeByName";
 35             # ----->
 36             
 37             # <-----
 38             # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
 39             use vars qw/
 40             %TmpDomainLookup
 41             $gi
 42             /;
 43 rizwank 1.1 # ----->
 44             
 45             
 46             #-----------------------------------------------------------------------------
 47             # PLUGIN FUNCTION: Init_pluginname
 48             #-----------------------------------------------------------------------------
 49             sub Init_geoip {
 50             	my $InitParams=shift;
 51             	my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
 52             
 53             	# <-----
 54             	# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
 55             	debug(" Plugin geoip: InitParams=$InitParams",1);
 56             	my $mode=$InitParams;
 57             	if ($type eq 'geoippureperl') {
 58             		if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE')  { $mode=Geo::IP::PurePerl::GEOIP_MEMORY_CACHE(); }
 59             		else { $mode=Geo::IP::PurePerl::GEOIP_STANDARD(); }
 60             	} else {
 61             		if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE')  { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
 62             		else { $mode=Geo::IP::GEOIP_STANDARD(); }
 63             	}
 64 rizwank 1.1 	%TmpDomainLookup=();
 65             	debug(" Plugin geoip: GeoIP initialized in mode $type $mode",1);
 66             	if ($type eq 'geoippureperl') {
 67             		$gi = Geo::IP::PurePerl->new($mode);
 68             	} else {
 69             		$gi = Geo::IP->new($mode);
 70             	}
 71             	# ----->
 72             
 73             	return ($checkversion?$checkversion:"$PluginHooksFunctions");
 74             }
 75             
 76             
 77             #-----------------------------------------------------------------------------
 78             # PLUGIN FUNCTION: GetCountryCodeByName_pluginname
 79             # UNIQUE: YES (Only one plugin using this function can be loaded)
 80             # GetCountryCodeByName is called to translate a host name into a country name.
 81             #-----------------------------------------------------------------------------
 82             sub GetCountryCodeByName_geoip {
 83                 my $param="$_[0]";
 84             	# <-----
 85 rizwank 1.1 	my $res=$TmpDomainLookup{$param}||'';
 86             	if (! $res) {
 87             		$res=lc($gi->country_code_by_name($param));
 88             		$TmpDomainLookup{$param}=$res;
 89             		if ($Debug) { debug("  Plugin geoip: GetCountryCodeByName for $param: [$res]",5); }
 90             	}
 91             	elsif ($Debug) { debug("  Plugin geoip: GetCountryCodeByName for $param: Already resolved to $res",5); }
 92             	# ----->
 93             	return $res;
 94             }
 95             
 96             #-----------------------------------------------------------------------------
 97             # PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
 98             # UNIQUE: YES (Only one plugin using this function can be loaded)
 99             # GetCountryCodeByAddr is called to translate an ip into a country name.
100             #-----------------------------------------------------------------------------
101             sub GetCountryCodeByAddr_geoip {
102                 my $param="$_[0]";
103             	# <-----
104             	my $res=$TmpDomainLookup{$param}||'';
105             	if (! $res) {
106 rizwank 1.1 		$res=lc($gi->country_code_by_addr($param));
107             		$TmpDomainLookup{$param}=$res;
108             		if ($Debug) { debug("  Plugin geoip: GetCountryCodeByAddr for $param: $res",5); }
109             	}
110             	elsif ($Debug) { debug("  Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to $res",5); }
111             	# ----->
112             	return $res;
113             }
114             
115             
116             1;	# Do not remove this line

Rizwan Kassim
Powered by
ViewCVS 0.9.2