1313# <-----
1414# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
1515use vars qw/ $type / ;
16- $type =' geoip2 ' ;
16+ $type =' geoip2_country ' ;
1717if (!eval (' require "GeoIP2/Database/Reader.pm";' )) {
1818 $error =$@ ;
1919 $ret =($error )?" Error:\n $error " :" " ;
@@ -41,7 +41,7 @@ no strict "refs";
4141# AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
4242my $PluginNeedAWStatsVersion =" 5.4" ;
4343my $PluginHooksFunctions =" GetCountryCodeByAddr GetCountryCodeByName ShowInfoHost" ;
44- my $PluginName = " geoip2 " ;
44+ my $PluginName = " geoip2_country " ;
4545my $LoadedOverride =0;
4646my $OverrideFile =" " ;
4747my %TmpDomainLookup ;
@@ -59,7 +59,7 @@ use Data::Validate::IP 0.25 qw( is_public_ip );
5959# -----------------------------------------------------------------------------
6060# PLUGIN FUNCTION: Init_pluginname
6161# -----------------------------------------------------------------------------
62- sub Init_geoip2 {
62+ sub Init_geoip2_country {
6363 my $InitParams =shift ;
6464 my $checkversion =&Check_Plugin_Version($PluginNeedAWStatsVersion );
6565
@@ -92,10 +92,10 @@ sub Init_geoip2 {
9292# UNIQUE: YES (Only one plugin using this function can be loaded)
9393# GetCountryCodeByAddr is called to translate an ip into a country code in lower case.
9494# -----------------------------------------------------------------------------
95- sub GetCountryCodeByAddr_geoip2 {
95+ sub GetCountryCodeByAddr_geoip2_country {
9696 my $param = shift ;
9797 if (! $param ) { return ' ' ; }
98- my $res = Lookup_geoip2 ($param );
98+ my $res = Lookup_geoip2_country ($param );
9999 return ($res ) ? lc ($res ) : ' unknown' ;
100100}
101101
@@ -105,8 +105,8 @@ sub GetCountryCodeByAddr_geoip2 {
105105# UNIQUE: YES (Only one plugin using this function can be loaded)
106106# GetCountryCodeByName is called to translate a host name into a country code in lower case.
107107# -----------------------------------------------------------------------------
108- sub GetCountryCodeByName_geoip2 {
109- return GetCountryCodeByAddr_geoip2 (@_ );
108+ sub GetCountryCodeByName_geoip2_country {
109+ return GetCountryCodeByAddr_geoip2_country (@_ );
110110}
111111
112112
@@ -119,7 +119,7 @@ sub GetCountryCodeByName_geoip2 {
119119# print "<TD>This is a new cell for $param</TD>";
120120# Parameters: Host name or ip
121121# -----------------------------------------------------------------------------
122- sub ShowInfoHost_geoip2 {
122+ sub ShowInfoHost_geoip2_country {
123123 my $param =" $_ [0]" ;
124124 # <-----
125125 if ($param eq ' __title__' ) {
@@ -142,8 +142,7 @@ sub ShowInfoHost_geoip2 {
142142 print " </th>" ;
143143 }
144144 elsif ($param ) {
145- print " <td>" ;
146- my $res = Lookup_geoip2($param );
145+ my $res = Lookup_geoip2_country($param );
147146 if ($res ) {
148147 $res = lc ($res );
149148 print $DomainsHashIDLib {$res }?$DomainsHashIDLib {$res }:" <span style=\" color: #$color_other \" >$Message [0]</span>" ;
@@ -164,7 +163,7 @@ sub ShowInfoHost_geoip2 {
164163# Useful for Intranet records
165164# CSV format: IP,2-char Country code
166165# -----------------------------------------------------------------------------
167- sub LoadOverrideFile_geoip2 {
166+ sub LoadOverrideFile_geoip2_country {
168167 my $filetoload =" " ;
169168 if ($OverrideFile ){
170169 if (!open (GEOIPFILE, $OverrideFile )){
@@ -203,10 +202,10 @@ sub LoadOverrideFile_geoip2{
203202# associated country code; or undefined if not available.
204203# GEOIP entry
205204# -----------------------------------------------------------------------------
206- sub Lookup_geoip2 {
205+ sub Lookup_geoip2_country {
207206 $param = shift ;
208- if (!$LoadedOverride ) { &LoadOverrideFile_geoip2 (); }
209- if ($Debug ) { debug(" Plugin $PluginName : Lookup_geoip2 for $param " ,5); }
207+ if (!$LoadedOverride ) { &LoadOverrideFile_geoip2_country (); }
208+ if ($Debug ) { debug(" Plugin $PluginName : Lookup_geoip2_country for $param " ,5); }
210209 if ($reader && !exists ($TmpDomainLookup {$param })) {
211210 $TmpDomainLookup {$param } = undef ; # negative entry to avoid repeated lookups
212211 # Resolve the parameter (either a name or an ip address) to a list of network addresses
@@ -216,7 +215,7 @@ sub Lookup_geoip2 {
216215 my ($err , $address , $servicename ) = Socket::getnameinfo($_ -> {addr }, Socket::NI_NUMERICHOST, Socket::NIx_NOSERV);
217216 next if ($err || !is_public_ip($address ));
218217
219- if ($Debug && $param ne $address ) { debug(" Plugin $PluginName : Lookup_geoip2 $param resolved to $address " ,5); }
218+ if ($Debug && $param ne $address ) { debug(" Plugin $PluginName : Lookup_geoip2_country $param resolved to $address " ,5); }
220219 eval {
221220 my $record = $reader -> country(ip => $address );
222221 $TmpDomainLookup {$param } = $record -> country()-> iso_code();
@@ -225,7 +224,7 @@ sub Lookup_geoip2 {
225224 }
226225 }
227226 my $res = $TmpDomainLookup {$param };
228- if ($Debug ) { debug(" Plugin $PluginName : Lookup_geoip2 for $param : [$res ]" ,5); }
227+ if ($Debug ) { debug(" Plugin $PluginName : Lookup_geoip2_country for $param : [$res ]" ,5); }
229228 return $res ;
230229}
231230
0 commit comments