]>
git.ipfire.org Git - people/pmueller/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
};
157 if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {
158 if($_ =~ /SRC\=([\d\.]+)/){
171 $datediff=$datediff-1;
173 $filestr="/var/log/messages";
175 $filestr="/var/log/messages.$datediff";
176 $filestr = "$filestr.gz" if -f
"$filestr.gz";
178 if (!(open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
179 $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
184 if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {
185 if($_ =~ /SRC\=([\d\.]+)/){
197 &Header
::showhttpheaders
();
198 &Header
::openpage
($Lang::tr
{'firewall log'}, 1, '');
199 &Header
::openbigbox
('100%', 'left', '', $errormessage);
202 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
203 print "<font class='base'>$errormessage </font>\n";
207 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
210 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
213 <td width='10%' class='base'>$Lang::tr{'month'}: </td>
215 <select name='MONTH'>
219 for ($month = 0; $month < 12; $month++)
222 if ($month == $cgiparams{'MONTH'}) {
223 print "selected='selected' "; }
224 print "value='$month'>$longmonths[$month]</option>\n";
229 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
234 for ($day = 1; $day <= 31; $day++)
237 if ($day == $cgiparams{'DAY'}) {
238 print "selected='selected' "; }
239 print "value='$day'>$day</option>\n";
244 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
245 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
246 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
247 <tr><td width='15%'>$Lang::tr{'source ip'}</td><td><input type='text' name='ip' value='$cgiparams{ip}'size='15'></td></tr>
256 &Header
::openbox
('100%', 'left', $Lang::tr
{'firewall log'});
257 print "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>";
260 $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; }
296 if($_ =~ /SRC\=([\d\.]+)/){
299 my $in = '-'; my $out = '-';
300 my $srcaddr = ''; my $dstaddr = '';
302 my $srcport = ''; my $dstport = '';
304 $_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/;
305 my $timestamp = $1; my $chain = $2; my $packet = $3;
306 $timestamp =~ /(...) (..) (..:..:..)/;
307 my $month = $1; my $day = $2; my $time = $3;
309 if ($a =~ /IN\=(\w+)/) { $iface = $1; }
310 if ($a =~ /OUT\=(\w+)/) { $out = $1; }
311 if ($a =~ /SRC\=([\d\.]+)/) { $srcaddr = $1; }
312 if ($a =~ /DST\=([\d\.]+)/) { $dstaddr = $1; }
313 if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; }
314 my $protostrlc = lc($protostr);
315 if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; }
316 if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; }
319 print "<tr bgcolor='${Header::table1colour}'>\n"; }
321 print "<tr bgcolor='${Header::table2colour}'>\n"; }
323 <TD ALIGN='CENTER'>$time</TD>
324 <TD ALIGN='CENTER'>$chain</TD>
325 <TD ALIGN='CENTER'>$iface</TD>
326 <TD ALIGN='CENTER'>$protostr</TD>
328 <table width='100%' cellpadding='0' cellspacing='0'><tr>
329 <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td>
332 <TD ALIGN='CENTER'>$srcport</TD>
334 <table width='100%' cellpadding='0' cellspacing='0'><tr>
335 <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td>
338 <TD ALIGN='CENTER'>$dstport</TD>
356 &Header
::closebigbox
();
358 &Header
::closepage
();
368 print "<td align='center' width='50%'>";
370 print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'older'}</a>"; }
372 print "$Lang::tr{'older'}"; }
375 print "<td align='center' width='50%'>";
377 print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'newer'}</a>"; }
379 print "$Lang::tr{'newer'}"; }