From e7b9ff07f5048e2fda1bcd60536fe9b9fe88fb41 Mon Sep 17 00:00:00 2001 From: eldy <> Date: Fri, 21 Nov 2003 22:38:41 +0000 Subject: [PATCH] Little speed improvment --- wwwroot/cgi-bin/awstats.pl | 398 ++++++++++++++++++------------------- 1 file changed, 198 insertions(+), 200 deletions(-) diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl index 79064775..b1028cf8 100644 --- a/wwwroot/cgi-bin/awstats.pl +++ b/wwwroot/cgi-bin/awstats.pl @@ -995,8 +995,8 @@ sub Read_Config { # Open config file $FileConfig=$FileSuffix=''; - foreach my $dir (@PossibleConfigDir) { - my $searchdir=$dir; + foreach (@PossibleConfigDir) { + my $searchdir=$_; if ($searchdir && $searchdir !~ /[\\\/]$/) { $searchdir .= "/"; } if (open(CONFIG,"$searchdir$PROG.$SiteConfig.conf")) { $FileConfig="$searchdir$PROG.$SiteConfig.conf"; $FileSuffix=".$SiteConfig"; last; } if (open(CONFIG,"$searchdir$PROG.conf")) { $FileConfig="$searchdir$PROG.conf"; $FileSuffix=''; last; } @@ -1124,7 +1124,7 @@ sub Parse_Config { next; } if ($param =~ /^AllowAccessFromWebToFollowingAuthenticatedUsers/) { - foreach my $elem (split(/\s+/,$value)) { push @AllowAccessFromWebToFollowingAuthenticatedUsers,$elem; } + foreach (split(/\s+/,$value)) { push @AllowAccessFromWebToFollowingAuthenticatedUsers,$_; } next; } if ($param =~ /^DefaultFile/) { @@ -1185,17 +1185,17 @@ sub Parse_Config { next; } if ($param =~ /^NotPageList/) { - foreach my $elem (split(/\s+/,$value)) { $NotPageList{$elem}=1; } + foreach (split(/\s+/,$value)) { $NotPageList{$_}=1; } $FoundNotPageList=1; next; } if ($param =~ /^ValidHTTPCodes/) { - foreach my $elem (split(/\s+/,$value)) { $ValidHTTPCodes{$elem}=1; } + foreach (split(/\s+/,$value)) { $ValidHTTPCodes{$_}=1; } $FoundValidHTTPCodes=1; next; } if ($param =~ /^ValidSMTPCodes/) { - foreach my $elem (split(/\s+/,$value)) { $ValidSMTPCodes{$elem}=1; } + foreach (split(/\s+/,$value)) { $ValidSMTPCodes{$_}=1; } $FoundValidSMTPCodes=1; next; } @@ -1298,15 +1298,15 @@ sub Read_Language_Data { my @PossibleLangDir=("$DirLang","${DIR}lang","/usr/share/awstats/lang","./lang"); my $FileLang=''; - foreach my $dir (@PossibleLangDir) { - my $searchdir=$dir; + foreach (@PossibleLangDir) { + my $searchdir=$_; if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; } if (open(LANG,"${searchdir}awstats-$_[0].txt")) { $FileLang="${searchdir}awstats-$_[0].txt"; last; } } # If file not found, we try english if (! $FileLang) { - foreach my $dir (@PossibleLangDir) { - my $searchdir=$dir; + foreach (@PossibleLangDir) { + my $searchdir=$_; if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; } if (open(LANG,"${searchdir}awstats-en.txt")) { $FileLang="${searchdir}awstats-en.txt"; last; } } @@ -1613,8 +1613,8 @@ sub Check_Config { debug(" DirCgi='$DirCgi'",2); debug(" DirIcons='$DirIcons'",2); debug(" SiteDomain=$SiteDomain",2); - foreach my $key (keys %MaxNbOf) { debug(" MaxNbOf{$key}=$MaxNbOf{$key}",2); } - foreach my $key (keys %MinHit) { debug(" MinHit{$key}=$MinHit{$key}",2); } + foreach (keys %MaxNbOf) { debug(" MaxNbOf{$_}=$MaxNbOf{$_}",2); } + foreach (keys %MinHit) { debug(" MinHit{$_}=$MinHit{$_}",2); } foreach my $extranum (1..@ExtraName-1) { debug(" ExtraConditionType[$extranum] is array ".join(',',@{$ExtraConditionType[$extranum]}),2); debug(" ExtraConditionTypeVal[$extranum] is array ".join(',',@{$ExtraConditionTypeVal[$extranum]}),2); @@ -1829,8 +1829,8 @@ sub Read_History_With_TmpUpdate { 'searchwords'=>24,'keywords'=>25, 'errors'=>26); my $order=(scalar keys %allsections)+1; - foreach my $code (keys %TrapInfosForHTTPErrorCodes) { $allsections{"sider_$code"}=$order++; } - foreach my $extranum (1..@ExtraName-1) { $allsections{"extra_$extranum"}=$order++; } + foreach (keys %TrapInfosForHTTPErrorCodes) { $allsections{"sider_$_"}=$order++; } + foreach (1..@ExtraName-1) { $allsections{"extra_$_"}=$order++; } my $withread=0; # Variable used to read old format history files @@ -1874,17 +1874,17 @@ sub Read_History_With_TmpUpdate { # Others if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowMiscStats)) { $SectionsToLoad{'misc'}=$order++; } if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && ($ShowHTTPErrorsStats || $ShowSMTPErrorsStats)) || $HTMLOutput{'errors'}) { $SectionsToLoad{'errors'}=$order++; } - foreach my $code (keys %TrapInfosForHTTPErrorCodes) { - if ($UpdateStats || $MigrateStats || $HTMLOutput{"errors$code"}) { $SectionsToLoad{"sider_$code"}=$order++; } + foreach (keys %TrapInfosForHTTPErrorCodes) { + if ($UpdateStats || $MigrateStats || $HTMLOutput{"errors$_"}) { $SectionsToLoad{"sider_$_"}=$order++; } } if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ShowClusterStats)) { $SectionsToLoad{'cluster'}=$order++; } - foreach my $extranum (1..@ExtraName-1) { - if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ExtraStatTypes[$extranum]) || $HTMLOutput{"extra$extranum"}) { $SectionsToLoad{"extra_$extranum"}=$order++; } + foreach (1..@ExtraName-1) { + if ($UpdateStats || $MigrateStats || ($HTMLOutput{'main'} && $ExtraStatTypes[$_]) || $HTMLOutput{"extra$_"}) { $SectionsToLoad{"extra_$_"}=$order++; } } } else { # Load only required sections my $order=1; - foreach my $key (split(/\s+/,$part)) { $SectionsToLoad{$key}=$order++; } + foreach (split(/\s+/,$part)) { $SectionsToLoad{$_}=$order++; } } # Define SectionsToSave (which sections to save) @@ -1892,8 +1892,8 @@ sub Read_History_With_TmpUpdate { if ($withupdate) { %SectionsToSave=%allsections; } if ($Debug) { - foreach my $section (sort { $SectionsToLoad{$a} <=> $SectionsToLoad{$b} } keys %SectionsToLoad) { debug(" Section '$section' is marked for load",2); } - foreach my $section (sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} } keys %SectionsToSave) { debug(" Section '$section' is marked for save",2); } + foreach (sort { $SectionsToLoad{$a} <=> $SectionsToLoad{$b} } keys %SectionsToLoad) { debug(" Section '$_' is marked for load",2); } + foreach (sort { $SectionsToSave{$a} <=> $SectionsToSave{$b} } keys %SectionsToSave) { debug(" Section '$_' is marked for save",2); } } # Define value for filetowrite and filetoread (Month before Year kept for backward compatibility) @@ -2322,11 +2322,11 @@ sub Read_History_With_TmpUpdate { if ($Debug) { debug(" End of UNKOWNIP section ($count entries, $countloaded loaded)"); } delete $SectionsToLoad{'visitor'}; # THIS SECTION IS NEVER SAVED. ONLY READ FOR MIGRATE AND CONVERTED INTO VISITOR SECTION - foreach my $key (keys %iptomigrate) { - $_host_p{$key}+=int($_host_p{'Unknown'}/$countloaded); - $_host_h{$key}+=int($_host_h{'Unknown'}/$countloaded); - $_host_k{$key}+=int($_host_k{'Unknown'}/$countloaded); - if ($iptomigrate{$key} > 0) { $_host_l{$key}=$iptomigrate{$key} }; + foreach (keys %iptomigrate) { + $_host_p{$_}+=int($_host_p{'Unknown'}/$countloaded); + $_host_h{$_}+=int($_host_h{'Unknown'}/$countloaded); + $_host_k{$_}+=int($_host_k{'Unknown'}/$countloaded); + if ($iptomigrate{$_} > 0) { $_host_l{$_}=$iptomigrate{$_} }; } delete $_host_p{'Unknown'}; delete $_host_h{'Unknown'}; @@ -2896,8 +2896,8 @@ sub Read_History_With_TmpUpdate { if ($loadrecord) { if ($field[1]) { if ($loadrecord==2) { - foreach my $word (split(/\+/,$field[0])) { # val1+val2 - $_keywords{$word}+=$field[1]; + foreach (split(/\+/,$field[0])) { # field[0] is "val1+val2+..." + $_keywords{$_}+=$field[1]; } } else { @@ -3072,13 +3072,13 @@ sub Read_History_With_TmpUpdate { # Process rest of data saved in 'wait' arrays (data for hosts that are not in history file or no history file found) # This can change some values for day, sider and session sections if ($Debug) { debug(" Processing data in 'wait' arrays",3); } - foreach my $key (keys %_waithost_e) { - if ($Debug) { debug(" Visit in 'wait' array for $key is a new visit",4); } - my $newtimehosts=($_waithost_s{$key}?$_waithost_s{$key}:$_host_s{$key}); - my $newtimehostl=($_waithost_l{$key}?$_waithost_l{$key}:$_host_l{$key}); - $_url_e{$_waithost_e{$key}}++; + foreach (keys %_waithost_e) { + if ($Debug) { debug(" Visit in 'wait' array for $_ is a new visit",4); } + my $newtimehosts=($_waithost_s{$_}?$_waithost_s{$_}:$_host_s{$_}); + my $newtimehostl=($_waithost_l{$_}?$_waithost_l{$_}:$_host_l{$_}); + $_url_e{$_waithost_e{$_}}++; $newtimehosts =~ /^(\d\d\d\d\d\d\d\d)/; $DayVisits{$1}++; - if ($_waithost_s{$key}) { + if ($_waithost_s{$_}) { # There was also a second session in processed log $_session{GetSessionRange($newtimehosts,$newtimehostl)}++; } @@ -3094,10 +3094,10 @@ sub Read_History_With_TmpUpdate { # Update offset in map section and last data in general section then close files if ($withupdate) { # Update offset of sections in the MAP section - foreach my $key (sort { $PosInFile{$a} <=> $PosInFile{$b} } keys %ValueInFile) { - debug(" Update offset of section $key=$ValueInFile{$key} in file at offset $PosInFile{$key}"); - if ($PosInFile{"$key"}) { - seek(HISTORYTMP,$PosInFile{"$key"},0); print HISTORYTMP $ValueInFile{"$key"}; + foreach (sort { $PosInFile{$a} <=> $PosInFile{$b} } keys %ValueInFile) { + debug(" Update offset of section $_=$ValueInFile{$_} in file at offset $PosInFile{$_}"); + if ($PosInFile{"$_"}) { + seek(HISTORYTMP,$PosInFile{"$_"},0); print HISTORYTMP $ValueInFile{"$_"}; } } # Save last data in general sections @@ -3203,11 +3203,11 @@ sub Save_History { print HISTORYTMP "POS_MISC ";$PosInFile{"misc"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; print HISTORYTMP "POS_ERRORS ";$PosInFile{"errors"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; print HISTORYTMP "POS_CLUSTER ";$PosInFile{"cluster"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; - foreach my $code (keys %TrapInfosForHTTPErrorCodes) { - print HISTORYTMP "POS_SIDER_$code ";$PosInFile{"sider_$code"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; + foreach (keys %TrapInfosForHTTPErrorCodes) { + print HISTORYTMP "POS_SIDER_$_ ";$PosInFile{"sider_$_"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; } - foreach my $extranum (1..@ExtraName-1) { - print HISTORYTMP "POS_EXTRA_$extranum ";$PosInFile{"extra_$extranum"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; + foreach (1..@ExtraName-1) { + print HISTORYTMP "POS_EXTRA_$_ ";$PosInFile{"extra_$_"}=tell HISTORYTMP;print HISTORYTMP "$spacebar\n"; } print HISTORYTMP "END_MAP\n"; } @@ -3252,13 +3252,13 @@ sub Save_History { $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_DAY ".(scalar keys %DayHits)."\n"; my $monthvisits=0; - foreach my $key (sort keys %DayHits) { - if ($key =~ /^$year$month/i) { # Found a day entry of the good month - my $page=$DayPages{$key}||0; - my $hits=$DayHits{$key}||0; - my $bytes=$DayBytes{$key}||0; - my $visits=$DayVisits{$key}||0; - print HISTORYTMP "$key $page $hits $bytes $visits\n"; + foreach (sort keys %DayHits) { + if ($_ =~ /^$year$month/i) { # Found a day entry of the good month + my $page=$DayPages{$_}||0; + my $hits=$DayHits{$_}||0; + my $bytes=$DayBytes{$_}||0; + my $visits=$DayVisits{$_}||0; + print HISTORYTMP "$_ $page $hits $bytes $visits\n"; $monthvisits+=$visits; } } @@ -3276,17 +3276,17 @@ sub Save_History { # We save page list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'Domain'},$MinHit{'Domain'},\%_domener_h,\%_domener_p); my %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - my $page=$_domener_p{$key}||0; - my $bytes=$_domener_k{$key}||0; # ||0 could be commented to reduce history file size - print HISTORYTMP "$key $page $_domener_h{$key} $bytes\n"; - } - foreach my $key (keys %_domener_h) { - if ($keysinkeylist{$key}) { next; } - my $page=$_domener_p{$key}||0; - my $bytes=$_domener_k{$key}||0; # ||0 could be commented to reduce history file size - print HISTORYTMP "$key $page $_domener_h{$key} $bytes\n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + my $page=$_domener_p{$_}||0; + my $bytes=$_domener_k{$_}||0; # ||0 could be commented to reduce history file size + print HISTORYTMP "$_ $page $_domener_h{$_} $bytes\n"; + } + foreach (keys %_domener_h) { + if ($keysinkeylist{$_}) { next; } + my $page=$_domener_p{$_}||0; + my $bytes=$_domener_k{$_}||0; # ||0 could be commented to reduce history file size + print HISTORYTMP "$_ $page $_domener_h{$_} $bytes\n"; } print HISTORYTMP "END_DOMAIN\n"; } @@ -3369,13 +3369,13 @@ sub Save_History { # We save login list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'LoginShown'},$MinHit{'Login'},\%_login_h,\%_login_p); my %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - print HISTORYTMP "$key ".int($_login_p{$key}||0)." ".int($_login_h{$key}||0)." ".int($_login_k{$key}||0)." ".($_login_l{$key}||'')."\n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + print HISTORYTMP "$_ ".int($_login_p{$_}||0)." ".int($_login_h{$_}||0)." ".int($_login_k{$_}||0)." ".($_login_l{$_}||'')."\n"; } - foreach my $key (keys %_login_h) { - if ($keysinkeylist{$key}) { next; } - print HISTORYTMP "$key ".int($_login_p{$key}||0)." ".int($_login_h{$key}||0)." ".int($_login_k{$key}||0)." ".($_login_l{$key}||'')."\n"; + foreach (keys %_login_h) { + if ($keysinkeylist{$_}) { next; } + print HISTORYTMP "$_ ".int($_login_p{$_}||0)." ".int($_login_h{$_}||0)." ".int($_login_k{$_}||0)." ".($_login_l{$_}||'')."\n"; } print HISTORYTMP "END_LOGIN\n"; } @@ -3388,13 +3388,13 @@ sub Save_History { # We save robot list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'RobotShown'},$MinHit{'Robot'},\%_robot_h,\%_robot_h); my %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - print HISTORYTMP "$key ".int($_robot_h{$key})." ".int($_robot_k{$key})." $_robot_l{$key} ".int($_robot_r{$key})." \n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + print HISTORYTMP "$_ ".int($_robot_h{$_})." ".int($_robot_k{$_})." $_robot_l{$_} ".int($_robot_r{$_})." \n"; } - foreach my $key (keys %_robot_h) { - if ($keysinkeylist{$key}) { next; } - print HISTORYTMP "$key ".int($_robot_h{$key})." ".int($_robot_k{$key})." $_robot_l{$key} ".int($_robot_r{$key})." \n"; + foreach (keys %_robot_h) { + if ($keysinkeylist{$_}) { next; } + print HISTORYTMP "$_ ".int($_robot_h{$_})." ".int($_robot_k{$_})." $_robot_l{$_} ".int($_robot_r{$_})." \n"; } print HISTORYTMP "END_ROBOT\n"; } @@ -3407,13 +3407,13 @@ sub Save_History { # We save robot list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'WormsShown'},$MinHit{'Worm'},\%_worm_h,\%_worm_h); my %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - print HISTORYTMP "$key ".int($_worm_h{$key})." $_worm_l{$key}\n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + print HISTORYTMP "$_ ".int($_worm_h{$_})." $_worm_l{$_}\n"; } - foreach my $key (keys %_worm_h) { - if ($keysinkeylist{$key}) { next; } - print HISTORYTMP "$key ".int($_worm_h{$key})." $_worm_l{$key}\n"; + foreach (keys %_worm_h) { + if ($keysinkeylist{$_}) { next; } + print HISTORYTMP "$_ ".int($_worm_h{$_})." $_worm_l{$_}\n"; } print HISTORYTMP "END_WORMS\n"; } @@ -3426,13 +3426,13 @@ sub Save_History { # We save sender email list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'EMailsShown'},$MinHit{'EMail'},\%_emails_h,\%_emails_h); my %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - print HISTORYTMP "$key ".int($_emails_h{$key}||0)." ".int($_emails_k{$key}||0)." $_emails_l{$key}\n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + print HISTORYTMP "$_ ".int($_emails_h{$_}||0)." ".int($_emails_k{$_}||0)." $_emails_l{$_}\n"; } - foreach my $key (keys %_emails_h) { - if ($keysinkeylist{$key}) { next; } - print HISTORYTMP "$key ".int($_emails_h{$key}||0)." ".int($_emails_k{$key}||0)." $_emails_l{$key}\n"; + foreach (keys %_emails_h) { + if ($keysinkeylist{$_}) { next; } + print HISTORYTMP "$_ ".int($_emails_h{$_}||0)." ".int($_emails_k{$_}||0)." $_emails_l{$_}\n"; } print HISTORYTMP "END_EMAILSENDER\n"; } @@ -3445,13 +3445,13 @@ sub Save_History { # We save receiver email list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'EMailsShown'},$MinHit{'EMail'},\%_emailr_h,\%_emailr_h); my %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - print HISTORYTMP "$key ".int($_emailr_h{$key}||0)." ".int($_emailr_k{$key}||0)." $_emailr_l{$key}\n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + print HISTORYTMP "$_ ".int($_emailr_h{$_}||0)." ".int($_emailr_k{$_}||0)." $_emailr_l{$_}\n"; } - foreach my $key (keys %_emailr_h) { - if ($keysinkeylist{$key}) { next; } - print HISTORYTMP "$key ".int($_emailr_h{$key}||0)." ".int($_emailr_k{$key}||0)." $_emailr_l{$key}\n"; + foreach (keys %_emailr_h) { + if ($keysinkeylist{$_}) { next; } + print HISTORYTMP "$_ ".int($_emailr_h{$_}||0)." ".int($_emailr_k{$_}||0)." $_emailr_l{$_}\n"; } print HISTORYTMP "END_EMAILRECEIVER\n"; } @@ -3462,7 +3462,7 @@ sub Save_History { print HISTORYTMP "# Session range - Number of visits\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_SESSION ".(scalar keys %_session)."\n"; - foreach my $key (keys %_session) { print HISTORYTMP "$key ".int($_session{$key})."\n"; } + foreach (keys %_session) { print HISTORYTMP "$_ ".int($_session{$_})."\n"; } print HISTORYTMP "END_SESSION\n"; } if ($sectiontosave eq 'sider') { # This section must be saved after VISITOR section is read @@ -3474,17 +3474,17 @@ sub Save_History { # We save page list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'PageShown'},$MinHit{'File'},\%_url_p,\%_url_p); %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - my $newkey=$key; + foreach (@keylist) { + $keysinkeylist{$_}=1; + my $newkey=$_; $newkey =~ s/([^:])\/\//$1\//g; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm - print HISTORYTMP "$newkey ".int($_url_p{$key}||0)." ".int($_url_k{$key}||0)." ".int($_url_e{$key}||0)." ".int($_url_x{$key}||0)."\n"; + print HISTORYTMP "$newkey ".int($_url_p{$_}||0)." ".int($_url_k{$_}||0)." ".int($_url_e{$_}||0)." ".int($_url_x{$_}||0)."\n"; } - foreach my $key (keys %_url_p) { - if ($keysinkeylist{$key}) { next; } - my $newkey=$key; + foreach (keys %_url_p) { + if ($keysinkeylist{$_}) { next; } + my $newkey=$_; $newkey =~ s/([^:])\/\//$1\//g; # Because some targeted url were taped with 2 / (Ex: //rep//file.htm). We must keep http://rep/file.htm - print HISTORYTMP "$newkey ".int($_url_p{$key}||0)." ".int($_url_k{$key}||0)." ".int($_url_e{$key}||0)." ".int($_url_x{$key}||0)."\n"; + print HISTORYTMP "$newkey ".int($_url_p{$_}||0)." ".int($_url_k{$_}||0)." ".int($_url_e{$_}||0)." ".int($_url_x{$_}||0)."\n"; } print HISTORYTMP "END_SIDER\n"; } @@ -3493,12 +3493,12 @@ sub Save_History { print HISTORYTMP "# Files type - Hits - Bandwidth - Bandwidth without compression - Bandwidth after compression\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_FILETYPES ".(scalar keys %_filetypes_h)."\n"; - foreach my $key (keys %_filetypes_h) { - my $hits=$_filetypes_h{$key}||0; - my $bytes=$_filetypes_k{$key}||0; - my $bytesbefore=$_filetypes_gz_in{$key}||0; - my $bytesafter=$_filetypes_gz_out{$key}||0; - print HISTORYTMP "$key $hits $bytes $bytesbefore $bytesafter\n"; + foreach (keys %_filetypes_h) { + my $hits=$_filetypes_h{$_}||0; + my $bytes=$_filetypes_k{$_}||0; + my $bytesbefore=$_filetypes_gz_in{$_}||0; + my $bytesafter=$_filetypes_gz_out{$_}||0; + print HISTORYTMP "$_ $hits $bytes $bytesbefore $bytesafter\n"; } print HISTORYTMP "END_FILETYPES\n"; } @@ -3507,7 +3507,7 @@ sub Save_History { print HISTORYTMP "# OS ID - Hits\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_OS ".(scalar keys %_os_h)."\n"; - foreach my $key (keys %_os_h) { print HISTORYTMP "$key $_os_h{$key}\n"; } + foreach (keys %_os_h) { print HISTORYTMP "$_ $_os_h{$_}\n"; } print HISTORYTMP "END_OS\n"; } if ($sectiontosave eq 'browser') { @@ -3515,7 +3515,7 @@ sub Save_History { print HISTORYTMP "# Browser ID - Hits\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_BROWSER ".(scalar keys %_browser_h)."\n"; - foreach my $key (keys %_browser_h) { print HISTORYTMP "$key $_browser_h{$key}\n"; } + foreach (keys %_browser_h) { print HISTORYTMP "$_ $_browser_h{$_}\n"; } print HISTORYTMP "END_BROWSER\n"; } if ($sectiontosave eq 'screensize') { @@ -3523,7 +3523,7 @@ sub Save_History { print HISTORYTMP "# Screen size - Hits\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_SCREENSIZE ".(scalar keys %_screensize_h)."\n"; - foreach my $key (keys %_screensize_h) { print HISTORYTMP "$key $_screensize_h{$key}\n"; } + foreach (keys %_screensize_h) { print HISTORYTMP "$_ $_screensize_h{$_}\n"; } print HISTORYTMP "END_SCREENSIZE\n"; } @@ -3533,7 +3533,7 @@ sub Save_History { print HISTORYTMP "# Unknown referer OS - Last visit date\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_UNKNOWNREFERER ".(scalar keys %_unknownreferer_l)."\n"; - foreach my $key (keys %_unknownreferer_l) { print HISTORYTMP "$key $_unknownreferer_l{$key}\n"; } + foreach (keys %_unknownreferer_l) { print HISTORYTMP "$_ $_unknownreferer_l{$_}\n"; } print HISTORYTMP "END_UNKNOWNREFERER\n"; } if ($sectiontosave eq 'unknownrefererbrowser') { @@ -3541,7 +3541,7 @@ sub Save_History { print HISTORYTMP "# Unknown referer Browser - Last visit date\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_UNKNOWNREFERERBROWSER ".(scalar keys %_unknownrefererbrowser_l)."\n"; - foreach my $key (keys %_unknownrefererbrowser_l) { print HISTORYTMP "$key $_unknownrefererbrowser_l{$key}\n"; } + foreach (keys %_unknownrefererbrowser_l) { print HISTORYTMP "$_ $_unknownrefererbrowser_l{$_}\n"; } print HISTORYTMP "END_UNKNOWNREFERERBROWSER\n"; } if ($sectiontosave eq 'origin') { @@ -3562,7 +3562,7 @@ sub Save_History { print HISTORYTMP "# Search engine referers ID - Pages - Hits\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_SEREFERRALS ".(scalar keys %_se_referrals_h)."\n"; - foreach my $key (keys %_se_referrals_h) { print HISTORYTMP "$key ".int($_se_referrals_p{$key}||0)." $_se_referrals_h{$key}\n"; } + foreach (keys %_se_referrals_h) { print HISTORYTMP "$_ ".int($_se_referrals_p{$_}||0)." $_se_referrals_h{$_}\n"; } print HISTORYTMP "END_SEREFERRALS\n"; } if ($sectiontosave eq 'pagerefs') { @@ -3574,19 +3574,19 @@ sub Save_History { # We save page list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'RefererShown'},$MinHit{'Refer'},\%_pagesrefs_h,\%_pagesrefs_p); %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - my $newkey=$key; + foreach (@keylist) { + $keysinkeylist{$_}=1; + my $newkey=$_; $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i; # Remove / at end of http://.../ but not at end of http://.../dir/ $newkey =~ s/\s/%20/g; - print HISTORYTMP "$newkey ".int($_pagesrefs_p{$key}||0)." $_pagesrefs_h{$key}\n"; + print HISTORYTMP "$newkey ".int($_pagesrefs_p{$_}||0)." $_pagesrefs_h{$_}\n"; } - foreach my $key (keys %_pagesrefs_h) { - if ($keysinkeylist{$key}) { next; } - my $newkey=$key; + foreach (keys %_pagesrefs_h) { + if ($keysinkeylist{$_}) { next; } + my $newkey=$_; $newkey =~ s/^http(s|):\/\/([^\/]+)\/$/http$1:\/\/$2/i; # Remove / at end of http://.../ but not at end of http://.../dir/ $newkey =~ s/\s/%20/g; - print HISTORYTMP "$newkey ".int($_pagesrefs_p{$key}||0)." $_pagesrefs_h{$key}\n"; + print HISTORYTMP "$newkey ".int($_pagesrefs_p{$_}||0)." $_pagesrefs_h{$_}\n"; } print HISTORYTMP "END_PAGEREFS\n"; } @@ -3605,13 +3605,13 @@ sub Save_History { $keysinkeylist{$key}=1; my $keyphrase=$key; print HISTORYTMP "$keyphrase $_keyphrases{$key}\n"; - foreach my $word (split(/\+/,$key)) { $_keywords{$word}+=$_keyphrases{$key}; } # To init %_keywords + foreach (split(/\+/,$key)) { $_keywords{$_}+=$_keyphrases{$key}; } # To init %_keywords } foreach my $key (keys %_keyphrases) { if ($keysinkeylist{$key}) { next; } my $keyphrase=$key; print HISTORYTMP "$keyphrase $_keyphrases{$key}\n"; - foreach my $word (split(/\+/,$key)) { $_keywords{$word}+=$_keyphrases{$key}; } # To init %_keywords + foreach (split(/\+/,$key)) { $_keywords{$_}+=$_keyphrases{$key}; } # To init %_keywords } print HISTORYTMP "END_SEARCHWORDS\n"; # Now save keywords section @@ -3623,15 +3623,15 @@ sub Save_History { # We save key list in score sorted order to get a -output faster and with less use of memory. &BuildKeyList($MaxNbOf{'KeywordsShown'},$MinHit{'Keyword'},\%_keywords,\%_keywords); %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - my $keyword=$key; - print HISTORYTMP "$keyword $_keywords{$key}\n"; + foreach (@keylist) { + $keysinkeylist{$_}=1; + my $keyword=$_; + print HISTORYTMP "$keyword $_keywords{$_}\n"; } - foreach my $key (keys %_keywords) { - if ($keysinkeylist{$key}) { next; } - my $keyword=$key; - print HISTORYTMP "$keyword $_keywords{$key}\n"; + foreach (keys %_keywords) { + if ($keysinkeylist{$_}) { next; } + my $keyword=$_; + print HISTORYTMP "$keyword $_keywords{$_}\n"; } print HISTORYTMP "END_KEYWORDS\n"; } @@ -3642,7 +3642,7 @@ sub Save_History { print HISTORYTMP "# Cluster ID - Pages - Hits - Bandwidth\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_CLUSTER ".(scalar keys %_cluster_h)."\n"; - foreach my $key (keys %_cluster_h) { print HISTORYTMP "$key ".int($_cluster_p{$key}||0)." ".int($_cluster_h{$key}||0)." ".int($_cluster_k{$key}||0)."\n"; } + foreach (keys %_cluster_h) { print HISTORYTMP "$_ ".int($_cluster_p{$_}||0)." ".int($_cluster_h{$_}||0)." ".int($_cluster_k{$_}||0)."\n"; } print HISTORYTMP "END_CLUSTER\n"; } if ($sectiontosave eq 'misc') { @@ -3650,7 +3650,7 @@ sub Save_History { print HISTORYTMP "# Misc ID - Pages - Hits - Bandwidth\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_MISC ".(scalar keys %MiscListCalc)."\n"; - foreach my $key (keys %MiscListCalc) { print HISTORYTMP "$key ".int($_misc_p{$key}||0)." ".int($_misc_h{$key}||0)." ".int($_misc_k{$key}||0)."\n"; } + foreach (keys %MiscListCalc) { print HISTORYTMP "$_ ".int($_misc_p{$_}||0)." ".int($_misc_h{$_}||0)." ".int($_misc_k{$_}||0)."\n"; } print HISTORYTMP "END_MISC\n"; } if ($sectiontosave eq 'errors') { @@ -3658,7 +3658,7 @@ sub Save_History { print HISTORYTMP "# Errors - Hits - Bandwidth\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_ERRORS ".(scalar keys %_errors_h)."\n"; - foreach my $key (keys %_errors_h) { print HISTORYTMP "$key $_errors_h{$key} ".int($_errors_k{$key}||0)."\n"; } + foreach (keys %_errors_h) { print HISTORYTMP "$_ $_errors_h{$_} ".int($_errors_k{$_}||0)."\n"; } print HISTORYTMP "END_ERRORS\n"; } # Other - Trapped errors @@ -3668,10 +3668,10 @@ sub Save_History { print HISTORYTMP "# URL with $code errors - Hits - Last URL referer\n"; $ValueInFile{$sectiontosave}=tell HISTORYTMP; print HISTORYTMP "BEGIN_SIDER_$code ".(scalar keys %_sider404_h)."\n"; - foreach my $key (keys %_sider404_h) { - my $newkey=$key; - my $newreferer=$_referer404_h{$key}||''; $newreferer =~ s/\s/%20/g; - print HISTORYTMP "$newkey $_sider404_h{$key} $newreferer\n"; + foreach (keys %_sider404_h) { + my $newkey=$_; + my $newreferer=$_referer404_h{$_}||''; $newreferer =~ s/\s/%20/g; + print HISTORYTMP "$newkey $_sider404_h{$_} $newreferer\n"; } print HISTORYTMP "END_SIDER_$code\n"; } @@ -3685,19 +3685,19 @@ sub Save_History { print HISTORYTMP "BEGIN_EXTRA_$extranum\n"; &BuildKeyList($MaxNbOfExtra[$extranum],$MinHitExtra[$extranum],\%{'_section_' . $extranum . '_h'},\%{'_section_' . $extranum . '_p'}); %keysinkeylist=(); - foreach my $key (@keylist) { - $keysinkeylist{$key}=1; - my $page=${'_section_' . $extranum . '_p'}{$key}||0; - my $bytes=${'_section_' . $extranum . '_k'}{$key}||0; - my $lastaccess=${'_section_' . $extranum . '_l'}{$key}||''; - print HISTORYTMP "$key $page ", ${'_section_' . $extranum . '_h'}{$key}, " $bytes $lastaccess\n"; next; + foreach (@keylist) { + $keysinkeylist{$_}=1; + my $page=${'_section_' . $extranum . '_p'}{$_}||0; + my $bytes=${'_section_' . $extranum . '_k'}{$_}||0; + my $lastaccess=${'_section_' . $extranum . '_l'}{$_}||''; + print HISTORYTMP "$_ $page ", ${'_section_' . $extranum . '_h'}{$_}, " $bytes $lastaccess\n"; next; } - foreach my $key (keys %{'_section_' . $extranum . '_h'}) { - if ($keysinkeylist{$key}) { next; } - my $page=${'_section_' . $extranum . '_p'}{$key}||0; - my $bytes=${'_section_' . $extranum . '_k'}{$key}||0; - my $lastaccess=${'_section_' . $extranum . '_l'}{$key}||''; - print HISTORYTMP "$key $page ", ${'_section_' . $extranum . '_h'}{$key}, " $bytes $lastaccess\n"; next; + foreach (keys %{'_section_' . $extranum . '_h'}) { + if ($keysinkeylist{$_}) { next; } + my $page=${'_section_' . $extranum . '_p'}{$_}||0; + my $bytes=${'_section_' . $extranum . '_k'}{$_}||0; + my $lastaccess=${'_section_' . $extranum . '_l'}{$_}||''; + print HISTORYTMP "$_ $page ", ${'_section_' . $extranum . '_h'}{$_}, " $bytes $lastaccess\n"; next; } print HISTORYTMP "END_EXTRA_$extranum\n"; } @@ -4540,8 +4540,8 @@ sub DefinePerlParsingFormat { if ($LogFormat =~ /^[1-6]$/) { # Pre-defined log format if ($LogFormat eq '1' || $LogFormat eq '6') { # Same than "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"". # %u (user) is "([^\\[]+)" instead of "[^ ]+" because can contain space (Lotus Notes). referer and ua might be "". - $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) (.+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\""; -# $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\""; +# $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) (.+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\""; + $PerlParsingFormat="([^ ]+) [^ ]+ ([^\\[]+) \\[([^ ]+) [^ ]+\\] \\\"([^ ]+) ([^ ]+) [^\\\"]+\\\" ([\\d|-]+) ([\\d|-]+) \\\"(.*?)\\\" \\\"([^\\\"]*)\\\""; $pos_host=0;$pos_logname=1;$pos_date=2;$pos_method=3;$pos_url=4;$pos_code=5;$pos_size=6;$pos_referer=7;$pos_agent=8; @fieldlib=('host','logname','date','method','url','code','size','referer','ua'); } @@ -4808,8 +4808,8 @@ sub ShowEmailSendersChart { print "\n"; print "