]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | use strict; | |
13 | ||
14 | # enable only the following on debugging purpose | |
15 | #use warnings; | |
16 | #use CGI::Carp 'fatalsToBrowser'; | |
17 | ||
986e08d9 | 18 | require '/var/ipfire/general-functions.pl'; |
cd1a2927 MT |
19 | require "${General::swroot}/lang.pl"; |
20 | require "${General::swroot}/header.pl"; | |
21 | ||
22 | use POSIX(); | |
23 | ||
24 | my %cgiparams=(); | |
25 | my $errormessage = ''; | |
26 | ||
27 | my @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 | ||
32 | my @now = localtime(); | |
33 | my $year = $now[5]+1900; | |
34 | ||
35 | $cgiparams{'MONTH'} = ''; | |
36 | $cgiparams{'DAY'} = ''; | |
37 | $cgiparams{'ACTION'} = ''; | |
38 | ||
39 | &Header::getcgihash(\%cgiparams); | |
40 | ||
41 | my $start = -1; | |
42 | if ($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 | ||
49 | if (!($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 | } | |
63 | elsif($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 | } | |
74 | elsif($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 | ||
86 | if (($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 | ||
93 | my $monthnum = $cgiparams{'MONTH'} + 1; | |
94 | my $monthstr = $monthnum <= 9 ? "0$monthnum" : "$monthnum"; | |
95 | my $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; | |
96 | my $daystr = $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}"; | |
97 | ||
98 | my $skip=0; | |
99 | my $filestr="/var/log/logwatch/$year-$monthstr-$daystr"; | |
100 | ||
101 | if (!(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 | ||
107 | if (! $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 | ||
123 | if ($errormessage) { | |
124 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
125 | print "<font class='base'>$errormessage </font>\n"; | |
126 | &Header::closebox(); | |
127 | } | |
128 | ||
129 | &Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); | |
130 | ||
131 | print <<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'> | |
138 | END | |
139 | ; | |
140 | for (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 | } | |
147 | print <<END | |
148 | </select> | |
149 | </td> | |
150 | <td width='10%' class='base'>$Lang::tr{'day'}:</td> | |
151 | <td width='25%'> | |
152 | <select name='DAY'> | |
153 | END | |
154 | ; | |
155 | for (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 | } | |
162 | print <<END | |
163 | </select> | |
164 | </td> | |
165 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td> | |
166 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></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> | |
172 | END | |
173 | ; | |
174 | ||
175 | &Header::closebox(); | |
176 | ||
177 | my $header = 0; | |
178 | my @content=(); | |
179 | ||
180 | if(!$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(); |