]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/calamaris/mkreport
3 # This code is distributed under the terms of the GPL
5 # (c) 2005,2006 marco.s
7 # $Id: mkreport.pl,v 2.0 2006/03/12 00:00:00 marco.s Exp $
14 my $swroot = "/var/ipfire";
15 my $apdir = "$swroot/proxy/calamaris";
16 my $squidlogdir = "/var/log/squid";
17 my $calamlogdir = "/var/log/calamaris";
18 my $reportdir = "$apdir/reports";
20 unless (-e
$reportdir) { mkdir($reportdir) }
27 my @now = localtime(time);
28 my $year = $now[5]+1900;
30 if (@ARGV[0] eq 'nogz')
36 if (@ARGV < 6) { die "ERROR: Too few arguments\n\n"; }
38 my $day_begin=@ARGV[0];
39 my $month_begin=@ARGV[1];
40 my $year_begin=@ARGV[2];
42 my $month_end=@ARGV[4];
43 my $year_end=@ARGV[5];
47 while ($i < @ARGV) { $commandline.=" @ARGV[$i++]"; }
49 $commandline.=" $calamlogdir/squid-$unique.log >> $reportdir/calamaris-$unique.log";
51 if (&processlogfiles
($day_begin,$month_begin,$year_begin,$day_end,$month_end,$year_end) > 0)
53 system("$apdir/bin/calamaris $commandline");
54 system("chown nobody.nobody $reportdir/calamaris-$unique.log");
57 if (-e
"$calamlogdir/squid-$unique.log") { unlink("$calamlogdir/squid-$unique.log"); }
59 # -------------------------------------------------------------------
67 my $year_from = $_[2];
72 if (($mon_from =~ /(3|5|8|10)/) && ($day_from > 30)) { $day_from=30 }
73 if (($mon_to =~ /(3|5|8|10)/) && ($day_to > 30)) { $day_to=30 }
74 if (($mon_from == 1) && ($day_from > 28)) { if ($year_from%4==0) { $day_from=29 } else { $day_from=28 } }
75 if (($mon_to == 1) && ($day_to > 28)) { if ($year_to%4==0) { $day_to=29 } else { $day_to=28 } }
77 my $date_now = timelocal
(0,0,0,$now[3],$now[4],$year);
78 my $date_from = timelocal
(0,0,0,$day_from,$mon_from,$year_from);
79 my $date_to = timelocal
(0,0,0,$day_to,$mon_to,$year_to);
81 # if (($date_from > $date_now) || ($date_from > $date_to)) { $year_from-- }
84 if (($mon_from =~ /(3|5|8|10)/) && ($day_from > 30)) { $day_from=30 }
85 if (($mon_from == 1) && ($day_from > 28)) { if ($year_from%4==0) { $day_from=29 } else { $day_from=28 } }
87 my $date_from = timelocal
(0,0,0,$day_from,$mon_from,$year_from);
88 my $date_to = timelocal
(59,59,23,$day_to,$mon_to,$year_to);
90 open (TMPLOG
,">>$calamlogdir/squid-$unique.log") or die "ERROR: Cannot write to $calamlogdir/squid-$unique.log\n";
92 unless ($skip_gzlogs) {
93 foreach $filestr (<$squidlogdir/*.gz
>)
95 if ($filestr =~ /access\.log/) {
96 open (LOG
,"gzip -dc $filestr |");
98 if (substr($_,0,10) >= $date_from) { if (substr($_,0,10) <= $date_to) { print TMPLOG
"$_"; } }
105 foreach $filestr (<$squidlogdir/*.log>)
107 if ($filestr =~ /access\.log/) {
110 if (substr($_,0,10) >= $date_from) { if (substr($_,0,10) <= $date_to) { print TMPLOG
"$_"; } }
118 return (-s
"$calamlogdir/squid-$unique.log");
122 # -------------------------------------------------------------------