#!/usr/bin/perl # # SmoothWall CGIs # # This code is distributed under the terms of the GPL # # (c) The SmoothWall Team # # $Id: summary.dat,v 1.3.2.14 2005/07/10 00:48:42 franck78 Exp $ # use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; use POSIX(); my %cgiparams=(); my $errormessage = ''; my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, $Lang::tr{'december'} ); my @now = localtime(); my $year = $now[5]+1900; $cgiparams{'MONTH'} = ''; $cgiparams{'DAY'} = ''; $cgiparams{'ACTION'} = ''; &Header::getcgihash(\%cgiparams); my $start = -1; if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'}) { my @temp = split(',',$ENV{'QUERY_STRING'}); $start = $temp[0]; $cgiparams{'MONTH'} = $temp[1]; $cgiparams{'DAY'} = $temp[2]; } if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || !($cgiparams{'DAY'} =~ /^(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)$/)) { # Reports are generated at the end of the day, so if nothing is selected # we need to display yesterdays (todays won't have been generated yet) my @temp_then=(); my @temp_now = localtime(time); $temp_now[4] = $now[4]; $temp_now[3] = $now[3]; @temp_then = localtime(POSIX::mktime(@temp_now) - 86400); ## Retrieve the same time on the previous day - ## 86400 seconds in a day $cgiparams{'MONTH'} = $temp_then[4]; $cgiparams{'DAY'} = $temp_then[3]; } elsif($cgiparams{'ACTION'} eq '>>') { my @temp_then=(); my @temp_now = localtime(time); $temp_now[4] = $cgiparams{'MONTH'}; $temp_now[3] = $cgiparams{'DAY'}; @temp_then = localtime(POSIX::mktime(@temp_now) + 86400); ## Retrieve the same time on the next day + ## 86400 seconds in a day $cgiparams{'MONTH'} = $temp_then[4]; $cgiparams{'DAY'} = $temp_then[3]; } elsif($cgiparams{'ACTION'} eq '<<') { my @temp_then=(); my @temp_now = localtime(time); $temp_now[4] = $cgiparams{'MONTH'}; $temp_now[3] = $cgiparams{'DAY'}; @temp_then = localtime(POSIX::mktime(@temp_now) - 86400); ## Retrieve the same time on the previous day - ## 86400 seconds in a day $cgiparams{'MONTH'} = $temp_then[4]; $cgiparams{'DAY'} = $temp_then[3]; } if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) { if ( ($cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) || ($cgiparams{'MONTH'} > $now[4]) ) { $year = $year - 1; } } my $monthnum = $cgiparams{'MONTH'} + 1; my $monthstr = $monthnum <= 9 ? "0$monthnum" : "$monthnum"; my $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; my $daystr = $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}"; my $skip=0; my $filestr="/var/log/logwatch/$year-$monthstr-$daystr"; if (!(open (FILE,$filestr))) { $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; $skip=1; # Note: This is in case the log does not exist for that date } if (! $skip && $cgiparams{'ACTION'} eq $Lang::tr{'export'}) { print "Content-type: text/plain\n\n"; while () { print "$_\r\n"; } close (FILE); exit 0; } &Header::showhttpheaders(); &Header::openpage($Lang::tr{'log summary'}, 1, ''); &Header::openbigbox('100%', 'left', '', $errormessage); if ($errormessage) { &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); print "$errormessage \n"; &Header::closebox(); } &Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); print <
$Lang::tr{'month'}: $Lang::tr{'day'}:
END ; &Header::closebox(); my $header = 0; my @content=(); if(!$skip) { while () { if (/^\s*--+ ([^-]+) Begin --+\s*$/) { # New Section. open box @content = (); &Header::openbox('100%', 'left', $Lang::tr{"ls_\L$1"} ? $Lang::tr{"ls_\L$1"} : $1); print "
";
    } elsif (/^\s*--+ ([^-]+) End --+\s*$/) {
      # End of Section, kill leading and trailing blanks, print info, close
      # box
      while ( $content[0] =~ /^\s*$/ ) { shift @content; }
      while ( $content[$#content] =~ /^\s*$/ ) { pop @content; }
      foreach $_ (@content) { $_ =~ s/\s*$//; print &Header::cleanhtml($_,"y")."\n"; }
      print "\n
"; &Header::closebox(); } elsif (/^\s*#+ LogWatch [^#]+[)] #+\s*$/) { # Start of logwatch header, skip it $header = 1; } elsif (/^\s*#+\s*$/) { # End of logwatch header $header = 0; } elsif (/^\s*#+ LogWatch End #+\s*$/) { # End of report } elsif ($header eq 0) { push(@content,$_); } } close (FILE); } &Header::closebigbox(); &Header::closepage();