]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/ids.dat
86207c2aa248dc355d6ce1378de7310ee7fa7d77
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
9 # Copyright (C) 18-03-2002 Mark Wormgoor <mark@wormgoor.com>
10 # - Added links to Snort database and ipinfo.cgi
12 # $Id: ids.dat,v 1.6.2.16 2005/06/14 08:25:30 eoberlander Exp $
17 # enable only the following on debugging purpose
19 #use CGI::Carp 'fatalsToBrowser';
21 require '/var/ipfire/general-functions.pl';
22 require "${General::swroot}/lang.pl";
23 require "${General::swroot}/header.pl";
26 my %mainsettings = ();
27 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
28 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
32 #workaround to suppress a warning when a variable is used only once
33 my @dummy = ( ${Header
::table1colour
}, ${Header
::table2colour
} );
39 my $errormessage = '';
41 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
42 'Sep', 'Oct', 'Nov', 'Dec' );
43 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
44 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
45 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
46 $Lang::tr
{'december'} );
48 my @now = localtime(time);
52 my $year = $now[5]+1900;
54 $cgiparams{'DAY'} = $now[3];
55 $cgiparams{'MONTH'} = $now[4];
56 $cgiparams{'ACTION'} = '';
58 &Header
::getcgihash
(\
%cgiparams);
59 $logsettings{'LOGVIEW_REVERSE'} = 'off';
60 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
61 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
62 $Header::viewsize
/= 5; # each ids is displayed on 5 lines
64 $now[4] = $cgiparams{'MONTH'}+1;
66 $now[4] = "0$now[4]"; }
69 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
71 my @temp = split(',',$ ENV
{'QUERY_STRING'});
73 $cgiparams{'MONTH'} = $temp[1];
74 $cgiparams{'DAY'} = $temp[2];
77 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
78 !($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)$/))
80 $cgiparams{'DAY'} = $now[3];
81 $cgiparams{'MONTH'} = $now[4];
83 elsif($cgiparams{'ACTION'} eq '>>')
86 my @temp_now = localtime(time);
87 $temp_now[4] = $cgiparams{'MONTH'};
88 $temp_now[3] = $cgiparams{'DAY'};
89 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
90 ## Retrieve the same time on the next day +
91 ## 86400 seconds in a day
92 $cgiparams{'MONTH'} = $temp_then[4];
93 $cgiparams{'DAY'} = $temp_then[3];
95 elsif($cgiparams{'ACTION'} eq '<<')
98 my @temp_now = localtime(time);
99 $temp_now[4] = $cgiparams{'MONTH'};
100 $temp_now[3] = $cgiparams{'DAY'};
101 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
102 ## Retrieve the same time on the previous day -
103 ## 86400 seconds in a day
104 $cgiparams{'MONTH'} = $temp_then[4];
105 $cgiparams{'DAY'} = $temp_then[3];
109 if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
112 if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
113 ( $cgiparams{'MONTH'} > $now[4] ) ) {
114 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
116 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
119 my $lastleap=($year-1)%4;
121 if ($lastleap == 0 && $tdoy < 60) {
132 $datediff=int(($doy-$tdoy)/7);
133 $dowd=($doy-$tdoy)%7;
134 if (($dow-$dowd)<1) {
135 $datediff=$datediff+1;
137 if (($dow-$dowd)==0) {
142 my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
143 my $monthnum = $cgiparams{'MONTH'} + 1;
144 my $monthstr = $monthnum <= 9 ?
"0$monthnum" : "$monthnum";
145 my $daystr = $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
148 my ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
153 $datediff=$datediff-1;
157 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
159 print "Content-type: text/plain\n\n";
160 print "IPFire IDS snort log\r\n";
161 print "Date: $cgiparams{'DAY'} $longmonths[$cgiparams{'MONTH'}]\r\n";
164 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
168 my ($datetime,$title,$priority,$classification,$srcip,$srcport,$destip,$destport,$sid,$refs) = split(/\|/);
170 print "Date: $datetime\n";
171 print "Name: $title\n";
172 print "Priority: $priority\n";
173 print "Type: $classification\n";
176 if ($srcport != "n/a") {
181 if ($destport != "n/a") {
186 print "Refs: $refs\n\n";
192 &Header
::showhttpheaders
();
194 &Header
::openpage
($Lang::tr
{'ids log viewer'}, 1, '');
196 &Header
::openbigbox
('100%', 'left', '', $errormessage);
199 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
200 print "<font class='base'>$errormessage </font>\n";
204 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
207 <form method='post' action="$ENV{'SCRIPT_NAME'}">
210 <td width='10%' class='base'>$Lang::tr{'month'}: </td>
212 <select name='MONTH'>
215 for (my $month = 0; $month < 12; $month++)
218 if ($month == $cgiparams{'MONTH'}) {
219 print 'selected="selected" '; }
220 print "value='$month'>$longmonths[$month]</option>\n";
225 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
230 for (my $day = 1; $day <= 31; $day++)
233 if ($day == $cgiparams{'DAY'}) {
234 print 'selected="selected" '; }
235 print "value='$day'>$day</option>\n";
240 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
241 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
242 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
243 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
252 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
253 print "<p><b>$Lang::tr{'snort hits'} $longmonthstr $daystr: $lines</b></p>";
256 $start = $lines - ${Header
::viewsize
}; }
257 if ($start >= $lines - ${Header
::viewsize
}) { $start = $lines - ${Header
::viewsize
}; };
258 if ($start < 0) { $start = 0; }
260 my $prev = $start - ${Header
::viewsize
};
261 my $next = $start + ${Header
::viewsize
};
263 if ($prev < 0) { $prev = 0; }
264 if ($next >= $lines) { $next = -1 }
265 if ($start == 0) { $prev = -1; }
266 my @slice = splice(@log, $start, ${Header
::viewsize
});
268 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
284 print "<tr bgcolor='$color{'color20'}'><td>\n"; }
286 print "<tr bgcolor='$color{'color22'}'><td>\n"; }
287 my ($datetime,$title,$priority,$classification,$srcip,$srcport,$destip,$destport,$sid,$refs) = split(/\|/);
291 <td width='15%'><b>$Lang::tr{'date'}:</b></td><td width='25%'>$datetime</td>
292 <td width='10%'><b>$Lang::tr{'name'}:</b></td><td width='50%'>$title</td>
294 <tr><td><b>$Lang::tr{'priority'}:</b></td><td>$priority</td>
295 <td><b>$Lang::tr{'type'}:</b></td><td>$classification</td>
297 <tr><td><b>$Lang::tr{'ipinfo'}:</b></td>
301 if ($srcip ne "n/a") {
302 print "<a href='/cgi-bin/ipinfo.cgi?ip=$srcip'>$srcip</a>";
306 print ":$srcport -> ";
307 if ($destip ne "n/a") {
308 print "<a href='/cgi-bin/ipinfo.cgi?ip=$destip'>$destip</a>";
316 <tr><td valign='top'><b>$Lang::tr{'references'}:</b></td><td valign='top'>
319 foreach my $ref (split(/,/,$refs)) {
320 if ($ref =~ m/url (.*)/) {
321 print "<a href='http://$1'>$1</a><br />";
322 } elsif ($ref =~ m/cve (.*)/) {
323 print "<a href='http://cve.mitre.org/cgi-bin/cvename.cgi?name=$1'>$1</a><br />";
324 } elsif ($ref =~ m/nessus (.*)/) {
325 print "<a href='http://cgi.nessus.org/plugins/dump.php3?id=$1'>Nessus $1</a><br />";
326 } elsif ($ref =~ m/bugtraq (.*)/) {
327 print "<a href='http://www.securityfocus.com/bid/$1'>Bugtraq $1</a><br />";
332 print $Lang::tr
{'none found'} unless $refs =~ /,/;
334 <td valign='top'><b>SID:</b></td>
339 print "<a href='http://www.snort.org/search/sid/$sid' ";
340 print "target='_blank'>$sid</a></td>\n";
361 &Header
::closebigbox
();
363 &Header
::closepage
();
367 our ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
371 $filestr="/var/log/snort/alert";
373 $filestr="/var/log/snort/alert.$datediff";
374 $filestr = "$filestr.gz" if -f
"$filestr.gz";
376 if (!(open (LOG
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
377 $errormessage="$errormessage$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
383 if ($_ =~ m/\[\*\*\]/) {
384 unless ($line == 1 || $date ne "$monthstr/$daystr") {
388 ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid) = ("n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a", "n/a");
390 $_ =~ m/:([0-9]{1,4})\] (.*) \[\*\*\]/;
391 $title = &Header
::cleanhtml
($2,"y");
393 if ($_ =~ m/Classification: (.*)\] \[Priority: (\d)\]/) {
394 $classification = &Header
::cleanhtml
($1,"y");
397 if ($_ =~ m/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}) \-\> ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) {
398 $srcip = $1 . "." . $2 . "." . $3 . "." . $4;
399 $destip = $5 . "." . $6 . "." . $7 . "." . $8;
401 if ($_ =~ m/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\:([0-9]{1,6}) \-\> ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\:([0-9]{1,6})/) {
402 $srcip = $1 . "." . $2 . "." . $3 . "." . $4;
404 $destip = $6 . "." . $7 . "." . $8 . "." . $9;
408 if ($_ =~ m/^([0-9\/]{3,5})\
-([0-9\
:]{5,8})\
.([0-9]{1,14})/) {
409 ($date,$time) = ($1,$2);
411 if ($_ =~ m/\[Xref \=\>.*\]/) {
412 $_ =~ s/\]\[Xref \=\> /, /g;
413 $_ =~ m/\[Xref \=\> (.*)\]/;
416 if ($_ =~ m/\[1:([0-9]+):[0-9]+\]/) {
421 unless ($line == 1 || $date ne "$monthstr/$daystr") { &append
; }
428 our ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
430 $log[$lines] = "$date $time|$title|$priority|$classification|$srcip|$srcport|$destip|$destport|$sid|";
432 $log[$lines] = "$log[$lines]$_,"; }
444 print "<td align='center' width='50%'>";
446 print "<a href='/cgi-bin/logs.cgi/ids.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'older'}</a>"; }
448 print "$Lang::tr{'older'}"; }
451 print "<td align='center' width='50%'>";
453 print "<a href='/cgi-bin/logs.cgi/ids.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'newer'}</a>"; }
455 print "$Lang::tr{'newer'}"; }