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