]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/ipblocklists.dat
5 # This code is distributed under the terms of the GPL
8 # page inspired from the initial firewalllog.dat
10 # Modified for IPFire by Christian Schmidt
11 # and Michael Tremer (www.ipfire.org)
15 # enable only the following on debugging purpose
17 #use CGI::Carp 'fatalsToBrowser';
19 require '/var/ipfire/general-functions.pl';
20 require "${General::swroot}/lang.pl";
21 require "${General::swroot}/header.pl";
23 require "${General::swroot}/ipblocklist-functions.pl";
24 require "${General::swroot}/ipblocklist/sources";
29 my $errormessage = '';
31 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
32 'Sep', 'Oct', 'Nov', 'Dec' );
33 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
34 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
35 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
36 $Lang::tr
{'december'} );
38 my @now = localtime();
42 my $year = $now[5]+1900;
44 $cgiparams{'DAY'} = $now[3];
45 $cgiparams{'MONTH'} = $now[4];
46 $cgiparams{'ACTION'} = '';
48 &Header
::getcgihash
(\
%cgiparams);
51 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
53 my @temp = split(',',$ENV{'QUERY_STRING'});
55 $cgiparams{'MONTH'} = $temp[1];
56 $cgiparams{'DAY'} = $temp[2];
59 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
60 !($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)$/))
62 $cgiparams{'DAY'} = $now[3];
63 $cgiparams{'MONTH'} = $now[4];
65 elsif($cgiparams{'ACTION'} eq '>>')
68 my @temp_now = localtime(time);
69 $temp_now[4] = $cgiparams{'MONTH'};
70 $temp_now[3] = $cgiparams{'DAY'};
71 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
72 ## Retrieve the same time on the next day -
73 ## 86400 seconds in a day
74 $cgiparams{'MONTH'} = $temp_then[4];
75 $cgiparams{'DAY'} = $temp_then[3];
77 elsif($cgiparams{'ACTION'} eq '<<')
80 my @temp_now = localtime(time);
81 $temp_now[4] = $cgiparams{'MONTH'};
82 $temp_now[3] = $cgiparams{'DAY'};
83 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
84 ## Retrieve the same time on the previous day -
85 ## 86400 seconds in a day
86 $cgiparams{'MONTH'} = $temp_then[4];
87 $cgiparams{'DAY'} = $temp_then[3];
90 if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
93 if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
94 ( $cgiparams{'MONTH'} > $now[4] ) ) {
95 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
97 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
100 my $lastleap=($year-1)%4;
102 if ($lastleap == 0 && $tdoy < 60) {
114 $datediff=int(($doy-$tdoy)/7);
115 $dowd=($doy-$tdoy)%7;
116 if (($dow-$dowd)<1) {
117 $datediff=$datediff+1;
119 if (($dow-$dowd)==0) {
124 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
125 my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
126 my $day = $cgiparams{'DAY'};
138 &General
::readhash
("${General::swroot}/ipblocklist/settings", \
%settings);
140 # Get all available blocklists.
141 my @blocklists = &IPblocklist
::get_blocklists
();
143 foreach my $blocklist (@blocklists)
145 $lists{$blocklist} = {} if ($settings{$blocklist} eq 'on');
151 $filestr="/var/log/messages";
153 $filestr="/var/log/messages.$datediff";
154 $filestr = "$filestr.gz" if -f
"$filestr.gz";
157 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
158 $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
160 # Note: This is in case the log does not exist for that date
170 if (/^${monthstr} ${daystr} ..:..:.. [\w\-]+ kernel:.*BLKLST_(\w+)\s*IN=(\w*)/)
174 if ($2 =~ m/ppp|red/)
181 $lists{$list}{out
}++;
193 $datediff=$datediff-1;
195 $filestr="/var/log/messages";
197 $filestr="/var/log/messages.$datediff";
198 $filestr = "$filestr.gz" if -f
"$filestr.gz";
200 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
201 $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
206 if (/^${monthstr} ${daystr} ..:..:.. [\w\-]+ kernel:.*BLKLST_(\w+)\s*IN=(\w+)/)
210 if ($2 =~ m/ppp|red/)
217 $lists{$list}{out
}++;
228 my $MODNAME="fwlogs";
230 &Header
::showhttpheaders
();
231 &Header
::openpage
($Lang::tr
{'ipblocklist logs'}, 1, '');
232 &Header
::openbigbox
('100%', 'left', '', $errormessage);
236 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
237 print "<font class='base'>$errormessage </font>\n";
241 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}");
244 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
247 <td width='10%' class='base'>$Lang::tr{'month'}: </td>
249 <select name='MONTH'>
253 for ($month = 0; $month < 12; $month++)
256 if ($month == $cgiparams{'MONTH'}) {
257 print "selected='selected' ";
259 print "value='$month'>$longmonths[$month]</option>\n";
264 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
269 for ($day = 1; $day <= 31; $day++)
272 if ($day == $cgiparams{'DAY'}) {
273 print "selected='selected' ";
275 print "value='$day'>$day</option>\n";
281 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
282 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
283 <td width='20%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
292 &Header
::openbox
('100%', 'left', $Lang::tr
{'firewall log'});
293 print "<p><b>$Lang::tr{'ipblocklist hits'} $longmonthstr $daystr: $lines</b></p>";
296 my %mainsettings = ();
297 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
298 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
300 my @lists = sort keys (%lists);
303 <table width='100%' class='tbl'>
305 <th align='center' class='boldbase' rowspan='2'></th>
306 <th align='left' class='boldbase' rowspan='2'><b>$Lang::tr{'ipblocklist id'}</b></th>
307 <th align='left' class='boldbase' rowspan='2'><b>$Lang::tr{'ipblocklist category'}</b></th>
308 <th align='center' class='boldbase' colspan='2'><b>$Lang::tr{'ipblocklist input'}</b></th>
309 <th align='center' class='boldbase' colspan='2'><b>$Lang::tr{'ipblocklist output'}</b></th>
312 <th align='center' class='boldbase'>$Lang::tr{'count'}</th>
313 <th align='center' class='boldbase'>$Lang::tr{'percentage'}</th>
314 <th align='center' class='boldbase'>$Lang::tr{'count'}</th>
315 <th align='center' class='boldbase'>$Lang::tr{'percentage'}</th>
321 my $lists = join ',', @lists;
323 foreach my $list (@lists)
325 my $col = ($lines++ % 2) ?
"bgcolor='$color{'color20'}'" : "bgcolor='$color{'color22'}'";
326 my $category = exists( $IPblocklist::List
::sources
{$list}) ?
$Lang::tr
{"ipblocklist category $IPblocklist::List::sources{$list}{'category'}"} : ' ';
330 print "<td align='center' $col><form method='post' action='showrequestfromblocklist.dat'><input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'> <input type='hidden' name='DAY' value='$cgiparams{'DAY'}'> <input type='hidden' name='blocklist' value='$list'><input type='hidden' name='blocklists' value='$lists'> <input type='submit' value='$Lang::tr{'details'}'></form></td>";
332 if (exists($IPblocklist::List
::sources
{$list}) and $IPblocklist::List
::sources
{$list}{'info'})
334 print "<td $col><a href='$IPblocklist::List::sources{$list}{info}' target='_blank'>$list</a></td>";
338 print "<td $col>$list</td>";
341 print "<td $col>$category</td>";
343 foreach my $direction ('in', 'out')
345 my $count = $lists{$list}{$direction} || 0;
346 my $percent = $directions{$direction} > 0 ?
$count * 100 / $directions{$direction} : 0;
347 $percent = sprintf("%.f", $percent);
348 print "<td align='center' class='boldbase' $col>$count</th>";
349 print "<td align='center' class='boldbase' $col>$percent%</th>";
360 &Header
::closebigbox
();
361 &Header
::closepage
();
364 #Automatic Updates is disabled