~ubuntu-branches/ubuntu/edgy/awstats/edgy

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, Charles Fry, Jonas Smedegaard
  • Date: 2005-09-19 22:41:16 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050919224116-6bo795sxx5nsosby
Tags: 6.4-2
[ Charles Fry ]
* New co-maintainer.
* Suggest libgeo-ipfree-perl. Closes: #316126 (thanks to Gunnar Wolf
  <gwolf@gwolf.org>).
* Fixed README.Debian path to configure.pl. Closes: #313093 (thanks to
  Michael De Nil <michael@flex-it.be>).

[ Jonas Smedegaard ]
* Acknowledge NMU. Closes: bug#322591.
* Bump up watch version, and adjust the default command (we have moved
  to SubVerSion).
* Add proto to URL in long description.
* User newer chown syntax in postinst (thanks to lintian).

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.14 $ - $Author: eldy $ - $Date: 2005/01/22 16:39:53 $
 
11
# $Revision: 1.15 $ - $Author: eldy $ - $Date: 2005/02/19 13:40:42 $
12
12
 
13
13
 
14
14
# <-----
31
31
# ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
32
32
# AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
33
33
my $PluginNeedAWStatsVersion="5.4";
34
 
my $PluginHooksFunctions="GetCountryCodeByAddr GetCountryCodeByName";
 
34
my $PluginHooksFunctions="GetCountryCodeByAddr GetCountryCodeByName ShowInfoHost";
35
35
# ----->
36
36
 
37
37
# <-----
113
113
}
114
114
 
115
115
 
 
116
#-----------------------------------------------------------------------------
 
117
# PLUGIN FUNCTION: ShowInfoHost_pluginname
 
118
# UNIQUE: NO (Several plugins using this function can be loaded)
 
119
# Function called to add additionnal columns to the Hosts report.
 
120
# This function is called when building rows of the report (One call for each
 
121
# row). So it allows you to add a column in report, for example with code :
 
122
#   print "<TD>This is a new cell for $param</TD>";
 
123
# Parameters: Host name or ip
 
124
#-----------------------------------------------------------------------------
 
125
sub ShowInfoHost_geoip {
 
126
    my $param="$_[0]";
 
127
        # <-----
 
128
        if ($param eq '__title__') {
 
129
        my $NewLinkParams=${QueryString};
 
130
        $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
 
131
        $NewLinkParams =~ s/(^|&)output(=\w*|$)//i;
 
132
        $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
 
133
        $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
 
134
        my $NewLinkTarget='';
 
135
        if ($DetailedReportsOnNewWindows) { $NewLinkTarget=" target=\"awstatsbis\""; }
 
136
        if (($FrameName eq 'mainleft' || $FrameName eq 'mainright') && $DetailedReportsOnNewWindows < 2) {
 
137
                $NewLinkParams.="&framename=mainright";
 
138
                $NewLinkTarget=" target=\"mainright\"";
 
139
        }
 
140
        $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
 
141
        if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
 
142
 
 
143
                print "<th width=\"80\">";
 
144
        print "<a href=\"#countries\">GeoIP<br>Country</a>";
 
145
        print "</th>";
 
146
        }
 
147
        elsif ($param) {
 
148
        my $ip=0;
 
149
                my $key;
 
150
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
 
151
                    $ip=4;
 
152
                        $key=$param;
 
153
                }
 
154
                elsif ($param =~ /^[0-9A-F]*:/i) {                                              # IPv6 address
 
155
                    $ip=6;
 
156
                        $key=$param;
 
157
                }
 
158
                print "<td>";
 
159
                if ($key && $ip==4) {
 
160
                my $res=lc($gi->country_code_by_addr($param)) if $gi;
 
161
                if ($Debug) { debug("  Plugin geoip: GetCountryByIp for $param: [$res]",5); }
 
162
                    if ($res) { print $DomainsHashIDLib{$res}; }
 
163
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
 
164
                }
 
165
                if ($key && $ip==6) {
 
166
                    print "<span style=\"color: #$color_other\">$Message[0]</span>";
 
167
                }
 
168
                if (! $key) {
 
169
                my $res=lc($gi->country_code_by_addr($param)) if $gi;
 
170
                if ($Debug) { debug("  Plugin geoip: GetCountryByHostname for $param: [$res]",5); }
 
171
                    if ($res) { print $DomainsHashIDLib{$res}; }
 
172
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
 
173
                }
 
174
                print "</td>";
 
175
        }
 
176
        else {
 
177
                print "<td>&nbsp;</td>";
 
178
        }
 
179
        return 1;
 
180
        # ----->
 
181
}
 
182
 
 
183
 
116
184
1;      # Do not remove this line