2023-03-07 09:57:42 +00:00
|
|
|
#!rsc by RouterOS
|
|
|
|
# RouterOS script: sms-action
|
2024-01-01 14:25:25 +00:00
|
|
|
# Copyright (c) 2018-2024 Christian Hesse <mail@eworm.de>
|
2023-03-07 09:57:42 +00:00
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
|
|
|
#
|
2024-04-04 19:45:02 +00:00
|
|
|
# requires RouterOS, version=7.13
|
2023-11-15 20:31:19 +00:00
|
|
|
#
|
2023-03-07 09:57:42 +00:00
|
|
|
# run action on received SMS
|
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/sms-action.md
|
|
|
|
|
|
|
|
:global GlobalFunctionsReady;
|
|
|
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
|
|
|
|
2024-03-06 14:28:55 +00:00
|
|
|
:do {
|
|
|
|
:local ScriptName [ :jobname ];
|
2023-03-07 09:57:42 +00:00
|
|
|
|
2024-03-04 12:48:01 +00:00
|
|
|
:global SmsAction;
|
2023-03-07 09:57:42 +00:00
|
|
|
|
2024-03-08 11:45:38 +00:00
|
|
|
:global LogPrint;
|
2024-03-04 12:48:01 +00:00
|
|
|
:global ValidateSyntax;
|
2023-03-07 09:57:42 +00:00
|
|
|
|
2024-03-06 14:28:55 +00:00
|
|
|
:local Action $action;
|
|
|
|
|
|
|
|
:if ([ :typeof $Action ] = "nothing") do={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint error $ScriptName ("This script is supposed to run from SMS hook with action=...");
|
|
|
|
:error false;
|
2024-03-04 12:48:01 +00:00
|
|
|
}
|
2023-03-07 09:57:42 +00:00
|
|
|
|
2024-03-04 12:48:01 +00:00
|
|
|
:local Code ($SmsAction->$Action);
|
|
|
|
:if ([ $ValidateSyntax $Code ] = true) do={
|
|
|
|
:log info ("Acting on SMS action '" . $Action . "': " . $Code);
|
|
|
|
:delay 1s;
|
|
|
|
[ :parse $Code ];
|
|
|
|
} else={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint warning $ScriptName ("The code for action '" . $Action . "' failed syntax validation!");
|
2024-03-04 12:48:01 +00:00
|
|
|
}
|
2024-03-06 14:28:55 +00:00
|
|
|
} on-error={ }
|