#!/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 "
\n"; 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 "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $i = 0; foreach $f (@search_fields) { print "\n" if ($i%2 == 0); print "\n"; print "\n"; if ($f eq "dst_iface") { print "\n"; } elsif ($f eq "proto") { print "\n"; } elsif ($f eq "dst_port" || $f eq "src_port") { print "\n"; } elsif ($f eq "src" || $f eq "dst") { print "\n"; } elsif ($f eq "first" || $f eq "last") { print ""; } elsif ($f eq "action") { print "\n"; } elsif ($f eq "rule") { printf "\n", $f, $in{$f."_what"}; } else { printf "\n", $f, $in{$f."_what"}; } print "\n"; print "\n" if ($i++%2 == 1); } # Show saved search @searches = &list_searches(); if (@searches) { print "\n"; print "\n"; print "\n"; } print "
",$text{'report_'.$f},"",&iface_input($f."_what", $in{$f."_what"}),"",&protocol_input($f."_what", $in{$f."_what"}),"",&service_input($f."_what", $in{$f."_what"}, 2, 0, 1); printf "\n", $f, $in{$f."_other"}; print "",&group_input($f."_what", $in{$f."_what"}, 2, 0); printf "\n", $f, $in{$f."_other"}; print ""; &date_input($in{$f."_day"}, $in{$f."_month"}, $in{$f."_year"}, $f); if ($f eq "first") { &hourmin_input($in{$f."_hour"} || "00", $in{$f."_min"} || "00", $f); } else { &hourmin_input($in{$f."_hour"} || "23", $in{$f."_min"} || "59", $f); } print "",&action_input($f."_what", $in{$f."_what"}, 1),"  
$text{'report_usesaved'}
\n"; print "
\n"; print "
\n"; # 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 "
\n"; $s = int($in{'start'}); $e = $in{'start'} + $config{'perpage'} - 1; $e = @logs-1 if ($e >= @logs); if ($s) { printf "%s\n", $prog, 0, "First page"; printf "%s\n", $prog, $s - $config{'perpage'}, "Previous page"; } print "",&text('report_pos', $s+1, $e+1, scalar(@logs)),"\n"; if ($e < @logs-1) { printf "%s\n", $prog, $s + $config{'perpage'}, "Next page"; printf "%s\n", $prog, int((@logs-1)/$config{'perpage'})*$config{'perpage'}, "Last page"; } print "
\n"; } else { # Can show them all $s = 0; $e = @logs - 1; } print "\n"; print " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "\n"; for($i=$s; $i<=$e; $i++) { $l = $logs[$i]; print "\n"; print "\n"; print "\n"; local @tm = localtime($l->{'time'}); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "
$text{'report_action'}$text{'report_rule2'}$text{'report_date'}$text{'report_time'}$text{'report_src'}$text{'report_dst'}$text{'report_dst_iface'}$text{'report_proto'}$text{'report_src_port'}$text{'report_dst_port'}
",$text{'rule_'.$l->{'action'}},"",$l->{'rule'} || "
","
",strftime("%d/%m/%Y", @tm),"",strftime("%H:%M:%S", @tm),"",$l->{'src'},"",$l->{'dst'},"",$l->{'dst_iface'} || "
","
",$l->{'proto'} || "
","
",$l->{'src_port'} || "
","
",$l->{'dst_port'} || "
","
\n"; } elsif ($anylogs) { print "$text{'report_none'}

\n"; } else { print "$text{'report_none2'}

\n"; } print "


\n"; print "\n"; if (@logs && &can_edit("report")) { # Show export button print "\n"; foreach $i (keys %in) { print "\n"; } print "\n"; print "\n"; print "\n"; $anyrows++; } if (@searchvars && &can_edit("report")) { # Show button to save this search print "\n"; foreach $i (keys %in) { print "\n"; } print "\n"; print "\n"; print "\n"; $anyrows++; } # Show button to select an old search #@searches = &list_searches(); #if (@searches) { # print "\n"; # print "\n"; # print "\n"; # print "\n"; # $anyrows++; # } print "
$text{'report_welfdesc'}
$text{'report_savedesc'}
\n"; print "$text{'report_savename'}\n"; printf "\n", $in{'save_name'}; print "
$text{'report_loaddesc'}
\n"; # print "$text{'report_savename'}\n"; # print "\n"; # print "
\n"; print "
\n" if ($anyrows); &footer("", $text{'index_return'}); # date_input(day, month, year, prefix) sub date_input { print ""; print "/"; print "/"; print &date_chooser_button("$_[3]_day", "$_[3]_month", "$_[3]_year"); print "\n"; } # hourmin_input(hour, min, prefix) sub hourmin_input { print ""; print ":"; print ""; print "\n"; }