# HG changeset patch # User Matti Hamalainen # Date 1250372835 -10800 # Node ID e4ffe2ce29a32b1c7e231c00236d572e9e257ad1 # Parent 9f02bf2207afddb731922d95f67d4c6af24557d6 Generalize timestamp conversion to strings; Re-enable setting of timestamps in global data even if timestamp < 0. diff -r 9f02bf2207af -r e4ffe2ce29a3 README --- a/README Sun Aug 16 00:35:10 2009 +0300 +++ b/README Sun Aug 16 00:47:15 2009 +0300 @@ -1,4 +1,4 @@ -Malicious Attack Livid Termination Filter daemon (maltfilter) v0.10.2 +Malicious Attack Livid Termination Filter daemon (maltfilter) v0.10.3 ===================================================================== Programmed by Matti 'ccr' Hämäläinen (C) Copyright 2009 Tecnic Software productions (TNSP) diff -r 9f02bf2207af -r e4ffe2ce29a3 maltfilter --- a/maltfilter Sun Aug 16 00:35:10 2009 +0300 +++ b/maltfilter Sun Aug 16 00:47:15 2009 +0300 @@ -10,7 +10,7 @@ use Date::Parse; use Net::IP; -my $progversion = "0.10.2"; +my $progversion = "0.10.3"; my $progbanner = "Malicious Attack Livid Termination Filter daemon (maltfilter) v$progversion\n". "Programmed by Matti 'ccr' Hamalainen \n". @@ -170,6 +170,15 @@ return $value; } +sub getTimeStr($) +{ + if ($_[0] >= 0) { + return scalar localtime($_[0]); + } else { + return "?"; + } +} + sub printH($$$$) { my $fh = $_[1]; @@ -257,9 +266,9 @@ printElem(!$m, $f, " | "); printTD($m, $f, sprintf("%-15s", getLink($m, $mip))); printElem(!$m, $f, " | "); - printTD($m, $f, scalar localtime($table->{$mip}{"date1"})); + printTD($m, $f, getTimeStr($table->{$mip}{"date1"})); printElem(!$m, $f, " | "); - printTD($m, $f, scalar localtime($table->{$mip}{"date2"})); + printTD($m, $f, getTimeStr($table->{$mip}{"date2"})); printElem(!$m, $f, " | "); my @reasons = (); foreach my $class (sort keys %{$table->{$mip}{"reason"}}) { @@ -303,7 +312,7 @@ printElem(!$m, $f, " | "); printTD($m, $f, sprintf("%-8d ", $table->{$_[0]}{"hits"}), $blocked); printElem(!$m, $f, " | "); - printTD($m, $f, scalar localtime($table->{$_[0]}{"date2"}), $blocked); + printTD($m, $f, getTimeStr($table->{$_[0]}{"date2"}), $blocked); printElem(!$m, $f, " | "); my $tmp = join(", ", sort keys %{$table->{$_[0]}{"reason"}}, $blocked); printTD($m, $f, sprintf("%-30s", $tmp), $blocked); @@ -373,7 +382,6 @@ open(STATUS, ">", $filename) or die("Could not open '".$filename."'!\n"); my $f = \*STATUS; - my $mtime = scalar localtime(); printElem($m, $f, " @@ -393,7 +401,7 @@ my $period = get_period($settings{"WEED_GLOBAL"}); printP($m, $f, - "Generated ".bb($m).$mtime.eb($m).". Data computed from ". + "Generated ".bb($m).getTimeStr(time()).eb($m).". Data computed from ". ($reportmode ? "complete logfile scan" : "a period of last $period").".\n"); printP($m, $f, "The hit classes marked as 'IPTABLES' are a pseudo-class meaning an\n". @@ -507,7 +515,7 @@ sub weed_do($) { my $mtime = $blocklist{$_[0]}; - mlog(2, "* Weeding $_[0] (".($mtime >= 0 ? scalar localtime($mtime) : $mtime)."\n"); + mlog(2, "* Weeding $_[0] (".getTimeStr($mtime)."\n"); exec_iptables("-D", "INPUT", "-s", $_[0], "-d", "0.0.0.0/0", "-j", $settings{"ACTION"}); delete($blocklist{$_[0]}); delete($statlist{$_[0]}); @@ -536,7 +544,7 @@ if (defined($statlist{$mip})) { my $mtime = $statlist{$mip}{"date2"}; if (!check_time2($mtime) && !defined($blocklist{$mip})) { - mlog(3, "* Deleting stale $mip (".($mtime >= 0 ? scalar localtime($mtime) : $mtime).")\n"); + mlog(3, "* Deleting stale $mip (".getTimeStr($mtime).")\n"); delete($statlist{$mip}); } } @@ -546,7 +554,7 @@ if (defined($ignorelist{$mip})) { my $mtime = $ignorelist{$mip}{"date2"}; if (!check_time2($mtime)) { - mlog(3, "* Deleting stale ignored $mip (".($mtime >= 0 ? scalar localtime($mtime) : $mtime).")\n"); + mlog(3, "* Deleting stale ignored $mip (".getTimeStr($mtime).")\n"); delete($ignorelist{$mip}); } } @@ -567,17 +575,15 @@ $struct->{$mip}{"reason"}{$mclass}{"msg"} = $mreason; } - if ($mdate > 0) { - if (!defined($struct->{$mip}{"date1"})) { - $struct->{$mip}{"date1"} = $mdate; - } - $struct->{$mip}{"date2"} = $mdate; + if (!defined($struct->{$mip}{"date1"})) { + $struct->{$mip}{"date1"} = $mdate; + } + $struct->{$mip}{"date2"} = $mdate; - if (!defined($struct->{$mip}{"reason"}{$mclass}{"date2"})) { - $struct->{$mip}{"reason"}{$mclass}{"date2"} = $mdate; - } + if (!defined($struct->{$mip}{"reason"}{$mclass}{"date2"})) { $struct->{$mip}{"reason"}{$mclass}{"date2"} = $mdate; } + $struct->{$mip}{"reason"}{$mclass}{"date2"} = $mdate; return $cnt; } @@ -629,7 +635,7 @@ my $level = shift; my $msg = shift; if ($LOGFILE) { - print $LOGFILE "[".scalar localtime()."] ".$msg if ($settings{"VERBOSITY"} > $level); + print $LOGFILE "[".getTimeStr(time())."] ".$msg if ($settings{"VERBOSITY"} > $level); } elsif ($settings{"DRY_RUN"}) { print STDERR $msg if ($settings{"VERBOSITY"} > $level); }