50 lines
1.6 KiB
Perl
Executable file
50 lines
1.6 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
$proxylogfile= "/usr/local/squid/logs/access.log";
|
|
$logdir= "/home/web/default/petar.company/stats/logs/";
|
|
$baseoutdir= "/home/web/default/petar.company/stats/logs/";
|
|
$configfile= "/home/web/default/petar.company/cfg_apps/webalizer/webalizer-squid.conf";
|
|
$webalizer= "/usr/local/bin/webalizer";
|
|
|
|
$nruseragent="2";
|
|
$topsites="300";
|
|
$topurl="300";
|
|
|
|
# Split dei logs del proxy in logs dei singoli hosts.
|
|
open (IN, $proxylogfile) or die "$0 - Can't open proxylog $proxylogfile: $!";
|
|
while (chomp($line=<IN>)){
|
|
($f1, $f2, $ip, $f4)=split(" ",$line);
|
|
open(OUT,">>$logdir/".$ip."-access.log") or die "$0 - Can't open create file ".$logdir.$ip."-access.log: $!";
|
|
print OUT $line."\n";
|
|
close(OUT);
|
|
}
|
|
close (IN);
|
|
|
|
# Creazione pagine statistiche singoli hosts
|
|
chdir($logdir) or die "$0 - Can't open dir $logdir: $!";
|
|
foreach $file (<*.log>) {
|
|
$hostname=substr($file,0,-11);
|
|
$reporttitle = "Uso Proxy da parte di ";
|
|
$outputdir=$baseoutdir.$hostname;
|
|
mkdir($baseoutdir.$hostname, 0777) if (! -d $baseoutdir.$hostname);
|
|
system("$webalizer -Q -c '$configfile' -n '$hostname' -o '$outputdir' -t '$reporttitle' -A '$nruseragent' -S '$topsites' -U '$topurl' -F squid $logdir$file");
|
|
|
|
unlink($logdir.$file);
|
|
}
|
|
|
|
# Creazione File index.html
|
|
open(OUT,">$logdir/index.html") or die "$0 - Can't create file ".$logdir."index.html: $!";
|
|
print OUT "<HTML>";
|
|
print OUT "<BODY BGCOLOR=#ffffff>";
|
|
print OUT "Statistiche d'uso dei seguenti hosts:";
|
|
print OUT "<UL>";
|
|
|
|
foreach $file (<*>) {
|
|
next if (!-d $file || $file =~ /^\.\.?$/ || substr($file,0,10) != "192.168.50" );
|
|
print OUT "<LI><a href='$file/index.html'>$file";
|
|
|
|
}
|
|
print OUT "</UL>";
|
|
close(OUT);
|
|
# The end
|
|
|