]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
no message
authoreldy <>
Mon, 25 Feb 2002 00:18:43 +0000 (00:18 +0000)
committereldy <>
Mon, 25 Feb 2002 00:18:43 +0000 (00:18 +0000)
tools/common2combined.pl
tools/logresolvemerge.pl

index c77f2f73d9d1206b81934fe521d37555f6fffffb..b7800721bf93612da0a8d6705d0d3108c67ed404 100644 (file)
@@ -2,32 +2,39 @@
 # With some other Unix Os, first line may be
 #!/usr/local/bin/perl
 # With Apache for Windows and ActiverPerl, first line may be
-#!c:/program files/activeperl/bin/perl
+#!C:/Program Files/ActiveState/bin/perl
 #-Description-------------------------------------------
-# Convert a common log file into a combined
+# Convert a common log file into a combined.
 # This tool is part of AWStats log analyzer but can be use
 # alone for any other log analyzer.
 # See COPYING.TXT file about AWStats GNU General Public License.
 #-------------------------------------------------------
-#use diagnostics;
-#use strict;
+use strict; no strict "refs";
+use diagnostics;
 
 
 #-------------------------------------------------------
 # Defines
 #-------------------------------------------------------
-
-# ---------- Init variables (Variable $TmpHashxxx are not initialized) --------
-($ParamFile)=();
+my $VERSION="1.1 (build 1)";
+
+# ---------- Init variables --------
+my $Debug=0;
+my $ShowSteps=0;
+my $DIR;
+my $PROG;
+my $Extension;
+my $DNSLookup=0;
+my $DirCgi="";
+my $DirData="";
+my $NbOfLinesForBenchmark=5000;
+my $NewReferer="-";            #$NewReferer="http://www.referersite.com/refererpage.html";
+my $NewUserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
 # ---------- Init hash arrays --------
-%monthnum = ();
-
-$VERSION="1.0 (build 2)";
-$NbOfLinesForBenchmark=5000;
-
-#$NewReferer="http://www.referersite.com/refererpage.html";
-$NewReferer="-";
-$NewUserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
+my %ParamFile=();
+my %linerecord=();
+my %timeconnexion=();
+my %corrupted=();
 
 
 
@@ -43,7 +50,7 @@ sub debug {
        my $level = $_[1] || 1;
        if ($Debug >= $level) { 
                my $debugstring = $_[0];
-               if ($ENV{"GATEWAY_INTERFACE"} ne "") { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br>"; }
+               if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br>"; }
                print "DEBUG $level - ".time." : $debugstring\n";
                }
        0;
@@ -54,7 +61,7 @@ sub debug {
 #-------------------------------------------------------
 # MAIN
 #-------------------------------------------------------
-$QueryString=""; for (0..@ARGV-1) { $QueryString .= "$ARGV[$_] "; }
+my $QueryString=""; for (0..@ARGV-1) { $QueryString .= "$ARGV[$_] "; }
 if ($QueryString =~ /debug=/i) { $Debug=$QueryString; $Debug =~ s/.*debug=//; $Debug =~ s/&.*//; $Debug =~ s/ .*//; }
 if ($QueryString =~ /dnslookup/i) { $DNSLookup=1; }
 if ($QueryString =~ /showsteps/i) { $ShowSteps=1; }
@@ -88,49 +95,49 @@ if (scalar keys %ParamFile == 0) {
 }
 
 # Get current time
-$nowtime=time;
-($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear) = localtime($nowtime);
+my $nowtime=time;
+my ($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear) = localtime($nowtime);
 if ($nowyear < 100) { $nowyear+=2000; } else { $nowyear+=1900; }
-$nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//;
+my $nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//;
 if (++$nowmonth < 10) { $nowmonth = "0$nowmonth"; }
 if ($nowday < 10) { $nowday = "0$nowday"; }
 if ($nowhour < 10) { $nowhour = "0$nowhour"; }
 if ($nowmin < 10) { $nowmin = "0$nowmin"; }
 if ($nowsec < 10) { $nowsec = "0$nowsec"; }
 # Get tomorrow time (will be used to discard some record with corrupted date (future date))
-($tomorrowsec,$tomorrowmin,$tomorrowhour,$tomorrowday,$tomorrowmonth,$tomorrowyear) = localtime($nowtime+86400);
+my ($tomorrowsec,$tomorrowmin,$tomorrowhour,$tomorrowday,$tomorrowmonth,$tomorrowyear) = localtime($nowtime+86400);
 if ($tomorrowyear < 100) { $tomorrowyear+=2000; } else { $tomorrowyear+=1900; }
-$tomorrowsmallyear=$tomorrowyear;$tomorrowsmallyear =~ s/^..//;
+my $tomorrowsmallyear=$tomorrowyear;$tomorrowsmallyear =~ s/^..//;
 if (++$tomorrowmonth < 10) { $tomorrowmonth = "0$tomorrowmonth"; }
 if ($tomorrowday < 10) { $tomorrowday = "0$tomorrowday"; }
 if ($tomorrowhour < 10) { $tomorrowhour = "0$tomorrowhour"; }
 if ($tomorrowmin < 10) { $tomorrowmin = "0$tomorrowmin"; }
 if ($tomorrowsec < 10) { $tomorrowsec = "0$tomorrowsec"; }
-$timetomorrow=$tomorrowyear.$tomorrowmonth.$tomorrowday.$tomorrowhour.$tomorrowmin.$tomorrowsec;       
+my $timetomorrow=$tomorrowyear.$tomorrowmonth.$tomorrowday.$tomorrowhour.$tomorrowmin.$tomorrowsec;    
 
 # Init other parameters
-if ($ENV{"GATEWAY_INTERFACE"} ne "") { $DirCgi=""; }
-if (($DirCgi ne "") && !($DirCgi =~ /\/$/) && !($DirCgi =~ /\\$/)) { $DirCgi .= "/"; }
-if ($DirData eq "" || $DirData eq ".") { $DirData=$DIR; }      # If not defined or choosed to "." value then DirData is current dir
-if ($DirData eq "")  { $DirData="."; }                                         # If current dir not defined then we put it to "."
+if ($ENV{"GATEWAY_INTERFACE"}) { $DirCgi=""; }
+if ($DirCgi && !($DirCgi =~ /\/$/) && !($DirCgi =~ /\\$/)) { $DirCgi .= "/"; }
+if (! $DirData || $DirData eq ".") { $DirData=$DIR; }  # If not defined or choosed to "." value then DirData is current dir
+if (! $DirData)  { $DirData="."; }                                             # If current dir not defined then we put it to "."
 $DirData =~ s/\/$//;
 if ($DNSLookup) { use Socket; }
-$NewDNSLookup=$DNSLookup;
-%monthlib =  ( "01","$message[60]","02","$message[61]","03","$message[62]","04","$message[63]","05","$message[64]","06","$message[65]","07","$message[66]","08","$message[67]","09","$message[68]","10","$message[69]","11","$message[70]","12","$message[71]" );
+#my %monthlib =  ( "01","$message[60]","02","$message[61]","03","$message[62]","04","$message[63]","05","$message[64]","06","$message[65]","07","$message[66]","08","$message[67]","09","$message[68]","10","$message[69]","11","$message[70]","12","$message[71]" );
 # monthnum must be in english because it's used to translate log date in apache log files which are always in english
-%monthnum =  ( "Jan","01","jan","01","Feb","02","feb","02","Mar","03","mar","03","Apr","04","apr","04","May","05","may","05","Jun","06","jun","06","Jul","07","jul","07","Aug","08","aug","08","Sep","09","sep","09","Oct","10","oct","10","Nov","11","nov","11","Dec","12","dec","12" );
+my %monthnum =  ( "Jan","01","jan","01","Feb","02","feb","02","Mar","03","mar","03","Apr","04","apr","04","May","05","may","05","Jun","06","jun","06","Jul","07","jul","07","Aug","08","aug","08","Sep","09","sep","09","Oct","10","oct","10","Nov","11","nov","11","Dec","12","dec","12" );
 
 #------------------------------------------
 # PROCESSING CURRENT LOG(s)
 #------------------------------------------
-%LogFileToDo=(); %NowNewLinePhase=(); %NbOfLinesRead=(); %NbOfLinesCorrupted=();
-$NbOfNewLinesProcessed=0; $NbOfNewLinesCorrupted=0;
-$logfilechosen=0;
-$starttime=time();
+my %LogFileToDo=(); my %NowNewLinePhase=(); my %NbOfLinesRead=(); my %NbOfLinesCorrupted=();
+my $NbOfNewLinesProcessed=0;
+my $NbOfNewLinesCorrupted=0;
+my $logfilechosen=0;
+my $starttime=time();
 
 # Define the LogFileToDo list
-my $cpt=1;
-foreach $key (keys %ParamFile) {
+$cpt=1;
+foreach my $key (keys %ParamFile) {
        if ($ParamFile{$key} !~ /\*/ && $ParamFile{$key} !~ /\?/) {
                &debug("Log file $ParamFile{$key} is added to LogFileToDo.");
                $LogFileToDo{$cpt}=$ParamFile{$key};
@@ -145,9 +152,9 @@ foreach $key (keys %ParamFile) {
                $ParamFile{$key} =~ s/\?/\./g;
                &debug("Search for file \"$ParamFile{$key}\" into \"$DirFile\"");
                opendir(DIR,"$DirFile");
-               @filearray = sort readdir DIR;
+               my @filearray = sort readdir DIR;
                close DIR;
-               foreach $i (0..$#filearray) {
+               foreach my $i (0..$#filearray) {
                        if ("$filearray[$i]" =~ /^$ParamFile{$key}$/ && "$filearray[$i]" ne "." && "$filearray[$i]" ne "..") {
                                &debug("Log file $filearray[$i] is added to LogFileToDo.");
                                $LogFileToDo{$cpt}="$DirFile/$filearray[$i]";
@@ -164,7 +171,7 @@ if (scalar keys %LogFileToDo == 0) {
 
 # Open all log files
 &debug("Start of processing ".(scalar keys %LogFileToDo)." log file(s)");
-foreach $logfilenb (keys %LogFileToDo) {
+foreach my $logfilenb (keys %LogFileToDo) {
        &debug("Open log file number $logfilenb: \"$LogFileToDo{$logfilenb}\"");
        open("LOG$logfilenb","$LogFileToDo{$logfilenb}") || error("Couldn't open log file \"$LogFileToDo{$logfilenb}\" : $!");
 }
@@ -173,7 +180,7 @@ while (1 == 1)
 {
        # BEGIN Read new record (for each log file or only for log file with record just processed)
        #------------------------------------------------------------------------------------------
-       foreach $logfilenb (keys %LogFileToDo) {
+       foreach my $logfilenb (keys %LogFileToDo) {
                if (($logfilechosen == 0) || ($logfilechosen == $logfilenb)) {
                        &debug("Search next record in file number $logfilenb",3);
                        # Read chosen log file until we found a record with good date or reaching end of file
@@ -234,39 +241,6 @@ while (1 == 1)
        $NbOfNewLinesProcessed++;
        if (($ShowSteps) && ($NbOfNewLinesProcessed % $NbOfLinesForBenchmark == 0)) { print STDERR "$NbOfNewLinesProcessed lines processed (".(time()-$starttime)." seconds, ".($NbOfNewLinesProcessed/(time()-$starttime))." lines/seconds)\n"; }
 
-       # Analyze: IP-address
-       #--------------------
-       if ($NewDNSLookup) {
-               $_ =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
-               $Host=$1;
-               if ($Host ne "") {
-                       $new=$TmpHashDNSLookup{$Host};  # TmpHashDNSLookup is a temporary hash table to increase speed
-                       if (!$new) {                                    # if $new undefined, $Host not yet resolved
-                               &debug(" Start of reverse DNS lookup for $Host",4);
-                               if ($MyDNSTable{$Host}) {
-                                       &debug(" End of reverse DNS lookup, found resolution of $Host in local MyDNSTable",4);
-                                       $new = $MyDNSTable{$Host};
-                               }
-                               else {
-                                       if (&SkipDNSLookup($Host)) {
-                                               &debug(" (Skipping this DNS lookup at user request.)",4);
-                                       }
-                                       else {
-                                               $new=gethostbyaddr(pack("C4",split(/\./,$Host)),AF_INET);       # This is very slow, may took 20 seconds
-                                       }
-                                       &debug(" End of reverse DNS lookup for $Host",4);
-                               }
-                               if ($new eq "") { $new="ip"; }
-                               $TmpHashDNSLookup{$Host}=$new;
-                       }
-                       # Here $Host is still xxx.xxx.xxx.xxx and $new is name or "ip" if reverse failed)
-                       if ($new ne "ip") { $_ =~ s/$Host/$new/; }
-           }
-               else {
-                       &debug(" No IP adresses found in this record.",3);
-               }
-       }
-
        # Print record if ready
        print "$linerecord{$logfilechosen} \"$NewReferer\" \"$NewUserAgent\"\n";
 
@@ -276,10 +250,10 @@ while (1 == 1)
 
 
 # Close all log files
-foreach $logfilenb (keys %LogFileToDo) {
+foreach my $logfilenb (keys %LogFileToDo) {
        &debug("Close log file number $logfilenb");
        close("LOG$logfilenb");
 }
 
 
-0;     # Do not remove this line
\ No newline at end of file
+0;     # Do not remove this line
index f61f58f0a76e13f74c919f27330051e5016098c8..9fba6a8474185ed5ce27ba5ddf20cc3d8cbbf57a 100644 (file)
@@ -2,7 +2,7 @@
 # With some other Unix Os, first line may be
 #!/usr/local/bin/perl
 # With Apache for Windows and ActiverPerl, first line may be
-#!c:/program files/activeperl/bin/perl
+#!C:/Program Files/ActiveState/bin/perl
 #-Description-------------------------------------------
 # Merge several log files into one and replace all IP addresses
 # with resolved DNS host name.
 # alone for any other log analyzer.
 # See COPYING.TXT file about AWStats GNU General Public License.
 #-------------------------------------------------------
-#use diagnostics;
-#use strict;
-
+use strict; no strict "refs";
+use diagnostics;
 #use Thread;
 
 
 #-------------------------------------------------------
 # Defines
 #-------------------------------------------------------
-
-# ---------- Init variables (Variable $TmpHashxxx are not initialized) --------
-($ParamFile)=();
+my $VERSION="1.1 (build 1)";
+
+# ---------- Init variables --------
+my $Debug=0;
+my $ShowSteps=0;
+my $DIR;
+my $PROG;
+my $Extension;
+my $DNSLookup=0;
+my $DirCgi="";
+my $DirData="";
+my $QueuePoolSize=10;
+my $NbOfLinesForBenchmark=5000;
+my $DNSLookupAlreadyDone=0;
 # ---------- Init arrays --------
-@wordlist = ();
+my @SkipDNSLookupFor=();
 # ---------- Init hash arrays --------
-%monthnum = ();
-
-$VERSION="1.0 (build 2)";
-$QueuePoolSize=10;
-$NbOfLinesForBenchmark=5000;
+my %ParamFile=();
+my %linerecord=();
+my %timeconnexion=();
+my %corrupted=();
+my %TmpHashDNSLookup=();
+my %QueueHosts=();
+my %QueueRecord=();
 
 # These table is used to make fast reverse DNS lookup for particular IP adresses. You can add your own IP adresses resolutions.
-%MyDNSTable = (
+my %MyDNSTable = (
 "256.256.256.1", "myworkstation1",
 "256.256.256.2", "myworkstation2"
 );
@@ -52,7 +64,7 @@ sub debug {
        my $level = $_[1] || 1;
        if ($Debug >= $level) { 
                my $debugstring = $_[0];
-               if ($ENV{"GATEWAY_INTERFACE"} ne "") { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br>"; }
+               if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br>"; }
                print "DEBUG $level - ".time." : $debugstring\n";
                }
        0;
@@ -78,7 +90,7 @@ sub warning {
 # Return:       0 or 1
 #--------------------------------------------------------------------
 sub IsAscii {
-       my $string=shift;
+       my $string=shift||"";
        debug("IsAscii($string)",4);
        if ($string =~ /^[\w\+\-\/\\\.%,;:=\"\'&?!\s]+$/) {
                debug(" Yes",4);
@@ -104,7 +116,7 @@ sub MakeDNSLookup {
 #-------------------------------------------------------
 # MAIN
 #-------------------------------------------------------
-$QueryString=""; for (0..@ARGV-1) { $QueryString .= "$ARGV[$_] "; }
+my $QueryString=""; for (0..@ARGV-1) { $QueryString .= "$ARGV[$_] "; }
 if ($QueryString =~ /debug=/i) { $Debug=$QueryString; $Debug =~ s/.*debug=//; $Debug =~ s/&.*//; $Debug =~ s/ .*//; }
 if ($QueryString =~ /dnslookup/i) { $DNSLookup=1; }
 if ($QueryString =~ /showsteps/i) { $ShowSteps=1; }
@@ -147,48 +159,48 @@ if (scalar keys %ParamFile == 0) {
 }
 
 # Get current time
-$nowtime=time;
-($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear) = localtime($nowtime);
+my $nowtime=time;
+my ($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear) = localtime($nowtime);
 if ($nowyear < 100) { $nowyear+=2000; } else { $nowyear+=1900; }
-$nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//;
+my $nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//;
 if (++$nowmonth < 10) { $nowmonth = "0$nowmonth"; }
 if ($nowday < 10) { $nowday = "0$nowday"; }
 if ($nowhour < 10) { $nowhour = "0$nowhour"; }
 if ($nowmin < 10) { $nowmin = "0$nowmin"; }
 if ($nowsec < 10) { $nowsec = "0$nowsec"; }
 # Get tomorrow time (will be used to discard some record with corrupted date (future date))
-($tomorrowsec,$tomorrowmin,$tomorrowhour,$tomorrowday,$tomorrowmonth,$tomorrowyear) = localtime($nowtime+86400);
+my ($tomorrowsec,$tomorrowmin,$tomorrowhour,$tomorrowday,$tomorrowmonth,$tomorrowyear) = localtime($nowtime+86400);
 if ($tomorrowyear < 100) { $tomorrowyear+=2000; } else { $tomorrowyear+=1900; }
-$tomorrowsmallyear=$tomorrowyear;$tomorrowsmallyear =~ s/^..//;
+my $tomorrowsmallyear=$tomorrowyear;$tomorrowsmallyear =~ s/^..//;
 if (++$tomorrowmonth < 10) { $tomorrowmonth = "0$tomorrowmonth"; }
 if ($tomorrowday < 10) { $tomorrowday = "0$tomorrowday"; }
 if ($tomorrowhour < 10) { $tomorrowhour = "0$tomorrowhour"; }
 if ($tomorrowmin < 10) { $tomorrowmin = "0$tomorrowmin"; }
 if ($tomorrowsec < 10) { $tomorrowsec = "0$tomorrowsec"; }
-$timetomorrow=$tomorrowyear.$tomorrowmonth.$tomorrowday.$tomorrowhour.$tomorrowmin.$tomorrowsec;       
+my $timetomorrow=$tomorrowyear.$tomorrowmonth.$tomorrowday.$tomorrowhour.$tomorrowmin.$tomorrowsec;    
 
 # Init other parameters
-if ($ENV{"GATEWAY_INTERFACE"} ne "") { $DirCgi=""; }
-if (($DirCgi ne "") && !($DirCgi =~ /\/$/) && !($DirCgi =~ /\\$/)) { $DirCgi .= "/"; }
-if ($DirData eq "" || $DirData eq ".") { $DirData=$DIR; }      # If not defined or choosed to "." value then DirData is current dir
-if ($DirData eq "")  { $DirData="."; }                                         # If current dir not defined then we put it to "."
+if ($ENV{"GATEWAY_INTERFACE"}) { $DirCgi=""; }
+if ($DirCgi && !($DirCgi =~ /\/$/) && !($DirCgi =~ /\\$/)) { $DirCgi .= "/"; }
+if (! $DirData || $DirData eq ".") { $DirData=$DIR; }  # If not defined or choosed to "." value then DirData is current dir
+if (! $DirData)  { $DirData="."; }                                             # If current dir not defined then we put it to "."
 $DirData =~ s/\/$//;
 if ($DNSLookup) { use Socket; }
-%monthlib =  ( "01","$message[60]","02","$message[61]","03","$message[62]","04","$message[63]","05","$message[64]","06","$message[65]","07","$message[66]","08","$message[67]","09","$message[68]","10","$message[69]","11","$message[70]","12","$message[71]" );
+#my %monthlib =  ( "01","$Message[60]","02","$Message[61]","03","$Message[62]","04","$Message[63]","05","$Message[64]","06","$Message[65]","07","$Message[66]","08","$Message[67]","09","$Message[68]","10","$Message[69]","11","$Message[70]","12","$Message[71]" );
 # monthnum must be in english because it's used to translate log date in apache log files which are always in english
-%monthnum =  ( "Jan","01","jan","01","Feb","02","feb","02","Mar","03","mar","03","Apr","04","apr","04","May","05","may","05","Jun","06","jun","06","Jul","07","jul","07","Aug","08","aug","08","Sep","09","sep","09","Oct","10","oct","10","Nov","11","nov","11","Dec","12","dec","12" );
+my %monthnum =  ( "Jan","01","jan","01","Feb","02","feb","02","Mar","03","mar","03","Apr","04","apr","04","May","05","may","05","Jun","06","jun","06","Jul","07","jul","07","Aug","08","aug","08","Sep","09","sep","09","Oct","10","oct","10","Nov","11","nov","11","Dec","12","dec","12" );
 
 #------------------------------------------
 # PROCESSING CURRENT LOG(s)
 #------------------------------------------
-%LogFileToDo=(); %NbOfLinesRead=();
-$NbOfNewLinesProcessed=0;
-$logfilechosen=0;
-$starttime=time();
+my %LogFileToDo=(); my %NbOfLinesRead=();
+my $NbOfNewLinesProcessed=0;
+my $logfilechosen=0;
+my $starttime=time();
 
 # Define the LogFileToDo list
 $cpt=1;
-foreach $key (keys %ParamFile) {
+foreach my $key (keys %ParamFile) {
        if ($ParamFile{$key} !~ /\*/ && $ParamFile{$key} !~ /\?/) {
                &debug("Log file $ParamFile{$key} is added to LogFileToDo.");
                $LogFileToDo{$cpt}=$ParamFile{$key};
@@ -203,9 +215,9 @@ foreach $key (keys %ParamFile) {
                $ParamFile{$key} =~ s/\?/\./g;
                &debug("Search for file \"$ParamFile{$key}\" into \"$DirFile\"");
                opendir(DIR,"$DirFile");
-               @filearray = sort readdir DIR;
+               my @filearray = sort readdir DIR;
                close DIR;
-               foreach $i (0..$#filearray) {
+               foreach my $i (0..$#filearray) {
                        if ("$filearray[$i]" =~ /^$ParamFile{$key}$/ && "$filearray[$i]" ne "." && "$filearray[$i]" ne "..") {
                                &debug("Log file $filearray[$i] is added to LogFileToDo.");
                                $LogFileToDo{$cpt}="$DirFile/$filearray[$i]";
@@ -222,17 +234,17 @@ if (scalar keys %LogFileToDo == 0) {
 
 # Open all log files
 &debug("Start of processing ".(scalar keys %LogFileToDo)." log file(s)");
-foreach $logfilenb (keys %LogFileToDo) {
+foreach my $logfilenb (keys %LogFileToDo) {
        &debug("Open log file number $logfilenb: \"$LogFileToDo{$logfilenb}\"");
        open("LOG$logfilenb","$LogFileToDo{$logfilenb}") || error("Couldn't open log file \"$LogFileToDo{$logfilenb}\" : $!");
 }
 
-$QueueCursor=1;
+my $QueueCursor=1;
 while (1 == 1)
 {
        # BEGIN Read new record (for each log file or only for log file with record just processed)
        #------------------------------------------------------------------------------------------
-       foreach $logfilenb (keys %LogFileToDo) {
+       foreach my $logfilenb (keys %LogFileToDo) {
                if (($logfilechosen == 0) || ($logfilechosen == $logfilenb)) {
                        &debug("Search next record in file number $logfilenb",3);
                        # Read chosen log file until we found a record with good date or reaching end of file
@@ -295,6 +307,7 @@ while (1 == 1)
 
        # Analyze: IP-address
        #--------------------
+       my $Host;
        if ($DNSLookup) {
                if ($_ =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) {
                        $Host=$1;
@@ -333,12 +346,13 @@ while (1 == 1)
        }
 
        # Put record in queue
+       debug("Add record $NbOfNewLinesProcessed in queue ($Host).",4);
        $QueueRecord{$NbOfNewLinesProcessed}=$_;
        $QueueHosts{$NbOfNewLinesProcessed}=$Host;
 
        # Print all records in queue that are ready
        debug("Check queue to write records ready to flush (QueueCursor=$QueueCursor, QueueSize=".(scalar keys %QueueRecord).")",4);
-       while ( ($QueueHosts{$QueueCursor} eq "NO_LOOKUP_REQUIRED") || ($TmpHashDNSLookup{$QueueHosts{$QueueCursor}}) ) {
+       while ( $QueueHosts{$QueueCursor} && ( ($QueueHosts{$QueueCursor} eq "NO_LOOKUP_REQUIRED") || ($TmpHashDNSLookup{$QueueHosts{$QueueCursor}}) ) ) {
                if ($QueueHosts{$QueueCursor} eq "NO_LOOKUP_REQUIRED") {
                        debug(" First elem in queue does not need reverse lookup. We pull it.",4);
                }
@@ -357,7 +371,7 @@ while (1 == 1)
 &debug("End of processing log file(s)");
 
 # Close all log files
-foreach $logfilenb (keys %LogFileToDo) {
+foreach my $logfilenb (keys %LogFileToDo) {
        &debug("Close log file number $logfilenb");
        close("LOG$logfilenb");
 }
@@ -368,6 +382,6 @@ foreach $logfilenb (keys %LogFileToDo) {
 
 
 # DNSLookup warning
-if ($DNSLookup && $DNSLookupAlreadyDone) { warning("Warning: $PROG has detected that some host names were already resolved in your logfile $DNSLookupAlreadyDone.\nIf DNS lookup was already made by the logger (web server) in all your log files, you should change your setup DNSLookup=1 into DNSLookup=0 to increase $PROG speed."); }
+if ($DNSLookup && $DNSLookupAlreadyDone) { warning("Warning: $PROG has detected that some host names were already resolved in your logfile $DNSLookupAlreadyDone.\nIf DNS lookup was already made by the logger (web server) in ALL your log files, you should not use -dnslookup option to increase $PROG speed."); }
 
 0;     # Do not remove this line