Firewallhitgraphs gefixt.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / logs.cgi / summary.dat
CommitLineData
cd1a2927
MT
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9# $Id: summary.dat,v 1.3.2.14 2005/07/10 00:48:42 franck78 Exp $
10#
11
12use strict;
13
14# enable only the following on debugging purpose
15#use warnings;
16#use CGI::Carp 'fatalsToBrowser';
17
986e08d9 18require '/var/ipfire/general-functions.pl';
cd1a2927
MT
19require "${General::swroot}/lang.pl";
20require "${General::swroot}/header.pl";
21
22use POSIX();
23
24my %cgiparams=();
25my $errormessage = '';
26
27my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
28 $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
29 $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
30 $Lang::tr{'december'} );
31
32my @now = localtime();
33my $year = $now[5]+1900;
34
35$cgiparams{'MONTH'} = '';
36$cgiparams{'DAY'} = '';
37$cgiparams{'ACTION'} = '';
38
39&Header::getcgihash(\%cgiparams);
40
41my $start = -1;
42if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'}) {
43 my @temp = split(',',$ENV{'QUERY_STRING'});
44 $start = $temp[0];
45 $cgiparams{'MONTH'} = $temp[1];
46 $cgiparams{'DAY'} = $temp[2];
47}
48
49if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
50 !($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)$/)) {
51 # Reports are generated at the end of the day, so if nothing is selected
52 # we need to display yesterdays (todays won't have been generated yet)
53 my @temp_then=();
54 my @temp_now = localtime(time);
55 $temp_now[4] = $now[4];
56 $temp_now[3] = $now[3];
57 @temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
58 ## Retrieve the same time on the previous day -
59 ## 86400 seconds in a day
60 $cgiparams{'MONTH'} = $temp_then[4];
61 $cgiparams{'DAY'} = $temp_then[3];
62}
63elsif($cgiparams{'ACTION'} eq '>>') {
64 my @temp_then=();
65 my @temp_now = localtime(time);
66 $temp_now[4] = $cgiparams{'MONTH'};
67 $temp_now[3] = $cgiparams{'DAY'};
68 @temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
69 ## Retrieve the same time on the next day +
70 ## 86400 seconds in a day
71 $cgiparams{'MONTH'} = $temp_then[4];
72 $cgiparams{'DAY'} = $temp_then[3];
73}
74elsif($cgiparams{'ACTION'} eq '<<') {
75 my @temp_then=();
76 my @temp_now = localtime(time);
77 $temp_now[4] = $cgiparams{'MONTH'};
78 $temp_now[3] = $cgiparams{'DAY'};
79 @temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
80 ## Retrieve the same time on the previous day -
81 ## 86400 seconds in a day
82 $cgiparams{'MONTH'} = $temp_then[4];
83 $cgiparams{'DAY'} = $temp_then[3];
84}
85
86if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) {
87 if ( ($cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
88 ($cgiparams{'MONTH'} > $now[4]) ) {
89 $year = $year - 1;
90 }
91}
92
93my $monthnum = $cgiparams{'MONTH'} + 1;
94my $monthstr = $monthnum <= 9 ? "0$monthnum" : "$monthnum";
95my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
96my $daystr = $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
97
98my $skip=0;
99my $filestr="/var/log/logwatch/$year-$monthstr-$daystr";
100
101if (!(open (FILE,$filestr))) {
102 $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
103 $skip=1;
104 # Note: This is in case the log does not exist for that date
105}
106
107if (! $skip && $cgiparams{'ACTION'} eq $Lang::tr{'export'}) {
108 print "Content-type: text/plain\n\n";
109
110 while (<FILE>) {
111 print "$_\r\n";
112 }
113 close (FILE);
114 exit 0;
115}
116
117&Header::showhttpheaders();
118
119&Header::openpage($Lang::tr{'log summary'}, 1, '');
120
121&Header::openbigbox('100%', 'left', '', $errormessage);
122
123if ($errormessage) {
124 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
125 print "<font class='base'>$errormessage&nbsp;</font>\n";
126 &Header::closebox();
127}
128
129&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
130
131print <<END
132<form method='post' action='$ENV{'SCRIPT_NAME'}'>
133<table width='100%'>
134<tr>
135 <td width='10%' class='base'>$Lang::tr{'month'}:</td>
136 <td width='25%'>
137 <select name='MONTH'>
138END
139;
140for (my $month = 0; $month < 12; $month++)
141{
142 print "\t<option ";
143 if ($month == $cgiparams{'MONTH'}) {
144 print "selected='selected' "; }
145 print "value='$month'>$longmonths[$month]</option>\n";
146}
147print <<END
148 </select>
149 </td>
150 <td width='10%' class='base'>$Lang::tr{'day'}:</td>
151 <td width='25%'>
152 <select name='DAY'>
153END
154;
155for (my $day = 1; $day <= 31; $day++)
156{
157 print "\t<option ";
158 if ($day == $cgiparams{'DAY'}) {
159 print "selected='selected' "; }
160 print "value='$day'>$day</option>\n";
161}
162print <<END
163</select>
164</td>
165<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='&lt;&lt;' /></td>
166<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='&gt;&gt;' /></td>
167<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
168<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
169</tr>
170</table>
171</form>
172END
173;
174
175&Header::closebox();
176
177my $header = 0;
178my @content=();
179
180if(!$skip)
181{
182 while (<FILE>) {
183 if (/^\s*--+ ([^-]+) Begin --+\s*$/) {
184 # New Section. open box
185 @content = ();
186 &Header::openbox('100%', 'left', $Lang::tr{"ls_\L$1"} ? $Lang::tr{"ls_\L$1"} : $1);
187 print "<pre>";
188 } elsif (/^\s*--+ ([^-]+) End --+\s*$/) {
189 # End of Section, kill leading and trailing blanks, print info, close
190 # box
191 while ( $content[0] =~ /^\s*$/ ) { shift @content; }
192 while ( $content[$#content] =~ /^\s*$/ ) { pop @content; }
193 foreach $_ (@content) { $_ =~ s/\s*$//; print &Header::cleanhtml($_,"y")."\n"; }
194 print "\n</pre>";
195 &Header::closebox();
196 } elsif (/^\s*#+ LogWatch [^#]+[)] #+\s*$/) {
197 # Start of logwatch header, skip it
198 $header = 1;
199 } elsif (/^\s*#+\s*$/) {
200 # End of logwatch header
201 $header = 0;
202 } elsif (/^\s*#+ LogWatch End #+\s*$/) {
203 # End of report
204 } elsif ($header eq 0) {
205 push(@content,$_);
206 }
207 }
208 close (FILE);
209}
210
211&Header::closebigbox();
212
213&Header::closepage();