From db7ecec332d5ebe99cec8b84d06ac2da4cb5a567 Mon Sep 17 00:00:00 2001 From: Maciej Filocha Date: Fri, 1 Apr 2016 11:52:20 +0000 Subject: [PATCH] Add Dynamic DNS Lookup --- wwwroot/cgi-bin/awstats.model.conf | 13 +++++++ wwwroot/cgi-bin/awstats.pl | 61 ++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/wwwroot/cgi-bin/awstats.model.conf b/wwwroot/cgi-bin/awstats.model.conf index 04ce2524..c6f02a9b 100644 --- a/wwwroot/cgi-bin/awstats.model.conf +++ b/wwwroot/cgi-bin/awstats.model.conf @@ -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 diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl index 9b864b3a..3c93f869 100755 --- a/wwwroot/cgi-bin/awstats.pl +++ b/wwwroot/cgi-bin/awstats.pl @@ -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 "" . ( $_robot_l{$key} ? '' : '' ) . "$host" - . ( $_robot_l{$key} ? '' : '' ) . ""; + . ( $_robot_l{$key} ? '' : '' ); + + 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 ""; &HTMLShowHostInfo($key); if ( $ShowHostsStats =~ /P/i ) { print "" @@ -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 ""; - print "$key"; + print "$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 ""; &HTMLShowHostInfo($key); if ( $ShowHostsStats =~ /P/i ) { print '' . ( Format_Number($_host_p{$key}) || " " ) . ''; -- 2.47.2