#!/usr/bin/perl # Show last few log entries, nicely parsed, with search form require './itsecur-lib.pl'; &can_use_error("report"); use POSIX; &ReadParse(); print "Refresh: $config{'refresh'}\r\n" if ($config{'refresh'}); &header($text{'report_title'}, ""); print &ui_hr(); if ($in{'reset'}) { # Clear all inputs %in = ( ); } elsif ($in{'save_name'}) { # Load up an old search $search = &get_search($in{'save_name'}); if ($search) { $oldstart = $in{'start'}; $oldend = $in{'end'}; %in = %$search; $in{'start'} = $oldstart; $in{'end'} = $oldend; } } # Show search form print &ui_form_start("list_report.cgi", "post"); print &ui_table_start(undef,"width=100%",2); print &ui_columns_row([&ui_submit($text{'report_search'}), &ui_submit($text{'report_reset'},"reset")], ["colspan=4 width=50%", "colspan=4 width=50%"]); my $i = 0; my @cols_row; my @sel; my $tx = ""; foreach $f (@search_fields) { @cols_row = () if ($i%2 == 0); push(@cols_row, $text{'report_'.$f}); @sel = (); if ($f eq "first" || $f eq "last") { foreach $m (0 .. 1) { push(@sel, [ $m, ( $text{'report_mode'.$m.$f} || $text{'report_mode'.$m} ), ($in{"${f}_mode"} == $m ? "selected" : "")]); } } else { foreach $m (0 .. 2) { push(@sel, [ $m, $text{'report_mode'.$m}, ($in{"${f}_mode"} == $m ? "selected" : "")]); } } push(@cols_row, &ui_select(${f}."_mode", undef, \@sel, 1) ); if ($f eq "dst_iface") { push(@cols_row, &iface_input($f."_what", $in{$f."_what"}) ); } elsif ($f eq "proto") { push(@cols_row, &protocol_input($f."_what", $in{$f."_what"}) ); } elsif ($f eq "dst_port" || $f eq "src_port") { push(@cols_row, &ui_textbox($f."_other", $in{$f."_other"}, 6) ); } elsif ($f eq "src" || $f eq "dst") { push(@cols_row, &group_input($f."_what", $in{$f."_what"}, 2, 0). &ui_textbox($f."_other", $in{$f."_other"}, 10) ); } elsif ($f eq "first" || $f eq "last") { $tx = ""; $tx .= &date_input($in{$f."_day"}, $in{$f."_month"}, $in{$f."_year"}, $f); if ($f eq "first") { $tx .= &hourmin_input($in{$f."_hour"} || "00", $in{$f."_min"} || "00", $f); } else { $tx .= &hourmin_input($in{$f."_hour"} || "23", $in{$f."_min"} || "59", $f); } push(@cols_row, $tx); } elsif ($f eq "action") { push(@cols_row, &action_input($f."_what", $in{$f."_what"}, 1) ); } elsif ($f eq "rule") { push(@cols_row, &ui_textbox($f."_what", $in{$f."_what"}, 5) ); } else { push(@cols_row, &ui_textbox($f."_what", $in{$f."_what"}, 20) ); } push(@cols_row, " " ); print &ui_columns_row(\@cols_row) if ($i++%2 == 1); } # Show saved search my @searches = &list_searches(); if (@searches) { @sel = (); print &ui_columns_row([" "],["colspan=8"]); push(@sel, ["", " ", ($in{'save_name'} eq "" ? "selected" : "")]); foreach $s (@searches) { push(@sel,[$s->{'save_name'}, $s->{'save_name'}, ($in{'save_name'} eq $s->{'save_name'} ? "selected" : "") ]); } print &ui_columns_row([$text{'report_usesaved'}, &ui_select("save_name", undef, \@sel, 1)], ["", "colspan=7"] ); } print &ui_table_end(); print &ui_form_end(undef,undef,1); print &ui_hr(); # Find those matching current search @logs = &parse_all_logs(); $anylogs = @logs; @logs = &filter_logs(\@logs, \%in, \@searchvars); if ($in{'save_name'}) { push(@searchvars, "save_name=".&urlize($in{'save_name'})); } # Show matching log entries if (@logs) { if (@searchvars) { $prog = "list_report.cgi?".join("&", @searchvars)."&"; } else { $prog = "list_report.cgi?"; } if (@logs > $config{'perpage'}) { # Need to show arrows print "
" );
print &ui_link($prog."start=".($s - $config{'perpage'}),
"
" );
}
print "".&text('report_pos', $s+1, $e+1, scalar(@logs))."\n";
if ($e < @logs-1) {
print &ui_link($prog."start=".($s + $config{'perpage'}),
"
" );
print &ui_link($prog."start=".(int((@logs-1)/$config{'perpage'})*$config{'perpage'}),
"
" );
}
print "\n"; } else { print "$text{'report_none2'}
\n";
}
print &ui_hr();
my $hastable = 0;
if (@logs && &can_edit("report")) {
# Show export button
print &ui_table_start(undef,"width=100%",2);
$hastable = 1;
print &ui_form_start("list_welf.cgi", "post");
foreach $i (keys %in) {
print &ui_hidden($i, &html_escape($in{$i}) );
}
print &ui_columns_row([&ui_submit($text{'report_welf'}), $text{'report_welfdesc'}], ["valign=middle","valign=middle"] );
print &ui_form_end(undef,undef,1);
$anyrows++;
}
if (@searchvars && &can_edit("report")) {
# Show button to save this search
print &ui_table_start(undef,"width=100%",2) if ( $hastable == 0 );
print &ui_form_start("save_search.cgi", "post");
foreach $i (keys %in) {
print &ui_hidden($i, &html_escape($in{$i}) );
}
print &ui_columns_row([&ui_submit($text{'report_save'}),
$text{'report_savedesc'}."
".
"".$text{'report_savename'}." ".
&ui_textbox("save_name", $in{'save_name'}, 30) ],
["valign=middle","valign=middle"] );
print &ui_form_end(undef,undef,1);
$anyrows++;
}
# Show button to select an old search
#@searches = &list_searches();
#if (@searches) {
# print "