~ubuntu-branches/ubuntu/lucid/awstats/lucid-updates

« back to all changes in this revision

Viewing changes to wwwroot/cgi-bin/plugins/geoip_isp_maxmind.pm

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2008-12-10 13:05:43 UTC
  • mfrom: (7.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081210130543-2sh59pphufllknju
Tags: 6.7.dfsg-5.1
* Non-maintainer upload by the Security Team.
* Strip '"' characters during URL decoding, fixing a cross-site
  scripting attack (CVE-2008-3714; CVE-2008-5080; Closes: #495432).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 $
10
10
 
11
11
 
12
12
# <-----
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)";
 
14
use vars qw/ $type /;
 
15
$type='geoip';
 
16
if (!eval ('require "Geo/IP.pm";')) {
 
17
        $error1=$@;
 
18
        $type='geoippureperl';
 
19
        if (!eval ('require "Geo/IP/PurePerl.pm";')) {
 
20
                $error2=$@;
 
21
                $ret=($error1||$error2)?"Error:\n$error1$error2":"";
 
22
                $ret.="Error: Need Perl module Geo::IP or Geo::IP::PurePerl";
 
23
                return $ret;
 
24
        }
16
25
}
17
26
# ----->
18
27
use strict;no strict "refs";
51
60
        my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
52
61
    $MAXNBOFSECTIONGIR=10;
53
62
    $MAXLENGTH=20;
54
 
    
 
63
 
55
64
        # <-----
56
65
        # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
57
66
        debug(" Plugin geoip_isp_maxmind: InitParams=$InitParams",1);
58
 
#    if ($UpdateStats) {
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);
65
 
#    }
 
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(); }
 
72
        } else {
 
73
                if ($mode eq '' || $mode eq 'GEOIP_MEMORY_CACHE')  { $mode=Geo::IP::GEOIP_MEMORY_CACHE(); }
 
74
                else { $mode=Geo::IP::GEOIP_STANDARD(); }
 
75
        }
 
76
        %TmpDomainLookup=();
 
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);
 
80
        } else {
 
81
                $geoip_isp_maxmind = Geo::IP->open($datafile, $mode);
 
82
        }
 
83
# Fails on some GeoIP version
 
84
#       debug(" Plugin geoip_isp_maxmind: GeoIP initialized database_info=".$geoip_isp_maxmind->database_info());
66
85
        # ----->
67
86
 
68
87
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
219
238
                }
220
239
                print "<td>";
221
240
                if ($key && $ip==4) {
222
 
                my $isp=$geoip_isp_maxmind->org_by_addr($param) if $geoip_isp_maxmind;
 
241
                my $isp;
 
242
                if ($type eq 'geoippureperl')
 
243
                        {
 
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;
 
246
                }
 
247
                else
 
248
                {
 
249
                        $isp=$geoip_isp_maxmind->isp_by_addr($param) if $geoip_isp_maxmind;
 
250
                }
223
251
                if ($Debug) { debug("  Plugin geoip_isp_maxmind: GetIspByIp for $param: [$isp]",5); }
224
252
                    if ($isp) {
225
253
                        if (length($isp) <= $MAXLENGTH) {
235
263
                    print "<span style=\"color: #$color_other\">$Message[0]</span>";
236
264
                }
237
265
                if (! $key) {
238
 
                my $isp=$geoip_isp_maxmind->org_by_name($param) if $geoip_isp_maxmind;
 
266
                my $isp;
 
267
                if ($type eq 'geoippureperl')
 
268
                        {
 
269
                        $isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
 
270
                }
 
271
                else
 
272
                {
 
273
                        $isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
 
274
                }
239
275
                if ($Debug) { debug("  Plugin geoip_isp_maxmind: GetIspByHostname for $param: [$isp]",5); }
240
276
                    if ($isp) {
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 {
265
 
    my $param="$_[0]";
 
301
#    my $param="$_[0]";
266
302
        # <-----
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
280
316
        # <-----
281
 
        my $isp = $geoip_isp_maxmind->org_by_addr($param) if $geoip_isp_maxmind;
 
317
        my $isp;
 
318
        if ($type eq 'geoippureperl')
 
319
        {
 
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;
 
322
        }
 
323
        else
 
324
        {
 
325
                $isp=$geoip_isp_maxmind->isp_by_addr($param) if $geoip_isp_maxmind;
 
326
        }
282
327
        if ($Debug) { debug("  Plugin geoip_isp_maxmind: GetIspByIp for $param: [$isp]",5); }
283
328
    if ($isp) {
284
329
        $isp =~ s/\s/_/g;
299
344
sub SectionProcessHostname_geoip_isp_maxmind {
300
345
    my $param="$_[0]";      # Param must be an IP
301
346
        # <-----
302
 
        my $isp = $geoip_isp_maxmind->org_by_name($param) if $geoip_isp_maxmind;
 
347
        my $isp;
 
348
        if ($type eq 'geoippureperl')
 
349
        {
 
350
                $isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
 
351
        }
 
352
        else
 
353
        {
 
354
                $isp=$geoip_isp_maxmind->isp_by_name($param) if $geoip_isp_maxmind;
 
355
        }
303
356
        if ($Debug) { debug("  Plugin geoip_isp_maxmind: GetIspByHostname for $param: [$isp]",5); }
304
357
    if ($isp) {
305
358
        $isp =~ s/\s/_/g;