"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "SquidAnalyzer.pm" between
squidanalyzer-6.5.tar.gz and squidanalyzer-6.6.tar.gz

About: SquidAnalyzer is a Squid (proxy) log analyzer.

SquidAnalyzer.pm  (squidanalyzer-6.5):SquidAnalyzer.pm  (squidanalyzer-6.6)
package SquidAnalyzer; package SquidAnalyzer;
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Project : Squid Log Analyzer # Project : Squid Log Analyzer
# Name : SquidAnalyzer.pm # Name : SquidAnalyzer.pm
# Language : Perl 5 # Language : Perl 5
# OS : All # OS : All
# Copyright: Copyright (c) 2001-2016 Gilles Darold - All rights reserved. # Copyright: Copyright (c) 2001-2017 Gilles Darold - All rights reserved.
# Licence : This program is free software; you can redistribute it # Licence : This program is free software; you can redistribute it
# and/or modify it under the same terms as Perl itself. # and/or modify it under the same terms as Perl itself.
# Author : Gilles Darold, gilles _AT_ darold _DOT_ net # Author : Gilles Darold, gilles _AT_ darold _DOT_ net
# Function : Main perl module for Squid Log Analyzer # Function : Main perl module for Squid Log Analyzer
# Usage : See documentation. # Usage : See documentation.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
use strict qw/vars/; use strict qw/vars/;
BEGIN { BEGIN {
use Exporter(); use Exporter();
use vars qw($VERSION $COPYRIGHT $AUTHOR @ISA @EXPORT $ZCAT_PROG $BZCAT_PR OG $XZCAT_PROG $RM_PROG); use vars qw($VERSION $COPYRIGHT $AUTHOR @ISA @EXPORT $ZCAT_PROG $BZCAT_PR OG $XZCAT_PROG $RM_PROG);
use POSIX qw/ strftime sys_wait_h /; use POSIX qw/ strftime sys_wait_h /;
use IO::File; use IO::File;
use Socket; use Socket ();
use Time::HiRes qw/ualarm/; use Time::HiRes qw/ualarm/;
use Time::Local qw/timelocal_nocheck timegm_nocheck/; use Time::Local qw/timelocal_nocheck timegm_nocheck/;
use Fcntl qw(:flock); use Fcntl qw(:flock);
use IO::Handle; use IO::Handle;
use FileHandle; use FileHandle;
use POSIX qw(locale_h); use POSIX qw(locale_h);
setlocale(LC_NUMERIC, ''); setlocale(LC_NUMERIC, '');
setlocale(LC_ALL, 'C'); setlocale(LC_ALL, 'C');
# Set all internal variable # Set all internal variable
$VERSION = '6.5'; $VERSION = '6.6';
$COPYRIGHT = 'Copyright (c) 2001-2016 Gilles Darold - All rights reserved $COPYRIGHT = 'Copyright (c) 2001-2017 Gilles Darold - All rights reserved
.'; .';
$AUTHOR = "Gilles Darold - gilles _AT_ darold _DOT_ net"; $AUTHOR = "Gilles Darold - gilles _AT_ darold _DOT_ net";
@ISA = qw(Exporter); @ISA = qw(Exporter);
@EXPORT = qw//; @EXPORT = qw//;
$| = 1; $| = 1;
} }
$ZCAT_PROG = "/bin/zcat"; $ZCAT_PROG = "/bin/zcat";
$BZCAT_PROG = "/bin/bzcat"; $BZCAT_PROG = "/bin/bzcat";
$RM_PROG = "/bin/rm"; $RM_PROG = "/bin/rm";
$XZCAT_PROG = "/bin/xzcat"; $XZCAT_PROG = "/usr/bin/xzcat";
# DNS Cache # DNS Cache
my %CACHE = (); my %CACHE = ();
# Color used to draw grpahs # Color used to draw grpahs
my @GRAPH_COLORS = ('#6e9dc9', '#f4ab3a', '#ac7fa8', '#8dbd0f'); my @GRAPH_COLORS = ('#6e9dc9', '#f4ab3a', '#ac7fa8', '#8dbd0f');
# Default translation srings # Default translation srings
my %Translate = ( my %Translate = (
'CharSet' => 'utf-8', 'CharSet' => 'utf-8',
skipping to change at line 130 skipping to change at line 130
'Mime_title' => 'Mime Type Statistics on', 'Mime_title' => 'Mime Type Statistics on',
'Mime_number' => 'Number of mime type', 'Mime_number' => 'Number of mime type',
'Network_title' => 'Network Statistics on', 'Network_title' => 'Network Statistics on',
'Network_number' => 'Number of network', 'Network_number' => 'Number of network',
'Duration' => 'Duration', 'Duration' => 'Duration',
'Time' => 'Time', 'Time' => 'Time',
'Largest' => 'Largest', 'Largest' => 'Largest',
'Url' => 'Url', 'Url' => 'Url',
'User_title' => 'User Statistics on', 'User_title' => 'User Statistics on',
'User_number' => 'Number of user', 'User_number' => 'Number of user',
'Url_title' => 'Top %d site on',
'Url_Hits_title' => 'Top %d Url hits on', 'Url_Hits_title' => 'Top %d Url hits on',
'Url_Bytes_title' => 'Top %d Url bytes on', 'Url_Bytes_title' => 'Top %d Url bytes on',
'Url_Duration_title' => 'Top %d Url duration on', 'Url_Duration_title' => 'Top %d Url duration on',
'Url_number' => 'Number of Url', 'Url_number' => 'Number of Url',
'Domain_Hits_title' => 'Top %d Domain hits on', 'Domain_Hits_title' => 'Top %d Domain hits on',
'Domain_Bytes_title' => 'Top %d Domain bytes on', 'Domain_Bytes_title' => 'Top %d Domain bytes on',
'Domain_Duration_title' => 'Top %d Domain duration on', 'Domain_Duration_title' => 'Top %d Domain duration on',
'Domain_number' => 'Number of domain', 'Domain_number' => 'Number of domain',
'Domain_graph_hits_title' => 'Domain Hits Statistics on', 'Domain_graph_hits_title' => 'Domain Hits Statistics on',
'Domain_graph_bytes_title' => 'Domain Bytes Statistiques on', 'Domain_graph_bytes_title' => 'Domain Bytes Statistics on',
'Second_domain_graph_hits_title' => 'Second level Hits Statistics on', 'Second_domain_graph_hits_title' => 'Second level Hits Statistics on',
'Second_domain_graph_bytes_title' => 'Second level Bytes Statistiques on' , 'Second_domain_graph_bytes_title' => 'Second level Bytes Statistics on',
'First_visit' => 'First visit', 'First_visit' => 'First visit',
'Last_visit' => 'Last visit', 'Last_visit' => 'Last visit',
'Globals_Statistics' => 'Globals Statistics', 'Globals_Statistics' => 'Globals Statistics',
'Legend' => 'Legend', 'Legend' => 'Legend',
'File_Generated' => 'File generated by', 'File_Generated' => 'File generated by',
'Up_link' => 'Up', 'Up_link' => 'Up',
'Click_year_stat' => 'Click on year\'s statistics link for details', 'Click_year_stat' => 'Click on year\'s statistics link for details',
'Mime_graph_hits_title' => 'Mime Type Hits Statistics on', 'Mime_graph_hits_title' => 'Mime Type Hits Statistics on',
'Mime_graph_bytes_title' => 'Mime Type MBytes Statistiques on', 'Mime_graph_bytes_title' => 'Mime Type MBytes Statistics on',
'User' => 'User', 'User' => 'User',
'Count' => 'Count', 'Count' => 'Count',
'WeekDay' => 'Su Mo Tu We Th Fr Sa', 'WeekDay' => 'Su Mo Tu We Th Fr Sa',
'Week' => 'Week', 'Week' => 'Week',
'Top_denied_link' => 'Top Denied', 'Top_denied_link' => 'Top Denied',
'Blocklist_acl_title' => 'Blocklist ACL use', 'Blocklist_acl_title' => 'Blocklist ACL use',
'Throughput' => 'Throughput', 'Throughput' => 'Throughput',
'Graph_throughput_title' => '%s throughput on', 'Graph_throughput_title' => '%s throughput on',
'Throughput_graph' => 'Bytes/sec', 'Throughput_graph' => 'Bytes/sec',
); );
skipping to change at line 414 skipping to change at line 415
my $cidr_regex = qr/^[a-fA-F0-9\.\:]+\/\d+$/; my $cidr_regex = qr/^[a-fA-F0-9\.\:]+\/\d+$/;
# Native log format squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt # Native log format squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt
my $native_format_regex1 = qr/^(\d+\.\d{3})\s+(\d+)\s+([^\s]+)\s+([^\s]+)\s+(\d+ )\s+([^\s]+)\s+(.*)/; my $native_format_regex1 = qr/^(\d+\.\d{3})\s+(\d+)\s+([^\s]+)\s+([^\s]+)\s+(\d+ )\s+([^\s]+)\s+(.*)/;
my $native_format_regex2 = qr/^([^\s]+?)\s+([^\s]+)\s+([^\s]+\/[^\s]+)\s+([^\s]+ )\s*/; my $native_format_regex2 = qr/^([^\s]+?)\s+([^\s]+)\s+([^\s]+\/[^\s]+)\s+([^\s]+ )\s*/;
#logformat common %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st %Ss:%Sh #logformat common %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st %Ss:%Sh
#logformat combined %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Refere r}>h" "%{User-Agent}>h" %Ss:%Sh #logformat combined %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Refere r}>h" "%{User-Agent}>h" %Ss:%Sh
my $common_format_regex1 = qr/([^\s]+)\s([^\s]+)\s([^\s]+)\s\[(\d+\/...\/\d+:\d+ :\d+:\d+\s[\d\+\-]+)\]\s"([^\s]+)\s([^\s]+)\s([^\s]+)"\s(\d+)\s+(\d+)(.*)\s([^\s :]+:[^\s]+)\s*([^\/]+\/[^\s]+|-)?$/; my $common_format_regex1 = qr/([^\s]+)\s([^\s]+)\s([^\s]+)\s\[(\d+\/...\/\d+:\d+ :\d+:\d+\s[\d\+\-]+)\]\s"([^\s]+)\s([^\s]+)\s([^\s]+)"\s(\d+)\s+(\d+)(.*)\s([^\s :]+:[^\s]+)\s*([^\/]+\/[^\s]+|-)?$/;
# Log format for SquidGuard logs # Log format for SquidGuard logs
my $sg_format_regex1 = qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) .* Re quest\(([^\/]+\/[^\/]+)\/[^\)]*\) ([^\s]+) ([^\s\\]+)\/[^\s]+ ([^\s]+) ([^\s]+) ([^\s]+)/; my $sg_format_regex1 = qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) .* Re quest\(([^\/]+\/[^\/]+)\/[^\)]*\) ([^\s]+) ([^\s\\]+)\/[^\s]+ ([^\s]+) ([^\s]+) ([^\s]+)/;
my $sg_format_regex2 = qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) .* (N ew setting|Added User|init domainlist|Going into emergency mode|ending emergency mode)/;
# Log format for ufdbGuard logs: BLOCK user clienthost aclname category url meth od # Log format for ufdbGuard logs: BLOCK user clienthost aclname category url meth od
my $ug_format_regex1 = qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) .* (B LOCK) ([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$/; my $ug_format_regex1 = qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) .* (B LOCK) ([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$/;
sub new sub new
{ {
my ($class, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone) = @_; my ($class, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone) = @_;
# Construct the class # Construct the class
my $self = {}; my $self = {};
bless $self, $class; bless $self, $class;
skipping to change at line 441 skipping to change at line 443
} }
sub localdie sub localdie
{ {
my ($self, $msg) = @_; my ($self, $msg) = @_;
print STDERR "$msg"; print STDERR "$msg";
unlink("$self->{pidfile}"); unlink("$self->{pidfile}");
# Cleanup old temporary files # Cleanup old temporary files
foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp') { foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp', 'ug_last_p arsed.tmp') {
unlink("$self->{pid_dir}/$tmp_file"); unlink("$self->{pid_dir}/$tmp_file");
} }
exit 1; exit 1;
} }
#### ####
# method used to fork as many child as wanted # method used to fork as many child as wanted
## ##
sub spawn sub spawn
skipping to change at line 553 skipping to change at line 555
$time = $4; $time = $4;
$time =~ /(\d+)\/(...)\/(\d+):(\d+):(\d+):(\d+)\s/; $time =~ /(\d+)\/(...)\/(\d+):(\d+):(\d+):(\d+)\s/;
if (!$self->{TimeZone}) { if (!$self->{TimeZone}) {
$time = timelocal_nocheck($6, $5, $4, $1, $month_number{$ 2} - 1, $3 - 1900); $time = timelocal_nocheck($6, $5, $4, $1, $month_number{$ 2} - 1, $3 - 1900);
} else { } else {
$time = timegm_nocheck($6, $5, $4, $1, $month_number{$2} - 1, $3 - 1900) + $tz; $time = timegm_nocheck($6, $5, $4, $1, $month_number{$2} - 1, $3 - 1900) + $tz;
} }
$self->{is_squidguard_log} = 0; $self->{is_squidguard_log} = 0;
$self->{is_ufdbguard_log} = 0; $self->{is_ufdbguard_log} = 0;
# SquidGuard log format # SquidGuard log format
} elsif ( $line =~ $sg_format_regex1 ) { } elsif (( $line =~ $sg_format_regex1 ) || ( $line =~ $sg_format_regex2 ) ) {
$self->{is_squidguard_log} = 1; $self->{is_squidguard_log} = 1;
$self->{is_ufdbguard_log} = 0; $self->{is_ufdbguard_log} = 0;
if (!$self->{TimeZone}) { if (!$self->{TimeZone}) {
$time = timelocal_nocheck($6, $5, $4, $3, $2 - 1, $1 - 19 00); $time = timelocal_nocheck($6, $5, $4, $3, $2 - 1, $1 - 19 00);
} else { } else {
$time = timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz; $time = timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz;
} }
# ufdbGuard log format # ufdbGuard log format
} elsif ( $line =~ $ug_format_regex1 ) { } elsif ( $line =~ $ug_format_regex1 ) {
$self->{is_ufdbguard_log} = 1; $self->{is_ufdbguard_log} = 1;
skipping to change at line 588 skipping to change at line 590
my ($self, $file) = @_; my ($self, $file) = @_;
my $logfile = new IO::File; my $logfile = new IO::File;
$logfile->open($file) || $self->localdie("ERROR: Unable to open log file $file. $!\n"); $logfile->open($file) || $self->localdie("ERROR: Unable to open log file $file. $!\n");
my $max_line = 10000; my $max_line = 10000;
my $i = 0; my $i = 0;
while (my $line = <$logfile>) { while (my $line = <$logfile>) {
chomp($line); chomp($line);
# SquidGuard log format # SquidGuard log format
if ( $line =~ $sg_format_regex1 ) { if (( $line =~ $sg_format_regex1 ) || ( $line =~ $sg_format_regex 2 )) {
$self->{is_squidguard_log} = 1; $self->{is_squidguard_log} = 1;
$self->{is_ufdbguard_log} = 0; $self->{is_ufdbguard_log} = 0;
last; last;
# ufdbGuard log format # ufdbGuard log format
} elsif ( $line =~ $ug_format_regex1 ) { } elsif ( $line =~ $ug_format_regex1 ) {
$self->{is_ufdbguard_log} = 1; $self->{is_ufdbguard_log} = 1;
$self->{is_squidguard_log} = 0; $self->{is_squidguard_log} = 0;
last; last;
# Squid native format # Squid native format
} elsif ( $line =~ $native_format_regex1 ) { } elsif ( $line =~ $native_format_regex1 ) {
skipping to change at line 629 skipping to change at line 631
my $line_count = 0; my $line_count = 0;
my $line_processed_count = 0; my $line_processed_count = 0;
my $line_stored_count = 0; my $line_stored_count = 0;
my $saved_queue_size = $self->{queue_size}; my $saved_queue_size = $self->{queue_size};
my $history_offset = $self->{end_offset}; my $history_offset = $self->{end_offset};
foreach my $lfile (@{$self->{LogFile}}) { foreach my $lfile (@{$self->{LogFile}}) {
# Detect if log file is from squid or squidguard # Detect if log file is from squid or squidguard
$self->get_log_format($lfile); $self->get_log_format($lfile);
if (!$self->{is_squidguard_log} && !$self->{is_ufdbguard_log}) { if ($self->{is_ufdbguard_log}) {
$history_offset = $self->{end_offset};
} elsif (!$self->{is_squidguard_log}) {
$history_offset = $self->{ug_end_offset}; $history_offset = $self->{ug_end_offset};
} else { } elsif ($self->{is_squidguard_log}) {
$history_offset = $self->{sg_end_offset}; $history_offset = $self->{sg_end_offset};
} else {
$history_offset = $self->{end_offset};
} }
print STDERR "Starting to parse logfile $lfile.\n" if (!$self->{Q uietMode}); print STDERR "Starting to parse logfile $lfile.\n" if (!$self->{Q uietMode});
if ((!-f $lfile) || (-z $lfile)) { if ((!-f $lfile) || (-z $lfile)) {
print STDERR "DEBUG: bad or empty log file $lfile.\n" if (!$self->{QuietMode}); print STDERR "DEBUG: bad or empty log file $lfile.\n" if (!$self->{QuietMode});
next; next;
} }
# Restore the right multiprocess queue # Restore the right multiprocess queue
$self->{queue_size} = $saved_queue_size; $self->{queue_size} = $saved_queue_size;
skipping to change at line 678 skipping to change at line 680
} else { } else {
$self->{sg_end_offset} = 0; $self->{sg_end_offset} = 0;
} }
} else { } else {
# Look at first line to see if the file should be parse from the begining. # Look at first line to see if the file should be parse from the begining.
my $logfile = new IO::File; my $logfile = new IO::File;
$logfile->open($lfile) || $self->localdie("ERROR: Unable to open log file $lfile. $!\n"); $logfile->open($lfile) || $self->localdie("ERROR: Unable to open log file $lfile. $!\n");
my $line = <$logfile>; my $line = <$logfile>;
chomp($line); chomp($line);
# Remove syslog header and mark the format
if ($line =~ s/^... \d+ \d{2}:\d{2}:\d{2} [^\s]+
[^\s]+ \d+ [^\s]+ (\d{10}\.\d{3}) /$1 /) {
print STDERR "DEBUG: log was generated th
rough syslog, the header will be removed.\n" if (!$self->{QuietMode});
$self->{Syslog} = 1;
}
my $curtime = $self->look_for_timestamp($line); my $curtime = $self->look_for_timestamp($line);
my $hist_time = $self->{history_time}; my $hist_time = $self->{history_time};
if ($self->{is_squidguard_log}) { if ($self->{is_squidguard_log}) {
$hist_time = $self->{sg_history_time}; $hist_time = $self->{sg_history_time};
} elsif ($self->{is_ufdbguard_log}) { } elsif ($self->{is_ufdbguard_log}) {
$hist_time = $self->{ug_history_time}; $hist_time = $self->{ug_history_time};
} }
# if the first timestamp is higher that the histo ry time, start from the beginning # if the first timestamp is higher that the histo ry time, start from the beginning
if ($curtime > $hist_time) { if ($curtime > $hist_time) {
skipping to change at line 703 skipping to change at line 711
} else { } else {
$self->{sg_end_offset} = 0; $self->{sg_end_offset} = 0;
} }
# If the size of the file is lower than the histo ry offset, parse this file from the beginning # If the size of the file is lower than the histo ry offset, parse this file from the beginning
} elsif ((lstat($lfile))[7] <= $history_offset) { } elsif ((lstat($lfile))[7] <= $history_offset) {
# move at begining of the file to see if this is a new one # move at begining of the file to see if this is a new one
$logfile->seek(0, 0); $logfile->seek(0, 0);
for (my $i = 1; $i <= 10000; $i++) { for (my $i = 1; $i <= 10000; $i++) {
$line = <$logfile>; $line = <$logfile>;
chomp($line); chomp($line);
# Remove syslog header and mark t
he format
if ($self->{Syslog}) {
$line =~ s/^[A-Z][a-z]{2}
\d{2}:\d{2}:\d{2} [^\s]+ [^\s]+ \d+ \[[^\]]+\] (\d{10}\.\d{3})/$1/;
}
$curtime = $self->look_for_timest amp($line); $curtime = $self->look_for_timest amp($line);
if ($curtime) { if ($curtime) {
# If timestamp found at s
tartup is lower than the history file,
# the file will not be pa
rsed at all.
if ($hist_time > $curtime ) { if ($hist_time > $curtime ) {
print STDERR "DEB print STDERR "DEB
UG: this file will not been parsed: $lfile, size lower than expected and $curtim UG: this file will not be parsed: $lfile, size is lower than expected.\n" if (!$
e is lower than history time $self->{history_time}.\n" if (!$self->{QuietMode}); self->{QuietMode});
print STDERR "DEB
UG: exploring $lfile, timestamp found at startup, $curtime, is lower than histor
y time $hist_time.\n" if (!$self->{QuietMode});
$line = 'NOK'; $line = 'NOK';
last; last;
} }
} }
} }
$logfile->close; $logfile->close;
# This file should be ommitted jump to th e next file # This file should be ommitted jump to th e next file
next if ($line eq 'NOK'); next if ($line eq 'NOK');
print STDERR "DEBUG: new file: $lfile, st art from the beginning.\n" if (!$self->{QuietMode}); print STDERR "DEBUG: new file: $lfile, st art from the beginning.\n" if (!$self->{QuietMode});
skipping to change at line 730 skipping to change at line 745
$self->{ug_end_offset} = 0; $self->{ug_end_offset} = 0;
} else { } else {
$self->{sg_end_offset} = 0; $self->{sg_end_offset} = 0;
} }
} else { } else {
# move at offset and see if next line is older than history time # move at offset and see if next line is older than history time
$logfile->seek($history_offset, 0); $logfile->seek($history_offset, 0);
for (my $i = 1; $i <= 10; $i++) { for (my $i = 1; $i <= 10; $i++) {
$line = <$logfile>; $line = <$logfile>;
chomp($line); chomp($line);
# Remove syslog header and mark t
he format
if ($self->{Syslog}) {
$line =~ s/^[A-Z][a-z]{2}
\d{2}:\d{2}:\d{2} [^\s]+ [^\s]+ \d+ \[[^\]]+\] (\d{10}\.\d{3})/$1/;
}
$curtime = $self->look_for_timest amp($line); $curtime = $self->look_for_timest amp($line);
if ($curtime) { if ($curtime) {
if ($curtime < $hist_time ) { if ($curtime < $hist_time ) {
my $tmp_time = CO RE::localtime($curtime); my $tmp_time = CO RE::localtime($curtime);
print STDERR "DEB UG: this file will not been parsed: $lfile, line after offset is older than expe cted: $curtime < $hist_time.\n" if (!$self->{QuietMode}); print STDERR "DEB UG: this file will not be parsed: $lfile, line after offset is older than expect ed: $curtime < $hist_time.\n" if (!$self->{QuietMode});
$line = 'NOK'; $line = 'NOK';
last; last;
} }
} }
} }
$logfile->close; $logfile->close;
# This file should be ommitted jump to th e next file # This file should be ommitted jump to th e next file
next if ($line eq 'NOK'); next if ($line eq 'NOK');
} }
$logfile->close; $logfile->close;
skipping to change at line 788 skipping to change at line 807
}); });
$child_count = $self->manage_queue_size(++$child_ count); $child_count = $self->manage_queue_size(++$child_ count);
} }
} }
} }
# Wait for last child stop # Wait for last child stop
$self->wait_all_childs() if ($self->{queue_size} > 1); $self->wait_all_childs() if ($self->{queue_size} > 1);
# Get the last information parsed in this file part # Get the last information parsed in this file part
foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp') { foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp', 'sg_last_p arsed.tmp') {
if (-e "$self->{pid_dir}/$tmp_file") { if (-e "$self->{pid_dir}/$tmp_file") {
if (open(IN, "$self->{pid_dir}/$tmp_file")) { if (open(IN, "$self->{pid_dir}/$tmp_file")) {
my %history_tmp = (); my %history_tmp = ();
while (my $l = <IN>) { while (my $l = <IN>) {
chomp($l); chomp($l);
my @data = split(/\s/, $l); my @data = split(/\s/, $l);
$history_tmp{"$data[0]$data[1]$data[2]"}{ $data[4]} = join(' ', @data); $history_tmp{"$data[0]$data[1]$data[2]"}{ $data[4]} = join(' ', @data);
$line_stored_count += $data[5]; $line_stored_count += $data[5];
skipping to change at line 819 skipping to change at line 838
} }
} }
} }
close(IN); close(IN);
foreach my $date (sort {$b <=> $a} keys %history_ tmp) { foreach my $date (sort {$b <=> $a} keys %history_ tmp) {
foreach my $offset (sort {$b <=> $a} keys %{$history_tmp{$date}}) { foreach my $offset (sort {$b <=> $a} keys %{$history_tmp{$date}}) {
my @data = split(/\s/, $history_t mp{$date}{$offset}); my @data = split(/\s/, $history_t mp{$date}{$offset});
$self->{last_year} = $data[0]; $self->{last_year} = $data[0];
$self->{last_month}{$data[0]} = $ data[1]; $self->{last_month}{$data[0]} = $ data[1];
$self->{last_day}{$data[0]} = $da ta[2]; $self->{last_day}{$data[0]} = $da ta[2];
if (!$self->{is_squidguard_log} & & !$self->{is_ufdbguard_log}) { if ($tmp_file eq 'last_parsed.tmp ') {
$self->{end_time} = $data [3]; $self->{end_time} = $data [3];
$self->{end_offset} = $da ta[4]; $self->{end_offset} = $da ta[4];
} elsif (!$self->{is_squidguard_l og}) { } elsif ($tmp_file eq 'ug_last_pa rsed.tmp') {
$self->{ug_end_time} = $d ata[3]; $self->{ug_end_time} = $d ata[3];
$self->{ug_end_offset} = $data[4]; $self->{ug_end_offset} = $data[4];
} else { } elsif ($tmp_file eq 'sg_last_pa rsed.tmp') {
$self->{sg_end_time} = $d ata[3]; $self->{sg_end_time} = $d ata[3];
$self->{sg_end_offset} = $data[4]; $self->{sg_end_offset} = $data[4];
} }
last; last;
} }
last; last;
} }
} else { } else {
print STDERR "ERROR: can't read last parsed line from $self->{pid_dir}/$tmp_file, $!\n"; print STDERR "ERROR: can't read last parsed line from $self->{pid_dir}/$tmp_file, $!\n";
} }
skipping to change at line 1054 skipping to change at line 1073
if (exists $self->{Exclude}{clients} && $client_ip) { if (exists $self->{Exclude}{clients} && $client_ip) {
foreach my $e (@{$self->{Exclude}{clients}}) { foreach my $e (@{$self->{Exclude}{clients}}) {
if ($client_ip =~ m#^$e$#i) { if ($client_ip =~ m#^$e$#i) {
return 1; return 1;
} }
} }
} }
# check for Network exclusion # check for Network exclusion
if (exists $self->{Exclude}{networks} && $client_ip) { if (exists $self->{Exclude}{networks} && $client_ip) {
foreach my $e (@{$self->{Include}{networks}}) { foreach my $e (@{$self->{Exclude}{networks}}) {
if (&check_ip($client_ip, $e)) { if (&check_ip($client_ip, $e)) {
return 1; return 1;
} }
} }
} }
# check for URL exclusion # check for URL exclusion
if (exists $self->{Exclude}{uris} && $url) { if (exists $self->{Exclude}{uris} && $url) {
foreach my $e (@{$self->{Exclude}{uris}}) { foreach my $e (@{$self->{Exclude}{uris}}) {
if ($url =~ m#^$e$#i) { if ($url =~ m#^$e$#i) {
skipping to change at line 1148 skipping to change at line 1167
my $elapsed = 0; my $elapsed = 0;
my $client_ip = ''; my $client_ip = '';
my $client_name = ''; my $client_name = '';
my $code = ''; my $code = '';
my $bytes = 0; my $bytes = 0;
my $method = ''; my $method = '';
my $url = ''; my $url = '';
my $login = ''; my $login = '';
my $status = ''; my $status = '';
my $mime_type = ''; my $mime_type = '';
$self->{Syslog} = 0;
my $acl = ''; my $acl = '';
my $line_count = 0; my $line_count = 0;
my $line_processed_count = 0; my $line_processed_count = 0;
my $line_stored_count = 0; my $line_stored_count = 0;
# Move directly to the start position # Move directly to the start position
if ($start_offset) { if ($start_offset) {
$logfile->seek($start_offset, 0); $logfile->seek($start_offset, 0);
skipping to change at line 1198 skipping to change at line 1218
# Store the current position in logfile # Store the current position in logfile
$self->{sg_end_offset} += length($line); $self->{sg_end_offset} += length($line);
} }
chomp($line); chomp($line);
next if (!$line); next if (!$line);
# skip immediately lines that squid is not able to tag. # skip immediately lines that squid is not able to tag.
next if ($line =~ / TAG_NONE(_ABORTED)?\//); next if ($line =~ / TAG_NONE(_ABORTED)?\//);
# Remove syslog header and mark the format
if ($self->{Syslog} == 1) {
$line =~ s/^... \d+ \d{2}:\d{2}:\d{2} [^\s]+ [^\s]+ \d+ [
^\s]+ (\d{10}\.\d{3}) /$1 /;
# Remove syslog header and mark the format
} elsif (!$self->{Syslog} && ($line =~ s/^... \d+ \d{2}:\d{2}:\d{
2} [^\s]+ [^\s]+ \d+ [^\s]+ (\d{10}\.\d{3}) /$1 /)) {
print STDERR "DEBUG: log was generated through syslog, th
e header will be removed.\n" if (!$self->{QuietMode});
$self->{Syslog} = 1;
} else {
$self->{Syslog} = 2;
}
# Number of log lines parsed # Number of log lines parsed
$line_count++; $line_count++;
# SquidAnalyzer supports the following squid log format: # SquidAnalyzer supports the following squid log format:
#logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt #logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt
#logformat squidmime %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt [%>h] [%<h] #logformat squidmime %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt [%>h] [%<h]
#logformat common %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st %Ss:%Sh #logformat common %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st %Ss:%Sh
#logformat combined %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh #logformat combined %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
# Parse log with format: time elapsed client code/status bytes me thod URL rfc931 peerstatus/peerhost mime_type # Parse log with format: time elapsed client code/status bytes me thod URL rfc931 peerstatus/peerhost mime_type
my $format = 'native'; my $format = 'native';
if ( $line =~ $native_format_regex1 ) { if ( !$self->{is_squidguard_log} && !$self->{is_ufdbguard_log} && ($line =~ $native_format_regex1) ) {
$time = $1; $time = $1;
$time += $tz; $time += $tz;
$elapsed = abs($2); $elapsed = abs($2);
$client_ip = $3; $client_ip = $3;
$code = $4; $code = $4;
$bytes = $5; $bytes = $5;
$method = $6; $method = $6;
$line = $7; $line = $7;
} elsif ( $line =~ $common_format_regex1 ) { if ($self->{TimeStart} || $self->{TimeStop}) {
my $hour = strftime("%H:%M", CORE::localtime($tim
e));
next if ($self->{TimeStart} && $hour lt $self->{T
imeStart});
last if ($self->{TimeStop} && $hour gt $self->{Ti
meStop});
}
} elsif ( !$self->{is_squidguard_log} && !$self->{is_ufdbguard_lo
g} && ($line =~ $common_format_regex1) ) {
$format = 'http'; $format = 'http';
$client_ip = $1; $client_ip = $1;
$elapsed = abs($2); $elapsed = abs($2);
$login = lc($3); $login = lc($3);
$time = $4; $time = $4;
$method = $5; $method = $5;
$url = lc($6); $url = lc($6);
$status = $8; $status = $8;
$bytes = $9; $bytes = $9;
$line = $10; $line = $10;
$code = $11; $code = $11;
$mime_type = $12; $mime_type = $12;
$time =~ /(\d+)\/(...)\/(\d+):(\d+):(\d+):(\d+)\s/; $time =~ /(\d+)\/(...)\/(\d+):(\d+):(\d+):(\d+)\s/;
next if ($self->{TimeStart} && "$4:$5" lt $self->{TimeSta
rt});
last if ($self->{TimeStop} && "$4:$5" gt $self->{TimeStop
});
if (!$self->{TimeZone}) { if (!$self->{TimeZone}) {
$time = timelocal_nocheck($6, $5, $4, $1, $month_ number{$2} - 1, $3 - 1900); $time = timelocal_nocheck($6, $5, $4, $1, $month_ number{$2} - 1, $3 - 1900);
} else { } else {
$time = timegm_nocheck($6, $5, $4, $1, $month_num ber{$2} - 1, $3 - 1900) + $tz; $time = timegm_nocheck($6, $5, $4, $1, $month_num ber{$2} - 1, $3 - 1900) + $tz;
} }
# Some site has corrupted mime_type, try to remove nasty characters # Some site has corrupted mime_type, try to remove nasty characters
$mime_type =~ s/[^\-\/\.\(\)\+\_,\=a-z0-9]+//igs; if ($mime_type =~ s/[^\-\/\.\(\)\+\_,\=a-z0-9]+//igs) {
} elsif ($line =~ $sg_format_regex1) { $mime_type = 'invalid/type';
}
} elsif ( !$self->{is_ufdbguard_log} && ($line =~ $sg_format_reg
ex1) ) {
$format = 'squidguard'; $format = 'squidguard';
$self->{is_squidguard_log} = 1; $self->{is_squidguard_log} = 1;
$acl = $7; $acl = $7;
$client_ip = $9; $client_ip = $9;
$elapsed = 0; $elapsed = 0;
$login = lc($10); $login = lc($10);
$method = $11; $method = $11;
$url = lc($8); $url = lc($8);
$status = 301; $status = 301;
$bytes = 0; $bytes = 0;
$code = $12 . ':'; $code = $12 . ':';
$mime_type = ''; $mime_type = '';
next if ($self->{TimeStart} && "$4:$5" lt $self->{TimeSta
rt});
last if ($self->{TimeStop} && "$4:$5" gt $self->{TimeStop
});
if (!$self->{TimeZone}) { if (!$self->{TimeZone}) {
$time = timelocal_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900); $time = timelocal_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900);
} else { } else {
$time = timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz; $time = timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz;
} }
# Log format for ufdbGuard logs: timestamp [pid] BLOCK user clien thost aclname category url method # Log format for ufdbGuard logs: timestamp [pid] BLOCK user clien thost aclname category url method
} elsif ($line =~ $ug_format_regex1) { } elsif ($line =~ $ug_format_regex1) {
$format = 'ufdbguard'; $format = 'ufdbguard';
$self->{is_ufdbguard_log} = 1; $self->{is_ufdbguard_log} = 1;
$acl = "$10/$11"; $acl = "$10/$11";
$client_ip = $9; $client_ip = $9;
$elapsed = 0; $elapsed = 0;
$login = lc($8); $login = lc($8);
$method = $13; $method = $13;
$url = lc($12); $url = lc($12);
$status = 301; $status = 301;
$bytes = 0; $bytes = 0;
$code = 'REDIRECT:'; $code = 'REDIRECT:';
$mime_type = ''; $mime_type = '';
next if ($self->{TimeStart} && "$4:$5" lt $self->{TimeSta
rt});
last if ($self->{TimeStop} && "$4:$5" gt $self->{TimeStop
});
if (!$self->{TimeZone}) { if (!$self->{TimeZone}) {
$time = timelocal_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900); $time = timelocal_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900);
} else { } else {
$time = timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz; $time = timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz;
} }
} else { } else {
next; next;
} }
if ($time) { if ($time) {
skipping to change at line 1327 skipping to change at line 1371
print STDERR "SQUIDGUARD LOG SET START TI ME: ", strftime("%a %b %e %H:%M:%S %Y", CORE::localtime($time)), "\n" if (!$self ->{QuietMode}); print STDERR "SQUIDGUARD LOG SET START TI ME: ", strftime("%a %b %e %H:%M:%S %Y", CORE::localtime($time)), "\n" if (!$self ->{QuietMode});
} }
} }
# Only store (HIT|UNMODIFIED)/(MISS|MODIFIED|TUNNEL)/(DEN IED|REDIRECT) status # Only store (HIT|UNMODIFIED)/(MISS|MODIFIED|TUNNEL)/(DEN IED|REDIRECT) status
# and peer CD_SIBLING_HIT/ aswell as peer SIBLING_HIT/... # and peer CD_SIBLING_HIT/ aswell as peer SIBLING_HIT/...
if ( ($code =~ m#(HIT|UNMODIFIED)[:/]#) || ($self->{Sibli ngHit} && ($line =~ / (CD_)?SIBLING_HIT/)) ) { if ( ($code =~ m#(HIT|UNMODIFIED)[:/]#) || ($self->{Sibli ngHit} && ($line =~ / (CD_)?SIBLING_HIT/)) ) {
$code = 'HIT'; $code = 'HIT';
} elsif ($code =~ m#(MISS|MODIFIED|TUNNEL)[:/]#) { } elsif ($code =~ m#(MISS|MODIFIED|TUNNEL)[:/]#) {
$code = 'MISS'; $code = 'MISS';
} elsif ($code =~ m#(DENIED|REDIRECT)[:/]#) { } elsif ($code =~ m#(DENIED|DENIED_REPLY|REDIRECT)[:/]#) {
$code = 'DENIED'; $code = 'DENIED';
} else { } else {
next; next;
} }
# With common and combined log format those fields have a lready been parsed # With common and combined log format those fields have a lready been parsed
if (($format eq 'native') && ($line =~ $native_format_reg ex2) ) { if (($format eq 'native') && ($line =~ $native_format_reg ex2) ) {
$url = lc($1); $url = lc($1);
$login = lc($2); $login = lc($2);
$status = lc($3); $status = lc($3);
$mime_type = lc($4); $mime_type = lc($4);
# Some site has corrupted mime_type, try to remov e nasty characters # Some site has corrupted mime_type, try to remov e nasty characters
$mime_type =~ s/[^\-\/\.\(\)\+\_,\=a-z0-9]+//igs; if ($mime_type =~ s/[^\-\/\.\(\)\+\_,\=a-z0-9]+//
igs) {
$mime_type = 'invalid/type';
}
} }
if ($url) { if ($url) {
if (!$mime_type || ($mime_type eq '-')) { if (!$mime_type || ($mime_type eq '-')) {
$mime_type = 'none'; $mime_type = 'none';
} }
# Do not parse some unwanted method # Do not parse some unwanted method
next if (($#{$self->{ExcludedMimes}} >= 0) && map {$mime_type =~ m#^$_$#} @{$self->{ExcludedMimes}}); next if (($#{$self->{ExcludedMimes}} >= 0) && map {$mime_type =~ m#^$_$#} @{$self->{ExcludedMimes}});
skipping to change at line 1382 skipping to change at line 1428
# Set default user login to client ip address # Set default user login to client ip address
# Anonymize all users # Anonymize all users
if ($self->{AnonymizeLogin} && ($client_ip ne $id )) { if ($self->{AnonymizeLogin} && ($client_ip ne $id )) {
if (!exists $self->{AnonymizedId}{$id}) { if (!exists $self->{AnonymizedId}{$id}) {
$self->{AnonymizedId}{$id} = &ano nymize_id(); $self->{AnonymizedId}{$id} = &ano nymize_id();
} }
$id = $self->{AnonymizedId}{$id}; $id = $self->{AnonymizedId}{$id};
} }
# Now parse data and generate statistics # Now parse data and generate statistics
$self->_parseData($time, $elapsed, $client_ip, $c ode, $bytes, $url, $id, $mime_type, $acl); $self->_parseData($time, $elapsed, $client_ip, $c ode, $bytes, $url, $id, $mime_type, $acl, $method);
$line_stored_count++; $line_stored_count++;
} }
$line_processed_count++; $line_processed_count++;
} }
} }
$logfile->close(); $logfile->close();
if ($self->{cur_year}) { if ($self->{cur_year}) {
# Save last parsed data # Save last parsed data
skipping to change at line 1536 skipping to change at line 1582
$self->{DNSLookupTimeout} = $options{DNSLookupTimeout} || 0.0001; $self->{DNSLookupTimeout} = $options{DNSLookupTimeout} || 0.0001;
$self->{DNSLookupTimeout} = int($self->{DNSLookupTimeout} * 1000000); $self->{DNSLookupTimeout} = int($self->{DNSLookupTimeout} * 1000000);
$self->{LogFile} = (); $self->{LogFile} = ();
$self->{queue_size} = 1; $self->{queue_size} = 1;
$self->{running_pids} = (); $self->{running_pids} = ();
$self->{pid_dir} = $pid_dir || '/tmp'; $self->{pid_dir} = $pid_dir || '/tmp';
$self->{child_count} = 0; $self->{child_count} = 0;
$self->{rebuild} = $rebuild || 0; $self->{rebuild} = $rebuild || 0;
$self->{is_squidguard_log} = 0; $self->{is_squidguard_log} = 0;
$self->{TimeZone} = $options{TimeZone} || $timezone || 0; $self->{TimeZone} = $options{TimeZone} || $timezone || 0;
$self->{Syslog} = 0;
$self->{UseUrlPort} = 1;
$self->{TimeStart} = $options{TimeStart} || '';
$self->{TimeStop} = $options{TimeStop} || '';
# Cleanup old temporary files # Cleanup old temporary files
foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp') { foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp', 'ug_last_p arsed.tmp') {
unlink("$self->{pid_dir}/$tmp_file"); unlink("$self->{pid_dir}/$tmp_file");
} }
$self->{CustomHeader} = $options{CustomHeader} || qq{<a href="$self->{Web Url}"><img src="$self->{WebUrl}images/logo-squidanalyzer.png" title="SquidAnalyz er $VERSION" border="0"></a> SquidAnalyzer}; $self->{CustomHeader} = $options{CustomHeader} || qq{<a href="$self->{Web Url}"><img src="$self->{WebUrl}images/logo-squidanalyzer.png" title="SquidAnalyz er $VERSION" border="0"></a> SquidAnalyzer};
$self->{ExcludedMethods} = (); $self->{ExcludedMethods} = ();
if ($options{ExcludedMethods}) { if ($options{ExcludedMethods}) {
push(@{$self->{ExcludedMethods}}, split(/\s*,\s*/, $options{Exclu dedMethods})); push(@{$self->{ExcludedMethods}}, split(/\s*,\s*/, $options{Exclu dedMethods}));
} }
$self->{ExcludedCodes} = (); $self->{ExcludedCodes} = ();
if ($options{ExcludedCodes}) { if ($options{ExcludedCodes}) {
skipping to change at line 1600 skipping to change at line 1650
if ($self->{OrderUrl} !~ /^(hits|bytes|duration)$/) { if ($self->{OrderUrl} !~ /^(hits|bytes|duration)$/) {
die "ERROR: OrderUrl must be one of these values: hits, bytes or duration\n"; die "ERROR: OrderUrl must be one of these values: hits, bytes or duration\n";
} }
if ($self->{OrderMime} !~ /^(hits|bytes)$/) { if ($self->{OrderMime} !~ /^(hits|bytes)$/) {
die "ERROR: OrderMime must be one of these values: hits or bytes\ n"; die "ERROR: OrderMime must be one of these values: hits or bytes\ n";
} }
%{$self->{NetworkAlias}} = $self->parse_network_aliases($options{NetworkA lias} || ''); %{$self->{NetworkAlias}} = $self->parse_network_aliases($options{NetworkA lias} || '');
%{$self->{UserAlias}} = $self->parse_user_aliases($options{UserAlias} || ''); %{$self->{UserAlias}} = $self->parse_user_aliases($options{UserAlias} || '');
%{$self->{Exclude}} = $self->parse_exclusion($options{Exclude} || '' ); %{$self->{Exclude}} = $self->parse_exclusion($options{Exclude} || '' );
%{$self->{Include}} = $self->parse_inclusion($options{Include} || '' ); %{$self->{Include}} = $self->parse_inclusion($options{Include} || '' );
%{$self->{NetworkAliasCache}} = ();
%{$self->{UserAliasCache}} = ();
$self->{has_nework_alias} = scalar keys %{$self->{NetworkAlias}};
$self->{has_user_alias} = scalar keys %{$self->{UserAlias}};
$self->{CostPrice} = $options{CostPrice} || 0; $self->{CostPrice} = $options{CostPrice} || 0;
$self->{Currency} = $options{Currency} || '&euro;'; $self->{Currency} = $options{Currency} || '&euro;';
$self->{TopNumber} = $options{TopNumber} || 10; $self->{TopNumber} = $options{TopNumber} || 10;
$self->{TopStorage} = $options{TopStorage} || 0;
$self->{TransfertUnit} = $options{TransfertUnit} || 'BYTES'; $self->{TransfertUnit} = $options{TransfertUnit} || 'BYTES';
if (!grep(/^$self->{TransfertUnit}$/i, 'BYTES', 'KB', 'MB', 'GB')) { if (!grep(/^$self->{TransfertUnit}$/i, 'BYTES', 'KB', 'MB', 'GB')) {
die "ERROR: TransfertUnit must be one of these values: KB, MB or GB\n"; die "ERROR: TransfertUnit must be one of these values: KB, MB or GB\n";
} else { } else {
if (uc($self->{TransfertUnit}) eq 'BYTES') { if (uc($self->{TransfertUnit}) eq 'BYTES') {
$self->{TransfertUnitValue} = 1; $self->{TransfertUnitValue} = 1;
$self->{TransfertUnit} = 'Bytes'; $self->{TransfertUnit} = 'Bytes';
} elsif (uc($self->{TransfertUnit}) eq 'KB') { } elsif (uc($self->{TransfertUnit}) eq 'KB') {
$self->{TransfertUnitValue} = 1024; $self->{TransfertUnitValue} = 1024;
} elsif (uc($self->{TransfertUnit}) eq 'MB') { } elsif (uc($self->{TransfertUnit}) eq 'MB') {
skipping to change at line 1772 skipping to change at line 1827
</div> </div>
}; };
} }
sub _gethostbyaddr sub _gethostbyaddr
{ {
my ($self, $ip) = @_; my ($self, $ip) = @_;
my $host = undef; my $host = undef;
my $err = '';
unless(exists $CACHE{$ip}) { unless(exists $CACHE{$ip}) {
eval { eval {
local $SIG{ALRM} = sub { die "DNS lookup timeout.\n"; }; local $SIG{ALRM} = sub { die "DNS lookup timeout.\n"; };
ualarm $self->{DNSLookupTimeout}; ualarm $self->{DNSLookupTimeout};
$host = gethostbyaddr(inet_aton($ip), AF_INET); my @addrs = ();
if ($] < 5.014) {
$host = gethostbyaddr(inet_aton($ip), AF_INET);
} else {
# We also need to resolve IPV6 addresses
if ($ip =~ /^\d+\.\d+\.\d+\.\d+$/) {
($err, @addrs) = Socket::getaddrinfo( $ip
, 0, { 'protocol' => Socket::IPPROTO_TCP, 'family' => Socket::AF_INET } );
} else {
($err, @addrs) = Socket::getaddrinfo( $ip
, 0, { 'protocol' => Socket::IPPROTO_TCP, 'family' => Socket::AF_INET6 } );
}
}
for my $addr (@addrs) {
($err, $host) = Socket::getnameinfo( $addr->{addr
});
last;
}
ualarm 0; ualarm 0;
}; };
if ($@) { if ($@) {
$CACHE{$ip} = undef; delete $CACHE{$ip};
#printf "_gethostbyaddr timeout : %s\n", $ip; if (!$self->{QuietMode}) {
warn "_gethostbyaddr timeout reach for ip: $ip, t
imeout can be adjusted with directive DNSLookupTimeout\n";
}
} elsif ($err) {
delete $CACHE{$ip};
if (!$self->{QuietMode}) {
warn "_gethostbyaddr error resolving ip: $ip, $er
r\n";
}
} }
else { else {
$CACHE{$ip} = $host; $CACHE{$ip} = $host;
#printf "_gethostbyaddr success : %s (%s)\n", $ip, $host; #printf "_gethostbyaddr success : %s (%s)\n", $ip, $host;
} }
} }
return $CACHE{$ip} || $ip; return $CACHE{$ip} || $ip;
} }
sub apply_network_alias
{
my ($self, $ip) = @_;
return $self->{NetworkAliasCache}{$ip} if (exists $self->{NetworkAliasCac
he}{$ip});
my $found = 0;
foreach my $r (keys %{$self->{NetworkAlias}}) {
if ($r =~ $cidr_regex) {
if (&check_ip($ip, $r)) {
$self->{NetworkAliasCache}{$ip} = $self->{Network
Alias}->{$r};
$ip = $self->{NetworkAlias}->{$r};
$found = 1;
last;
}
} elsif ($ip =~ /^$r/) {
$self->{NetworkAliasCache}{$ip} = $self->{NetworkAlias}->
{$r};
$ip = $self->{NetworkAlias}->{$r};
$found = 1;
last;
}
}
$self->{NetworkAliasCache}{$ip} = $ip if (!$found);
return $ip;
}
sub apply_user_alias
{
my ($self, $id) = @_;
return $self->{UserAliasCache}{$id} if (exists $self->{UserAliasCache}{$i
d});
my $found = 0;
foreach my $u (keys %{$self->{UserAlias}}) {
if ( $id =~ /^$u$/i ) {
$self->{UserAliasCache}{$id} = $self->{UserAlias}->{$u};
$id = $self->{UserAlias}->{$u};
$found = 1;
last;
}
}
$self->{UserAliasCache}{$id} = $id if (!$found);
return $id;
}
sub _parseData sub _parseData
{ {
my ($self, $time, $elapsed, $client, $code, $bytes, $url, $id, $type, $ac l) = @_; my ($self, $time, $elapsed, $client, $code, $bytes, $url, $id, $type, $ac l, $method) = @_;
# Save original IP address for dns resolving # Save original IP address for dns resolving
my $client_ip_addr = $client; my $client_ip_addr = $client;
# Get the current year and month # Get the current year and month
my ($sec,$min,$hour,$day,$month,$year,$wday,$yday,$isdst) = CORE::localti me($time); my ($sec,$min,$hour,$day,$month,$year,$wday,$yday,$isdst) = CORE::localti me($time);
$year += 1900; $year += 1900;
$month = sprintf("%02d", $month + 1); $month = sprintf("%02d", $month + 1);
$day = sprintf("%02d", $day); $day = sprintf("%02d", $day);
skipping to change at line 1824 skipping to change at line 1948
if (!$self->{no_week_stat}) { if (!$self->{no_week_stat}) {
if ("$year$month$day" ne "$self->{cur_year}$self->{cur_month}$sel f->{cur_day}") { if ("$year$month$day" ne "$self->{cur_year}$self->{cur_month}$sel f->{cur_day}") {
my $wn = &get_week_number($year, $month, $day); my $wn = &get_week_number($year, $month, $day);
if (!grep(/^$year\/$month\/$wn$/, @{$self->{week_parsed}} )) { if (!grep(/^$year\/$month\/$wn$/, @{$self->{week_parsed}} )) {
push(@{$self->{week_parsed}}, "$year/$month/$wn") ; push(@{$self->{week_parsed}}, "$year/$month/$wn") ;
} }
} }
} }
# Extract the domainname part of the URL # Extract the domainname part of the URL
$url =~ s/:\d+.*//; $url =~ s/:\d+.*// if (!$self->{UseUrlPort});
$url =~ m/^[^\/]+\/\/([^\/]+)/; $url =~ m/^[^\/]+\/\/([^\/]+)/;
my $dest = $1 || $url; my $dest = $1 || $url;
# Replace username by his dnsname if there's no username # Replace username by his dnsname if there's no username
# (login is equal to ip) and if client is an ip address # (login is equal to ip) and if client is an ip address
if ( ($id eq $client) && $self->{UseClientDNSName}) { if ( ($id eq $client) && $self->{UseClientDNSName}) {
if ($client =~ $ip_regexp) { if ($client =~ $ip_regexp) {
my $dnsname = $self->_gethostbyaddr($client); my $dnsname = $self->_gethostbyaddr($client);
if ($dnsname) { if ($dnsname) {
$id = $dnsname; $id = $dnsname;
} }
} }
} }
# Replace network by his aliases if any # Replace network by his aliases if any
my $network = ''; my $network = (!$self->{has_nework_alias}) ? $client : $self->apply_netwo
foreach my $r (keys %{$self->{NetworkAlias}}) { rk_alias($client);
if ($r =~ $cidr_regex) {
if (&check_ip($client, $r)) {
$network = $self->{NetworkAlias}->{$r};
last;
}
} elsif ($client =~ /^$r/) {
$network = $self->{NetworkAlias}->{$r};
last;
}
}
# Set default to a class A network # Set default to a class C network
if (!$network) { if (!$network) {
$client =~ /^(.*)([:\.]+)\d+$/; $client =~ /^(.*)([:\.]+)\d+$/;
$network = "$1$2". "0"; $network = "$1$2". "0";
} }
# Replace username by his alias if any # Replace username by his alias if any
foreach my $u (keys %{$self->{UserAlias}}) { $id = (!$self->{has_user_alias}) ? $id : $self->apply_user_alias($id);
if ( $id =~ /^$u$/i ) {
$id = $self->{UserAlias}->{$u};
last;
}
}
# Stores last parsed date part # Stores last parsed date part
if (!$self->{last_year} || ("$year$month$day" gt "$self->{last_year}$self ->{last_month}{$self->{last_year}}$self->{last_day}{$self->{last_year}}")) { if (!$self->{last_year} || ("$year$month$day" gt "$self->{last_year}$self ->{last_month}{$self->{last_year}}$self->{last_day}{$self->{last_year}}")) {
$self->{last_year} = $year; $self->{last_year} = $year;
$self->{last_month}{$self->{last_year}} = $month; $self->{last_month}{$self->{last_year}} = $month;
$self->{last_day}{$self->{last_year}} = $day; $self->{last_day}{$self->{last_year}} = $day;
} }
# Stores first parsed date part # Stores first parsed date part
if (!$self->{first_year} || ("$self->{first_year}$self->{first_month}{$se lf->{first_year}}" gt "$year$month")) { if (!$self->{first_year} || ("$self->{first_year}$self->{first_month}{$se lf->{first_year}}" gt "$year$month")) {
skipping to change at line 1909 skipping to change at line 2017
#### Store url statistics #### Store url statistics
if ($self->{UrlReport}) { if ($self->{UrlReport}) {
$self->{stat_denied_url_hour}{$id}{$dest}{hits}++; $self->{stat_denied_url_hour}{$id}{$dest}{hits}++;
$self->{stat_denied_url_hour}{$id}{$dest}{firsthit} = $ti me if (!$self->{stat_denied_url_hour}{$id}{$dest}{firsthit} || ($time < $self->{ stat_denied_url_hour}{$id}{$dest}{firsthit})); $self->{stat_denied_url_hour}{$id}{$dest}{firsthit} = $ti me if (!$self->{stat_denied_url_hour}{$id}{$dest}{firsthit} || ($time < $self->{ stat_denied_url_hour}{$id}{$dest}{firsthit}));
$self->{stat_denied_url_hour}{$id}{$dest}{lasthit} = $tim e if (!$self->{stat_denied_url_hour}{$id}{$dest}{lasthit} || ($time > $self->{st at_denied_url_hour}{$id}{$dest}{lasthit})); $self->{stat_denied_url_hour}{$id}{$dest}{lasthit} = $tim e if (!$self->{stat_denied_url_hour}{$id}{$dest}{lasthit} || ($time > $self->{st at_denied_url_hour}{$id}{$dest}{lasthit}));
$self->{stat_denied_url_hour}{$id}{$dest}{blacklist}{$acl }++ if ($acl); $self->{stat_denied_url_hour}{$id}{$dest}{blacklist}{$acl }++ if ($acl);
$self->{stat_denied_url_day}{$id}{$dest}{hits}++; $self->{stat_denied_url_day}{$id}{$dest}{hits}++;
$self->{stat_denied_url_day}{$id}{$dest}{firsthit} = $tim e if (!$self->{stat_denied_url_day}{$id}{$dest}{firsthit} || ($time < $self->{st at_denied_url_day}{$id}{$dest}{firsthit})); $self->{stat_denied_url_day}{$id}{$dest}{firsthit} = $tim e if (!$self->{stat_denied_url_day}{$id}{$dest}{firsthit} || ($time < $self->{st at_denied_url_day}{$id}{$dest}{firsthit}));
$self->{stat_denied_url_day}{$id}{$dest}{lasthit} = $time if (!$self->{stat_denied_url_day}{$id}{$dest}{lasthit} || ($time > $self->{stat _denied_url_day}{$id}{$dest}{lasthit})); $self->{stat_denied_url_day}{$id}{$dest}{lasthit} = $time if (!$self->{stat_denied_url_day}{$id}{$dest}{lasthit} || ($time > $self->{stat _denied_url_day}{$id}{$dest}{lasthit}));
$self->{stat_denied_url_day}{$id}{$dest}{blacklist}{$acl} ++ if ($acl); $self->{stat_denied_url_day}{$id}{$dest}{blacklist}{$acl} ++ if ($acl);
$self->{stat_user_hour}{$id}{$hour}{hits} += 0;
$self->{stat_user_hour}{$id}{$hour}{bytes} += 0;
$self->{stat_user_hour}{$id}{$hour}{duration} += 0;
$self->{stat_user_day}{$id}{$self->{last_day}}{hits} += 0
;
$self->{stat_user_day}{$id}{$self->{last_day}}{bytes} +=
0;
$self->{stat_user_day}{$id}{$self->{last_day}}{duration}
+= 0;
} }
return; return;
} }
#### Store client statistics #### Store client statistics
if ($self->{UserReport}) { if ($self->{UserReport}) {
$self->{stat_user_hour}{$id}{$hour}{hits}++; $self->{stat_user_hour}{$id}{$hour}{hits}++;
$self->{stat_user_hour}{$id}{$hour}{bytes} += $bytes; $self->{stat_user_hour}{$id}{$hour}{bytes} += $bytes;
$self->{stat_user_hour}{$id}{$hour}{duration} += $elapsed; $self->{stat_user_hour}{$id}{$hour}{duration} += $elapsed;
$self->{stat_user_day}{$id}{$self->{last_day}}{hits}++; $self->{stat_user_day}{$id}{$self->{last_day}}{hits}++;
skipping to change at line 1967 skipping to change at line 2081
$self->{stat_throughput_hour}{$code}{$hour}{elapsed} += $elapsed; $self->{stat_throughput_hour}{$code}{$hour}{elapsed} += $elapsed;
$self->{stat_throughput_day}{$code}{$self->{last_day}}{elapsed} += $elaps ed; $self->{stat_throughput_day}{$code}{$self->{last_day}}{elapsed} += $elaps ed;
#### Store url statistics #### Store url statistics
if ($self->{UrlReport}) { if ($self->{UrlReport}) {
$self->{stat_user_url_hour}{$id}{$dest}{duration} += $elapsed; $self->{stat_user_url_hour}{$id}{$dest}{duration} += $elapsed;
$self->{stat_user_url_hour}{$id}{$dest}{hits}++; $self->{stat_user_url_hour}{$id}{$dest}{hits}++;
$self->{stat_user_url_hour}{$id}{$dest}{bytes} += $bytes; $self->{stat_user_url_hour}{$id}{$dest}{bytes} += $bytes;
$self->{stat_user_url_hour}{$id}{$dest}{firsthit} = $time if (!$s elf->{stat_user_url_hour}{$id}{$dest}{firsthit} || ($time < $self->{stat_user_ur l_hour}{$id}{$dest}{firsthit})); $self->{stat_user_url_hour}{$id}{$dest}{firsthit} = $time if (!$s elf->{stat_user_url_hour}{$id}{$dest}{firsthit} || ($time < $self->{stat_user_ur l_hour}{$id}{$dest}{firsthit}));
$self->{stat_user_url_hour}{$id}{$dest}{lasthit} = $time if (!$se lf->{stat_user_url_hour}{$id}{$dest}{lasthit} || ($time > $self->{stat_user_url_ hour}{$id}{$dest}{lasthit})); $self->{stat_user_url_hour}{$id}{$dest}{lasthit} = $time if (!$se lf->{stat_user_url_hour}{$id}{$dest}{lasthit} || ($time > $self->{stat_user_url_ hour}{$id}{$dest}{lasthit}));
if (!exists $self->{stat_user_url_hour}{$id}{$dest}{arr_last} ||
($#{$self->{stat_user_url_hour}{$id}{$dest}{arr_last}} < 9) || ($time > ($self->
{stat_user_url_hour}{$id}{$dest}{arr_last}[-1]+300))) {
push(@{$self->{stat_user_url_hour}{$id}{$dest}{arr_last}}
, $time);
shift(@{$self->{stat_user_url_hour}{$id}{$dest}{arr_last}
}) if ($#{$self->{stat_user_url_hour}{$id}{$dest}{arr_last}} > 9);
}
$self->{stat_user_url_day}{$id}{$dest}{duration} += $elapsed; $self->{stat_user_url_day}{$id}{$dest}{duration} += $elapsed;
$self->{stat_user_url_day}{$id}{$dest}{hits}++; $self->{stat_user_url_day}{$id}{$dest}{hits}++;
$self->{stat_user_url_day}{$id}{$dest}{firsthit} = $time if (!$se lf->{stat_user_url_day}{$id}{$dest}{firsthit} || ($time < $self->{stat_user_url_ day}{$id}{$dest}{firsthit})); $self->{stat_user_url_day}{$id}{$dest}{firsthit} = $time if (!$se lf->{stat_user_url_day}{$id}{$dest}{firsthit} || ($time < $self->{stat_user_url_ day}{$id}{$dest}{firsthit}));
$self->{stat_user_url_day}{$id}{$dest}{lasthit} = $time if (!$sel f->{stat_user_url_day}{$id}{$dest}{lasthit} || ($time > $self->{stat_user_url_da y}{$id}{$dest}{lasthit})); $self->{stat_user_url_day}{$id}{$dest}{lasthit} = $time if (!$sel f->{stat_user_url_day}{$id}{$dest}{lasthit} || ($time > $self->{stat_user_url_da y}{$id}{$dest}{lasthit}));
$self->{stat_user_url_day}{$id}{$dest}{bytes} += $bytes; $self->{stat_user_url_day}{$id}{$dest}{bytes} += $bytes;
if ($code eq 'HIT') { if ($code eq 'HIT') {
$self->{stat_user_url_day}{$id}{$dest}{cache_hit}++; $self->{stat_user_url_day}{$id}{$dest}{cache_hit}++;
$self->{stat_user_url_day}{$id}{$dest}{cache_bytes} += $b ytes; $self->{stat_user_url_day}{$id}{$dest}{cache_bytes} += $b ytes;
} }
if (!exists $self->{stat_user_url_day}{$id}{$dest}{arr_last} || (
$#{$self->{stat_user_url_day}{$id}{$dest}{arr_last}} < 9) || ($time > ($self->{s
tat_user_url_day}{$id}{$dest}{arr_last}[-1]+1800))) {
push(@{$self->{stat_user_url_day}{$id}{$dest}{arr_last}},
$time);
shift(@{$self->{stat_user_url_day}{$id}{$dest}{arr_last}}
) if ($#{$self->{stat_user_url_day}{$id}{$dest}{arr_last}} > 9);
}
} }
#### Store user per networks statistics #### Store user per networks statistics
if ($self->{UserReport}) { if ($self->{UserReport}) {
$self->{stat_netuser_hour}{$network}{$id}{duration} += $elapsed; $self->{stat_netuser_hour}{$network}{$id}{duration} += $elapsed;
$self->{stat_netuser_hour}{$network}{$id}{bytes} += $bytes; $self->{stat_netuser_hour}{$network}{$id}{bytes} += $bytes;
$self->{stat_netuser_hour}{$network}{$id}{hits}++; $self->{stat_netuser_hour}{$network}{$id}{hits}++;
if ($bytes > $self->{stat_netuser_hour}{$network}{$id}{largest_fi le_size}) { if ($bytes > $self->{stat_netuser_hour}{$network}{$id}{largest_fi le_size}) {
$self->{stat_netuser_hour}{$network}{$id}{largest_file_si ze} = $bytes; $self->{stat_netuser_hour}{$network}{$id}{largest_file_si ze} = $bytes;
$self->{stat_netuser_hour}{$network}{$id}{largest_file_ur l} = $url; $self->{stat_netuser_hour}{$network}{$id}{largest_file_ur l} = $url;
skipping to change at line 2001 skipping to change at line 2123
$self->{stat_netuser_day}{$network}{$id}{largest_file_siz e} = $bytes; $self->{stat_netuser_day}{$network}{$id}{largest_file_siz e} = $bytes;
$self->{stat_netuser_day}{$network}{$id}{largest_file_url } = $url; $self->{stat_netuser_day}{$network}{$id}{largest_file_url } = $url;
} }
} }
#### Store mime type statistics #### Store mime type statistics
$self->{stat_mime_type_hour}{"$type"}{hits}++; $self->{stat_mime_type_hour}{"$type"}{hits}++;
$self->{stat_mime_type_hour}{"$type"}{bytes} += $bytes; $self->{stat_mime_type_hour}{"$type"}{bytes} += $bytes;
$self->{stat_mime_type_day}{"$type"}{hits}++; $self->{stat_mime_type_day}{"$type"}{hits}++;
$self->{stat_mime_type_day}{"$type"}{bytes} += $bytes; $self->{stat_mime_type_day}{"$type"}{bytes} += $bytes;
} }
sub _load_history sub _load_history
{ {
my ($self, $type, $year, $month, $day, $path, $kind, $wn, @wd) = @_; my ($self, $type, $year, $month, $day, $path, $kind, $wn, @wd) = @_;
#### Load history #### Load history
if ($type eq 'day') { if ($type eq 'day') {
foreach my $d ("01" .. "31") { foreach my $d ("01" .. "31") {
$self->_read_stat($year, $month, $d, 'day', $kind); $self->_read_stat($year, $month, $d, 'day', $kind);
skipping to change at line 2270 skipping to change at line 2391
"blacklist=" . $bl . "blacklist=" . $bl .
"\n"); "\n");
} }
} }
$self->{"stat_denied_url_$type"} = (); $self->{"stat_denied_url_$type"} = ();
} }
#### Save url statistics per user #### Save url statistics per user
if ($kind eq 'stat_user_url') { if ($kind eq 'stat_user_url') {
foreach my $id (sort {$a cmp $b} keys %{$self->{"stat_user_url_$t ype"}}) { foreach my $id (sort {$a cmp $b} keys %{$self->{"stat_user_url_$t ype"}}) {
foreach my $dest (keys %{$self->{"stat_user_url_$type"}{$ my $i = 0;
id}}) { foreach my $dest (sort {
$self->{"stat_user_url_$type"}{$id}{$b}{$self->{O
rderUrl}} <=> $self->{"stat_user_url_$type"}{$id}{$a}{$self->{OrderUrl}}
} keys %{$self->{"stat_user_url_$
type"}{$id}}) {
last if ($self->{TopStorage} && ($i > $self->{Top
Storage}));
my $u = $id; my $u = $id;
$u = '-' if (!$self->{UserReport}); $u = '-' if (!$self->{UserReport});
$i++;
$fh->print( $fh->print(
"$id hits=" . $self->{"stat_user_url_$typ e"}{$id}{$dest}{hits} . ";" . "$id hits=" . $self->{"stat_user_url_$typ e"}{$id}{$dest}{hits} . ";" .
"bytes=" . $self->{"stat_user_url_$type"} {$id}{$dest}{bytes} . ";" . "bytes=" . $self->{"stat_user_url_$type"} {$id}{$dest}{bytes} . ";" .
"duration=" . $self->{"stat_user_url_$typ e"}{$id}{$dest}{duration} . ";" . "duration=" . $self->{"stat_user_url_$typ e"}{$id}{$dest}{duration} . ";" .
"first=" . $self->{"stat_user_url_$type"} {$id}{$dest}{firsthit} . ";" . "first=" . $self->{"stat_user_url_$type"} {$id}{$dest}{firsthit} . ";" .
"last=" . $self->{"stat_user_url_$type"}{ $id}{$dest}{lasthit} . ";" . "last=" . $self->{"stat_user_url_$type"}{ $id}{$dest}{lasthit} . ";" .
"url=$dest;" . "url=$dest;" .
"cache_hit=" . ($self->{"stat_user_url_$t ype"}{$id}{$dest}{cache_hit}||0) . ";" . "cache_hit=" . ($self->{"stat_user_url_$t ype"}{$id}{$dest}{cache_hit}||0) . ";" .
"cache_bytes=" . ($self->{"stat_user_url_ "cache_bytes=" . ($self->{"stat_user_url_
$type"}{$id}{$dest}{cache_bytes}||0) . "\n"); $type"}{$id}{$dest}{cache_bytes}||0) . ";" .
"arr_last=" . join(',', @{$self->{"stat_u
ser_url_$type"}{$id}{$dest}{arr_last}}) . "\n");
} }
} }
$self->{"stat_user_url_$type"} = (); $self->{"stat_user_url_$type"} = ();
} }
#### Save user statistics #### Save user statistics
if ($kind eq 'stat_user') { if ($kind eq 'stat_user') {
foreach my $id (sort {$a cmp $b} keys %{$self->{"stat_user_$type" }}) { foreach my $id (sort {$a cmp $b} keys %{$self->{"stat_user_$type" }}) {
my $name = $id; my $name = $id;
$name =~ s/\s+//g; $name =~ s/\s+//g;
skipping to change at line 2376 skipping to change at line 2503
} }
if (!$month) { if (!$month) {
$type = 'month'; $type = 'month';
} }
my $path = join('/', $year, $month, $day); my $path = join('/', $year, $month, $day);
$path =~ s/[\/]+$//; $path =~ s/[\/]+$//;
return if (! -d "$self->{Output}/$path"); return if (! -d "$self->{Output}/$path");
#print STDERR "Reading data from previous dat files for $sum_type($type)
in $self->{Output}/$path/$kind.dat\n" if (!$self->{QuietMode});
my $k = ''; my $k = '';
my $key = ''; my $key = '';
$key = $day if ($sum_type eq 'day'); $key = $day if ($sum_type eq 'day');
$key = $month if ($sum_type eq 'month'); $key = $month if ($sum_type eq 'month');
$sum_type ||= $type; $sum_type ||= $type;
#### Read previous cache statistics #### Read previous cache statistics
if (!$kind || ($kind eq 'stat_code')) { if (!$kind || ($kind eq 'stat_code')) {
my $dat_file_code = new IO::File; my $dat_file_code = new IO::File;
if ($dat_file_code->open("$self->{Output}/$path/stat_code.dat")) { if ($dat_file_code->open("$self->{Output}/$path/stat_code.dat")) {
skipping to change at line 2551 skipping to change at line 2676
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{firsthit} = $5 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url "}{firsthit} || ($5 < $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{firsthit}) ); $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{firsthit} = $5 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url "}{firsthit} || ($5 < $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{firsthit}) );
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{lasthit} = $6 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url" }{lasthit} || ($6 > $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{lasthit})); $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{lasthit} = $6 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url" }{lasthit} || ($6 > $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{lasthit}));
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{cache_hit} += $8; $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{cache_hit} += $8;
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{cache_bytes} += $9; $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{cache_bytes} += $9;
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusio ns('', '', $url)) { if ($self->check_exclusio ns('', '', $url)) {
delete $self->{"s tat_user_url_$sum_type"}{$id}{"$url"}; delete $self->{"s tat_user_url_$sum_type"}{$id}{"$url"};
next; next;
} }
} }
if ($l =~ s/^;arr_last=(.*)//) {
my $incr = 1800;
$incr = 300 if ($sum_type
eq 'hour');
$incr = 86400 if ($sum_ty
pe eq 'month');
foreach my $tm (split(/,/
, $1)) {
if (!exists $self
->{"stat_user_url_$sum_type"}{$id}{$url}{arr_last} || ($#{$self->{"stat_user_url
_$sum_type"}{$id}{$url}{arr_last}} < 9) || ($tm > ${$self->{"stat_user_url_$sum_
type"}{$id}{$url}{arr_last}}[-1] + $incr)) {
push(@{$s
elf->{"stat_user_url_$sum_type"}{$id}{$url}{arr_last}}, $tm);
shift(@{$
self->{"stat_user_url_$sum_type"}{$id}{$url}{arr_last}}) if ($#{$self->{"stat_us
er_url_$sum_type"}{$id}{$url}{arr_last}} > 9);
}
}
}
} elsif ($l =~ s/^([^\s]+)\s+hits=(\d+);b ytes=(\d+);duration=([\-\d]+);first=([^;]*);last=([^;]*);url=(.*)$//) { } elsif ($l =~ s/^([^\s]+)\s+hits=(\d+);b ytes=(\d+);duration=([\-\d]+);first=([^;]*);last=([^;]*);url=(.*)$//) {
my $url = $7; my $url = $7;
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{hits} += $2; $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{hits} += $2;
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{bytes} += $3; $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{bytes} += $3;
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{duration} += abs($4); $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{duration} += abs($4);
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{firsthit} = $5 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url "}{firsthit} || ($5 < $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{firsthit}) ); $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{firsthit} = $5 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url "}{firsthit} || ($5 < $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{firsthit}) );
$self->{"stat_user_url_$sum_type" }{$id}{"$url"}{lasthit} = $6 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url" }{lasthit} || ($6 > $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{lasthit})); $self->{"stat_user_url_$sum_type" }{$id}{"$url"}{lasthit} = $6 if (!$self->{"stat_user_url_$sum_type"}{$id}{"$url" }{lasthit} || ($6 > $self->{"stat_user_url_$sum_type"}{$id}{"$url"}{lasthit}));
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusio ns('', '', $url)) { if ($self->check_exclusio ns('', '', $url)) {
delete $self->{"s tat_user_url_$sum_type"}{$id}{"$url"}; delete $self->{"s tat_user_url_$sum_type"}{$id}{"$url"};
skipping to change at line 2591 skipping to change at line 2727
} }
$error++; $error++;
} }
$i++; $i++;
} }
$dat_file_user_url->close(); $dat_file_user_url->close();
} }
} }
if (!$kind || ($kind eq 'stat_denied_url')) { if (!$kind || ($kind eq 'stat_denied_url')) {
my $dat_file_denied_url = new IO::File; my $dat_file_denied_url = new IO::File;
if ($dat_file_denied_url->open("$self->{Output}/$path/sta t_denied_url.dat")) { if ($dat_file_denied_url->open("$self->{Output}/$path/sta t_denied_url.dat")) {
my $i = 1; my $i = 1;
my $error = 0; my $error = 0;
while (my $l = <$dat_file_denied_url>) { while (my $l = <$dat_file_denied_url>) {
chomp($l); chomp($l);
my $id = ''; my $id = '';
if ($l =~ /^([^\s]+)\s+hits=/) { if ($l =~ /^([^\s]+)\s+hits=/) {
$id = $1; $id = $1;
} }
skipping to change at line 2674 skipping to change at line 2811
if (!$data) { if (!$data) {
# Assume backward compatibility # Assume backward compatibility
$l =~ s/^(.*)\shits_$type=/hits_$type=/; $l =~ s/^(.*)\shits_$type=/hits_$type=/;
$net = $1; $net = $1;
$data = $l; $data = $l;
} }
if ($self->{rebuild} && !exists $self->{NetworkAl ias}->{$net}) { if ($self->{rebuild} && !exists $self->{NetworkAl ias}->{$net}) {
next if (!$self->check_inclusions('', $ne t)); next if (!$self->check_inclusions('', $ne t));
next if ($self->check_exclusions('', $net )); next if ($self->check_exclusions('', $net ));
}
if ($self->{UpdateAlias}) {
# Replace network by his aliases if any
$net = (!$self->{has_nework_alias}) ? $ne
t : $self->apply_network_alias($net)
} }
if ($data =~ s/^hits_$type=([^;]+);bytes_$type=([ ^;]+);duration_$type=([^;]+);largest_file_size=([^;]*);largest_file_url=(.*)$//) { if ($data =~ s/^hits_$type=([^;]+);bytes_$type=([ ^;]+);duration_$type=([^;]+);largest_file_size=([^;]*);largest_file_url=(.*)$//) {
my $hits = $1 || ''; my $hits = $1 || '';
my $bytes = $2 || ''; my $bytes = $2 || '';
my $duration = $3 || ''; my $duration = $3 || '';
if ($4 > $self->{"stat_netmax_$sum_type"} {$net}{largest_file_size}) { if ($4 > $self->{"stat_netmax_$sum_type"} {$net}{largest_file_size}) {
$self->{"stat_netmax_$sum_type"}{ $net}{largest_file_size} = $4; $self->{"stat_netmax_$sum_type"}{ $net}{largest_file_size} = $4;
$self->{"stat_netmax_$sum_type"}{ $net}{largest_file_url} = $5; $self->{"stat_netmax_$sum_type"}{ $net}{largest_file_url} = $5;
skipping to change at line 2741 skipping to change at line 2884
$net = $1; $net = $1;
$id = $2; $id = $2;
$data = $l; $data = $l;
} }
if ($self->{rebuild}) { if ($self->{rebuild}) {
next if (!$self->check_inclusions ($id, $net)); next if (!$self->check_inclusions ($id, $net));
next if ($self->check_exclusions( $id, $net)); next if ($self->check_exclusions( $id, $net));
} }
# Replace network by his aliases if any
$net = (!$self->{has_nework_alias}) ? $ne
t : $self->apply_network_alias($net);
# Anonymize all users # Anonymize all users
if ($self->{AnonymizeLogin} && ($id !~ /^ Anon[a-zA-Z0-9]{16}$/)) { if ($self->{AnonymizeLogin} && ($id !~ /^ Anon[a-zA-Z0-9]{16}$/)) {
if (!exists $self->{AnonymizedId} {$id}) { if (!exists $self->{AnonymizedId} {$id}) {
$self->{AnonymizedId}{$id } = &anonymize_id(); $self->{AnonymizedId}{$id } = &anonymize_id();
} }
$id = $self->{AnonymizedId}{$id}; $id = $self->{AnonymizedId}{$id};
} }
if ($data =~ s/^hits=(\d+);bytes=(\d+);du ration=([\-\d]+);largest_file_size=([^;]*);largest_file_url=(.*)$//) { if ($data =~ s/^hits=(\d+);bytes=(\d+);du ration=([\-\d]+);largest_file_size=([^;]*);largest_file_url=(.*)$//) {
$self->{"stat_netuser_$sum_type"} {$net}{$id}{hits} += $1; $self->{"stat_netuser_$sum_type"} {$net}{$id}{hits} += $1;
skipping to change at line 2952 skipping to change at line 3098
$outdir ||= $self->{Output}; $outdir ||= $self->{Output};
print STDERR "Building HTML output into $outdir\n" if (!$self->{QuietMode }); print STDERR "Building HTML output into $outdir\n" if (!$self->{QuietMode });
# Load history data for incremental scan # Load history data for incremental scan
my $old_year = 0; my $old_year = 0;
my $old_month = 0; my $old_month = 0;
my $old_day = 0; my $old_day = 0;
my $p_month = 0; my $p_month = 0;
my $p_year = 0; my $p_year = 0;
if ($self->{history_time} || $self->{sg_history_time}) { my $p_week = 0;
my @ltime = CORE::localtime($self->{history_time}); if ($self->{history_time} || $self->{sg_history_time} || $self->{begin_ti
me}) {
my @ltime = CORE::localtime($self->{history_time} || $self->{sg_h
istory_time} || $self->{begin_time});
if ($self->{is_squidguard_log}) { if ($self->{is_squidguard_log}) {
@ltime = CORE::localtime($self->{sg_history_time}); @ltime = CORE::localtime($self->{sg_history_time} || $sel f->{begin_time});
} elsif ($self->{is_ufdbguard_log}) { } elsif ($self->{is_ufdbguard_log}) {
@ltime = CORE::localtime($self->{ug_history_time}); @ltime = CORE::localtime($self->{ug_history_time} || $sel f->{begin_time});
} }
$old_year = $ltime[5]+1900; $old_year = $ltime[5]+1900;
$old_month = $ltime[4]+1; $old_month = $ltime[4]+1;
$old_month = "0$old_month" if ($old_month < 10); $old_month = "0$old_month" if ($old_month < 10);
$old_day = $ltime[3]; $old_day = $ltime[3];
$old_day = "0$old_day" if ($old_day < 10); $old_day = "0$old_day" if ($old_day < 10);
# Set oldest stat to preserve based on history time, not current time # Set oldest stat to preserve based on history time, not current time
if ($self->{preserve} > 0) { if ($self->{preserve} > 0) {
if (!$self->{is_squidguard_log} && !$self->{is_ufdbguard_ log}) { if (!$self->{is_squidguard_log} && !$self->{is_ufdbguard_ log}) {
@ltime = CORE::localtime($self->{history_time}-($ self->{preserve}*2592000)); @ltime = CORE::localtime($self->{history_time}-($ self->{preserve}*2592000));
} elsif (!$self->{is_squidguard_log}) { } elsif (!$self->{is_squidguard_log}) {
@ltime = CORE::localtime($self->{ug_history_time} -($self->{preserve}*2592000)); @ltime = CORE::localtime($self->{ug_history_time} -($self->{preserve}*2592000));
} else { } else {
@ltime = CORE::localtime($self->{sg_history_time} -($self->{preserve}*2592000)); @ltime = CORE::localtime($self->{sg_history_time} -($self->{preserve}*2592000));
} }
$p_year = $ltime[5]+1900; $p_year = $ltime[5]+1900;
$p_month = $ltime[4]+1; $p_month = $ltime[4]+1;
$p_month = sprintf("%02d", $p_month); $p_month = sprintf("%02d", $p_month);
print STDERR "Obsolete statistics before $p_year-$p_month $p_week = &get_week_number($p_year, $p_month, "01");
\n" if (!$self->{QuietMode});
print STDERR "Obsolete statistics before $p_year-$p_month
, week $p_year-$p_week\n" if (!$self->{QuietMode});
} }
} }
# Generate all HTML output # Remove obsolete directories first
opendir(DIR, $outdir) || die "Error: can't opendir $outdir: $!"; opendir(DIR, $outdir) || die "Error: can't opendir $outdir: $!";
my @years = grep { /^\d{4}$/ && -d "$outdir/$_"} readdir(DIR); my @years = grep { /^\d{4}$/ && -d "$outdir/$_"} readdir(DIR);
closedir DIR; closedir DIR;
if ($self->{preserve} && $p_year) {
foreach my $y (sort {$a <=> $b} @years) {
# Remove the full year repository if it is older that the
last year to preserve
if ($y < $p_year) {
print STDERR "Removing obsolete statistics for ye
ar $y\n" if (!$self->{QuietMode});
system ($RM_PROG, "-rf", "$outdir/$y");
next;
}
# Remove the full month repository if it is older that th
e last month to preserve
opendir(DIR, "$outdir/$y") || $self->localdie("FATAL: can
't opendir $outdir/$y: $!");
my @months = grep { /^\d{2}$/ && -d "$outdir/$y/$_"} read
dir(DIR);
closedir DIR;
foreach my $m (sort {$a <=> $b} @months) {
if ("$y$m" < "$p_year$p_month") {
print STDERR "Removing obsolete statistic
s for month $y-$m\n" if (!$self->{QuietMode});
system ($RM_PROG, "-rf", "$outdir/$y/$m")
;
}
}
# Remove the full week repository if it is older that the
last week to preserve
opendir(DIR, "$outdir/$y") || $self->localdie("FATAL: can
't opendir $outdir/$y: $!");
my @weeks = grep { -d "$outdir/$y/$_" && /^week\d{2}/ }
readdir(DIR);
closedir DIR;
map { s/^week(\d{2})/$1/; } @weeks;
foreach my $w (sort {$a <=> $b} @weeks) {
# Remove the full week repository if it is older
that the last date to preserve
if ("$y$w" < "$p_year$p_week") {
print STDERR "Removing obsolete statistic
s for week $y-week$w\n" if (!$self->{QuietMode});
system ($RM_PROG, "-rf", "$outdir/$y/week
$w");
}
}
}
}
# Generate all HTML output
opendir(DIR, $outdir) || die "Error: can't opendir $outdir: $!";
@years = grep { /^\d{4}$/ && -d "$outdir/$_"} readdir(DIR);
closedir DIR;
$self->{child_count} = 0; $self->{child_count} = 0;
my @years_cal = (); my @years_cal = ();
my @months_cal = (); my @months_cal = ();
my @weeks_cal = (); my @weeks_cal = ();
my @array_count = (); my @array_count = ();
foreach my $y (sort {$a <=> $b} @years) { foreach my $y (sort {$a <=> $b} @years) {
next if (!$y || ($y < $self->{first_year})); next if (!$y || ($y < $self->{first_year}));
next if ($self->check_build_date($y)); next if ($self->check_build_date($y));
# Remove the full year repository if it is older that the last da next if ($y < $old_year);
te to preserve
if ($p_year && ($y < $p_year)) {
print STDERR "Removing obsolete statistics for year $y\n"
if (!$self->{QuietMode});
system ($RM_PROG, "-rf", "$outdir/$y");
next;
}
next if (!$p_year && ($y < $old_year));
opendir(DIR, "$outdir/$y") || $self->localdie("FATAL: can't opend ir $outdir/$y: $!"); opendir(DIR, "$outdir/$y") || $self->localdie("FATAL: can't opend ir $outdir/$y: $!");
my @months = grep { /^\d{2}$/ && -d "$outdir/$y/$_"} readdir(DIR) ; my @months = grep { /^\d{2}$/ && -d "$outdir/$y/$_"} readdir(DIR) ;
my @weeks = grep { /^week\d{2}$/ && -d "$outdir/$y/$_"} readdir( DIR); my @weeks = grep { /^week\d{2}$/ && -d "$outdir/$y/$_"} readdir( DIR);
closedir DIR; closedir DIR;
my @weeks_to_build = (); my @weeks_to_build = ();
foreach my $m (sort {$a <=> $b} @months) { foreach my $m (sort {$a <=> $b} @months) {
next if (!$m || ($m < $self->{first_month}{$y})); next if (!$m || ($m < $self->{first_month}{$y}));
next if ($self->check_build_date($y, $m)); next if ($self->check_build_date($y, $m));
# Remove the full month repository if it is older that th
e last date to preserve
if ($p_year && ("$y$m" < "$p_year$p_month")) {
print STDERR "Removing obsolete statistics for mo
nth $y-$m\n" if (!$self->{QuietMode});
system ($RM_PROG, "-rf", "$outdir/$y/$m");
next;
}
next if ("$y$m" < "$old_year$old_month"); next if ("$y$m" < "$old_year$old_month");
opendir(DIR, "$outdir/$y/$m") || $self->localdie("FATAL: can't opendir $outdir/$y/$m: $!"); opendir(DIR, "$outdir/$y/$m") || $self->localdie("FATAL: can't opendir $outdir/$y/$m: $!");
my @days = grep { /^\d{2}$/ && -d "$outdir/$y/$m/$_"} rea ddir(DIR); my @days = grep { /^\d{2}$/ && -d "$outdir/$y/$m/$_"} rea ddir(DIR);
closedir DIR; closedir DIR;
foreach my $d (sort {$a <=> $b} @days) { foreach my $d (sort {$a <=> $b} @days) {
next if ($self->check_build_date($y, $m, $d)); next if ($self->check_build_date($y, $m, $d));
next if ("$y$m$d" < "$old_year$old_month$old_day" ); next if ("$y$m$d" < "$old_year$old_month$old_day" );
print STDERR "Generating statistics for day $y-$m -$d\n" if (!$self->{QuietMode}); print STDERR "Generating statistics for day $y-$m -$d\n" if (!$self->{QuietMode});
$self->gen_html_output($outdir, $y, $m, $d); $self->gen_html_output($outdir, $y, $m, $d);
push(@array_count, "$outdir/$y/$m/$d"); push(@array_count, "$outdir/$y/$m/$d");
skipping to change at line 3041 skipping to change at line 3215
foreach my $w (sort @weeks_to_build) { foreach my $w (sort @weeks_to_build) {
$w = sprintf("%02d", $w+1); $w = sprintf("%02d", $w+1);
push(@array_count, "$outdir/$y/week$w"); push(@array_count, "$outdir/$y/week$w");
print STDERR "Generating statistics for week $w o n year $y\n" if (!$self->{QuietMode}); print STDERR "Generating statistics for week $w o n year $y\n" if (!$self->{QuietMode});
$self->gen_html_output($outdir, $y, '', '', $w); $self->gen_html_output($outdir, $y, '', '', $w);
} }
} }
print STDERR "Generating statistics for year $y\n" if (!$self->{Q uietMode}); print STDERR "Generating statistics for year $y\n" if (!$self->{Q uietMode});
$self->gen_html_output($outdir, $y); $self->gen_html_output($outdir, $y);
push(@years_cal, "$outdir/$y"); push(@years_cal, "$outdir/$y");
} }
# Wait for last child stop # Wait for last child stop
$self->wait_all_childs() if ($self->{queue_size} > 1); $self->wait_all_childs() if ($self->{queue_size} > 1);
# Set calendar in each new files by replacing SA_CALENDAR_SA in the right HTML code # Set calendar in each new files by replacing SA_CALENDAR_SA in the right HTML code
# Same with number of users, urls and domains # Same with number of users, urls and domains
foreach my $p (@years_cal) { foreach my $p (@years_cal) {
$p =~ /\/(\d+)$/; $p =~ /\/(\d+)$/;
my $stat_date = $self->set_date($1); my $stat_date = $self->set_date($1);
skipping to change at line 3797 skipping to change at line 3970
$l =~ s/^(.*)\shits_$type=/hits_$type=/; $l =~ s/^(.*)\shits_$type=/hits_$type=/;
$network = $1; $network = $1;
$data = $l; $data = $l;
} }
$data =~ /^hits_$type=([^;]+);bytes_$type=([^;]+);duration_$type= ([^;]+);largest_file_size=([^;]*);largest_file_url=(.*)/; $data =~ /^hits_$type=([^;]+);bytes_$type=([^;]+);duration_$type= ([^;]+);largest_file_size=([^;]*);largest_file_url=(.*)/;
if ($self->{rebuild} && !exists $self->{NetworkAlias}->{$network} ) { if ($self->{rebuild} && !exists $self->{NetworkAlias}->{$network} ) {
next if (!$self->check_inclusions('', $network)); next if (!$self->check_inclusions('', $network));
next if ($self->check_exclusions('', $network)); next if ($self->check_exclusions('', $network));
} }
if ($self->{UpdateAlias}) {
# Replace network by his aliases if any
$network = (!$self->{has_nework_alias}) ? $network : $sel
f->apply_network_alias($network);
}
my $hits = $1 || ''; my $hits = $1 || '';
my $bytes = $2 || ''; my $bytes = $2 || '';
my $duration = $3 || ''; my $duration = $3 || '';
$network_stat{$network}{largest_file} = $4; $network_stat{$network}{largest_file} = $4;
$network_stat{$network}{url} = $5; $network_stat{$network}{url} = $5;
$hits =~ s/,$//; $hits =~ s/,$//;
$bytes =~ s/,$//; $bytes =~ s/,$//;
$duration =~ s/,$//; $duration =~ s/,$//;
my %hits_tmp = split(/[:,]/, $hits); my %hits_tmp = split(/[:,]/, $hits);
foreach my $tmp (sort {$a <=> $b} keys %hits_tmp) { foreach my $tmp (sort {$a <=> $b} keys %hits_tmp) {
skipping to change at line 3859 skipping to change at line 4037
$first = '01'; $first = '01';
$title = $Translate{'Daily'} || 'Daily'; $title = $Translate{'Daily'} || 'Daily';
$unit = $Translate{'Days'} || 'Days'; $unit = $Translate{'Days'} || 'Days';
} elsif ($type eq 'month') { } elsif ($type eq 'month') {
$last = '12'; $last = '12';
$first = '01'; $first = '01';
$title = $Translate{'Monthly'} || 'Monthly'; $title = $Translate{'Monthly'} || 'Monthly';
$unit = $Translate{'Months'} || 'Months'; $unit = $Translate{'Months'} || 'Months';
} }
my $trfunit = $self->{TransfertUnit} || 'B';
$trfunit = 'B' if ($trfunit eq 'BYTE');
print $out "<h3>$Translate{'Network_number'}: $nnet</h3>\n"; print $out "<h3>$Translate{'Network_number'}: $nnet</h3>\n";
print $out qq{ print $out qq{
<table class="sortable stata"> <table class="sortable stata">
<thead> <thead>
<tr> <tr>
<th>$Translate{'Network_link'}</th> <th>$Translate{'Network_link'}</th>
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th> <th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Duration'} (%)</th> <th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Throughput'} (B/s)</th> <th>$Translate{'Throughput'} ($trfunit/s)</th>
}; };
print $out qq{ print $out qq{
<th>$Translate{'Cost'} $self->{Currency}</th> <th>$Translate{'Cost'} $self->{Currency}</th>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $out qq{ print $out qq{
<th>$Translate{'Users'}</th> <th>$Translate{'Users'}</th>
} if ($self->{UserReport}); } if ($self->{UserReport});
print $out qq{ print $out qq{
<th>$Translate{'Largest'}</th> <th>$Translate{'Largest'}</th>
<th style="text-align: left;">$Translate{'Url'}</th> <th style="text-align: left;">$Translate{'Url'}</th>
skipping to change at line 3899 skipping to change at line 4080
my $h_percent = '0.0'; my $h_percent = '0.0';
$h_percent = sprintf("%2.2f", ($network_stat{$net}{hits}/$total_h it) * 100) if ($total_hit); $h_percent = sprintf("%2.2f", ($network_stat{$net}{hits}/$total_h it) * 100) if ($total_hit);
my $b_percent = '0.0'; my $b_percent = '0.0';
$b_percent = sprintf("%2.2f", ($network_stat{$net}{bytes}/$total_ bytes) * 100) if ($total_bytes); $b_percent = sprintf("%2.2f", ($network_stat{$net}{bytes}/$total_ bytes) * 100) if ($total_bytes);
my $d_percent = '0.0'; my $d_percent = '0.0';
$d_percent = sprintf("%2.2f", ($network_stat{$net}{duration}/$tot al_duration) * 100) if ($total_duration); $d_percent = sprintf("%2.2f", ($network_stat{$net}{duration}/$tot al_duration) * 100) if ($total_duration);
my $total_cost = sprintf("%2.2f", int($network_stat{$net}{bytes}/ 1000000) * $self->{CostPrice}); my $total_cost = sprintf("%2.2f", int($network_stat{$net}{bytes}/ 1000000) * $self->{CostPrice});
my $total_throughput = int($network_stat{$net}{bytes} / (($networ k_stat{$net}{duration}/1000) || 1) ); my $total_throughput = int($network_stat{$net}{bytes} / (($networ k_stat{$net}{duration}/1000) || 1) );
my $comma_throughput = $self->format_bytes($total_throughput); my $comma_throughput = $self->format_bytes($total_throughput);
$network_stat{$net}{duration} = &parse_duration(int($network_stat {$net}{duration}/1000)); $network_stat{$net}{duration} = &parse_duration(int($network_stat {$net}{duration}/1000));
my $show = $net; my $show = (!$self->{has_nework_alias}) ? $net : $self->apply_net
if ($net =~ /^(\d+\.\d+\.\d+)/) { work_alias($net);
$show = "$1.0";
foreach my $r (keys %{$self->{NetworkAlias}}) {
if ($r =~ /^\d+\.\d+\.\d+\.\d+\/\d+$/) {
if (&check_ip($net, $r)) {
$show = $self->{NetworkAlias}->{$
r};
last;
}
} elsif ($show =~ /$r/) {
$show = $self->{NetworkAlias}->{$r};
last;
}
}
}
my $comma_bytes = $self->format_bytes($network_stat{$net}{bytes}) ; my $comma_bytes = $self->format_bytes($network_stat{$net}{bytes}) ;
print $out qq{ print $out qq{
<tr> <tr>
<td><a href="networks/$net/$net.html">$show</a></td> <td><a href="networks/$net/$net.html">$show</a></td>
<td>$network_stat{$net}{hits} <span class="italicPercent">($h_percent)</span></t d> <td>$network_stat{$net}{hits} <span class="italicPercent">($h_percent)</span></t d>
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td> <td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
<td>$network_stat{$net}{duration} <span class="italicPercent">($d_percent)</span ></td> <td>$network_stat{$net}{duration} <span class="italicPercent">($d_percent)</span ></td>
<td>$comma_throughput</td> <td>$comma_throughput</td>
}; };
print $out qq{ print $out qq{
<td>$total_cost</td> <td>$total_cost</td>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
if (!-d "$outdir/networks/$net") { if (!-d "$outdir/networks/$net") {
mkdir("$outdir/networks/$net", 0755) || return; mkdir("$outdir/networks/$net", 0755) || return;
} }
my $outnet = new IO::File; my $outnet = new IO::File;
$outnet->open(">$outdir/networks/$net/$net.html") || return; $outnet->open(">$outdir/networks/$net/$net.html") || return;
# Print the HTML header # Print the HTML header
my $cal = 'SA_CALENDAR_SA'; my $cal = '';
$self->_print_header(\$outnet, $self->{menu2}, $cal, $sortpos); $self->_print_header(\$outnet, $self->{menu2}, $cal, $sortpos);
print $outnet $self->_print_title("$Translate{'Network_title'} $s how -", $stat_date, $week); print $outnet $self->_print_title("$Translate{'Network_title'} $s how -", $stat_date, $week);
my @hits = (); my @hits = ();
my @bytes = (); my @bytes = ();
for ("$first" .. "$last") { for ("$first" .. "$last") {
if (exists $detail_network_stat{$net}{$_}{hits}) { if (exists $detail_network_stat{$net}{$_}{hits}) {
push(@hits, "[ $_, " . $detail_network_stat{$net} {$_}{hits} . " ]"); push(@hits, "[ $_, " . $detail_network_stat{$net} {$_}{hits} . " ]");
} else { } else {
push(@hits, "[ $_, 0 ]"); push(@hits, "[ $_, 0 ]");
skipping to change at line 4154 skipping to change at line 4320
$title = $Translate{'Monthly'} || 'Monthly'; $title = $Translate{'Monthly'} || 'Monthly';
$unit = $Translate{'Months'} || 'Months'; $unit = $Translate{'Months'} || 'Months';
} }
%total_user_detail = (); %total_user_detail = ();
print $out $self->_print_title($Translate{'User_title'}, $stat_date, $wee k); print $out $self->_print_title($Translate{'User_title'}, $stat_date, $wee k);
print $out "<h3>$Translate{'User_number'}: $nuser</h3>\n"; print $out "<h3>$Translate{'User_number'}: $nuser</h3>\n";
my $trfunit = $self->{TransfertUnit} || 'B';
$trfunit = 'B' if ($trfunit eq 'BYTE');
print $out qq{ print $out qq{
<table class="sortable stata" > <table class="sortable stata" >
<thead> <thead>
<tr> <tr>
<th>$Translate{'Users'}</th> <th>$Translate{'Users'}</th>
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th> <th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Duration'} (%)</th> <th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Throughput'} (B/s)</th> <th>$Translate{'Throughput'} ($trfunit/s)</th>
}; };
print $out qq{ print $out qq{
<th>$Translate{'Cost'} $self->{Currency}</th> <th>$Translate{'Cost'} $self->{Currency}</th>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $out qq{ print $out qq{
<th>$Translate{'Largest'}</th> <th>$Translate{'Largest'}</th>
<th style="text-align: left;">$Translate{'Url'}</th> <th style="text-align: left;">$Translate{'Url'}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
skipping to change at line 4190 skipping to change at line 4359
my $h_percent = '0.0'; my $h_percent = '0.0';
$h_percent = sprintf("%2.2f", ($user_stat{$usr}{hits}/$total_hit) * 100) if ($total_hit); $h_percent = sprintf("%2.2f", ($user_stat{$usr}{hits}/$total_hit) * 100) if ($total_hit);
my $b_percent = '0.0'; my $b_percent = '0.0';
$b_percent = sprintf("%2.2f", ($user_stat{$usr}{bytes}/$total_byt es) * 100) if ($total_bytes); $b_percent = sprintf("%2.2f", ($user_stat{$usr}{bytes}/$total_byt es) * 100) if ($total_bytes);
my $d_percent = '0.0'; my $d_percent = '0.0';
$d_percent = sprintf("%2.2f", ($user_stat{$usr}{duration}/$total_ duration) * 100) if ($total_duration); $d_percent = sprintf("%2.2f", ($user_stat{$usr}{duration}/$total_ duration) * 100) if ($total_duration);
my $total_cost = sprintf("%2.2f", int($user_stat{$usr}{bytes}/100 0000) * $self->{CostPrice}); my $total_cost = sprintf("%2.2f", int($user_stat{$usr}{bytes}/100 0000) * $self->{CostPrice});
my $total_throughput = int($user_stat{$usr}{bytes} / (($user_stat {$usr}{duration}/1000) || 1)); my $total_throughput = int($user_stat{$usr}{bytes} / (($user_stat {$usr}{duration}/1000) || 1));
my $comma_throughput = $self->format_bytes($total_throughput); my $comma_throughput = $self->format_bytes($total_throughput);
$user_stat{$usr}{duration} = &parse_duration(int($user_stat{$usr} {duration}/1000)); $user_stat{$usr}{duration} = &parse_duration(int($user_stat{$usr} {duration}/1000));
my $show = $usr; my $show = (!$self->{has_user_alias}) ? $usr : $self->apply_user_
foreach my $u (keys %{$self->{UserAlias}}) { alias($usr);
if ( $usr =~ /^$u$/i ) {
$show = $self->{UserAlias}->{$u};
last;
}
}
$show =~ s/_SPC_/ /g; $show =~ s/_SPC_/ /g;
my $upath = &escape($usr); my $upath = &escape($usr);
my $comma_bytes = $self->format_bytes($user_stat{$usr}{bytes}); my $comma_bytes = $self->format_bytes($user_stat{$usr}{bytes});
if ($self->{UrlReport}) { if ($self->{UrlReport}) {
print $out qq{ print $out qq{
<tr> <tr>
<td><a href="users/$upath/$upath.html">$show</a></td> <td><a href="users/$upath/$upath.html">$show</a></td>
}; };
} else { } else {
print $out qq{ print $out qq{
skipping to change at line 4232 skipping to change at line 4395
<td>$comma_largest</td> <td>$comma_largest</td>
<td style="text-align: left;">$user_stat{$usr}{url}</td> <td style="text-align: left;">$user_stat{$usr}{url}</td>
</tr>}; </tr>};
if (!-d "$outdir/users/$upath") { if (!-d "$outdir/users/$upath") {
mkdir("$outdir/users/$upath", 0755) || return; mkdir("$outdir/users/$upath", 0755) || return;
} }
my $outusr = new IO::File; my $outusr = new IO::File;
$outusr->open(">$outdir/users/$upath/$upath.html") || return; $outusr->open(">$outdir/users/$upath/$upath.html") || return;
# Print the HTML header # Print the HTML header
my $cal = 'SA_CALENDAR_SA'; my $cal = '';
$self->_print_header(\$outusr, $self->{menu2}, $cal, $sortpos); $self->_print_header(\$outusr, $self->{menu2}, $cal, $sortpos);
print $outusr $self->_print_title("$Translate{'User_title'} $usr my $usr_lbl = $usr;
-", $stat_date, $week); $usr_lbl =~ s/_SPC_/ /g;
print $outusr $self->_print_title("$Translate{'User_title'} $usr_
lbl -", $stat_date, $week);
my @hits = (); my @hits = ();
my @bytes = (); my @bytes = ();
for my $d ("$first" .. "$last") { for my $d ("$first" .. "$last") {
if (exists $detail_user_stat{$usr}{$d}{hits}) { if (exists $detail_user_stat{$usr}{$d}{hits}) {
push(@hits, "[ $d, $detail_user_stat{$usr}{$d}{hi ts} ]"); push(@hits, "[ $d, $detail_user_stat{$usr}{$d}{hi ts} ]");
} else { } else {
push(@hits, "[ $d, 0 ]"); push(@hits, "[ $d, 0 ]");
} }
if (exists $detail_user_stat{$usr}{$d}{bytes}) { if (exists $detail_user_stat{$usr}{$d}{bytes}) {
skipping to change at line 4299 skipping to change at line 4464
print $outusr qq{ print $outusr qq{
<div id="container"> <div id="container">
$user_bytes $user_bytes
</div> </div>
</td></tr></table> </td></tr></table>
}; };
$user_bytes = ''; $user_bytes = '';
delete $user_stat{$usr}; delete $user_stat{$usr};
if ($self->{UrlReport}) { if ($self->{UrlReport}) {
$self->_print_user_denied_detail(\$outusr, $outdir, $usr, $type);
$self->_print_user_detail(\$outusr, $outdir, $usr, $type) ; $self->_print_user_detail(\$outusr, $outdir, $usr, $type) ;
} }
$self->_print_footer(\$outusr); $self->_print_footer(\$outusr);
$outusr->close(); $outusr->close();
} }
$sortpos = 1; $sortpos = 1;
$sortpos = 2 if ($self->{OrderUser} eq 'bytes'); $sortpos = 2 if ($self->{OrderUser} eq 'bytes');
$sortpos = 3 if ($self->{OrderUser} eq 'duration'); $sortpos = 3 if ($self->{OrderUser} eq 'duration');
print $out qq{ print $out qq{
</tbody> </tbody>
skipping to change at line 4375 skipping to change at line 4541
$netuser_stat{$user}{largest_file} = $4; $netuser_stat{$user}{largest_file} = $4;
$total_hit += $1; $total_hit += $1;
$total_bytes += $2; $total_bytes += $2;
$total_duration += $3; $total_duration += $3;
$netuser_stat{$user}{url} = $5; $netuser_stat{$user}{url} = $5;
} }
$infile->close(); $infile->close();
my $nuser = scalar keys %netuser_stat; my $nuser = scalar keys %netuser_stat;
my $trfunit = $self->{TransfertUnit} || 'B';
$trfunit = 'B' if ($trfunit eq 'BYTE');
print $$out qq{ print $$out qq{
<h3>$Translate{'User_number'}: $nuser</h3> <h3>$Translate{'User_number'}: $nuser</h3>
}; };
print $$out qq{ print $$out qq{
<table class="sortable stata"> <table class="sortable stata">
<thead> <thead>
<tr> <tr>
<th>$Translate{'Users'}</th> <th>$Translate{'Users'}</th>
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th> <th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Duration'} (%)</th> <th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Throughput'} (B/s)</th> <th>$Translate{'Throughput'} ($trfunit/s)</th>
}; };
print $$out qq{ print $$out qq{
<th>$Translate{'Cost'} $self->{Currency}</th> <th>$Translate{'Cost'} $self->{Currency}</th>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $$out qq{ print $$out qq{
<th>$Translate{'Largest'}</th> <th>$Translate{'Largest'}</th>
<th style="text-align: left;">$Translate{'Url'}</th> <th style="text-align: left;">$Translate{'Url'}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
skipping to change at line 4410 skipping to change at line 4579
my $h_percent = '0.0'; my $h_percent = '0.0';
$h_percent = sprintf("%2.2f", ($netuser_stat{$usr}{hits}/$total_h it) * 100) if ($total_hit); $h_percent = sprintf("%2.2f", ($netuser_stat{$usr}{hits}/$total_h it) * 100) if ($total_hit);
my $b_percent = '0.0'; my $b_percent = '0.0';
$b_percent = sprintf("%2.2f", ($netuser_stat{$usr}{bytes}/$total_ bytes) * 100) if ($total_bytes); $b_percent = sprintf("%2.2f", ($netuser_stat{$usr}{bytes}/$total_ bytes) * 100) if ($total_bytes);
my $d_percent = '0.0'; my $d_percent = '0.0';
$d_percent = sprintf("%2.2f", ($netuser_stat{$usr}{duration}/$tot al_duration) * 100) if ($total_duration); $d_percent = sprintf("%2.2f", ($netuser_stat{$usr}{duration}/$tot al_duration) * 100) if ($total_duration);
my $total_cost = sprintf("%2.2f", int($netuser_stat{$usr}{bytes}/ 1000000) * $self->{CostPrice}); my $total_cost = sprintf("%2.2f", int($netuser_stat{$usr}{bytes}/ 1000000) * $self->{CostPrice});
my $total_throughput = int($netuser_stat{$usr}{bytes} / (($netuse r_stat{$usr}{duration}/1000) || 1) ); my $total_throughput = int($netuser_stat{$usr}{bytes} / (($netuse r_stat{$usr}{duration}/1000) || 1) );
my $comma_throughput = $self->format_bytes($total_throughput); my $comma_throughput = $self->format_bytes($total_throughput);
$netuser_stat{$usr}{duration} = &parse_duration(int($netuser_stat {$usr}{duration}/1000)); $netuser_stat{$usr}{duration} = &parse_duration(int($netuser_stat {$usr}{duration}/1000));
my $show = $usr; my $show = (!$self->{has_user_alias}) ? $usr : $self->apply_user_
foreach my $u (keys %{$self->{UserAlias}}) { alias($usr);
if ( $usr =~ /^$u$/i ) {
$show = $self->{UserAlias}->{$u};
last;
}
}
$show =~ s/_SPC_/ /g; $show =~ s/_SPC_/ /g;
my $url = &escape($usr); my $url = &escape($usr);
my $comma_bytes = $self->format_bytes($netuser_stat{$usr}{bytes}) ; my $comma_bytes = $self->format_bytes($netuser_stat{$usr}{bytes}) ;
if ($self->{UrlReport}) { if ($self->{UrlReport}) {
print $$out qq{ print $$out qq{
<tr> <tr>
<td><a href="../../users/$url/$url.html">$show</a></td> <td><a href="../../users/$url/$url.html">$show</a></td>
}; };
} else { } else {
print $$out qq{ print $$out qq{
skipping to change at line 4459 skipping to change at line 4622
}; };
return $nuser; return $nuser;
} }
sub _print_user_detail sub _print_user_detail
{ {
my ($self, $out, $outdir, $usr, $type) = @_; my ($self, $out, $outdir, $usr, $type) = @_;
$0 = "squid-analyzer: Printing user details statistics in $outdir"; $0 = "squid-analyzer: Printing user details statistics in $outdir";
# Load code statistics # Load user statistics
my $infile = new IO::File; my $infile = new IO::File;
$infile->open("$outdir/stat_user_url.dat") || return; $infile->open("$outdir/stat_user_url.dat") || return;
my %url_stat = (); my %url_stat = ();
my $total_hit = 0; my $total_hit = 0;
my $total_bytes = 0; my $total_bytes = 0;
my $total_duration = 0; my $total_duration = 0;
my $total_cache_hit = 0; my $total_cache_hit = 0;
my $total_cache_bytes = 0; my $total_cache_bytes = 0;
my $ok = 0; my $ok = 0;
while(my $l = <$infile>) { while(my $l = <$infile>) {
skipping to change at line 4483 skipping to change at line 4646
next if ($user ne $usr); next if ($user ne $usr);
$ok = 1; $ok = 1;
if ($self->{rebuild}) { if ($self->{rebuild}) {
next if (!$self->check_inclusions($user)); next if (!$self->check_inclusions($user));
next if ($self->check_exclusions($user)); next if ($self->check_exclusions($user));
} }
if ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);first=([^ ;]*);last=([^;]*);url=(.*?);cache_hit=(\d*);cache_bytes=(\d*)/) { if ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);first=([^ ;]*);last=([^;]*);url=(.*?);cache_hit=(\d*);cache_bytes=(\d*)/) {
my $url = $6; my $url = $6;
$url_stat{$url}{hits} = $1; $url_stat{$url}{hits} += $1;
$url_stat{$url}{bytes} = $2; $url_stat{$url}{bytes} += $2;
$url_stat{$url}{duration} = abs($3); $url_stat{$url}{duration} += abs($3);
$url_stat{$url}{firsthit} = $4 if (!$url_stat{$url}{first hit} || ($4 < $url_stat{$url}{firsthit})); $url_stat{$url}{firsthit} = $4 if (!$url_stat{$url}{first hit} || ($4 < $url_stat{$url}{firsthit}));
$url_stat{$url}{lasthit} = $5 if (!$url_stat{$url}{lasthi t} || ($5 > $url_stat{$url}{lasthit})); $url_stat{$url}{lasthit} = $5 if (!$url_stat{$url}{lasthi t} || ($5 > $url_stat{$url}{lasthit}));
$url_stat{$url}{cache_hit} = $7; $url_stat{$url}{cache_hit} += $7;
$url_stat{$url}{cache_bytes} = $8; $url_stat{$url}{cache_bytes} += $8;
if ($self->check_exclusions('','',$url)) { if ($self->check_exclusions('','',$url)) {
delete $url_stat{$url}; delete $url_stat{$url};
next; next;
} }
$total_hit += $url_stat{$url}{hits} || 0; $total_hit += $url_stat{$url}{hits} || 0;
$total_bytes += $url_stat{$url}{bytes} || 0; $total_bytes += $url_stat{$url}{bytes} || 0;
$total_duration += $url_stat{$url}{duration} || 0; $total_duration += $url_stat{$url}{duration} || 0;
$total_cache_hit += $url_stat{$url}{cache_hit} || 0; $total_cache_hit += $url_stat{$url}{cache_hit} || 0;
$total_cache_bytes += $url_stat{$url}{cache_bytes} || 0; $total_cache_bytes += $url_stat{$url}{cache_bytes} || 0;
if ($data =~ /;arr_last=(.*)/) {
push(@{$url_stat{$url}{arr_last}}, split(/,/, $1)
);
map { $_ = ucfirst(strftime("%b %d %T", CORE::loc
altime($_))); } @{$url_stat{$url}{arr_last}};
}
} elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);firs t=([^;]*);last=([^;]*);url=(.*)/) { } elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);firs t=([^;]*);last=([^;]*);url=(.*)/) {
my $url = $6; my $url = $6;
$url_stat{$6}{hits} = $1; $url_stat{$6}{hits} += $1;
$url_stat{$6}{bytes} = $2; $url_stat{$6}{bytes} += $2;
$url_stat{$6}{duration} = abs($3); $url_stat{$6}{duration} += abs($3);
$url_stat{$6}{firsthit} = $4 if (!$url_stat{$6}{firsthit} || ($4 < $url_stat{$6}{firsthit})); $url_stat{$6}{firsthit} = $4 if (!$url_stat{$6}{firsthit} || ($4 < $url_stat{$6}{firsthit}));
$url_stat{$6}{lasthit} = $5 if (!$url_stat{$6}{lasthit} | | ($5 > $url_stat{$6}{lasthit})); $url_stat{$6}{lasthit} = $5 if (!$url_stat{$6}{lasthit} | | ($5 > $url_stat{$6}{lasthit}));
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusions('','',$url)) { if ($self->check_exclusions('','',$url)) {
delete $url_stat{$url}; delete $url_stat{$url};
next; next;
} }
} }
$total_hit += $url_stat{$url}{hits} || 0; $total_hit += $url_stat{$url}{hits} || 0;
$total_bytes += $url_stat{$url}{bytes} || 0; $total_bytes += $url_stat{$url}{bytes} || 0;
$total_duration += $url_stat{$url}{duration} || 0; $total_duration += $url_stat{$url}{duration} || 0;
} elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);url= (.*)/) { } elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);url= (.*)/) {
my $url = $4; my $url = $4;
$url_stat{$4}{hits} = $1; $url_stat{$4}{hits} += $1;
$url_stat{$4}{bytes} = $2; $url_stat{$4}{bytes} += $2;
$url_stat{$4}{duration} = abs($3); $url_stat{$4}{duration} = abs($3);
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusions('','',$url)) { if ($self->check_exclusions('','',$url)) {
delete $url_stat{$url}; delete $url_stat{$url};
next; next;
} }
} }
$total_hit += $url_stat{$url}{hits} || 0; $total_hit += $url_stat{$url}{hits} || 0;
$total_bytes += $url_stat{$url}{bytes} || 0; $total_bytes += $url_stat{$url}{bytes} || 0;
$total_duration += $url_stat{$url}{duration} || 0; $total_duration += $url_stat{$url}{duration} || 0;
} }
} }
$infile->close(); $infile->close();
my $trfunit = $self->{TransfertUnit} || 'B';
$trfunit = 'B' if ($trfunit eq 'BYTE');
my $nurl = scalar keys %url_stat; my $nurl = scalar keys %url_stat;
my $t1 = $Translate{"Url_title"};
$t1 =~ s/\%d/$self->{TopNumber}\/$nurl/;
print $$out qq{ print $$out qq{
<h3>$Translate{'Url_number'}: $nurl</h3> <h3>$t1</h3>
<table class="sortable stata"> <table class="sortable stata">
<thead> <thead>
<tr> <tr>
<th>$Translate{'Url'}</th> <th>$Translate{'Url'}</th>
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th> <th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Duration'} (%)</th> <th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Throughput'} (B/s)</th> <th>$Translate{'Throughput'} ($trfunit/s)</th>
<th>$Translate{'Last_visit'}</th>
}; };
print $$out qq{ print $$out qq{
<th>$Translate{'First_visit'}</th> <th>$Translate{'First_visit'}</th>
<th>$Translate{'Last_visit'}</th>
} if ($type eq 'hour'); } if ($type eq 'hour');
print $$out qq{ print $$out qq{
<th>$Translate{'Cost'} $self->{Currency}</th> <th>$Translate{'Cost'} $self->{Currency}</th>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $$out qq{ print $$out qq{
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
}; };
$total_duration = abs($total_duration); $total_duration = abs($total_duration);
my $i = 0;
foreach my $url (sort { $url_stat{$b}{"$self->{OrderUrl}"} <=> $url_stat{ $a}{"$self->{OrderUrl}"} } keys %url_stat) { foreach my $url (sort { $url_stat{$b}{"$self->{OrderUrl}"} <=> $url_stat{ $a}{"$self->{OrderUrl}"} } keys %url_stat) {
my $h_percent = '0.0'; my $h_percent = '0.0';
$h_percent = sprintf("%2.2f", ($url_stat{$url}{hits}/$total_hit) * 100) if ($total_hit); $h_percent = sprintf("%2.2f", ($url_stat{$url}{hits}/$total_hit) * 100) if ($total_hit);
my $b_percent = '0.0'; my $b_percent = '0.0';
$b_percent = sprintf("%2.2f", ($url_stat{$url}{bytes}/$total_byte s) * 100) if ($total_bytes); $b_percent = sprintf("%2.2f", ($url_stat{$url}{bytes}/$total_byte s) * 100) if ($total_bytes);
my $d_percent = '0.0'; my $d_percent = '0.0';
$d_percent = sprintf("%2.2f", ($url_stat{$url}{duration}/$total_d uration) * 100) if ($total_duration); $d_percent = sprintf("%2.2f", ($url_stat{$url}{duration}/$total_d uration) * 100) if ($total_duration);
my $total_cost = sprintf("%2.2f", int($url_stat{$url}{bytes}/1000 000) * $self->{CostPrice}); my $total_cost = sprintf("%2.2f", int($url_stat{$url}{bytes}/1000 000) * $self->{CostPrice});
my $comma_bytes = $self->format_bytes($url_stat{$url}{bytes}); my $comma_bytes = $self->format_bytes($url_stat{$url}{bytes});
my $total_throughput = int($url_stat{$url}{bytes} / (($url_stat{$ url}{duration}/1000) || 1) ); my $total_throughput = int($url_stat{$url}{bytes} / (($url_stat{$ url}{duration}/1000) || 1) );
skipping to change at line 4592 skipping to change at line 4767
$firsthit = ucfirst(strftime("%T", CORE::localtim e($url_stat{$url}{firsthit}))); $firsthit = ucfirst(strftime("%T", CORE::localtim e($url_stat{$url}{firsthit})));
} else { } else {
$firsthit = '-'; $firsthit = '-';
} }
if ($url_stat{$url}{lasthit}) { if ($url_stat{$url}{lasthit}) {
$lasthit = ucfirst(strftime("%T", CORE::localtime ($url_stat{$url}{lasthit}))); $lasthit = ucfirst(strftime("%T", CORE::localtime ($url_stat{$url}{lasthit})));
} else { } else {
$firsthit = '-'; $firsthit = '-';
} }
} }
if (exists $url_stat{$url}{arr_last}) {
$lasthit = qq{
<div class="tooltipLink"><span class="information">$lasthit</span><div class="to
oltip">
<table><tr><th>$Translate{'Last_visit'}</th></tr>
};
foreach my $tm (reverse @{$url_stat{$url}{arr_last}}) {
$lasthit .= "<tr><td>$tm</td></tr>\n";
}
$lasthit .= "</table>\n</div></div>\n";
}
print $$out qq{ print $$out qq{
<tr> <tr>
<td><a href="http://$url/" target="_blank" class="domainLink">$url</a></td> <td><a href="http://$url/" target="_blank" class="domainLink">$url</a></td>
<td>$url_stat{$url}{hits} <span class="italicPercent">($h_percent)</span></td> <td>$url_stat{$url}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td> <td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
<td>$url_stat{$url}{duration} <span class="italicPercent">($d_percent)</span></t d> <td>$url_stat{$url}{duration} <span class="italicPercent">($d_percent)</span></t d>
<td>$comma_throughput</td> <td>$comma_throughput</td>
<td>$lasthit</td>
}; };
print $$out qq{ print $$out qq{
<td>$firsthit</td> <td>$firsthit</td>
<td>$lasthit</td>
} if ($type eq 'hour'); } if ($type eq 'hour');
print $$out qq{ print $$out qq{
<td>$total_cost</td> <td>$total_cost</td>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $$out qq{ print $$out qq{
</tr>}; </tr>};
$i++;
last if ($i > $self->{TopNumber});
} }
my $sortpos = 1; my $sortpos = 1;
$sortpos = 2 if ($self->{OrderUrl} eq 'bytes'); print $$out qq{
$sortpos = 3 if ($self->{OrderUrl} eq 'duration'); </tbody>
</table>
};
}
sub _print_user_denied_detail
{
my ($self, $out, $outdir, $usr, $type) = @_;
$0 = "squid-analyzer: Printing user denied statistics in $outdir";
# Load user URL statistics
my $infile = new IO::File;
$infile->open("$outdir/stat_denied_url.dat") || return;
my %denied_stat = ();
my $total_hits = 0;
while (my $l = <$infile>) {
chomp($l);
my ($user, $data) = split(/\s/, $l);
next if ($user ne $usr);
if ($self->{rebuild}) {
next if (!$self->check_inclusions($user));
next if ($self->check_exclusions($user));
}
if ($data =~ /hits=(\d+);first=([^;]*);last=([^;]*);url=(.*);blac
klist=(.*)/) {
my $hits = $1;
my $firsthit = $2;
my $lasthit = $3;
my $url = $4;
my $blacklist = $5;
if ($self->{rebuild}) {
next if ($self->check_exclusions('','',$url));
}
$total_hits += $hits;
$denied_stat{$url}{hits} += $hits;
if ($lasthit =~ /^(\d{10})\d+/) {
$lasthit = $1;
}
if ($firsthit =~ /^(\d{10})\d+/) {
$firsthit = $1;
}
$denied_stat{$url}{firsthit} = $firsthit if (!$denied_sta
t{$url}{firsthit} || ($firsthit < $denied_stat{$url}{firsthit}));
$denied_stat{$url}{lasthit} = $lasthit if (!$denied_stat{
$url}{lasthit} || ($lasthit > $denied_stat{$url}{lasthit}));
$denied_stat{$url}{users}{$user}++ if ($self->{TopUrlUser
} && $self->{UserReport});
if ($blacklist) {
my %tmp = split(/,/, $blacklist);
foreach my $k (keys %tmp) {
$denied_stat{$url}{blacklist}{$k} += $tmp
{$k};
$denied_stat{$url}{users}{$user}{blacklis
t}{$k} += $tmp{$k} if ($self->{TopUrlUser} && $self->{UserReport});
}
}
}
}
$infile->close();
return if (!$total_hits);
print $$out qq{
<h3>$Translate{'Top_denied_link'}</h3>
<table class="sortable stata">
<thead>
<tr>
<th>$Translate{'Url'}</th>
<th>Blocklist ACLs</th>
<th>$Translate{'Requests'} (%)</th>
<th>$Translate{'Last_visit'}</th>
};
print $$out qq{
<th>$Translate{'First_visit'}</th>
} if ($type eq 'hour');
print $$out qq{
</tr>
</thead>
<tbody>
};
my $i = 0;
foreach my $u (sort { $denied_stat{$b}{hits} <=> $denied_stat{$a}{hits} }
keys %denied_stat) {
my $h_percent = '0.0';
$h_percent = sprintf("%2.2f", ($denied_stat{$u}{hits}/$total_hits
) * 100) if ($total_hits);
my $firsthit = '-';
if ($denied_stat{$u}{firsthit} && ($denied_stat{$u}{firsthit} =~
/^\d{10}(\.\d{3})?$/)) {
$firsthit = ucfirst(strftime("%b %d %T", CORE::localtime(
$denied_stat{$u}{firsthit})));
}
my $lasthit = '-';
if ($denied_stat{$u}{lasthit} && ($denied_stat{$u}{lasthit} =~ /^
\d{10}(\.\d{3})?$/)) {
$lasthit = ucfirst(strftime("%b %d %T", CORE::localtime($
denied_stat{$u}{lasthit})));
}
if ($type eq 'hour') {
if ($denied_stat{$u}{firsthit} && ($denied_stat{$u}{first
hit} =~ /^\d{10}(\.\d{3})?$/)) {
$firsthit = ucfirst(strftime("%T", CORE::localtim
e($denied_stat{$u}{firsthit})));
} else {
$firsthit = '-';
}
if ($denied_stat{$u}{lasthit} && ($denied_stat{$u}{lasthi
t} =~ /^\d{10}(\.\d{3})?$/)) {
$lasthit = ucfirst(strftime("%T", CORE::localtime
($denied_stat{$u}{lasthit})));
} else {
$firsthit = '-';
}
}
my $bl = '-';
if (exists $denied_stat{$u}{blacklist}) {
$bl = '';
foreach my $k (sort keys %{$denied_stat{$u}{blacklist}})
{
$bl .= $k . '=' . $denied_stat{$u}{blacklist}{$k
} . ' ';
}
}
print $$out qq{
<tr><td>
<a href="http://$u/" target="_blank" class="domainLink">$u</a>
</td>
<td>$bl</td>
<td>$denied_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$lasthit</td>
};
print $$out qq{
<td>$firsthit</td>
} if ($type eq 'hour');
$i++;
last if ($i > $self->{TopNumber});
}
print $$out qq{ print $$out qq{
</tbody> </tbody>
</table> </table>
}; };
} }
sub _print_top_url_stat sub _print_top_url_stat
{ {
my ($self, $outdir, $year, $month, $day, $week) = @_; my ($self, $outdir, $year, $month, $day, $week) = @_;
skipping to change at line 4669 skipping to change at line 4978
if ($self->{UserReport}) { if ($self->{UserReport}) {
if ($self->{AnonymizeLogin} && ($user !~ /^Anon[a-zA-Z0-9 ]{16}$/)) { if ($self->{AnonymizeLogin} && ($user !~ /^Anon[a-zA-Z0-9 ]{16}$/)) {
if (!exists $self->{AnonymizedId}{$user}) { if (!exists $self->{AnonymizedId}{$user}) {
$self->{AnonymizedId}{$user} = &anonymize _id(); $self->{AnonymizedId}{$user} = &anonymize _id();
} }
$user = $self->{AnonymizedId}{$user}; $user = $self->{AnonymizedId}{$user};
} }
} else { } else {
$user = '-'; $user = '-';
} }
my $url = '';
my $hits = 0;
my $bytes = 0;
my $duration = 0;
if ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);first=([^ ;]*);last=([^;]*);url=(.*?);cache_hit=(\d*);cache_bytes=(\d*)/) { if ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);first=([^ ;]*);last=([^;]*);url=(.*?);cache_hit=(\d*);cache_bytes=(\d*)/) {
my $url = $6; $url = $6;
$url_stat{$url}{hits} = $1; $hits = $1;
$url_stat{$url}{bytes} = $2; $bytes = $2;
$url_stat{$url}{duration} = abs($3); $duration = abs($3);
$url_stat{$url}{firsthit} = $4 if (!$url_stat{$url}{first hit} || ($4 < $url_stat{$url}{firsthit})); $url_stat{$url}{firsthit} = $4 if (!$url_stat{$url}{first hit} || ($4 < $url_stat{$url}{firsthit}));
$url_stat{$url}{lasthit} = $5 if (!$url_stat{$url}{lasthi t} || ($5 > $url_stat{$url}{lasthit})); $url_stat{$url}{lasthit} = $5 if (!$url_stat{$url}{lasthi t} || ($5 > $url_stat{$url}{lasthit}));
$url_stat{$url}{cache_hit} = $7; $url_stat{$url}{cache_hit} += $7;
$url_stat{$url}{cache_bytes} = $8; $url_stat{$url}{cache_bytes} += $8;
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusions('','',$url)) { if ($self->check_exclusions('','',$url)) {
delete $url_stat{$url}; delete $url_stat{$url};
next; next;
} }
} }
$total_hits += $url_stat{$url}{hits} || 0;
$total_bytes += $url_stat{$url}{bytes} || 0;
$total_duration += $url_stat{$url}{duration} || 0;
$total_cache_hit += $url_stat{$url}{cache_hit} || 0; $total_cache_hit += $url_stat{$url}{cache_hit} || 0;
$total_cache_bytes += $url_stat{$url}{cache_bytes} || 0; $total_cache_bytes += $url_stat{$url}{cache_bytes} || 0;
} elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);firs t=([^;]*);last=([^;]*);url=(.*)/) { } elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);firs t=([^;]*);last=([^;]*);url=(.*)/) {
my $url = $6; $url = $6;
$url_stat{$url}{hits} = $1; $hits = $1;
$url_stat{$url}{bytes} = $2; $bytes = $2;
$url_stat{$url}{duration} = abs($3); $duration = abs($3);
$url_stat{$url}{firsthit} = $4 if (!$url_stat{$url}{first hit} || ($4 < $url_stat{$url}{firsthit})); $url_stat{$url}{firsthit} = $4 if (!$url_stat{$url}{first hit} || ($4 < $url_stat{$url}{firsthit}));
$url_stat{$url}{lasthit} = $5 if (!$url_stat{$url}{lasthi t} || ($5 > $url_stat{$url}{lasthit})); $url_stat{$url}{lasthit} = $5 if (!$url_stat{$url}{lasthi t} || ($5 > $url_stat{$url}{lasthit}));
$url_stat{$url}{users}{$user}++ if ($self->{TopUrlUser} & & $self->{UserReport});
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusions('','',$url)) { if ($self->check_exclusions('','',$url)) {
delete $url_stat{$url}; delete $url_stat{$url};
next; next;
} }
} }
$total_hits += $url_stat{$url}{hits} || 0;
$total_bytes += $url_stat{$url}{bytes} || 0;
$total_duration += $url_stat{$url}{duration} || 0;
} elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);url= (.*)/) { } elsif ($data =~ /hits=(\d+);bytes=(\d+);duration=([\-\d]+);url= (.*)/) {
my $url = $4; $url = $4;
$url_stat{$url}{hits} = $1; $hits = $1;
$url_stat{$url}{bytes} = $2; $bytes = $2;
$url_stat{$url}{duration} = abs($3); $duration = abs($3);
$url_stat{$url}{users}{$user}++ if ($self->{TopUrlUser} &
& $self->{UserReport});
if ($self->{rebuild}) { if ($self->{rebuild}) {
if ($self->check_exclusions('','',$url)) { if ($self->check_exclusions('','',$url)) {
delete $url_stat{$url}; delete $url_stat{$url};
next; next;
} }
} }
$total_hits += $url_stat{$url}{hits} || 0; }
$total_bytes += $url_stat{$url}{bytes} || 0; $url_stat{$url}{hits} += $hits;
$total_duration += $url_stat{$url}{duration} || 0; $url_stat{$url}{bytes} += $bytes;
$url_stat{$url}{duration} += $duration;
$total_hits += $url_stat{$url}{hits} || 0;
$total_bytes += $url_stat{$url}{bytes} || 0;
$total_duration += $url_stat{$url}{duration} || 0;
if ($url && $self->{TopUrlUser} && $self->{UserReport}) {
$url_stat{$url}{users}{$user}{hits} += $hits;
$url_stat{$url}{users}{$user}{bytes} += $bytes;
$url_stat{$url}{users}{$user}{duration} += $bytes;
} }
} }
$infile->close(); $infile->close();
# Store number of urls # Store number of urls
my $nurl = scalar keys %url_stat; my $nurl = scalar keys %url_stat;
my $outf = new IO::File; my $outf = new IO::File;
$outf->open(">>$outdir/stat_count.dat") || return; $outf->open(">>$outdir/stat_count.dat") || return;
flock($outf, 2) || die "FATAL: can't acquire lock on file $outdir/stat_co unt.dat, $!\n"; flock($outf, 2) || die "FATAL: can't acquire lock on file $outdir/stat_co unt.dat, $!\n";
$outf->print("urls:$nurl\n"); $outf->print("urls:$nurl\n");
$outf->close; $outf->close;
my $file = $outdir . '/url.html'; my $file = $outdir . '/url.html';
my $out = new IO::File; my $out = new IO::File;
$out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\ n"); $out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\ n");
my $sortpos = 1; my $sortpos = 1;
$sortpos = 2 if ($self->{OrderUrl} eq 'bytes');
$sortpos = 3 if ($self->{OrderUrl} eq 'duration'); my $trfunit = $self->{TransfertUnit} || 'B';
$trfunit = 'B' if ($trfunit eq 'BYTE');
# Print the HTML header # Print the HTML header
my $cal = 'SA_CALENDAR_SA'; my $cal = 'SA_CALENDAR_SA';
$cal = '' if ($week); $cal = '' if ($week);
$self->_print_header(\$out, $self->{menu}, $cal, $sortpos); $self->_print_header(\$out, $self->{menu}, $cal, $sortpos);
print $out "<h3>$Translate{'Url_number'}: $nurl</h3>\n"; print $out "<h3>$Translate{'Url_number'}: $nurl</h3>\n";
for my $tpe ('Hits', 'Bytes', 'Duration') { for my $tpe ('Hits', 'Bytes', 'Duration') {
my $t1 = $Translate{"Url_${tpe}_title"}; my $t1 = $Translate{"Url_${tpe}_title"};
$t1 =~ s/\%d/$self->{TopNumber}/; $t1 =~ s/\%d/$self->{TopNumber}/;
if ($tpe eq 'Hits') { if ($tpe eq 'Hits') {
print $out $self->_print_title($t1, $stat_date, $week); print $out $self->_print_title($t1, $stat_date, $week);
} else { } else {
print $out "<h4>$t1 $stat_date</h4><div class=\"line-sepa rator\"></div>\n"; print $out "<h4>$t1 $stat_date</h4><div class=\"line-sepa rator\"></div>\n";
} }
print $out qq{ print $out qq{
<table class="sortable stata"> <table class="sortable stata">
<thead> <thead>
<tr> <tr>
<th>$Translate{'Url'}</th> <th>$Translate{'Url'}</th>
};
if ($tpe eq 'Hits') {
print $out qq{
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th> <th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Duration'} (%)</th> <th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Throughput'} (B/s)</th> }
} elsif ($tpe eq 'Bytes') {
print $out qq{
<th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Requests'} (%)</th>
<th>$Translate{'Duration'} (%)</th>
}
} else {
print $out qq{
<th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th>
}
}
print $out qq{
<th>$Translate{'Throughput'} ($trfunit/s)</th>
<th>$Translate{'Last_visit'}</th>
}; };
print $out qq{ print $out qq{
<th>$Translate{'First_visit'}</th> <th>$Translate{'First_visit'}</th>
<th>$Translate{'Last_visit'}</th>
} if ($type eq 'hour'); } if ($type eq 'hour');
print $out qq{ print $out qq{
<th>$Translate{'Cost'} $self->{Currency}</th> <th>$Translate{'Cost'} $self->{Currency}</th>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $out qq{ print $out qq{
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
}; };
$total_duration = abs($total_duration); $total_duration = abs($total_duration);
skipping to change at line 4814 skipping to change at line 5145
$firsthit = '-'; $firsthit = '-';
} }
if ($url_stat{$u}{lasthit}) { if ($url_stat{$u}{lasthit}) {
$lasthit = ucfirst(strftime("%T", CORE::l ocaltime($url_stat{$u}{lasthit}))); $lasthit = ucfirst(strftime("%T", CORE::l ocaltime($url_stat{$u}{lasthit})));
} else { } else {
$firsthit = '-'; $firsthit = '-';
} }
} }
print $out "<tr><td>\n"; print $out "<tr><td>\n";
if (exists $url_stat{$u}{users} && $self->{UserReport}) { if (exists $url_stat{$u}{users} && $self->{UserReport}) {
print $out qq{ my $label = 'Duration';
<div class="tooltipLink"><span class="information"><a href="http://$u/" target=" if ($tpe eq 'Bytes') {
_blank" class="domainLink">$u</a></span><div class="tooltip"> $label = 'Megabytes';
<table><tr><th>$Translate{'User'}</th><th>$Translate{'Count'}</th></tr> } elsif ($tpe eq 'Hits') {
}; $label = 'Requests';
}
print $out "<div class=\"tooltipLink\"><span clas
s=\"information\"><a href=\"http://$u/\" target=\"_blank\" class=\"domainLink\">
$u</a></span><div class=\"tooltip\"><table><tr><th>$Translate{'User'}</th><th>$T
ranslate{$label}</th></tr>\n";
my $k = 1; my $k = 1;
foreach my $user (sort { $url_stat{$u}{users}{$b} foreach my $user (sort { $url_stat{$u}{users}{$b}
<=> $url_stat{$u}{users}{$a} } keys %{$url_stat{$u}{users}}) { {lc($tpe)} <=> $url_stat{$u}{users}{$a}{lc($tpe)} } keys %{$url_stat{$u}{users}}
print $out "<tr><td>$user</td><td>$url_st ) {
at{$u}{users}{$user}</td></tr>\n"; my $value = $url_stat{$u}{users}{$user}{l
c($tpe)};
if ($tpe eq 'Bytes') {
$value = $self->format_bytes($val
ue);
} elsif ($tpe eq 'Duration') {
$value = &parse_duration(int($val
ue/1000));
}
my $usr_lbl = $user;
$usr_lbl =~ s/_SPC_/ /g;
print $out "<tr><td>$usr_lbl</td><td>$val
ue</td></tr>\n";
$k++; $k++;
last if ($k > $self->{TopUrlUser}); last if ($k > $self->{TopUrlUser});
} }
print $out "</table>\n</div></div>\n"; print $out "</table>\n</div></div>\n";
} else { } else {
print $out "<a href=\"http://$u/\" target=\"_blan k\" class=\"domainLink\">$u</a>\n"; print $out "<a href=\"http://$u/\" target=\"_blan k\" class=\"domainLink\">$u</a>\n";
} }
print $out qq{ print $out qq{</td>};
</td> if ($tpe eq 'Hits') {
print $out qq{
<td>$url_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td> <td>$url_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td> <td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
<td>$duration <span class="italicPercent">($d_percent)</span></td> <td>$duration <span class="italicPercent">($d_percent)</span></td>
};
} elsif ($tpe eq 'Bytes') {
print $out qq{
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
<td>$url_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$duration <span class="italicPercent">($d_percent)</span></td>
};
} else {
print $out qq{
<td>$duration <span class="italicPercent">($d_percent)</span></td>
<td>$url_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
};
}
print $out qq{
<td>$comma_throughput</span></td> <td>$comma_throughput</span></td>
<td>$lasthit</td>
}; };
print $out qq{ print $out qq{
<td>$firsthit</td> <td>$firsthit</td>
<td>$lasthit</td>
} if ($type eq 'hour'); } if ($type eq 'hour');
print $out qq{ print $out qq{
<td>$total_cost</td> <td>$total_cost</td>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $out qq{ print $out qq{</tr>};
</tr>};
$i++; $i++;
last if ($i > $self->{TopNumber}); last if ($i > $self->{TopNumber});
} }
print $out qq{</tbody></table>}; print $out qq{</tbody></table>};
# Do not show other tables if required # Do not show other tables if required
last if ($self->{UrlHitsOnly}); last if ($self->{UrlHitsOnly});
} }
print $out qq{ print $out qq{
<div class="uplink"> <div class="uplink">
skipping to change at line 4912 skipping to change at line 5269
if (!exists $self->{AnonymizedId}{$user}) { if (!exists $self->{AnonymizedId}{$user}) {
$self->{AnonymizedId}{$user} = &anonymize _id(); $self->{AnonymizedId}{$user} = &anonymize _id();
} }
$user = $self->{AnonymizedId}{$user}; $user = $self->{AnonymizedId}{$user};
} }
} else { } else {
$user = '-'; $user = '-';
} }
if ($data =~ /hits=(\d+);first=([^;]*);last=([^;]*);url=(.*);blac klist=(.*)/) { if ($data =~ /hits=(\d+);first=([^;]*);last=([^;]*);url=(.*);blac klist=(.*)/) {
my $hits = $1;
my $firsthit = $2;
my $lasthit = $3;
my $url = $4;
my $blacklist = $5;
if ($self->{rebuild}) { if ($self->{rebuild}) {
next if ($self->check_exclusions('','',$4)); next if ($self->check_exclusions('','',$url));
} }
$denied_stat{$4}{hits} = $1; $total_hits += $hits;
$denied_stat{$4}{firsthit} = $2 if (!$denied_stat{$4}{fir $denied_stat{$url}{hits} += $hits;
sthit} || ($2 < $denied_stat{$4}{firsthit})); if ($lasthit =~ /^(\d{10})\d+/) {
$denied_stat{$4}{lasthit} = $3 if (!$denied_stat{$4}{last $lasthit = $1;
hit} || ($3 > $denied_stat{$4}{lasthit})); }
$total_hits += $1; if ($firsthit =~ /^(\d{10})\d+/) {
$denied_stat{$4}{users}{$user}++ if ($self->{TopUrlUser} $firsthit = $1;
&& $self->{UserReport}); }
if ($5) { $denied_stat{$url}{firsthit} = $firsthit if (!$denied_sta
my %tmp = split(/,/, $5); t{$url}{firsthit} || ($firsthit < $denied_stat{$url}{firsthit}));
$denied_stat{$url}{lasthit} = $lasthit if (!$denied_stat{
$url}{lasthit} || ($lasthit > $denied_stat{$url}{lasthit}));
$denied_stat{$url}{users}{$user}++ if ($self->{TopUrlUser
} && $self->{UserReport});
if ($blacklist) {
my %tmp = split(/,/, $blacklist);
foreach my $k (keys %tmp) { foreach my $k (keys %tmp) {
$denied_stat{$4}{blacklist}{$k} += $tmp{$ $denied_stat{$url}{blacklist}{$k} += $tmp
k}; {$k};
$denied_stat{$4}{users}{$user}{blacklist} $denied_stat{$url}{users}{$user}{blacklis
{$k} += $tmp{$k} if ($self->{TopUrlUser} && $self->{UserReport}); t}{$k} += $tmp{$k} if ($self->{TopUrlUser} && $self->{UserReport});
$total_acl += $tmp{$k}; $total_acl += $tmp{$k};
} }
} }
} }
} }
$infile->close(); $infile->close();
# Store number of denieds # Store number of denieds
my $ndenied = scalar keys %denied_stat; my $ndenied = scalar keys %denied_stat;
my $outf = new IO::File; my $outf = new IO::File;
skipping to change at line 4973 skipping to change at line 5341
} }
} }
if (scalar keys %data_acl) { if (scalar keys %data_acl) {
print $out $self->_print_title($Translate{"Blocklist_acl_title"}, $stat_date, $week); print $out $self->_print_title($Translate{"Blocklist_acl_title"}, $stat_date, $week);
my $squidguard_acl = $self->flotr2_piegraph(1, 'squidguard_acl', $Translate{"Blocklist_acl_title"}, $Translate{'Blocklist_acl_graph'}, '', %data_ acl); my $squidguard_acl = $self->flotr2_piegraph(1, 'squidguard_acl', $Translate{"Blocklist_acl_title"}, $Translate{'Blocklist_acl_graph'}, '', %data_ acl);
print $out qq{<table class="graphs"><tr><td>$squidguard_acl</td>< /tr></table>}; print $out qq{<table class="graphs"><tr><td>$squidguard_acl</td>< /tr></table>};
} }
my $t1 = $Translate{"Url_Hits_title"}; my $t1 = $Translate{"Url_Hits_title"};
$t1 =~ s/\%d/$self->{TopNumber}/; $t1 =~ s/\%d/$self->{TopNumber}/;
print $out $self->_print_title($t1, $stat_date, $week); print $out $self->_print_title($t1, $stat_date, $week);
print $out qq{ print $out qq{
<table class="sortable stata"> <table class="sortable stata">
<thead> <thead>
<tr> <tr>
<th>$Translate{'Url'}</th> <th>$Translate{'Url'}</th>
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{'Last_visit'}</th>
}; };
print $out qq{ print $out qq{
<th>$Translate{'First_visit'}</th> <th>$Translate{'First_visit'}</th>
<th>$Translate{'Last_visit'}</th>
} if ($type eq 'hour'); } if ($type eq 'hour');
print $out qq{<th>Blocklist ACLs</th>}; print $out qq{<th>Blocklist ACLs</th>};
print $out qq{ print $out qq{
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
}; };
my $i = 0; my $i = 0;
foreach my $u (sort { $denied_stat{$b}{hits} <=> $denied_stat{$a}{hits} } keys %denied_stat) { foreach my $u (sort { $denied_stat{$b}{hits} <=> $denied_stat{$a}{hits} } keys %denied_stat) {
my $h_percent = '0.0'; my $h_percent = '0.0';
$h_percent = sprintf("%2.2f", ($denied_stat{$u}{hits}/$total_hits ) * 100) if ($total_hits); $h_percent = sprintf("%2.2f", ($denied_stat{$u}{hits}/$total_hits ) * 100) if ($total_hits);
my $firsthit = '-'; my $firsthit = '-';
if ($denied_stat{$u}{firsthit}) { if ($denied_stat{$u}{firsthit} && ($denied_stat{$u}{firsthit} =~
$firsthit = ucfirst(strftime("%b %d %T", localtime($denie /^\d{10}(\.\d{3})?$/)) {
d_stat{$u}{firsthit}))); $firsthit = ucfirst(strftime("%b %d %T", CORE::localtime(
$denied_stat{$u}{firsthit})));
} }
my $lasthit = '-'; my $lasthit = '-';
if ($denied_stat{$u}{lasthit}) { if ($denied_stat{$u}{lasthit} && ($denied_stat{$u}{lasthit} =~ /^
$lasthit = ucfirst(strftime("%b %d %T", localtime($denied \d{10}(\.\d{3})?$/)) {
_stat{$u}{lasthit}))); $lasthit = ucfirst(strftime("%b %d %T", CORE::localtime($
denied_stat{$u}{lasthit})));
} }
if ($type eq 'hour') { if ($type eq 'hour') {
if ($denied_stat{$u}{firsthit}) { if ($denied_stat{$u}{firsthit} && ($denied_stat{$u}{first
$firsthit = ucfirst(strftime("%T", localtime($den hit} =~ /^\d{10}(\.\d{3})?$/)) {
ied_stat{$u}{firsthit}))); $firsthit = ucfirst(strftime("%T", CORE::localtim
e($denied_stat{$u}{firsthit})));
} else { } else {
$firsthit = '-'; $firsthit = '-';
} }
if ($denied_stat{$u}{lasthit}) { if ($denied_stat{$u}{lasthit} && ($denied_stat{$u}{lasthi
$lasthit = ucfirst(strftime("%T", localtime($deni t} =~ /^\d{10}(\.\d{3})?$/)) {
ed_stat{$u}{lasthit}))); $lasthit = ucfirst(strftime("%T", CORE::localtime
($denied_stat{$u}{lasthit})));
} else { } else {
$firsthit = '-'; $firsthit = '-';
} }
} }
print $out "<tr><td>\n"; print $out "<tr><td>\n";
if (exists $denied_stat{$u}{users} && $self->{UserReport}) { if (exists $denied_stat{$u}{users} && $self->{UserReport}) {
print $out qq{ print $out qq{
<div class="tooltipLink"><span class="information"><a href="http://$u/" target=" _blank" class="domainLink">$u</a></span><div class="tooltip"> <div class="tooltipLink"><span class="information"><a href="http://$u/" target=" _blank" class="domainLink">$u</a></span><div class="tooltip">
<table><tr><th>$Translate{'User'}</th><th>$Translate{'Count'}</th></tr> <table><tr><th>$Translate{'User'}</th><th>$Translate{'Count'}</th></tr>
}; };
my $k = 1; my $k = 1;
foreach my $user (sort { $denied_stat{$u}{users}{$b} <=> $denied_stat{$u}{users}{$a} } keys %{$denied_stat{$u}{users}}) { foreach my $user (sort { $denied_stat{$u}{users}{$b} <=> $denied_stat{$u}{users}{$a} } keys %{$denied_stat{$u}{users}}) {
print $out "<tr><td>$user</td><td>$denied_stat{$u my $usr_lbl = $user;
}{users}{$user}</td></tr>\n"; $usr_lbl =~ s/_SPC_/ /g;
print $out "<tr><td>$usr_lbl</td><td>$denied_stat
{$u}{users}{$user}</td></tr>\n";
$k++; $k++;
last if ($k > $self->{TopUrlUser}); last if ($k > $self->{TopUrlUser});
} }
print $out "</table>\n</div></div>"; print $out "</table>\n</div></div>";
} else { } else {
print $out "<a href=\"http://$u/\" target=\"_blank\" clas s=\"domainLink\">$u</a>\n"; print $out "<a href=\"http://$u/\" target=\"_blank\" clas s=\"domainLink\">$u</a>\n";
} }
print $out qq{ print $out qq{
</td> </td>
<td>$denied_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td> <td>$denied_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$lasthit</td>
}; };
print $out qq{ print $out qq{
<td>$firsthit</td> <td>$firsthit</td>
<td>$lasthit</td>
} if ($type eq 'hour'); } if ($type eq 'hour');
my $bl = '-'; my $bl = '-';
if (exists $denied_stat{$u}{blacklist}) { if (exists $denied_stat{$u}{blacklist}) {
$bl = ''; $bl = '';
foreach my $k (sort keys %{$denied_stat{$u}{blacklist}}) { foreach my $k (sort keys %{$denied_stat{$u}{blacklist}}) {
$bl .= $k . '=' . $denied_stat{$u}{blacklist}{$k } . ' '; $bl .= $k . '=' . $denied_stat{$u}{blacklist}{$k } . ' ';
} }
} }
print $out qq{ print $out qq{
<td>$bl</td> <td>$bl</td>
skipping to change at line 5147 skipping to change at line 5518
$url = $4; $url = $4;
$hits = $1; $hits = $1;
$bytes = $2; $bytes = $2;
$duration = abs($3); $duration = abs($3);
} }
if ($self->{rebuild}) { if ($self->{rebuild}) {
next if ($self->check_exclusions('','',$url)); next if ($self->check_exclusions('','',$url));
} }
$url =~ s/:\d+//;
my $done = 0; my $done = 0;
if ($url !~ /\.\d+$/) { if ($url !~ /\.\d+$/) {
if ($url =~ $tld_pattern1) { if ($url =~ $tld_pattern1) {
$domain_stat{"$1$2"}{hits} += $hits; $domain_stat{"$1$2"}{hits} += $hits;
$domain_stat{"$1$2"}{bytes} += $bytes; $domain_stat{"$1$2"}{bytes} += $bytes;
$domain_stat{"$1$2"}{duration} += $duration; $domain_stat{"$1$2"}{duration} += $duration;
$domain_stat{"$1$2"}{firsthit} = $first if (!$dom ain_stat{"$1$2"}{firsthit} || ($first < $domain_stat{"$1$2"}{firsthit})); $domain_stat{"$1$2"}{firsthit} = $first if (!$dom ain_stat{"$1$2"}{firsthit} || ($first < $domain_stat{"$1$2"}{firsthit}));
$domain_stat{"$1$2"}{lasthit} = $last if (!$domai n_stat{"$1$2"}{lasthit} || ($last > $domain_stat{"$1$2"}{lasthit})); $domain_stat{"$1$2"}{lasthit} = $last if (!$domai n_stat{"$1$2"}{lasthit} || ($last > $domain_stat{"$1$2"}{lasthit}));
$domain_stat{"$1$2"}{users}{$user}++ if ($self->{ TopUrlUser} && $self->{UserReport});
$domain_stat{"$1$2"}{cache_hit} += $cache_hit; $domain_stat{"$1$2"}{cache_hit} += $cache_hit;
$domain_stat{"$1$2"}{cache_bytes} += $cache_bytes ; $domain_stat{"$1$2"}{cache_bytes} += $cache_bytes ;
$perdomain{"$2"}{hits} += $hits; $perdomain{"$2"}{hits} += $hits;
$perdomain{"$2"}{bytes} += $bytes; $perdomain{"$2"}{bytes} += $bytes;
$perdomain{"$2"}{cache_hit} += $cache_hit; $perdomain{"$2"}{cache_hit} += $cache_hit;
$perdomain{"$2"}{cache_bytes} += $cache_bytes; $perdomain{"$2"}{cache_bytes} += $cache_bytes;
$done = 1; $done = 1;
} elsif ($url =~ $tld_pattern2) { } elsif ($url =~ $tld_pattern2) {
$domain_stat{"$1$2"}{hits} += $hits; $domain_stat{"$1$2"}{hits} += $hits;
$domain_stat{"$1$2"}{bytes} += $bytes; $domain_stat{"$1$2"}{bytes} += $bytes;
$domain_stat{"$1$2"}{duration} += $duration; $domain_stat{"$1$2"}{duration} += $duration;
$domain_stat{"$1$2"}{firsthit} = $first if (!$dom ain_stat{"$1$2"}{firsthit} || ($first < $domain_stat{"$1$2"}{firsthit})); $domain_stat{"$1$2"}{firsthit} = $first if (!$dom ain_stat{"$1$2"}{firsthit} || ($first < $domain_stat{"$1$2"}{firsthit}));
$domain_stat{"$1$2"}{lasthit} = $last if (!$domai n_stat{"$1$2"}{lasthit} || ($last > $domain_stat{"$1$2"}{lasthit})); $domain_stat{"$1$2"}{lasthit} = $last if (!$domai n_stat{"$1$2"}{lasthit} || ($last > $domain_stat{"$1$2"}{lasthit}));
$domain_stat{"$1$2"}{users}{$user}++ if ($self->{ TopUrlUser} && $self->{UserReport});
$domain_stat{"$1$2"}{cache_hit} += $cache_hit; $domain_stat{"$1$2"}{cache_hit} += $cache_hit;
$domain_stat{"$1$2"}{cache_bytes} += $cache_bytes ; $domain_stat{"$1$2"}{cache_bytes} += $cache_bytes ;
$perdomain{"$2"}{hits} += $hits; $perdomain{"$2"}{hits} += $hits;
$perdomain{"$2"}{bytes} += $bytes; $perdomain{"$2"}{bytes} += $bytes;
$perdomain{"$2"}{cache_hit} += $cache_hit; $perdomain{"$2"}{cache_hit} += $cache_hit;
$perdomain{"$2"}{cache_bytes} += $cache_bytes; $perdomain{"$2"}{cache_bytes} += $cache_bytes;
$done = 1; $done = 1;
} }
if ($self->{TopUrlUser} && $self->{UserReport}) {
$domain_stat{"$1$2"}{users}{$user}{hits} += $hits
;
$domain_stat{"$1$2"}{users}{$user}{bytes}+= $byte
s;
$domain_stat{"$1$2"}{users}{$user}{duration}+= $d
uration;
}
} }
if (!$done) { if (!$done) {
$perdomain{'others'}{hits} += $hits; $perdomain{'others'}{hits} += $hits;
$perdomain{'others'}{bytes} += $bytes; $perdomain{'others'}{bytes} += $bytes;
$domain_stat{'unknown'}{hits} += $hits; $domain_stat{'unknown'}{hits} += $hits;
$domain_stat{'unknown'}{bytes} += $bytes; $domain_stat{'unknown'}{bytes} += $bytes;
$domain_stat{'unknown'}{duration} += $duration; $domain_stat{'unknown'}{duration} += $duration;
$domain_stat{'unknown'}{firsthit} = $first if (!$domain_s tat{'unknown'}{firsthit} || ($first < $domain_stat{'unknown'}{firsthit})); $domain_stat{'unknown'}{firsthit} = $first if (!$domain_s tat{'unknown'}{firsthit} || ($first < $domain_stat{'unknown'}{firsthit}));
$domain_stat{'unknown'}{lasthit} = $last if (!$domain_sta t{'unknown'}{lasthit} || ($last > $domain_stat{'unknown'}{lasthit})); $domain_stat{'unknown'}{lasthit} = $last if (!$domain_sta t{'unknown'}{lasthit} || ($last > $domain_stat{'unknown'}{lasthit}));
$domain_stat{'unknown'}{users}{$user}++ if ($self->{TopUr if ($self->{TopUrlUser} && $self->{UserReport}) {
lUser} && $self->{UserReport}); $domain_stat{'unknown'}{users}{$user}{hits} += $h
its;
$domain_stat{'unknown'}{users}{$user}{bytes}+= $b
ytes;
$domain_stat{'unknown'}{users}{$user}{duration}+=
$duration;
}
$domain_stat{'unknown'}{cache_hit} += $cache_hit; $domain_stat{'unknown'}{cache_hit} += $cache_hit;
$domain_stat{'unknown'}{cache_bytes} += $cache_bytes; $domain_stat{'unknown'}{cache_bytes} += $cache_bytes;
$perdomain{'others'}{cache_hit} += $cache_hit; $perdomain{'others'}{cache_hit} += $cache_hit;
$perdomain{'others'}{cache_bytes} += $cache_bytes; $perdomain{'others'}{cache_bytes} += $cache_bytes;
} }
$total_hits += $hits; $total_hits += $hits;
$total_bytes += $bytes; $total_bytes += $bytes;
$total_duration += $duration; $total_duration += $duration;
$total_cache_hit += $cache_hit; $total_cache_hit += $cache_hit;
$total_cache_bytes += $cache_bytes; $total_cache_bytes += $cache_bytes;
skipping to change at line 5214 skipping to change at line 5594
$outf->open(">>$outdir/stat_count.dat") || return; $outf->open(">>$outdir/stat_count.dat") || return;
flock($outf, 2) || die "FATAL: can't acquire lock on file $outdir/stat_co unt.dat, $!\n"; flock($outf, 2) || die "FATAL: can't acquire lock on file $outdir/stat_co unt.dat, $!\n";
$outf->print("domains:$ndom\n"); $outf->print("domains:$ndom\n");
$outf->close; $outf->close;
my $file = $outdir . '/domain.html'; my $file = $outdir . '/domain.html';
my $out = new IO::File; my $out = new IO::File;
$out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\ n"); $out->open(">$file") || $self->localdie("ERROR: Unable to open $file. $!\ n");
my $sortpos = 1; my $sortpos = 1;
$sortpos = 2 if ($self->{OrderUrl} eq 'bytes');
$sortpos = 3 if ($self->{OrderUrl} eq 'duration');
# Print the HTML header # Print the HTML header
my $cal = 'SA_CALENDAR_SA'; my $cal = 'SA_CALENDAR_SA';
$cal = '' if ($week); $cal = '' if ($week);
$self->_print_header(\$out, $self->{menu}, $cal, $sortpos); $self->_print_header(\$out, $self->{menu}, $cal, $sortpos);
print $out "<h3>$Translate{'Domain_number'}: $ndom</h3>\n"; print $out "<h3>$Translate{'Domain_number'}: $ndom</h3>\n";
$total_hits ||= 1; $total_hits ||= 1;
$total_bytes ||= 1; $total_bytes ||= 1;
for my $tpe ('Hits', 'Bytes', 'Duration') { for my $tpe ('Hits', 'Bytes', 'Duration') {
skipping to change at line 5325 skipping to change at line 5703
<div id="container"> <div id="container">
$domain2_bytes $domain2_bytes
</div> </div>
</td></tr></table>}; </td></tr></table>};
$domain_bytes = ''; $domain_bytes = '';
$domain2_bytes = ''; $domain2_bytes = '';
%data = (); %data = ();
} else { } else {
print $out "<h4>$t1 $stat_date</h4><div class=\"line-sepa rator\"></div>\n"; print $out "<h4>$t1 $stat_date</h4><div class=\"line-sepa rator\"></div>\n";
} }
my $trfunit = $self->{TransfertUnit} || 'B';
$trfunit = 'B' if ($trfunit eq 'BYTE');
print $out qq{ print $out qq{
<table class="sortable stata"> <table class="sortable stata">
<thead> <thead>
<tr> <tr>
<th>$Translate{'Url'}</th> <th>$Translate{'Url'}</th>
};
if ($tpe eq 'Hits') {
print $out qq{
<th>$Translate{'Requests'} (%)</th> <th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th> <th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Duration'} (%)</th> <th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Throughput'} (B/s)</th> };
} elsif ($tpe eq 'Bytes') {
print $out qq{
<th>$Translate{$self->{TransfertUnit}} (%)</th>
<th>$Translate{'Requests'} (%)</th>
<th>$Translate{'Duration'} (%)</th>
};
} else {
print $out qq{
<th>$Translate{'Duration'} (%)</th>
<th>$Translate{'Requests'} (%)</th>
<th>$Translate{$self->{TransfertUnit}} (%)</th>
};
}
print $out qq{
<th>$Translate{'Throughput'} ($trfunit/s)</th>
<th>$Translate{'Last_visit'}</th>
}; };
print $out qq{ print $out qq{
<th>$Translate{'First_visit'}</th> <th>$Translate{'First_visit'}</th>
<th>$Translate{'Last_visit'}</th>
} if ($type eq 'hour'); } if ($type eq 'hour');
print $out qq{ print $out qq{
<th>$Translate{'Cost'} $self->{Currency}</th> <th>$Translate{'Cost'} $self->{Currency}</th>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $out qq{ print $out qq{
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
}; };
$total_duration = abs($total_duration); $total_duration = abs($total_duration);
skipping to change at line 5385 skipping to change at line 5785
if ($domain_stat{$u}{lasthit}) { if ($domain_stat{$u}{lasthit}) {
$lasthit = ucfirst(strftime("%T", CORE::l ocaltime($domain_stat{$u}{lasthit}))); $lasthit = ucfirst(strftime("%T", CORE::l ocaltime($domain_stat{$u}{lasthit})));
} else { } else {
$lasthit = '-'; $lasthit = '-';
} }
} }
print $out "<tr><td>\n"; print $out "<tr><td>\n";
if (exists $domain_stat{$u}{users} && $self->{UserReport} ) { if (exists $domain_stat{$u}{users} && $self->{UserReport} ) {
my $dname = "*.$u"; my $dname = "*.$u";
$dname = $u if (grep(/^$u$/i, 'localhost', 'unkno wn')); $dname = $u if (grep(/^$u$/i, 'localhost', 'unkno wn'));
print $out qq{ my $label = 'Duration';
<div class="tooltipLink"><span class="information">$dname</span><div class="tool if ($tpe eq 'Bytes') {
tip"> $label = 'Megabytes';
<table><tr><th>$Translate{'User'}</th><th>$Translate{'Count'}</th></tr> } elsif ($tpe eq 'Hits') {
}; $label = 'Requests';
}
print $out "<div class=\"tooltipLink\"><span clas
s=\"information\">$dname</span><div class=\"tooltip\"><table><tr><th>$Translate{
'User'}</th><th>$Translate{$label}</th></tr>\n";
my $k = 1; my $k = 1;
foreach my $user (sort { $domain_stat{$u}{users}{ foreach my $user (sort { $domain_stat{$u}{users}{
$b} <=> $domain_stat{$u}{users}{$a} } keys %{$domain_stat{$u}{users}}) { $b}{lc($tpe)} <=> $domain_stat{$u}{users}{$a}{lc($tpe)} } keys %{$domain_stat{$u
print $out "<tr><td>$user</td><td>$domain }{users}}) {
_stat{$u}{users}{$user}</td></tr>\n"; my $value = $domain_stat{$u}{users}{$user
}{lc($tpe)};
if ($tpe eq 'Bytes') {
$value = $self->format_bytes($val
ue);
} elsif ($tpe eq 'Duration') {
$value = &parse_duration(int($val
ue/1000));
}
my $usr_lbl = $user;
$usr_lbl =~ s/_SPC_/ /g;
print $out "<tr><td>$usr_lbl</td><td>$val
ue</td></td></tr>\n";
$k++; $k++;
last if ($k > $self->{TopUrlUser}); last if ($k > $self->{TopUrlUser});
} }
print $out "</table>\n"; print $out "</table>\n";
} else { } else {
print $out "*.$u\n"; print $out "*.$u\n";
} }
print $out qq{ print $out qq{
</div></div> </div></div>
</td> </td>
};
if ($tpe eq 'Hits') {
print $out qq{
<td>$domain_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td> <td>$domain_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td> <td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
<td>$duration <span class="italicPercent">($d_percent)</span></td> <td>$duration <span class="italicPercent">($d_percent)</span></td>
};
} elsif ($tpe eq 'Bytes') {
print $out qq{
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
<td>$domain_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$duration <span class="italicPercent">($d_percent)</span></td>
};
} else {
print $out qq{
<td>$duration <span class="italicPercent">($d_percent)</span></td>
<td>$domain_stat{$u}{hits} <span class="italicPercent">($h_percent)</span></td>
<td>$comma_bytes <span class="italicPercent">($b_percent)</span></td>
};
}
print $out qq{
<td>$comma_throughput</td> <td>$comma_throughput</td>
<td>$lasthit</td>
}; };
print $out qq{ print $out qq{
<td>$firsthit</td> <td>$firsthit</td>
<td>$lasthit</td> } if ($type eq 'hour');
} if ($type eq 'hour');
print $out qq{ print $out qq{
<td>$total_cost</td> <td>$total_cost</td>
} if ($self->{CostPrice}); } if ($self->{CostPrice});
print $out qq{ print $out qq{
</tr>}; </tr>};
$i++; $i++;
last if ($i > $self->{TopNumber}); last if ($i > $self->{TopNumber});
} }
print $out qq{</tbody></table>}; print $out qq{</tbody></table>};
# Do not show other tables if required # Do not show other tables if required
 End of changes. 155 change blocks. 
243 lines changed or deleted 785 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS