From ea09a18d3f05b20ff7f1ec25aea74f32d68ca5e0 Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Thu, 3 Nov 2022 23:43:08 +0100 Subject: sms-forward: support hooks --- sms-forward | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'sms-forward') diff --git a/sms-forward b/sms-forward index 8dce464..802da48 100644 --- a/sms-forward +++ b/sms-forward @@ -1,6 +1,7 @@ #!rsc by RouterOS # RouterOS script: sms-forward # Copyright (c) 2013-2023 Christian Hesse +# Anatoly Bubenkov # https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md # # forward SMS to e-mail @@ -11,12 +12,14 @@ :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } :global Identity; +:global SmsForwardHooks; :global IfThenElse; :global LogPrintExit2; :global ScriptLock; :global SendNotification2; :global SymbolForNotification; +:global ValidateSyntax; :global WaitFullyConnected; $ScriptLock $0; @@ -45,6 +48,25 @@ $WaitFullyConnected; } else={ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ " type " . $SmsVal->"type" . ":\n" . $SmsVal->"message"); + :foreach Hook in=$SmsForwardHooks do={ + :if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={ + :if ([ $ValidateSyntax ($Hook->"command") ] = true) do={ + $LogPrintExit2 info $0 ("Running hook '" . $Hook->"match" . "': " . \ + $Hook->"command") false; + :do { + [ :parse ($Hook->"command") ]; + :set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . \ + $Hook->"command"); + } on-error={ + $LogPrintExit2 warning $0 ("The code for hook '" . $Hook->"match" . \ + "' failed to run!") false; + } + } else={ + $LogPrintExit2 warning $0 ("The code for hook '" . $Hook->"match" . \ + "' failed syntax validation!") false; + } + } + } :set Delete ($Delete, $Sms); } } -- cgit v1.2.3-54-g00ecf