]>
git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/showrequestfromip.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);
52 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
54 my @temp = split(',',$ENV{'QUERY_STRING'});
56 $cgiparams{'MONTH'} = $temp[1];
57 $cgiparams{'DAY'} = $temp[2];
58 $cgiparams{ip
} = $temp[3];
61 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
62 !($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)$/))
64 $cgiparams{'DAY'} = $now[3];
65 $cgiparams{'MONTH'} = $now[4];
67 elsif($cgiparams{'ACTION'} eq '>>')
70 my @temp_now = localtime(time);
71 $temp_now[4] = $cgiparams{'MONTH'};
72 $temp_now[3] = $cgiparams{'DAY'};
73 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
74 ## Retrieve the same time on the next day -
75 ## 86400 seconds in a day
76 $cgiparams{'MONTH'} = $temp_then[4];
77 $cgiparams{'DAY'} = $temp_then[3];
79 elsif($cgiparams{'ACTION'} eq '<<')
82 my @temp_now = localtime(time);
83 $temp_now[4] = $cgiparams{'MONTH'};
84 $temp_now[3] = $cgiparams{'DAY'};
85 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
86 ## Retrieve the same time on the previous day -
87 ## 86400 seconds in a day
88 $cgiparams{'MONTH'} = $temp_then[4];
89 $cgiparams{'DAY'} = $temp_then[3];
92 if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
95 if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
96 ( $cgiparams{'MONTH'} > $now[4] ) ) {
97 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
99 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
102 my $lastleap=($year-1)%4;
104 if ($lastleap == 0 && $tdoy < 60) {
115 $datediff=int(($doy-$tdoy)/7);
116 $dowd=($doy-$tdoy)%7;
117 if (($dow-$dowd)<1) {
118 $datediff=$datediff+1;
120 if (($dow-$dowd)==0) {
125 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
126 my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
127 my $day = $cgiparams{'DAY'};
138 $filestr="/var/log/messages";
140 $filestr="/var/log/messages.$datediff";
141 $filestr = "$filestr.gz" if -f
"$filestr.gz";
144 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
145 $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
147 # Note: This is in case the log does not exist for that date
151 my $ip = $cgiparams{ip
};
156 if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {
157 if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) {
170 $datediff=$datediff-1;
172 $filestr="/var/log/messages";
174 $filestr="/var/log/messages.$datediff";
175 $filestr = "$filestr.gz" if -f
"$filestr.gz";
177 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
178 $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
183 if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {
184 if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) {
196 &Header
::showhttpheaders
();
197 &Header
::openpage
($Lang::tr
{'firewall log ip'}, 1, '');
198 &Header
::openbigbox
('100%', 'left', '', $errormessage);
201 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
202 print "<font class='base'>$errormessage </font>\n";
206 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
209 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
212 <td width='10%' class='base'>$Lang::tr{'month'}: </td>
214 <select name='MONTH'>
218 for ($month = 0; $month < 12; $month++)
221 if ($month == $cgiparams{'MONTH'}) {
222 print "selected='selected' "; }
223 print "value='$month'>$longmonths[$month]</option>\n";
228 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
233 for ($day = 1; $day <= 31; $day++)
236 if ($day == $cgiparams{'DAY'}) {
237 print "selected='selected' "; }
238 print "value='$day'>$day</option>\n";
243 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
244 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
245 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
246 <tr><td width='15%'>$Lang::tr{'source ip'}</td><td><input type='text' name='ip' value='$cgiparams{ip}'size='15'></td></tr>
255 &Header
::openbox
('100%', 'left', $Lang::tr
{'firewall log ip'});
256 print "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>";
259 $start = $lines - ${Header
::viewsize
};
261 if ($start >= $lines - ${Header
::viewsize
}) { $start = $lines - ${Header
::viewsize
}; };
262 if ($start < 0) { $start = 0; }
264 my $prev = $start - ${Header
::viewsize
};
265 my $next = $start + ${Header
::viewsize
};
267 if ($prev < 0) { $prev = 0; }
268 if ($next >= $lines) { $next = -1 }
269 if ($start == 0) { $prev = -1; }
271 if ($lines != 0) { &oldernewer
(); }
276 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
277 <td width='13%' align='center' class='boldbase'><b>$Lang::tr{'chain'}</b></td>
278 <td width='5%' align='center' class='boldbase'><b>$Lang::tr{'iface'}</b></td>
279 <td width='5%' align='center' class='boldbase'><b>$Lang::tr{'proto'}</b></td>
280 <td width='16%' align='center' class='boldbase'><b>$Lang::tr{'source'}</b></td>
281 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'src port'}</b></td>
282 <td width='16%' align='center' class='boldbase'><b>$Lang::tr{'destination'}</b></td>
283 <td width='16%' align='center' class='boldbase'><b>$Lang::tr{'dst port'}</b></td>
288 my @slice = splice(@log, $start, ${Header
::viewsize
});
290 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
293 foreach $_ (@slice) {
295 # Check whether valid ipv4 or ipv6 address
296 if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) {
299 my $in = '-'; my $out = '-';
300 my $srcaddr = ''; my $dstaddr = '';
302 my $srcport = ''; my $dstport = '';
304 # If ipv6 uses bridge, the use PHYSIN, otherwise use IN
305 if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {}
306 elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {}
307 my $timestamp = $1; my $chain = $2; my $packet = $3;
308 $timestamp =~ /(...) (..) (..:..:..)/;
309 my $month = $1; my $day = $2; my $time = $3;
311 # If ipv6 uses bridge, the use PHYSIN and PHYSOUT, otherwise use IN and OUT
312 if ($a =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($a =~ /IN=(\w+)/) { $iface = $1; }
313 if ($a =~ /PHYSOUT=(\w+)/) { $out = $1; } elsif ($a =~ /OUT=(\w+)/) { $out = $1; }
314 # Detect ipv4 and ipv6 addresses
315 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; }
316 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; }
317 if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; }
318 my $protostrlc = lc($protostr);
319 if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; }
320 if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; }
323 print "<tr bgcolor='${Header::table1colour}'>\n";
326 print "<tr bgcolor='${Header::table2colour}'>\n";
329 <td align='center'>$time</td>
330 <td align='center'>$chain</td>
331 <td align='center'>$iface</td>
332 <td align='center'>$protostr</td>
334 <table width='100%' cellpadding='0' cellspacing='0'><tr>
335 <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td>
338 <td align='center'>$srcport</td>
340 <table width='100%' cellpadding='0' cellspacing='0'><tr>
341 <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td>
344 <td align='center'>$dstport</td>
360 print"<table width='100%'><tr><td align='center'><a href='/cgi-bin/logs.cgi/firewalllogip.dat'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td></tr></table>";
364 &Header
::closebigbox
();
366 &Header
::closepage
();
376 print "<td align='center' width='50%'>";
378 print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'older'}</a>";
381 print "$Lang::tr{'older'}";
385 print "<td align='center' width='50%'>";
387 print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'newer'}</a>";
390 print "$Lang::tr{'newer'}";