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

« back to all changes in this revision

Viewing changes to wwwroot/cgi-bin/plugins/geoip.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:
8
8
#-----------------------------------------------------------------------------
9
9
# Perl Required Modules: Geo::IP or Geo::IP::PurePerl
10
10
#-----------------------------------------------------------------------------
11
 
# $Revision: 1.21 $ - $Author: eldy $ - $Date: 2005/08/23 20:14:06 $
 
11
# $Revision: 1.24 $ - $Author: eldy $ - $Date: 2006/05/06 02:51:34 $
12
12
 
13
13
 
14
14
# <-----
15
15
# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
16
16
use vars qw/ $type /;
17
17
$type='geoip';
18
 
if (!eval ('require "Geo/IP.pm";'))     {
 
18
if (!eval ('require "Geo/IP.pm";')) {
 
19
        $error1=$@;
19
20
        $type='geoippureperl';
20
 
        if (!eval ('require "Geo/IP/PurePerl.pm";')) { return $@?"Error: $@":"Error: Need Perl module Geo::IP or Geo::IP::PurePerl"; }
 
21
        if (!eval ('require "Geo/IP/PurePerl.pm";')) {
 
22
                $error2=$@;
 
23
                $ret=($error1||$error2)?"Error:\n$error1$error2":"";
 
24
                $ret.="Error: Need Perl module Geo::IP or Geo::IP::PurePerl";
 
25
                return $ret;
 
26
        }
21
27
}
22
28
# ----->
23
29
use strict;no strict "refs";
63
69
                else { $mode=Geo::IP::GEOIP_STANDARD(); }
64
70
        }
65
71
        %TmpDomainLookup=();
66
 
        debug(" Plugin geoip: GeoIP initialized in mode $type $mode",1);
 
72
        debug(" Plugin geoip: GeoIP initialized type=$type mode=$mode",1);
67
73
        if ($type eq 'geoippureperl') {
68
74
                $gi = Geo::IP::PurePerl->open($datafile, $mode);
69
75
        } else {
70
76
                $gi = Geo::IP->open($datafile, $mode);
71
77
        }
 
78
# Fails on some GeoIP version
 
79
#       debug(" Plugin geoip: GeoIP initialized database_info=".$gi->database_info());
72
80
        # ----->
73
81
 
74
82
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
76
84
 
77
85
 
78
86
#-----------------------------------------------------------------------------
 
87
# PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
 
88
# UNIQUE: YES (Only one plugin using this function can be loaded)
 
89
# GetCountryCodeByAddr is called to translate an ip into a country code in lower case.
 
90
#-----------------------------------------------------------------------------
 
91
sub GetCountryCodeByAddr_geoip {
 
92
    my $param="$_[0]";
 
93
        # <-----
 
94
        my $res=$TmpDomainLookup{$param}||'';
 
95
        if (! $res) {
 
96
                $res=lc($gi->country_code_by_addr($param)) || 'unknown';
 
97
                $TmpDomainLookup{$param}=$res;
 
98
                if ($Debug) { debug("  Plugin geoip: GetCountryCodeByAddr for $param: [$res]",5); }
 
99
        }
 
100
        elsif ($Debug) { debug("  Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to [$res]",5); }
 
101
        # ----->
 
102
        return $res;
 
103
}
 
104
 
 
105
 
 
106
#-----------------------------------------------------------------------------
79
107
# PLUGIN FUNCTION: GetCountryCodeByName_pluginname
80
108
# UNIQUE: YES (Only one plugin using this function can be loaded)
81
 
# GetCountryCodeByName is called to translate a host name into a country name.
 
109
# GetCountryCodeByName is called to translate a host name into a country code in lower case.
82
110
#-----------------------------------------------------------------------------
83
111
sub GetCountryCodeByName_geoip {
84
112
    my $param="$_[0]";
85
113
        # <-----
86
114
        my $res=$TmpDomainLookup{$param}||'';
87
115
        if (! $res) {
88
 
                $res=lc($gi->country_code_by_name($param));
89
 
                $TmpDomainLookup{$param}=$res || 'unknown';
 
116
                $res=lc($gi->country_code_by_name($param)) || 'unknown';
 
117
                $TmpDomainLookup{$param}=$res;
90
118
                if ($Debug) { debug("  Plugin geoip: GetCountryCodeByName for $param: [$res]",5); }
91
119
        }
92
 
        elsif ($Debug) { debug("  Plugin geoip: GetCountryCodeByName for $param: Already resolved to $res",5); }
93
 
        # ----->
94
 
        return $res;
95
 
}
96
 
 
97
 
#-----------------------------------------------------------------------------
98
 
# PLUGIN FUNCTION: GetCountryCodeByAddr_pluginname
99
 
# UNIQUE: YES (Only one plugin using this function can be loaded)
100
 
# GetCountryCodeByAddr is called to translate an ip into a country name.
101
 
#-----------------------------------------------------------------------------
102
 
sub GetCountryCodeByAddr_geoip {
103
 
    my $param="$_[0]";
104
 
        # <-----
105
 
        my $res=$TmpDomainLookup{$param}||'';
106
 
        if (! $res) {
107
 
                $res=lc($gi->country_code_by_addr($param));
108
 
                $TmpDomainLookup{$param}=$res || 'unknown';
109
 
                if ($Debug) { debug("  Plugin geoip: GetCountryCodeByAddr for $param: $res",5); }
110
 
        }
111
 
        elsif ($Debug) { debug("  Plugin geoip: GetCountryCodeByAddr for $param: Already resolved to $res",5); }
 
120
        elsif ($Debug) { debug("  Plugin geoip: GetCountryCodeByName for $param: Already resolved to [$res]",5); }
112
121
        # ----->
113
122
        return $res;
114
123
}