From 744542e92539eb6ad39c84eca05258f82e1dd47a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 28 Sep 2020 20:20:19 +0200 Subject: [PATCH] log-forward: add rate limit to prevent flooding --- log-forward | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/log-forward b/log-forward index 7da8a4a..27aa19c 100644 --- a/log-forward +++ b/log-forward @@ -10,6 +10,7 @@ :global LogForwardFilter; :global LogForwardFilterMessage; :global LogForwardLast; +:global LogForwardRateLimit; :global LogPrintExit; :global MailServerIsUp; @@ -20,6 +21,15 @@ $ScriptLock "log-forward"; +:if ([ :typeof $LogForwardRateLimit ] = "nothing") do={ + :set LogForwardRateLimit 0; +} + +:if ($LogForwardRateLimit > 30) do={ + :set LogForwardRateLimit ($LogForwardRateLimit - 1); + $LogPrintExit info ("Rate limit in action, not forwarding logs!") true; +} + $WaitFullyConnected; :if ([ $MailServerIsUp ] = false) do={ @@ -48,5 +58,10 @@ $WaitFullyConnected; ("The log on " . $Identity . " contains these " . $Count . " messages after " . \ [ / system resource get uptime ] . " uptime.\n" . $Messages); + :set LogForwardRateLimit ($LogForwardRateLimit + 10); :set LogForwardLast ($MessageVal->".id"); +} else={ + :if ($LogForwardRateLimit > 0) do={ + :set LogForwardRateLimit ($LogForwardRateLimit - 1); + } }