]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Add Dynamic DNS Lookup 26/head
authorMaciej Filocha <m.filocha@icm.edu.pl>
Fri, 1 Apr 2016 11:52:20 +0000 (11:52 +0000)
committerMaciej Filocha <m.filocha@icm.edu.pl>
Fri, 1 Apr 2016 11:52:20 +0000 (11:52 +0000)
wwwroot/cgi-bin/awstats.model.conf
wwwroot/cgi-bin/awstats.pl

index 04ce2524c584820725a90e9fcf98919a99ce9828..c6f02a9b4e1e74bcd21e2d05df4c5532ab6ff84a 100644 (file)
@@ -191,6 +191,19 @@ HostAliases="localhost 127.0.0.1 REGEX[myserver\.com$]"
 DNSLookup=2
 
 
+# For very large sites, setting DNSLookup to 0 (or 2) might be the only
+# reasonable choice. DynamicDNSLookup allows to resolve host names for
+# items shown in html tables only.
+# Possible values:
+# 0 - No dynamic DNS lookup 
+# 1 - Dynamic DNS lookup enabled
+# 2 - Dynamic DNS lookup enabled (including static DNS cache file as a second
+#     source)
+# Default: 0
+#
+DynamicDNSLookup=0
+
+
 # When AWStats updates its statistics, it stores results of its analysis in 
 # files (AWStats database). All those files are written in the directory
 # defined by the "DirData" parameter. Set this value to the directory where
index 9b864b3a9e30325872fac88e304f3fc1bf9f361f..3c93f8690cc708717b60bf2da9477c746d900a16 100755 (executable)
@@ -182,7 +182,7 @@ $BuildHistoryFormat    = 'text';
 $ExtraTrackedRowsLimit = 500;
 $DatabaseBreak         = 'month';
 use vars qw/
-  $DebugMessages $AllowToUpdateStatsFromBrowser $EnableLockForUpdate $DNSLookup $AllowAccessFromWebToAuthenticatedUsersOnly
+  $DebugMessages $AllowToUpdateStatsFromBrowser $EnableLockForUpdate $DNSLookup $DynamicDNSLookup $AllowAccessFromWebToAuthenticatedUsersOnly
   $BarHeight $BarWidth $CreateDirDataIfNotExists $KeepBackupOfHistoricFiles
   $NbOfLinesParsed $NbOfLinesDropped $NbOfLinesCorrupted $NbOfLinesComment $NbOfLinesBlank $NbOfOldLines $NbOfNewLines
   $NbOfLinesShowsteps $NewLinePhase $NbOfLinesForCorruptedLog $PurgeLogFile $ArchiveLogRecords
@@ -199,6 +199,7 @@ use vars qw/
        $AllowToUpdateStatsFromBrowser,
        $EnableLockForUpdate,
        $DNSLookup,
+       $DynamicDNSLookup,
        $AllowAccessFromWebToAuthenticatedUsersOnly,
        $BarHeight,
        $BarWidth,
@@ -241,7 +242,7 @@ use vars qw/
        $DecodePunycode
   )
   = (
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   );
 use vars qw/
@@ -12534,11 +12535,37 @@ sub HTMLShowHosts{
                &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
                        \%_host_l );
        }
+       my $regipv4=qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
+
+       if ( $DynamicDNSLookup == 2 ) {
+               # Use static DNS file
+               &Read_DNS_Cache( \%MyDNSTable, "$DNSStaticCacheFile", "", 1 );
+       }
+
        foreach my $key (@keylist) {
                my $host = CleanXSS($key);
                print "<tr><td class=\"aws\">"
                  . ( $_robot_l{$key} ? '<b>'  : '' ) . "$host"
-                 . ( $_robot_l{$key} ? '</b>' : '' ) . "</td>";
+                 . ( $_robot_l{$key} ? '</b>' : '' );
+
+               if ($DynamicDNSLookup) {
+                       # Dynamic reverse DNS lookup
+                       if ($host =~ /$regipv4/o) {
+                               my $lookupresult=lc(gethostbyaddr(pack("C4",split(/\./,$host)),AF_INET));       # This may be slow
+                               if (! $lookupresult || $lookupresult =~ /$regipv4/o || ! IsAscii($lookupresult)) {
+                                       if ( $DynamicDNSLookup == 2 ) {
+                                               # Check static DNS file
+                                               $lookupresult = $MyDNSTable{$host};
+                                               if ($lookupresult) { print " ($lookupresult)"; }
+                                               else { print ""; }
+                                       }
+                                       else { print ""; }
+                               }
+                               else { print " ($lookupresult)"; }
+                       }
+               }
+
+               print "</td>";
                &HTMLShowHostInfo($key);
                if ( $ShowHostsStats =~ /P/i ) {
                        print "<td>"
@@ -14912,9 +14939,35 @@ sub HTMLMainHosts{
        my $total_p = my $total_h = my $total_k = 0;
        my $count = 0;
        
+       my $regipv4 = qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; 
+
+        if ( $DynamicDNSLookup == 2 ) {
+               # Use static DNS file
+                &Read_DNS_Cache( \%MyDNSTable, "$DNSStaticCacheFile", "", 1 );
+        }
+
        foreach my $key (@keylist) {
                print "<tr>";
-               print "<td class=\"aws\">$key</td>";
+               print "<td class=\"aws\">$key";
+
+               if ($DynamicDNSLookup) {
+                       # Dynamic reverse DNS lookup
+                       if ($key =~ /$regipv4/o) {
+                               my $lookupresult=lc(gethostbyaddr(pack("C4",split(/\./,$key)),AF_INET));        # This may be slow
+                               if (! $lookupresult || $lookupresult =~ /$regipv4/o || ! IsAscii($lookupresult)) {
+                                        if ( $DynamicDNSLookup == 2 ) {
+                                                # Check static DNS file
+                                                $lookupresult = $MyDNSTable{$key};
+                                                if ($lookupresult) { print " ($lookupresult)"; }
+                                                else { print ""; }
+                                        }
+                                        else { print ""; }
+                                }
+                                else { print " ($lookupresult)"; }
+                        }
+                }
+
+               print "</td>";
                &HTMLShowHostInfo($key);
                if ( $ShowHostsStats =~ /P/i ) {
                        print '<td>' . ( Format_Number($_host_p{$key}) || "&nbsp;" ) . '</td>';