]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/showrequestfromblocklist.dat
4 # This code is distributed under the terms of the GPL
7 # page inspired from the initial firewalllog.dat
9 # Modified for IPFire by Christian Schmidt (www.ipfire.org)
11 # enable only the following on debugging purpose
13 #use CGI::Carp 'fatalsToBrowser';
15 require '/var/ipfire/general-functions.pl';
16 require "${General::swroot}/lang.pl";
17 require "${General::swroot}/header.pl";
21 #workaround to suppress a warning when a variable is used only once
22 my @dummy = ( ${Header
::table2colour
} );
27 my $errormessage = '';
29 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
30 'Sep', 'Oct', 'Nov', 'Dec' );
31 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
32 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
33 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
34 $Lang::tr
{'december'} );
36 my @now = localtime();
40 my $year = $now[5]+1900;
42 $cgiparams{'DAY'} = $now[3];
43 $cgiparams{'MONTH'} = $now[4];
44 $cgiparams{'ACTION'} = '';
46 &Header
::getcgihash
(\
%cgiparams);
48 $logsettings{'LOGVIEW_REVERSE'} = 'off';
49 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
53 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
55 my @temp = split(',',$ENV{'QUERY_STRING'}, 5);
57 $cgiparams{'MONTH'} = shift @temp;
58 $cgiparams{'DAY'} = shift @temp;
59 $cgiparams{'blocklist'} = shift @temp;
60 $cgiparams{'blocklists'} = shift @temp;
63 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
64 !($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)$/))
66 $cgiparams{'DAY'} = $now[3];
67 $cgiparams{'MONTH'} = $now[4];
69 elsif($cgiparams{'ACTION'} eq '>>')
72 my @temp_now = localtime(time);
73 $temp_now[4] = $cgiparams{'MONTH'};
74 $temp_now[3] = $cgiparams{'DAY'};
75 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
76 ## Retrieve the same time on the next day -
77 ## 86400 seconds in a day
78 $cgiparams{'MONTH'} = $temp_then[4];
79 $cgiparams{'DAY'} = $temp_then[3];
81 elsif($cgiparams{'ACTION'} eq '<<')
84 my @temp_now = localtime(time);
85 $temp_now[4] = $cgiparams{'MONTH'};
86 $temp_now[3] = $cgiparams{'DAY'};
87 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
88 ## Retrieve the same time on the previous day -
89 ## 86400 seconds in a day
90 $cgiparams{'MONTH'} = $temp_then[4];
91 $cgiparams{'DAY'} = $temp_then[3];
94 if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
97 if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
98 ( $cgiparams{'MONTH'} > $now[4] ) ) {
99 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
101 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
104 my $lastleap=($year-1)%4;
106 if ($lastleap == 0 && $tdoy < 60) {
114 if ($cgiparams{'blocklists'})
116 @blocklists = split ',', $cgiparams{'blocklists'};
123 $datediff=int(($doy-$tdoy)/7);
124 $dowd=($doy-$tdoy)%7;
125 if (($dow-$dowd)<1) {
126 $datediff=$datediff+1;
128 if (($dow-$dowd)==0) {
133 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
134 my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
135 my $day = $cgiparams{'DAY'};
146 $filestr="/var/log/messages";
148 $filestr="/var/log/messages.$datediff";
149 $filestr = "$filestr.gz" if -f
"$filestr.gz";
152 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
153 $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
155 # Note: This is in case the log does not exist for that date
159 my $blocklist = $cgiparams{blocklist
};
164 if (/^${monthstr} ${daystr} ..:..:.. [\w\-]+ kernel:.*BLKLST_(\w+)\s?IN=.*/) {
165 if($1 eq $blocklist){
176 $datediff=$datediff-1;
178 $filestr="/var/log/messages";
180 $filestr="/var/log/messages.$datediff";
181 $filestr = "$filestr.gz" if -f
"$filestr.gz";
183 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
184 $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
189 if (/^${monthstr} ${daystr} ..:..:.. [\w\-]+ kernel:.*BLKLST_(\w+)\s?IN=.*/) {
190 if($1 eq $blocklist){
200 &Header
::showhttpheaders
();
201 &Header
::openpage
($Lang::tr
{'ipblocklist log list'}, 1, '');
202 &Header
::openbigbox
('100%', 'left', '', $errormessage);
205 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
206 print "<font class='base'>$errormessage </font>\n";
210 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
213 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
214 <input type='hidden' name='blocklists' value='$cgiparams{blocklists}'>
217 <td width='10%' class='base'>$Lang::tr{'month'}: </td>
219 <select name='MONTH'>
223 for ($month = 0; $month < 12; $month++)
226 if ($month == $cgiparams{'MONTH'}) {
227 print "selected='selected' "; }
228 print "value='$month'>$longmonths[$month]</option>\n";
233 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
238 for ($day = 1; $day <= 31; $day++)
241 if ($day == $cgiparams{'DAY'}) {
242 print "selected='selected' "; }
243 print "value='$day'>$day</option>\n";
248 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
249 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
250 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
251 <tr><td width='15%'>$Lang::tr{'ipblocklist id'}</td><td><select name='blocklist'>
255 foreach my $option (@blocklists)
257 my $selected = $option eq $cgiparams{blocklist
} ?
' selected' : '';
258 print "<option value='$option'$selected>$option</option>";
271 &Header
::openbox
('100%', 'left', $Lang::tr
{'ipblocklist log list'});
272 print "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>";
275 $start = $lines - ${Header
::viewsize
};
277 if ($start >= $lines - ${Header
::viewsize
}) { $start = $lines - ${Header
::viewsize
}; };
278 if ($start < 0) { $start = 0; }
280 my $prev = $start - ${Header
::viewsize
};
281 my $next = $start + ${Header
::viewsize
};
283 if ($prev < 0) { $prev = 0; }
284 if ($next >= $lines) { $next = -1 }
285 if ($start == 0) { $prev = -1; }
287 if ($lines != 0) { &oldernewer
(); }
292 <td width='12%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
293 <td width='6%' align='center' class='boldbase'><b>$Lang::tr{'iface'}</b></td>
294 <td width='6%' align='center' class='boldbase'><b>$Lang::tr{'proto'}</b></td>
295 <td width='18%' align='center' class='boldbase'><b>$Lang::tr{'source'}</b></td>
296 <td width='15%' align='center' class='boldbase'><b>$Lang::tr{'src port'}</b></td>
297 <td width='18%' align='center' class='boldbase'><b>$Lang::tr{'destination'}</b></td>
298 <td width='15%' align='center' class='boldbase'><b>$Lang::tr{'dst port'}</b></td>
303 my @slice = splice(@log, $start, ${Header
::viewsize
});
305 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
308 foreach $_ (@slice) {
310 # Check whether valid ipv4 or ipv6 address
311 if (($_ =~ /BLKLST_(\w+)\s?IN=/)) {
312 if($1 eq $blocklist) {
313 my $in = '-'; my $out = '-';
314 my $srcaddr = ''; my $dstaddr = '';
316 my $srcport = ''; my $dstport = '';
318 # If ipv6 uses bridge, the use PHYSIN, otherwise use IN
319 if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:.*(IN=.*)(PHYSIN=.*)$/) {}
320 elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {}
321 my $timestamp = $1; my $packet = $2;
322 $timestamp =~ /(...) (..) (..:..:..)/;
323 my $month = $1; my $day = $2; my $time = $3;
325 # If ipv6 uses bridge, the use PHYSIN and PHYSOUT, otherwise use IN and OUT
326 if ($a =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($a =~ /IN=(\w+)/) { $iface = $1; }
327 if ($a =~ /PHYSOUT=(\w+)/) { $out = $1; } elsif ($a =~ /OUT=(\w+)/) { $out = $1; }
328 # Detect ipv4 and ipv6 addresses
329 if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; }
330 if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; }
331 if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; }
332 my $protostrlc = lc($protostr);
333 if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; }
334 if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; }
337 print "<tr bgcolor='${Header::table1colour}'>\n";
340 print "<tr bgcolor='${Header::table2colour}'>\n";
343 <td align='center'>$time</td>
344 <td align='center'>$iface</td>
345 <td align='center'>$protostr</td>
347 <table width='100%' cellpadding='0' cellspacing='0'><tr>
348 <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td>
351 <td align='center'>$srcport</td>
353 <table width='100%' cellpadding='0' cellspacing='0'><tr>
354 <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td>
357 <td align='center'>$dstport</td>
373 print"<table width='100%'><tr><td align='center'><a href='/cgi-bin/logs.cgi/ipblocklists.dat'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td></tr></table>";
377 &Header
::closebigbox
();
379 &Header
::closepage
();
389 my $blocklists = join ',', @blocklists;
391 print "<td align='center' width='50%'>";
393 print "<a href='/cgi-bin/logs.cgi/showrequestfromblocklist.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{blocklist},$blocklists'>$Lang::tr{'older'}</a>";
396 print "$Lang::tr{'older'}";
400 print "<td align='center' width='50%'>";
402 print "<a href='/cgi-bin/logs.cgi/showrequestfromblocklist.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{blocklist},$blocklists'>$Lang::tr{'newer'}</a>";
405 print "$Lang::tr{'newer'}";