]>
Commit | Line | Data |
---|---|---|
10e4f239 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: urlfilter.dat,v 1.4 2005/05/15 00:00:00 marco Exp $ | |
10 | # | |
11 | ||
12 | use strict; | |
13 | ||
14 | # enable only the following on debugging purpose | |
15 | #use warnings; | |
16 | #use CGI::Carp 'fatalsToBrowser'; | |
17 | ||
18 | use POSIX(); | |
19 | ||
20 | require '/var/ipfire/general-functions.pl'; | |
21 | require "${General::swroot}/lang.pl"; | |
22 | require "${General::swroot}/header.pl"; | |
23 | ||
24 | my $dbdir = "${General::swroot}/urlfilter/blacklists"; | |
25 | my $logdir = "/var/log/squidGuard"; | |
26 | ||
27 | my %cgiparams=(); | |
28 | my %logsettings=(); | |
29 | my %filtersettings=(); | |
30 | my %selected=(); | |
31 | ||
32 | my $errormessage=''; | |
33 | ||
34 | my @log=(); | |
35 | my $logarch=''; | |
36 | my $date=''; | |
37 | my $time=''; | |
38 | my $pid=''; | |
39 | my @loginfo=(); | |
40 | my @ip=(); | |
41 | my @category=(); | |
42 | my $dsturl=''; | |
43 | my $site=''; | |
44 | my $attr1=''; | |
45 | my $attr2=''; | |
46 | ||
47 | my $start=0; | |
48 | my $prev=0; | |
49 | my $next=0; | |
50 | my $lines=0; | |
51 | my @slice=(); | |
52 | ||
53 | my @then=(); | |
54 | my @temp=(); | |
55 | my @temp_then=(); | |
56 | my @temp_now=(); | |
57 | my $lastleap=''; | |
58 | ||
59 | my $day=''; | |
60 | my $daystr=''; | |
61 | my $month=''; | |
62 | my $monthstr=''; | |
63 | my $longmonthstr=''; | |
64 | my $year=''; | |
65 | ||
66 | my $logday=''; | |
67 | my $logmonth=''; | |
68 | my $logyear=''; | |
69 | ||
70 | my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', | |
71 | 'Sep', 'Oct', 'Nov', 'Dec' ); | |
72 | my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, | |
73 | $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, | |
74 | $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, | |
75 | $Lang::tr{'december'} ); | |
76 | ||
77 | my @now = localtime(time); | |
78 | my $doy = $now[7]; | |
79 | my $tdoy = $now[7]; | |
80 | my $year = $now[5]+1900; | |
81 | ||
82 | $cgiparams{'DAY'} = $now[3]; | |
83 | $cgiparams{'MONTH'} = $now[4]; | |
84 | $cgiparams{'LOGTYPE'} = 'urlfilter'; | |
85 | ||
86 | &Header::getcgihash(\%cgiparams); | |
87 | $logsettings{'LOGVIEW_REVERSE'} = 'off'; | |
88 | &General::readhash("${General::swroot}/logging/settings", \%logsettings); | |
89 | if (-e "${General::swroot}/urlfilter/settings") | |
90 | { | |
91 | &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings); | |
92 | } | |
93 | ||
94 | $now[4] = $cgiparams{'MONTH'}+1; | |
95 | if($now[4] < 10) { | |
96 | $now[4] = "0$now[4]"; } | |
97 | ||
98 | $start = -1; | |
99 | ||
100 | if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'}) | |
101 | { | |
102 | @temp = split(',',$ ENV{'QUERY_STRING'}); | |
103 | $start = $temp[0]; | |
104 | $cgiparams{'MONTH'} = $temp[1]; | |
105 | $cgiparams{'DAY'} = $temp[2]; | |
106 | $cgiparams{'LOGTYPE'} = $temp[3]; | |
107 | } | |
108 | ||
109 | if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || | |
110 | !($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)$/)) | |
111 | { | |
112 | $cgiparams{'DAY'} = $now[3]; | |
113 | $cgiparams{'MONTH'} = $now[4]; | |
114 | } | |
115 | elsif($cgiparams{'ACTION'} eq '>>') | |
116 | { | |
117 | @temp_now = localtime(time); | |
118 | $temp_now[4] = $cgiparams{'MONTH'}; | |
119 | $temp_now[3] = $cgiparams{'DAY'}; | |
120 | @temp_then = localtime(POSIX::mktime(@temp_now) + 86400); | |
121 | ## Retrieve the same time on the next day - | |
122 | ## 86400 seconds in a day | |
123 | $cgiparams{'MONTH'} = $temp_then[4]; | |
124 | $cgiparams{'DAY'} = $temp_then[3]; | |
125 | } | |
126 | elsif($cgiparams{'ACTION'} eq '<<') | |
127 | { | |
128 | @temp_now = localtime(time); | |
129 | $temp_now[4] = $cgiparams{'MONTH'}; | |
130 | $temp_now[3] = $cgiparams{'DAY'}; | |
131 | @temp_then = localtime(POSIX::mktime(@temp_now) - 86400); | |
132 | ## Retrieve the same time on the previous day - | |
133 | ## 86400 seconds in a day | |
134 | $cgiparams{'MONTH'} = $temp_then[4]; | |
135 | $cgiparams{'DAY'} = $temp_then[3]; | |
136 | } | |
137 | ||
138 | $monthstr = $shortmonths[$cgiparams{'MONTH'}]; | |
139 | $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; | |
140 | ||
141 | if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) | |
142 | { | |
143 | @then = (); | |
144 | if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) || | |
145 | ( $cgiparams{'MONTH'} > $now[4] ) ) { | |
146 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 )); | |
147 | } else { | |
148 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 )); | |
149 | } | |
150 | $tdoy = $then[7]; | |
151 | $lastleap=($year-1)%4; | |
152 | if ($tdoy>$doy) { | |
153 | if ($lastleap == 0 && $tdoy < 60) { | |
154 | $doy=$tdoy+366; | |
155 | } else { | |
156 | $doy=$doy+365; | |
157 | } | |
158 | } | |
159 | } | |
160 | ||
161 | $day = $cgiparams{'DAY'}; | |
162 | if ($day <= 9) { | |
163 | $daystr = " $day"; | |
164 | } else { | |
165 | $daystr = $day; | |
166 | } | |
167 | if ($day < 10) { | |
168 | $day = "0$day"; | |
169 | } | |
170 | ||
171 | &processevent; | |
172 | ||
173 | if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}) | |
174 | { | |
175 | print "Content-type: text/plain\n\n"; | |
176 | print "IPCop URL filter log\r\n"; | |
177 | print "Section: $cgiparams{'LOGTYPE'}\r\n"; | |
178 | print "Date: $daystr $longmonthstr\r\n"; | |
179 | print "\r\n"; | |
180 | ||
181 | if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; } | |
182 | ||
183 | foreach (@log) | |
184 | { | |
185 | ($date,$time,$pid,@loginfo) = split(/ /); | |
186 | @ip = split(/\//,$loginfo[2]); | |
187 | @category = split(/\//,$loginfo[0]); | |
188 | $dsturl = $loginfo[1]; | |
189 | $loginfo[3] =~ s/\%5c/\\/; | |
190 | print "$date "; | |
191 | print "$time "; | |
192 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
193 | { | |
194 | print "$pid "; | |
195 | print "@loginfo"; | |
196 | } else { | |
197 | print "$category[1] "; | |
198 | print "$ip[0] "; | |
199 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "$loginfo[3] "; } | |
200 | print "$dsturl"; | |
201 | print "\n"; | |
202 | } | |
203 | } | |
204 | ||
205 | exit; | |
206 | } | |
207 | ||
208 | &Header::showhttpheaders(); | |
209 | ||
210 | &Header::openpage($Lang::tr{'urlfilter log viewer'}, 1, ''); | |
211 | ||
212 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
213 | ||
214 | if ($errormessage) { | |
215 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
216 | print "<font class='base'>$errormessage </font>\n"; | |
217 | &Header::closebox(); | |
218 | } | |
219 | ||
220 | &Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); | |
221 | ||
222 | $selected{'LOGTYPE'}{$cgiparams{'LOGTYPE'}} = "selected='selected'"; | |
223 | ||
224 | print <<END | |
225 | <form method='post' action="$ENV{'SCRIPT_NAME'}"> | |
226 | <table width='100%'> | |
227 | <tr> | |
228 | <td width='8%' class='base'>$Lang::tr{'section'}</td> | |
229 | <td width='15%' class='base'> | |
230 | <select name='LOGTYPE' size='1'> | |
231 | <option value='urlfilter' $selected{'LOGTYPE'}{'urlfilter'} = "selected='selected'">$Lang::tr{'urlfilter url filter'}</option> | |
232 | <option value='squidGuard' $selected{'LOGTYPE'}{'squidGuard'} = "selected='selected'">squidGuard</option> | |
233 | </select> | |
234 | </td> | |
235 | ||
236 | <td width='8%' class='base'>$Lang::tr{'month'}:</td> | |
237 | <td width='15%'> | |
238 | <select name='MONTH'> | |
239 | END | |
240 | ; | |
241 | for ($month = 0; $month < 12; $month++) | |
242 | { | |
243 | print "\t<option "; | |
244 | if ($month == $cgiparams{'MONTH'}) { | |
245 | print 'selected="selected" '; } | |
246 | print "value='$month'>$longmonths[$month]</option>\n"; | |
247 | } | |
248 | print <<END | |
249 | </select> | |
250 | </td> | |
251 | <td width='8%' class='base'>$Lang::tr{'day'}:</td> | |
252 | <td width='15%'> | |
253 | <select name='DAY'> | |
254 | END | |
255 | ; | |
256 | for ($day = 1; $day <= 31; $day++) | |
257 | { | |
258 | print "\t<option "; | |
259 | if ($day == $cgiparams{'DAY'}) { | |
260 | print 'selected="selected" '; } | |
261 | print "value='$day'>$day</option>\n"; | |
262 | } | |
263 | print <<END | |
264 | </select> | |
265 | </td> | |
266 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td> | |
267 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td> | |
268 | <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td> | |
269 | <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td> | |
270 | </tr> | |
271 | </table> | |
272 | </form> | |
273 | END | |
274 | ; | |
275 | ||
276 | &Header::closebox(); | |
277 | ||
278 | &Header::openbox('100%', 'left', $Lang::tr{'log'}); | |
279 | ||
280 | $lines = @log; | |
281 | ||
282 | if ($start == -1) { $start = $lines - $Header::viewsize; } | |
283 | if ($start >= $lines - $Header::viewsize) { $start = $lines - $Header::viewsize; }; | |
284 | if ($start < 0) { $start = 0; } | |
285 | ||
286 | $prev = $start - $Header::viewsize; | |
287 | $next = $start + $Header::viewsize; | |
288 | ||
289 | if ($prev < 0) { $prev = 0; } | |
290 | if ($next >= $lines) { $next = -1 } | |
291 | if ($start == 0) { $prev = -1; } | |
292 | ||
293 | if ($cgiparams{'LOGTYPE'} eq 'urlfilter') | |
294 | { | |
295 | print "<b>$Lang::tr{'urlfilter log summary'} $longmonthstr $daystr: $lines</b><p>\n"; | |
296 | } | |
297 | ||
298 | @slice = splice(@log, $start, $Header::viewsize); | |
299 | ||
300 | if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } | |
301 | ||
302 | if ($lines) | |
303 | { | |
304 | ||
305 | $lines = 0; | |
306 | ||
307 | print "<table width='100%'>\n"; | |
308 | unless ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
309 | { | |
310 | print "<tr>\n"; | |
311 | print "<td align='center'><b>$Lang::tr{'urlfilter time'}</b></td>\n"; | |
312 | print "<td align='center'><b>$Lang::tr{'urlfilter category'}</b></td>\n"; | |
313 | print "<td align='center'><b>$Lang::tr{'urlfilter client'}</b></td>\n"; | |
314 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "<td align='center'><b>$Lang::tr{'urlfilter username'}</b></td>\n"; } | |
315 | print "<td align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>\n"; | |
316 | print "</tr>\n"; | |
317 | } | |
318 | ||
319 | foreach (@slice) | |
320 | { | |
321 | undef $attr1; undef $attr2; | |
322 | $lines++; | |
323 | ($date,$time,$pid,@loginfo) = split(/ /); | |
324 | @ip = split(/\//,$loginfo[2]); | |
325 | @category = split(/\//,$loginfo[0]); | |
326 | $dsturl = $loginfo[1]; | |
327 | $loginfo[3] =~ s/\%5c/\\/; | |
328 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') { | |
329 | if (@loginfo[0] =~ /squidGuard/) { $attr1 .= "<b>"; $attr2 .= "</b>"; } | |
330 | if (@loginfo[1] =~ /ready/) { $attr1 .= "<b><font color='$Header::colourgreen'>"; $attr2 .= "</font></b>"; } | |
331 | if (@loginfo[2] =~ /emergency/) { $attr1 .= "<b><font color='$Header::colourerr'>"; $attr2 .= "</font></b>"; } | |
332 | print "<tr>\n"; | |
333 | } else { | |
334 | if ($lines % 2) { print "<tr bgcolor='$Header::table1colour'>\n"; } else { print "<tr bgcolor='$Header::table2colour'>\n"; } | |
335 | } | |
336 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') { | |
337 | print "<td nowrap>$time $pid $attr1@loginfo$attr2</td>\n"; | |
338 | } else { | |
339 | print "<td width='10%' align='center' nowrap>$time</td>\n"; | |
340 | print "<td width='11%' align='center' nowrap>$category[1]</td>\n"; | |
341 | print "<td width='15%' align='center' nowrap>$ip[0]</td>\n"; | |
342 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') | |
343 | { | |
344 | print "<td width='12%' align='center' nowrap>$loginfo[3]</td>\n"; | |
345 | $site = substr($dsturl,0,55); | |
346 | if (length($dsturl) > 55) { $site .= "..."; } | |
347 | } else { | |
348 | $site = substr($dsturl,0,69); | |
349 | if (length($dsturl) > 69) { $site .= "..."; } | |
350 | } | |
351 | #print "<td>$site</td>\n"; | |
352 | print "<td><a href='$dsturl' title='$dsturl' target='_blank'>$site</a></td>\n"; | |
353 | } | |
354 | print "</tr>\n"; | |
355 | } | |
356 | ||
357 | print "</table><br>\n"; | |
358 | ||
359 | } | |
360 | ||
361 | &oldernewer(); | |
362 | ||
363 | &Header::closebox(); | |
364 | ||
365 | &Header::closebigbox(); | |
366 | ||
367 | &Header::closepage(); | |
368 | ||
369 | # ------------------------------------------------------------------- | |
370 | ||
371 | sub processevent | |
372 | { | |
373 | my $filestr=''; | |
374 | ||
375 | undef @log; | |
376 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
377 | { | |
378 | $filestr = "$logdir/squidGuard.log"; | |
379 | foreach $logarch (<$filestr.*.gz>) | |
380 | { | |
381 | open (LOG,"gzip -dc $logarch |"); | |
382 | foreach (<LOG>) { | |
383 | ($date,$time,$pid,@loginfo) = split(/ /); | |
384 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
385 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
386 | } | |
387 | close(LOG); | |
388 | } | |
389 | open (LOG,$filestr); | |
390 | foreach (<LOG>) { | |
391 | ($date,$time,$pid,@loginfo) = split(/ /); | |
392 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
393 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
394 | } | |
395 | close(LOG); | |
396 | } else { | |
397 | foreach $logarch (<$logdir/*.gz>) | |
398 | { | |
399 | if ($logarch !~ /squidGuard\.log/) { | |
400 | open (LOG,"gzip -dc $logarch |"); | |
401 | foreach (<LOG>) { | |
402 | ($date,$time,$pid,@loginfo) = split(/ /); | |
403 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
404 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
405 | } | |
406 | close(LOG); | |
407 | } | |
408 | } | |
409 | foreach $filestr (<$logdir/*.log>) | |
410 | { | |
411 | if ($filestr !~ /squidGuard\.log/) { | |
412 | open (LOG,$filestr); | |
413 | foreach (<LOG>) { | |
414 | ($date,$time,$pid,@loginfo) = split(/ /); | |
415 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
416 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
417 | } | |
418 | close(LOG); | |
419 | } | |
420 | } | |
421 | @log = sort { substr($a,11,8) cmp substr($b,11,8) } @log; | |
422 | ||
423 | } | |
424 | } | |
425 | ||
426 | # ------------------------------------------------------------------- | |
427 | ||
428 | sub oldernewer | |
429 | { | |
430 | print "<table width='100%'>"; | |
431 | print "<tr>"; | |
432 | ||
433 | print "<td align='center' width='50%'>"; | |
434 | if ($prev != -1) { | |
435 | print "<a href='$ENV{'SCRIPT_NAME'}?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'older'}</a>"; } | |
436 | else { | |
437 | print "$Lang::tr{'older'}"; } | |
438 | print "</td>\n"; | |
439 | ||
440 | print "<td align='center' width='50%'>"; | |
441 | if ($next != -1) { | |
442 | print "<a href='$ENV{'SCRIPT_NAME'}?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'newer'}</a>"; } | |
443 | else { | |
444 | print "$Lang::tr{'newer'}"; } | |
445 | print "</td>\n"; | |
446 | ||
447 | print "</tr>"; | |
448 | print "</table>"; | |
449 | } | |
450 | ||
451 | # ------------------------------------------------------------------- | |
452 | #!/usr/bin/perl | |
453 | # | |
454 | # SmoothWall CGIs | |
455 | # | |
456 | # This code is distributed under the terms of the GPL | |
457 | # | |
458 | # (c) The SmoothWall Team | |
459 | # | |
460 | # $Id: urlfilter.dat,v 1.4 2005/05/15 00:00:00 marco Exp $ | |
461 | # | |
462 | ||
463 | use strict; | |
464 | ||
465 | # enable only the following on debugging purpose | |
466 | #use warnings; | |
467 | #use CGI::Carp 'fatalsToBrowser'; | |
468 | ||
469 | use POSIX(); | |
470 | ||
471 | require '/var/ipfire/general-functions.pl'; | |
472 | require "${General::swroot}/lang.pl"; | |
473 | require "${General::swroot}/header.pl"; | |
474 | ||
475 | my $dbdir = "${General::swroot}/urlfilter/blacklists"; | |
476 | my $logdir = "/var/log/squidGuard"; | |
477 | ||
478 | my %cgiparams=(); | |
479 | my %logsettings=(); | |
480 | my %filtersettings=(); | |
481 | my %selected=(); | |
482 | ||
483 | my $errormessage=''; | |
484 | ||
485 | my @log=(); | |
486 | my $logarch=''; | |
487 | my $date=''; | |
488 | my $time=''; | |
489 | my $pid=''; | |
490 | my @loginfo=(); | |
491 | my @ip=(); | |
492 | my @category=(); | |
493 | my $dsturl=''; | |
494 | my $site=''; | |
495 | my $attr1=''; | |
496 | my $attr2=''; | |
497 | ||
498 | my $start=0; | |
499 | my $prev=0; | |
500 | my $next=0; | |
501 | my $lines=0; | |
502 | my @slice=(); | |
503 | ||
504 | my @then=(); | |
505 | my @temp=(); | |
506 | my @temp_then=(); | |
507 | my @temp_now=(); | |
508 | my $lastleap=''; | |
509 | ||
510 | my $day=''; | |
511 | my $daystr=''; | |
512 | my $month=''; | |
513 | my $monthstr=''; | |
514 | my $longmonthstr=''; | |
515 | my $year=''; | |
516 | ||
517 | my $logday=''; | |
518 | my $logmonth=''; | |
519 | my $logyear=''; | |
520 | ||
521 | my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', | |
522 | 'Sep', 'Oct', 'Nov', 'Dec' ); | |
523 | my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, | |
524 | $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, | |
525 | $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, | |
526 | $Lang::tr{'december'} ); | |
527 | ||
528 | my @now = localtime(time); | |
529 | my $doy = $now[7]; | |
530 | my $tdoy = $now[7]; | |
531 | my $year = $now[5]+1900; | |
532 | ||
533 | $cgiparams{'DAY'} = $now[3]; | |
534 | $cgiparams{'MONTH'} = $now[4]; | |
535 | $cgiparams{'LOGTYPE'} = 'urlfilter'; | |
536 | ||
537 | &Header::getcgihash(\%cgiparams); | |
538 | $logsettings{'LOGVIEW_REVERSE'} = 'off'; | |
539 | &General::readhash("${General::swroot}/logging/settings", \%logsettings); | |
540 | if (-e "${General::swroot}/urlfilter/settings") | |
541 | { | |
542 | &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings); | |
543 | } | |
544 | ||
545 | $now[4] = $cgiparams{'MONTH'}+1; | |
546 | if($now[4] < 10) { | |
547 | $now[4] = "0$now[4]"; } | |
548 | ||
549 | $start = -1; | |
550 | ||
551 | if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'}) | |
552 | { | |
553 | @temp = split(',',$ ENV{'QUERY_STRING'}); | |
554 | $start = $temp[0]; | |
555 | $cgiparams{'MONTH'} = $temp[1]; | |
556 | $cgiparams{'DAY'} = $temp[2]; | |
557 | $cgiparams{'LOGTYPE'} = $temp[3]; | |
558 | } | |
559 | ||
560 | if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || | |
561 | !($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)$/)) | |
562 | { | |
563 | $cgiparams{'DAY'} = $now[3]; | |
564 | $cgiparams{'MONTH'} = $now[4]; | |
565 | } | |
566 | elsif($cgiparams{'ACTION'} eq '>>') | |
567 | { | |
568 | @temp_now = localtime(time); | |
569 | $temp_now[4] = $cgiparams{'MONTH'}; | |
570 | $temp_now[3] = $cgiparams{'DAY'}; | |
571 | @temp_then = localtime(POSIX::mktime(@temp_now) + 86400); | |
572 | ## Retrieve the same time on the next day - | |
573 | ## 86400 seconds in a day | |
574 | $cgiparams{'MONTH'} = $temp_then[4]; | |
575 | $cgiparams{'DAY'} = $temp_then[3]; | |
576 | } | |
577 | elsif($cgiparams{'ACTION'} eq '<<') | |
578 | { | |
579 | @temp_now = localtime(time); | |
580 | $temp_now[4] = $cgiparams{'MONTH'}; | |
581 | $temp_now[3] = $cgiparams{'DAY'}; | |
582 | @temp_then = localtime(POSIX::mktime(@temp_now) - 86400); | |
583 | ## Retrieve the same time on the previous day - | |
584 | ## 86400 seconds in a day | |
585 | $cgiparams{'MONTH'} = $temp_then[4]; | |
586 | $cgiparams{'DAY'} = $temp_then[3]; | |
587 | } | |
588 | ||
589 | $monthstr = $shortmonths[$cgiparams{'MONTH'}]; | |
590 | $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; | |
591 | ||
592 | if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) | |
593 | { | |
594 | @then = (); | |
595 | if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) || | |
596 | ( $cgiparams{'MONTH'} > $now[4] ) ) { | |
597 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 )); | |
598 | } else { | |
599 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 )); | |
600 | } | |
601 | $tdoy = $then[7]; | |
602 | $lastleap=($year-1)%4; | |
603 | if ($tdoy>$doy) { | |
604 | if ($lastleap == 0 && $tdoy < 60) { | |
605 | $doy=$tdoy+366; | |
606 | } else { | |
607 | $doy=$doy+365; | |
608 | } | |
609 | } | |
610 | } | |
611 | ||
612 | $day = $cgiparams{'DAY'}; | |
613 | if ($day <= 9) { | |
614 | $daystr = " $day"; | |
615 | } else { | |
616 | $daystr = $day; | |
617 | } | |
618 | if ($day < 10) { | |
619 | $day = "0$day"; | |
620 | } | |
621 | ||
622 | &processevent; | |
623 | ||
624 | if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}) | |
625 | { | |
626 | print "Content-type: text/plain\n\n"; | |
627 | print "IPCop URL filter log\r\n"; | |
628 | print "Section: $cgiparams{'LOGTYPE'}\r\n"; | |
629 | print "Date: $daystr $longmonthstr\r\n"; | |
630 | print "\r\n"; | |
631 | ||
632 | if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; } | |
633 | ||
634 | foreach (@log) | |
635 | { | |
636 | ($date,$time,$pid,@loginfo) = split(/ /); | |
637 | @ip = split(/\//,$loginfo[2]); | |
638 | @category = split(/\//,$loginfo[0]); | |
639 | $dsturl = $loginfo[1]; | |
640 | $loginfo[3] =~ s/\%5c/\\/; | |
641 | print "$date "; | |
642 | print "$time "; | |
643 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
644 | { | |
645 | print "$pid "; | |
646 | print "@loginfo"; | |
647 | } else { | |
648 | print "$category[1] "; | |
649 | print "$ip[0] "; | |
650 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "$loginfo[3] "; } | |
651 | print "$dsturl"; | |
652 | print "\n"; | |
653 | } | |
654 | } | |
655 | ||
656 | exit; | |
657 | } | |
658 | ||
659 | &Header::showhttpheaders(); | |
660 | ||
661 | &Header::openpage($Lang::tr{'urlfilter log viewer'}, 1, ''); | |
662 | ||
663 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
664 | ||
665 | if ($errormessage) { | |
666 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
667 | print "<font class='base'>$errormessage </font>\n"; | |
668 | &Header::closebox(); | |
669 | } | |
670 | ||
671 | &Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); | |
672 | ||
673 | $selected{'LOGTYPE'}{$cgiparams{'LOGTYPE'}} = "selected='selected'"; | |
674 | ||
675 | print <<END | |
676 | <form method='post' action="$ENV{'SCRIPT_NAME'}"> | |
677 | <table width='100%'> | |
678 | <tr> | |
679 | <td width='8%' class='base'>$Lang::tr{'section'}</td> | |
680 | <td width='15%' class='base'> | |
681 | <select name='LOGTYPE' size='1'> | |
682 | <option value='urlfilter' $selected{'LOGTYPE'}{'urlfilter'} = "selected='selected'">$Lang::tr{'urlfilter url filter'}</option> | |
683 | <option value='squidGuard' $selected{'LOGTYPE'}{'squidGuard'} = "selected='selected'">squidGuard</option> | |
684 | </select> | |
685 | </td> | |
686 | ||
687 | <td width='8%' class='base'>$Lang::tr{'month'}:</td> | |
688 | <td width='15%'> | |
689 | <select name='MONTH'> | |
690 | END | |
691 | ; | |
692 | for ($month = 0; $month < 12; $month++) | |
693 | { | |
694 | print "\t<option "; | |
695 | if ($month == $cgiparams{'MONTH'}) { | |
696 | print 'selected="selected" '; } | |
697 | print "value='$month'>$longmonths[$month]</option>\n"; | |
698 | } | |
699 | print <<END | |
700 | </select> | |
701 | </td> | |
702 | <td width='8%' class='base'>$Lang::tr{'day'}:</td> | |
703 | <td width='15%'> | |
704 | <select name='DAY'> | |
705 | END | |
706 | ; | |
707 | for ($day = 1; $day <= 31; $day++) | |
708 | { | |
709 | print "\t<option "; | |
710 | if ($day == $cgiparams{'DAY'}) { | |
711 | print 'selected="selected" '; } | |
712 | print "value='$day'>$day</option>\n"; | |
713 | } | |
714 | print <<END | |
715 | </select> | |
716 | </td> | |
717 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td> | |
718 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td> | |
719 | <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td> | |
720 | <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td> | |
721 | </tr> | |
722 | </table> | |
723 | </form> | |
724 | END | |
725 | ; | |
726 | ||
727 | &Header::closebox(); | |
728 | ||
729 | &Header::openbox('100%', 'left', $Lang::tr{'log'}); | |
730 | ||
731 | $lines = @log; | |
732 | ||
733 | if ($start == -1) { $start = $lines - $Header::viewsize; } | |
734 | if ($start >= $lines - $Header::viewsize) { $start = $lines - $Header::viewsize; }; | |
735 | if ($start < 0) { $start = 0; } | |
736 | ||
737 | $prev = $start - $Header::viewsize; | |
738 | $next = $start + $Header::viewsize; | |
739 | ||
740 | if ($prev < 0) { $prev = 0; } | |
741 | if ($next >= $lines) { $next = -1 } | |
742 | if ($start == 0) { $prev = -1; } | |
743 | ||
744 | if ($cgiparams{'LOGTYPE'} eq 'urlfilter') | |
745 | { | |
746 | print "<b>$Lang::tr{'urlfilter log summary'} $longmonthstr $daystr: $lines</b><p>\n"; | |
747 | } | |
748 | ||
749 | @slice = splice(@log, $start, $Header::viewsize); | |
750 | ||
751 | if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } | |
752 | ||
753 | if ($lines) | |
754 | { | |
755 | ||
756 | $lines = 0; | |
757 | ||
758 | print "<table width='100%'>\n"; | |
759 | unless ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
760 | { | |
761 | print "<tr>\n"; | |
762 | print "<td align='center'><b>$Lang::tr{'urlfilter time'}</b></td>\n"; | |
763 | print "<td align='center'><b>$Lang::tr{'urlfilter category'}</b></td>\n"; | |
764 | print "<td align='center'><b>$Lang::tr{'urlfilter client'}</b></td>\n"; | |
765 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "<td align='center'><b>$Lang::tr{'urlfilter username'}</b></td>\n"; } | |
766 | print "<td align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>\n"; | |
767 | print "</tr>\n"; | |
768 | } | |
769 | ||
770 | foreach (@slice) | |
771 | { | |
772 | undef $attr1; undef $attr2; | |
773 | $lines++; | |
774 | ($date,$time,$pid,@loginfo) = split(/ /); | |
775 | @ip = split(/\//,$loginfo[2]); | |
776 | @category = split(/\//,$loginfo[0]); | |
777 | $dsturl = $loginfo[1]; | |
778 | $loginfo[3] =~ s/\%5c/\\/; | |
779 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') { | |
780 | if (@loginfo[0] =~ /squidGuard/) { $attr1 .= "<b>"; $attr2 .= "</b>"; } | |
781 | if (@loginfo[1] =~ /ready/) { $attr1 .= "<b><font color='$Header::colourgreen'>"; $attr2 .= "</font></b>"; } | |
782 | if (@loginfo[2] =~ /emergency/) { $attr1 .= "<b><font color='$Header::colourerr'>"; $attr2 .= "</font></b>"; } | |
783 | print "<tr>\n"; | |
784 | } else { | |
785 | if ($lines % 2) { print "<tr bgcolor='$Header::table1colour'>\n"; } else { print "<tr bgcolor='$Header::table2colour'>\n"; } | |
786 | } | |
787 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') { | |
788 | print "<td nowrap>$time $pid $attr1@loginfo$attr2</td>\n"; | |
789 | } else { | |
790 | print "<td width='10%' align='center' nowrap>$time</td>\n"; | |
791 | print "<td width='11%' align='center' nowrap>$category[1]</td>\n"; | |
792 | print "<td width='15%' align='center' nowrap>$ip[0]</td>\n"; | |
793 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') | |
794 | { | |
795 | print "<td width='12%' align='center' nowrap>$loginfo[3]</td>\n"; | |
796 | $site = substr($dsturl,0,55); | |
797 | if (length($dsturl) > 55) { $site .= "..."; } | |
798 | } else { | |
799 | $site = substr($dsturl,0,69); | |
800 | if (length($dsturl) > 69) { $site .= "..."; } | |
801 | } | |
802 | #print "<td>$site</td>\n"; | |
803 | print "<td><a href='$dsturl' title='$dsturl' target='_blank'>$site</a></td>\n"; | |
804 | } | |
805 | print "</tr>\n"; | |
806 | } | |
807 | ||
808 | print "</table><br>\n"; | |
809 | ||
810 | } | |
811 | ||
812 | &oldernewer(); | |
813 | ||
814 | &Header::closebox(); | |
815 | ||
816 | &Header::closebigbox(); | |
817 | ||
818 | &Header::closepage(); | |
819 | ||
820 | # ------------------------------------------------------------------- | |
821 | ||
822 | sub processevent | |
823 | { | |
824 | my $filestr=''; | |
825 | ||
826 | undef @log; | |
827 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
828 | { | |
829 | $filestr = "$logdir/squidGuard.log"; | |
830 | foreach $logarch (<$filestr.*.gz>) | |
831 | { | |
832 | open (LOG,"gzip -dc $logarch |"); | |
833 | foreach (<LOG>) { | |
834 | ($date,$time,$pid,@loginfo) = split(/ /); | |
835 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
836 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
837 | } | |
838 | close(LOG); | |
839 | } | |
840 | open (LOG,$filestr); | |
841 | foreach (<LOG>) { | |
842 | ($date,$time,$pid,@loginfo) = split(/ /); | |
843 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
844 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
845 | } | |
846 | close(LOG); | |
847 | } else { | |
848 | foreach $logarch (<$logdir/*.gz>) | |
849 | { | |
850 | if ($logarch !~ /squidGuard\.log/) { | |
851 | open (LOG,"gzip -dc $logarch |"); | |
852 | foreach (<LOG>) { | |
853 | ($date,$time,$pid,@loginfo) = split(/ /); | |
854 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
855 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
856 | } | |
857 | close(LOG); | |
858 | } | |
859 | } | |
860 | foreach $filestr (<$logdir/*.log>) | |
861 | { | |
862 | if ($filestr !~ /squidGuard\.log/) { | |
863 | open (LOG,$filestr); | |
864 | foreach (<LOG>) { | |
865 | ($date,$time,$pid,@loginfo) = split(/ /); | |
866 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
867 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
868 | } | |
869 | close(LOG); | |
870 | } | |
871 | } | |
872 | @log = sort { substr($a,11,8) cmp substr($b,11,8) } @log; | |
873 | ||
874 | } | |
875 | } | |
876 | ||
877 | # ------------------------------------------------------------------- | |
878 | ||
879 | sub oldernewer | |
880 | { | |
881 | print "<table width='100%'>"; | |
882 | print "<tr>"; | |
883 | ||
884 | print "<td align='center' width='50%'>"; | |
885 | if ($prev != -1) { | |
886 | print "<a href='$ENV{'SCRIPT_NAME'}?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'older'}</a>"; } | |
887 | else { | |
888 | print "$Lang::tr{'older'}"; } | |
889 | print "</td>\n"; | |
890 | ||
891 | print "<td align='center' width='50%'>"; | |
892 | if ($next != -1) { | |
893 | print "<a href='$ENV{'SCRIPT_NAME'}?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'newer'}</a>"; } | |
894 | else { | |
895 | print "$Lang::tr{'newer'}"; } | |
896 | print "</td>\n"; | |
897 | ||
898 | print "</tr>"; | |
899 | print "</table>"; | |
900 | } | |
901 | ||
902 | # ------------------------------------------------------------------- | |
903 | #!/usr/bin/perl | |
904 | # | |
905 | # SmoothWall CGIs | |
906 | # | |
907 | # This code is distributed under the terms of the GPL | |
908 | # | |
909 | # (c) The SmoothWall Team | |
910 | # | |
911 | # $Id: urlfilter.dat,v 1.4 2005/05/15 00:00:00 marco Exp $ | |
912 | # | |
913 | ||
914 | use strict; | |
915 | ||
916 | # enable only the following on debugging purpose | |
917 | #use warnings; | |
918 | #use CGI::Carp 'fatalsToBrowser'; | |
919 | ||
920 | use POSIX(); | |
921 | ||
922 | require '/var/ipfire/general-functions.pl'; | |
923 | require "${General::swroot}/lang.pl"; | |
924 | require "${General::swroot}/header.pl"; | |
925 | ||
926 | my $dbdir = "${General::swroot}/urlfilter/blacklists"; | |
927 | my $logdir = "/var/log/squidGuard"; | |
928 | ||
929 | my %cgiparams=(); | |
930 | my %logsettings=(); | |
931 | my %filtersettings=(); | |
932 | my %selected=(); | |
933 | ||
934 | my $errormessage=''; | |
935 | ||
936 | my @log=(); | |
937 | my $logarch=''; | |
938 | my $date=''; | |
939 | my $time=''; | |
940 | my $pid=''; | |
941 | my @loginfo=(); | |
942 | my @ip=(); | |
943 | my @category=(); | |
944 | my $dsturl=''; | |
945 | my $site=''; | |
946 | my $attr1=''; | |
947 | my $attr2=''; | |
948 | ||
949 | my $start=0; | |
950 | my $prev=0; | |
951 | my $next=0; | |
952 | my $lines=0; | |
953 | my @slice=(); | |
954 | ||
955 | my @then=(); | |
956 | my @temp=(); | |
957 | my @temp_then=(); | |
958 | my @temp_now=(); | |
959 | my $lastleap=''; | |
960 | ||
961 | my $day=''; | |
962 | my $daystr=''; | |
963 | my $month=''; | |
964 | my $monthstr=''; | |
965 | my $longmonthstr=''; | |
966 | my $year=''; | |
967 | ||
968 | my $logday=''; | |
969 | my $logmonth=''; | |
970 | my $logyear=''; | |
971 | ||
972 | my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', | |
973 | 'Sep', 'Oct', 'Nov', 'Dec' ); | |
974 | my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, | |
975 | $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, | |
976 | $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, | |
977 | $Lang::tr{'december'} ); | |
978 | ||
979 | my @now = localtime(time); | |
980 | my $doy = $now[7]; | |
981 | my $tdoy = $now[7]; | |
982 | my $year = $now[5]+1900; | |
983 | ||
984 | $cgiparams{'DAY'} = $now[3]; | |
985 | $cgiparams{'MONTH'} = $now[4]; | |
986 | $cgiparams{'LOGTYPE'} = 'urlfilter'; | |
987 | ||
988 | &Header::getcgihash(\%cgiparams); | |
989 | $logsettings{'LOGVIEW_REVERSE'} = 'off'; | |
990 | &General::readhash("${General::swroot}/logging/settings", \%logsettings); | |
991 | if (-e "${General::swroot}/urlfilter/settings") | |
992 | { | |
993 | &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings); | |
994 | } | |
995 | ||
996 | $now[4] = $cgiparams{'MONTH'}+1; | |
997 | if($now[4] < 10) { | |
998 | $now[4] = "0$now[4]"; } | |
999 | ||
1000 | $start = -1; | |
1001 | ||
1002 | if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'}) | |
1003 | { | |
1004 | @temp = split(',',$ ENV{'QUERY_STRING'}); | |
1005 | $start = $temp[0]; | |
1006 | $cgiparams{'MONTH'} = $temp[1]; | |
1007 | $cgiparams{'DAY'} = $temp[2]; | |
1008 | $cgiparams{'LOGTYPE'} = $temp[3]; | |
1009 | } | |
1010 | ||
1011 | if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || | |
1012 | !($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)$/)) | |
1013 | { | |
1014 | $cgiparams{'DAY'} = $now[3]; | |
1015 | $cgiparams{'MONTH'} = $now[4]; | |
1016 | } | |
1017 | elsif($cgiparams{'ACTION'} eq '>>') | |
1018 | { | |
1019 | @temp_now = localtime(time); | |
1020 | $temp_now[4] = $cgiparams{'MONTH'}; | |
1021 | $temp_now[3] = $cgiparams{'DAY'}; | |
1022 | @temp_then = localtime(POSIX::mktime(@temp_now) + 86400); | |
1023 | ## Retrieve the same time on the next day - | |
1024 | ## 86400 seconds in a day | |
1025 | $cgiparams{'MONTH'} = $temp_then[4]; | |
1026 | $cgiparams{'DAY'} = $temp_then[3]; | |
1027 | } | |
1028 | elsif($cgiparams{'ACTION'} eq '<<') | |
1029 | { | |
1030 | @temp_now = localtime(time); | |
1031 | $temp_now[4] = $cgiparams{'MONTH'}; | |
1032 | $temp_now[3] = $cgiparams{'DAY'}; | |
1033 | @temp_then = localtime(POSIX::mktime(@temp_now) - 86400); | |
1034 | ## Retrieve the same time on the previous day - | |
1035 | ## 86400 seconds in a day | |
1036 | $cgiparams{'MONTH'} = $temp_then[4]; | |
1037 | $cgiparams{'DAY'} = $temp_then[3]; | |
1038 | } | |
1039 | ||
1040 | $monthstr = $shortmonths[$cgiparams{'MONTH'}]; | |
1041 | $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; | |
1042 | ||
1043 | if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) | |
1044 | { | |
1045 | @then = (); | |
1046 | if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) || | |
1047 | ( $cgiparams{'MONTH'} > $now[4] ) ) { | |
1048 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 )); | |
1049 | } else { | |
1050 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 )); | |
1051 | } | |
1052 | $tdoy = $then[7]; | |
1053 | $lastleap=($year-1)%4; | |
1054 | if ($tdoy>$doy) { | |
1055 | if ($lastleap == 0 && $tdoy < 60) { | |
1056 | $doy=$tdoy+366; | |
1057 | } else { | |
1058 | $doy=$doy+365; | |
1059 | } | |
1060 | } | |
1061 | } | |
1062 | ||
1063 | $day = $cgiparams{'DAY'}; | |
1064 | if ($day <= 9) { | |
1065 | $daystr = " $day"; | |
1066 | } else { | |
1067 | $daystr = $day; | |
1068 | } | |
1069 | if ($day < 10) { | |
1070 | $day = "0$day"; | |
1071 | } | |
1072 | ||
1073 | &processevent; | |
1074 | ||
1075 | if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}) | |
1076 | { | |
1077 | print "Content-type: text/plain\n\n"; | |
1078 | print "IPCop URL filter log\r\n"; | |
1079 | print "Section: $cgiparams{'LOGTYPE'}\r\n"; | |
1080 | print "Date: $daystr $longmonthstr\r\n"; | |
1081 | print "\r\n"; | |
1082 | ||
1083 | if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; } | |
1084 | ||
1085 | foreach (@log) | |
1086 | { | |
1087 | ($date,$time,$pid,@loginfo) = split(/ /); | |
1088 | @ip = split(/\//,$loginfo[2]); | |
1089 | @category = split(/\//,$loginfo[0]); | |
1090 | $dsturl = $loginfo[1]; | |
1091 | $loginfo[3] =~ s/\%5c/\\/; | |
1092 | print "$date "; | |
1093 | print "$time "; | |
1094 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
1095 | { | |
1096 | print "$pid "; | |
1097 | print "@loginfo"; | |
1098 | } else { | |
1099 | print "$category[1] "; | |
1100 | print "$ip[0] "; | |
1101 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "$loginfo[3] "; } | |
1102 | print "$dsturl"; | |
1103 | print "\n"; | |
1104 | } | |
1105 | } | |
1106 | ||
1107 | exit; | |
1108 | } | |
1109 | ||
1110 | &Header::showhttpheaders(); | |
1111 | ||
1112 | &Header::openpage($Lang::tr{'urlfilter log viewer'}, 1, ''); | |
1113 | ||
1114 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
1115 | ||
1116 | if ($errormessage) { | |
1117 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
1118 | print "<font class='base'>$errormessage </font>\n"; | |
1119 | &Header::closebox(); | |
1120 | } | |
1121 | ||
1122 | &Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); | |
1123 | ||
1124 | $selected{'LOGTYPE'}{$cgiparams{'LOGTYPE'}} = "selected='selected'"; | |
1125 | ||
1126 | print <<END | |
1127 | <form method='post' action="$ENV{'SCRIPT_NAME'}"> | |
1128 | <table width='100%'> | |
1129 | <tr> | |
1130 | <td width='8%' class='base'>$Lang::tr{'section'}</td> | |
1131 | <td width='15%' class='base'> | |
1132 | <select name='LOGTYPE' size='1'> | |
1133 | <option value='urlfilter' $selected{'LOGTYPE'}{'urlfilter'} = "selected='selected'">$Lang::tr{'urlfilter url filter'}</option> | |
1134 | <option value='squidGuard' $selected{'LOGTYPE'}{'squidGuard'} = "selected='selected'">squidGuard</option> | |
1135 | </select> | |
1136 | </td> | |
1137 | ||
1138 | <td width='8%' class='base'>$Lang::tr{'month'}:</td> | |
1139 | <td width='15%'> | |
1140 | <select name='MONTH'> | |
1141 | END | |
1142 | ; | |
1143 | for ($month = 0; $month < 12; $month++) | |
1144 | { | |
1145 | print "\t<option "; | |
1146 | if ($month == $cgiparams{'MONTH'}) { | |
1147 | print 'selected="selected" '; } | |
1148 | print "value='$month'>$longmonths[$month]</option>\n"; | |
1149 | } | |
1150 | print <<END | |
1151 | </select> | |
1152 | </td> | |
1153 | <td width='8%' class='base'>$Lang::tr{'day'}:</td> | |
1154 | <td width='15%'> | |
1155 | <select name='DAY'> | |
1156 | END | |
1157 | ; | |
1158 | for ($day = 1; $day <= 31; $day++) | |
1159 | { | |
1160 | print "\t<option "; | |
1161 | if ($day == $cgiparams{'DAY'}) { | |
1162 | print 'selected="selected" '; } | |
1163 | print "value='$day'>$day</option>\n"; | |
1164 | } | |
1165 | print <<END | |
1166 | </select> | |
1167 | </td> | |
1168 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td> | |
1169 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td> | |
1170 | <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td> | |
1171 | <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td> | |
1172 | </tr> | |
1173 | </table> | |
1174 | </form> | |
1175 | END | |
1176 | ; | |
1177 | ||
1178 | &Header::closebox(); | |
1179 | ||
1180 | &Header::openbox('100%', 'left', $Lang::tr{'log'}); | |
1181 | ||
1182 | $lines = @log; | |
1183 | ||
1184 | if ($start == -1) { $start = $lines - $Header::viewsize; } | |
1185 | if ($start >= $lines - $Header::viewsize) { $start = $lines - $Header::viewsize; }; | |
1186 | if ($start < 0) { $start = 0; } | |
1187 | ||
1188 | $prev = $start - $Header::viewsize; | |
1189 | $next = $start + $Header::viewsize; | |
1190 | ||
1191 | if ($prev < 0) { $prev = 0; } | |
1192 | if ($next >= $lines) { $next = -1 } | |
1193 | if ($start == 0) { $prev = -1; } | |
1194 | ||
1195 | if ($cgiparams{'LOGTYPE'} eq 'urlfilter') | |
1196 | { | |
1197 | print "<b>$Lang::tr{'urlfilter log summary'} $longmonthstr $daystr: $lines</b><p>\n"; | |
1198 | } | |
1199 | ||
1200 | @slice = splice(@log, $start, $Header::viewsize); | |
1201 | ||
1202 | if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } | |
1203 | ||
1204 | if ($lines) | |
1205 | { | |
1206 | ||
1207 | $lines = 0; | |
1208 | ||
1209 | print "<table width='100%'>\n"; | |
1210 | unless ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
1211 | { | |
1212 | print "<tr>\n"; | |
1213 | print "<td align='center'><b>$Lang::tr{'urlfilter time'}</b></td>\n"; | |
1214 | print "<td align='center'><b>$Lang::tr{'urlfilter category'}</b></td>\n"; | |
1215 | print "<td align='center'><b>$Lang::tr{'urlfilter client'}</b></td>\n"; | |
1216 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "<td align='center'><b>$Lang::tr{'urlfilter username'}</b></td>\n"; } | |
1217 | print "<td align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>\n"; | |
1218 | print "</tr>\n"; | |
1219 | } | |
1220 | ||
1221 | foreach (@slice) | |
1222 | { | |
1223 | undef $attr1; undef $attr2; | |
1224 | $lines++; | |
1225 | ($date,$time,$pid,@loginfo) = split(/ /); | |
1226 | @ip = split(/\//,$loginfo[2]); | |
1227 | @category = split(/\//,$loginfo[0]); | |
1228 | $dsturl = $loginfo[1]; | |
1229 | $loginfo[3] =~ s/\%5c/\\/; | |
1230 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') { | |
1231 | if (@loginfo[0] =~ /squidGuard/) { $attr1 .= "<b>"; $attr2 .= "</b>"; } | |
1232 | if (@loginfo[1] =~ /ready/) { $attr1 .= "<b><font color='$Header::colourgreen'>"; $attr2 .= "</font></b>"; } | |
1233 | if (@loginfo[2] =~ /emergency/) { $attr1 .= "<b><font color='$Header::colourerr'>"; $attr2 .= "</font></b>"; } | |
1234 | print "<tr>\n"; | |
1235 | } else { | |
1236 | if ($lines % 2) { print "<tr bgcolor='$Header::table1colour'>\n"; } else { print "<tr bgcolor='$Header::table2colour'>\n"; } | |
1237 | } | |
1238 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') { | |
1239 | print "<td nowrap>$time $pid $attr1@loginfo$attr2</td>\n"; | |
1240 | } else { | |
1241 | print "<td width='10%' align='center' nowrap>$time</td>\n"; | |
1242 | print "<td width='11%' align='center' nowrap>$category[1]</td>\n"; | |
1243 | print "<td width='15%' align='center' nowrap>$ip[0]</td>\n"; | |
1244 | if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') | |
1245 | { | |
1246 | print "<td width='12%' align='center' nowrap>$loginfo[3]</td>\n"; | |
1247 | $site = substr($dsturl,0,55); | |
1248 | if (length($dsturl) > 55) { $site .= "..."; } | |
1249 | } else { | |
1250 | $site = substr($dsturl,0,69); | |
1251 | if (length($dsturl) > 69) { $site .= "..."; } | |
1252 | } | |
1253 | #print "<td>$site</td>\n"; | |
1254 | print "<td><a href='$dsturl' title='$dsturl' target='_blank'>$site</a></td>\n"; | |
1255 | } | |
1256 | print "</tr>\n"; | |
1257 | } | |
1258 | ||
1259 | print "</table><br>\n"; | |
1260 | ||
1261 | } | |
1262 | ||
1263 | &oldernewer(); | |
1264 | ||
1265 | &Header::closebox(); | |
1266 | ||
1267 | &Header::closebigbox(); | |
1268 | ||
1269 | &Header::closepage(); | |
1270 | ||
1271 | # ------------------------------------------------------------------- | |
1272 | ||
1273 | sub processevent | |
1274 | { | |
1275 | my $filestr=''; | |
1276 | ||
1277 | undef @log; | |
1278 | if ($cgiparams{'LOGTYPE'} eq 'squidGuard') | |
1279 | { | |
1280 | $filestr = "$logdir/squidGuard.log"; | |
1281 | foreach $logarch (<$filestr.*.gz>) | |
1282 | { | |
1283 | open (LOG,"gzip -dc $logarch |"); | |
1284 | foreach (<LOG>) { | |
1285 | ($date,$time,$pid,@loginfo) = split(/ /); | |
1286 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
1287 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
1288 | } | |
1289 | close(LOG); | |
1290 | } | |
1291 | open (LOG,$filestr); | |
1292 | foreach (<LOG>) { | |
1293 | ($date,$time,$pid,@loginfo) = split(/ /); | |
1294 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
1295 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
1296 | } | |
1297 | close(LOG); | |
1298 | } else { | |
1299 | foreach $logarch (<$logdir/*.gz>) | |
1300 | { | |
1301 | if ($logarch !~ /squidGuard\.log/) { | |
1302 | open (LOG,"gzip -dc $logarch |"); | |
1303 | foreach (<LOG>) { | |
1304 | ($date,$time,$pid,@loginfo) = split(/ /); | |
1305 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
1306 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
1307 | } | |
1308 | close(LOG); | |
1309 | } | |
1310 | } | |
1311 | foreach $filestr (<$logdir/*.log>) | |
1312 | { | |
1313 | if ($filestr !~ /squidGuard\.log/) { | |
1314 | open (LOG,$filestr); | |
1315 | foreach (<LOG>) { | |
1316 | ($date,$time,$pid,@loginfo) = split(/ /); | |
1317 | ($logyear,$logmonth,$logday) = split(/-/,$date); | |
1318 | if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) } | |
1319 | } | |
1320 | close(LOG); | |
1321 | } | |
1322 | } | |
1323 | @log = sort { substr($a,11,8) cmp substr($b,11,8) } @log; | |
1324 | ||
1325 | } | |
1326 | } | |
1327 | ||
1328 | # ------------------------------------------------------------------- | |
1329 | ||
1330 | sub oldernewer | |
1331 | { | |
1332 | print "<table width='100%'>"; | |
1333 | print "<tr>"; | |
1334 | ||
1335 | print "<td align='center' width='50%'>"; | |
1336 | if ($prev != -1) { | |
1337 | print "<a href='$ENV{'SCRIPT_NAME'}?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'older'}</a>"; } | |
1338 | else { | |
1339 | print "$Lang::tr{'older'}"; } | |
1340 | print "</td>\n"; | |
1341 | ||
1342 | print "<td align='center' width='50%'>"; | |
1343 | if ($next != -1) { | |
1344 | print "<a href='$ENV{'SCRIPT_NAME'}?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'newer'}</a>"; } | |
1345 | else { | |
1346 | print "$Lang::tr{'newer'}"; } | |
1347 | print "</td>\n"; | |
1348 | ||
1349 | print "</tr>"; | |
1350 | print "</table>"; | |
1351 | } | |
1352 | ||
1353 | # ------------------------------------------------------------------- |