]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
New: Minor changes on geoip and hostinfo plugins
authoreldy <>
Sat, 19 Feb 2005 13:40:46 +0000 (13:40 +0000)
committereldy <>
Sat, 19 Feb 2005 13:40:46 +0000 (13:40 +0000)
wwwroot/cgi-bin/plugins/geoip.pm
wwwroot/cgi-bin/plugins/geoip_isp_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_org_maxmind.pm
wwwroot/cgi-bin/plugins/geoip_region_maxmind.pm
wwwroot/cgi-bin/plugins/hostinfo.pm

index 2579b523b269198a0c7ed159f0002e3dc3bd4606..02a836fc82e29b5e540fddb36f4ac9fd005c717d 100644 (file)
@@ -31,7 +31,7 @@ use strict;no strict "refs";
 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
 my $PluginNeedAWStatsVersion="5.4";
-my $PluginHooksFunctions="GetCountryCodeByAddr GetCountryCodeByName";
+my $PluginHooksFunctions="GetCountryCodeByAddr GetCountryCodeByName ShowInfoHost";
 # ----->
 
 # <-----
@@ -113,4 +113,72 @@ sub GetCountryCodeByAddr_geoip {
 }
 
 
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: ShowInfoHost_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to add additionnal columns to the Hosts report.
+# This function is called when building rows of the report (One call for each
+# row). So it allows you to add a column in report, for example with code :
+#   print "<TD>This is a new cell for $param</TD>";
+# Parameters: Host name or ip
+#-----------------------------------------------------------------------------
+sub ShowInfoHost_geoip {
+    my $param="$_[0]";
+       # <-----
+       if ($param eq '__title__') {
+       my $NewLinkParams=${QueryString};
+       $NewLinkParams =~ s/(^|&)update(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&)output(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&)staticlinks(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&)framename=[^&]*//i;
+       my $NewLinkTarget='';
+       if ($DetailedReportsOnNewWindows) { $NewLinkTarget=" target=\"awstatsbis\""; }
+       if (($FrameName eq 'mainleft' || $FrameName eq 'mainright') && $DetailedReportsOnNewWindows < 2) {
+               $NewLinkParams.="&framename=mainright";
+               $NewLinkTarget=" target=\"mainright\"";
+       }
+       $NewLinkParams =~ tr/&/&/s; $NewLinkParams =~ s/^&//; $NewLinkParams =~ s/&$//;
+       if ($NewLinkParams) { $NewLinkParams="${NewLinkParams}&"; }
+
+               print "<th width=\"80\">";
+        print "<a href=\"#countries\">GeoIP<br>Country</a>";
+        print "</th>";
+       }
+       elsif ($param) {
+        my $ip=0;
+               my $key;
+               if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
+                   $ip=4;
+                       $key=$param;
+               }
+               elsif ($param =~ /^[0-9A-F]*:/i) {                                              # IPv6 address
+                   $ip=6;
+                       $key=$param;
+               }
+               print "<td>";
+               if ($key && $ip==4) {
+               my $res=lc($gi->country_code_by_addr($param)) if $gi;
+               if ($Debug) { debug("  Plugin geoip: GetCountryByIp for $param: [$res]",5); }
+                   if ($res) { print $DomainsHashIDLib{$res}; }
+                   else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
+               }
+               if ($key && $ip==6) {
+                   print "<span style=\"color: #$color_other\">$Message[0]</span>";
+               }
+               if (! $key) {
+               my $res=lc($gi->country_code_by_addr($param)) if $gi;
+               if ($Debug) { debug("  Plugin geoip: GetCountryByHostname for $param: [$res]",5); }
+                   if ($res) { print $DomainsHashIDLib{$res}; }
+                   else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
+               }
+               print "</td>";
+       }
+       else {
+               print "<td>&nbsp;</td>";
+       }
+       return 1;
+       # ----->
+}
+
+
 1;     # Do not remove this line
index 2745dc624b4bd3e154f24cf2e68a676d86ee6d59..ee00b2722316fa796362c7c0b390dfbb133fdcea 100644 (file)
@@ -38,6 +38,7 @@ $geoip_isp_maxmind
 %_isp_k
 %_isp_l
 $MAXNBOFSECTIONGIR
+$MAXLENGTH
 /;
 # ----->
 
@@ -49,6 +50,7 @@ sub Init_geoip_isp_maxmind {
        my $InitParams=shift;
        my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
     $MAXNBOFSECTIONGIR=10;
+    $MAXLENGTH=20;
     
        # <-----
        # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
@@ -218,7 +220,14 @@ sub ShowInfoHost_geoip_isp_maxmind {
                if ($key && $ip==4) {
                my $isp=$geoip_isp_maxmind->org_by_addr($param) if $geoip_isp_maxmind;
                if ($Debug) { debug("  Plugin geoip_isp_maxmind: GetIspByIp for $param: [$isp]",5); }
-                   if ($isp) { print "$isp"; }
+                   if ($isp) {
+                       if (length($isp) <= $MAXLENGTH) {
+                           print "$isp";
+                       }
+                       else {
+                           print substr($isp,0,$MAXLENGTH).'...';
+                       }
+                   }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
                }
                if ($key && $ip==6) {
@@ -227,7 +236,14 @@ sub ShowInfoHost_geoip_isp_maxmind {
                if (! $key) {
                my $isp=$geoip_isp_maxmind->org_by_name($param) if $geoip_isp_maxmind;
                if ($Debug) { debug("  Plugin geoip_isp_maxmind: GetIspByHostname for $param: [$isp]",5); }
-                   if ($isp) { print "$isp"; }
+                   if ($isp) {
+                       if (length($isp) <= $MAXLENGTH) {
+                           print "$isp";
+                       }
+                       else {
+                           print substr($isp,0,$MAXLENGTH).'...';
+                       }
+                   }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
                }
                print "</td>";
index 4eabaf100276bbec55e805f163c26be4b463935b..401842196d3b3ee51390612d8cfad5d9553b89d2 100644 (file)
@@ -38,6 +38,7 @@ $geoip_org_maxmind
 %_org_k
 %_org_l
 $MAXNBOFSECTIONGIR
+$MAXLENGTH
 /;
 # ----->
 
@@ -49,6 +50,7 @@ sub Init_geoip_org_maxmind {
        my $InitParams=shift;
        my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
     $MAXNBOFSECTIONGIR=10;
+    $MAXLENGTH=20;
     
        # <-----
        # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
@@ -218,7 +220,14 @@ sub ShowInfoHost_geoip_org_maxmind {
                if ($key && $ip==4) {
                my $org=$geoip_org_maxmind->org_by_addr($param) if $geoip_org_maxmind;
                if ($Debug) { debug("  Plugin geoip_org_maxmind: GetOrgByIp for $param: [$org]",5); }
-                   if ($org) { print "$org"; }
+                   if ($org) {
+                       if (length($org) <= $MAXLENGTH) {
+                           print "$org";
+                       }
+                       else {
+                           print substr($org,0,$MAXLENGTH).'...';
+                       }
+                   }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
                }
                if ($key && $ip==6) {
@@ -227,7 +236,14 @@ sub ShowInfoHost_geoip_org_maxmind {
                if (! $key) {
                my $org=$geoip_org_maxmind->org_by_name($param) if $geoip_org_maxmind;
                if ($Debug) { debug("  Plugin geoip_org_maxmind: GetOrgByHostname for $param: [$org]",5); }
-                   if ($org) { print "$org"; }
+                   if ($org) {
+                       if (length($org) <= $MAXLENGTH) {
+                           print "$org";
+                       }
+                       else {
+                           print substr($org,0,$MAXLENGTH).'...';
+                       }
+                   }
                    else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
                }
                print "</td>";
index 6b86e950e673d8c40cef8cf587cb14ef5992d1cc..c5a21440f2b2bac5b417593e2e694a469565ab71 100755 (executable)
@@ -316,12 +316,22 @@ sub ShowInfoHost_geoip_region_maxmind {
                my ($res1,$res2,$countryregion)=();
                ($res1,$res2)=$geoip_region_maxmind->region_by_name($param) if $geoip_region_maxmind;
                if ($Debug) { debug("  Plugin geoip_region_maxmind: GetRegionByIp for $param: [${res1}_${res2}]",5); }
-            if ($res1 =~ /\w\w/) { print $DomainsHashIDLib{lc($res1)}||uc($res1); }
-            else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
-            if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
-                print "&nbsp;(";
-                print $region{lc($res1)}{uc($res2)};
-                print ")";
+            if (! $PluginsLoaded{'init'}{'geoip'}) {
+                # Show country
+                if ($res1 =~ /\w\w/) { print $DomainsHashIDLib{lc($res1)}||uc($res1); }
+                else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
+                # Show region
+                if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
+                    print "&nbsp;(";
+                    print $region{lc($res1)}{uc($res2)};
+                    print ")";
+                }
+            }
+            else {
+                if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
+                    print $region{lc($res1)}{uc($res2)};
+                }
+                else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
             }
                }
                if ($key && $ip==6) {
@@ -331,12 +341,22 @@ sub ShowInfoHost_geoip_region_maxmind {
                my ($res1,$res2,$countryregion)=();
                ($res1,$res2)=$geoip_region_maxmind->region_by_name($param) if $geoip_region_maxmind;
                if ($Debug) { debug("  Plugin geoip_region_maxmind: GetRegionByName for $param: [${res1}_${res2}]",5); }
-            if ($res1 =~ /\w\w/) { print $DomainsHashIDLib{lc($res1)}||uc($res1); }
-            else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
-            if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
-                print "&nbsp;(";
-                print $region{lc($res1)}{uc($res2)};
-                print ")";
+            if (! $PluginsLoaded{'init'}{'geoip'}) {
+                # Show country
+                if ($res1 =~ /\w\w/) { print $DomainsHashIDLib{lc($res1)}||uc($res1); }
+                else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
+                # Show region
+                if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
+                    print "&nbsp;(";
+                    print $region{lc($res1)}{uc($res2)};
+                    print ")";
+                }
+            }
+            else {
+                if ($res1 =~ /\w\w/ && $res2 =~ /\w\w/) {
+                    print $region{lc($res1)}{uc($res2)};
+                }
+                else { print "<span style=\"color: #$color_other\">$Message[0]</span>"; }
             }
                }
                print "</td>";
index 0e260be8b42c2c5d27fd7f7bd4d09359eab8522f..10473193e43415b2c98ceeec3fadf02867dccf5a 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #-----------------------------------------------------------------------------
 # HostInfo AWStats plugin
-# This plugin allow you to add information on hosts, like whois fields.
+# This plugin allow you to add information on hosts, like whois fields.
 #-----------------------------------------------------------------------------
 # Perl Required Modules: XWhois
 #-----------------------------------------------------------------------------
@@ -12,6 +12,7 @@
 # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
 push @INC, "${DIR}/plugins";
 if (!eval ('require "Net/XWhois.pm";')) { return $@?"Error: $@":"Error: Need Perl module Net::XWhois"; }
+if (!eval ('require "Digest/MD5.pm";')) { return $@?"Error: $@":"Error: Need Perl module Digest::MD5"; }
 # ----->
 use strict;no strict "refs";
 
@@ -72,8 +73,7 @@ sub AddHTMLBodyHeader_hostinfo {
 function neww(a,b) {
 var wfeatures="directories=0,menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,width=$WIDTHINFO,height=$HEIGHTINFO,left=" + eval("(screen.width - $WIDTHINFO)/2") + ",top=" + eval("(screen.height - $HEIGHTINFO)/2");
 EOF
-       print "if (b==1) { fen=window.open('".XMLEncode("$AWScript?$urlparam&host")."='+a,'whois',wfeatures); }\n";
-       print "if (b==2) { fen=window.open('".XMLEncode("$AWScript?$urlparam&host")."='+a,'whois',wfeatures); }\n";
+       print "fen=window.open('".XMLEncode("$AWScript?$urlparam&host")."='+a+'&key='+b,'whois',wfeatures);\n";
 print <<EOF;
 }
 </script>
@@ -102,22 +102,19 @@ sub ShowInfoHost_hostinfo {
        }
        elsif ($param) {
                my $keyforwhois;
-               my $linkforwhois;
                if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { # IPv4 address
                        $keyforwhois=$param;
-                       $linkforwhois=2;
                }
-               elsif ($param =~ /^[0-9A-F]*:/i) {                                                      # IPv6 address
+               elsif ($param =~ /^[0-9A-F]*:/i) {                                              # IPv6 address
                        $keyforwhois=$param;
-                       $linkforwhois=2;
                }
                else {  # Hostname
                        $param =~ /([-\w]+\.[-\w]+\.(?:au|uk|jp|nz))$/ or $param =~ /([-\w]+\.[-\w]+)$/;
                        $keyforwhois=$1;
-                       $linkforwhois=1;
                }
                print "<td>";
-               if ($keyforwhois && $linkforwhois) { print "<a href=\"javascript:neww('$keyforwhois',$linkforwhois)\">?</a>"; }
+#              if ($keyforwhois) { print "<a href=\"javascript:neww('$keyforwhois','".md5_hex("${keyforwhois}XXX")."')\">?</a>"; }
+               if ($keyforwhois) { print "<a href=\"javascript:neww('$keyforwhois','${keyforwhois}XXX')\">?</a>"; }
                else { print "&nbsp;" }
                print "</td>";
        }