4
4
# This plugin allow you to add a city report.
5
5
# Need the licensed ISP database from Maxmind.
6
6
#-----------------------------------------------------------------------------
7
# Perl Required Modules: Geo::IP (Geo::IP::PurePerl is not yet supported)
7
# Perl Required Modules: Geo::IP or Geo::IP::PurePerl
8
8
#-----------------------------------------------------------------------------
9
# $Revision: 1.5 $ - $Author: eldy $ - $Date: 2005/12/14 23:44:33 $
9
# $Revision: 1.9 $ - $Author: eldy $ - $Date: 2006/05/06 02:54:48 $
13
13
# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
14
if (!eval ('require "Geo/IP.pm";')) {
15
return $@?"Error: $@":"Error: Need Perl module Geo::IP (Geo::IP::PurePerl is not yet supported)";
16
if (!eval ('require "Geo/IP.pm";')) {
18
$type='geoippureperl';
19
if (!eval ('require "Geo/IP/PurePerl.pm";')) {
21
$ret=($error1||$error2)?"Error:\n$error1$error2":"";
22
$ret.="Error: Need Perl module Geo::IP or Geo::IP::PurePerl";
18
27
use strict;no strict "refs";
51
60
my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
52
61
$MAXNBOFSECTIONGIR=10;
56
65
# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
57
66
debug(" Plugin geoip_isp_maxmind: InitParams=$InitParams",1);
59
my ($mode,$datafile)=split(/\s+/,$InitParams,2);
60
if (! $datafile) { $datafile="GeoIPISP.dat"; }
61
if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE') { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
62
else { $mode=Geo::IP::GEOIP_STANDARD(); }
63
debug(" Plugin geoip_isp_maxmind: GeoIP initialized in mode $mode",1);
64
$geoip_isp_maxmind = Geo::IP->open($datafile, $mode);
67
my ($mode,$datafile)=split(/\s+/,$InitParams,2);
68
if (! $datafile) { $datafile="GeoIPIsp.dat"; }
69
if ($type eq 'geoippureperl') {
70
if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE') { $mode=Geo::IP::PurePerl::GEOIP_MEMORY_CACHE(); }
71
else { $mode=Geo::IP::PurePerl::GEOIP_STANDARD(); }
73
if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE') { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
74
else { $mode=Geo::IP::GEOIP_STANDARD(); }
77
debug(" Plugin geoip_isp_maxmind: GeoIP initialized type=$type mode=$mode",1);
78
if ($type eq 'geoippureperl') {
79
$geoip_isp_maxmind = Geo::IP::PurePerl->open($datafile, $mode);
81
$geoip_isp_maxmind = Geo::IP->open($datafile, $mode);
83
# Fails on some GeoIP version
84
# debug(" Plugin geoip_isp_maxmind: GeoIP initialized database_info=".$geoip_isp_maxmind->database_info());
68
87
return ($checkversion?$checkversion:"$PluginHooksFunctions");
221
240
if ($key && $ip==4) {
222
my $isp=$geoip_isp_maxmind->org_by_addr($param) if $geoip_isp_maxmind;
242
if ($type eq 'geoippureperl')
244
# Function isp_by_addr does not exists in PurePerl but isp_by_name do same
245
$isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
249
$isp=$geoip_isp_maxmind->isp_by_addr($param) if $geoip_isp_maxmind;
223
251
if ($Debug) { debug(" Plugin geoip_isp_maxmind: GetIspByIp for $param: [$isp]",5); }
225
253
if (length($isp) <= $MAXLENGTH) {
235
263
print "<span style=\"color: #$color_other\">$Message[0]</span>";
238
my $isp=$geoip_isp_maxmind->org_by_name($param) if $geoip_isp_maxmind;
267
if ($type eq 'geoippureperl')
269
$isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
273
$isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
239
275
if ($Debug) { debug(" Plugin geoip_isp_maxmind: GetIspByHostname for $param: [$isp]",5); }
241
277
if (length($isp) <= $MAXLENGTH) {
262
298
# UNIQUE: NO (Several plugins using this function can be loaded)
263
299
#-----------------------------------------------------------------------------
264
300
sub SectionInitHashArray_geoip_isp_maxmind {
267
303
if ($Debug) { debug(" Plugin geoip_isp_maxmind: Init_HashArray"); }
268
304
%_isp_p = %_isp_h = %_isp_k = %_isp_l =();
278
314
sub SectionProcessIp_geoip_isp_maxmind {
279
315
my $param="$_[0]"; # Param must be an IP
281
my $isp = $geoip_isp_maxmind->org_by_addr($param) if $geoip_isp_maxmind;
318
if ($type eq 'geoippureperl')
320
# Function isp_by_addr does not exists in PurePerl but isp_by_name do same
321
$isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
325
$isp=$geoip_isp_maxmind->isp_by_addr($param) if $geoip_isp_maxmind;
282
327
if ($Debug) { debug(" Plugin geoip_isp_maxmind: GetIspByIp for $param: [$isp]",5); }
284
329
$isp =~ s/\s/_/g;
299
344
sub SectionProcessHostname_geoip_isp_maxmind {
300
345
my $param="$_[0]"; # Param must be an IP
302
my $isp = $geoip_isp_maxmind->org_by_name($param) if $geoip_isp_maxmind;
348
if ($type eq 'geoippureperl')
350
$isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
354
$isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
303
356
if ($Debug) { debug(" Plugin geoip_isp_maxmind: GetIspByHostname for $param: [$isp]",5); }
305
358
$isp =~ s/\s/_/g;