mode-button: drop all global variables

With RouterOS 7.24 (actually 7.24beta1 I think) the mode, reset and wps
button scripts are run with limited policy. This causes global variables
not being available... So let's drop them here.

This is kind of inconvenient, but we can live with it. The second script
'mode-button-scheduler' is run from scheduler and does not suffer that
limitation.
This commit is contained in:
Christian Hesse 2026-07-17 09:24:47 +02:00
parent 198b088faa
commit 68dfe26198

View file

@ -10,26 +10,21 @@
# https://rsc.eworm.de/doc/mode-button.md
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global LogPrint;
:local Scheduler [ /system/scheduler/find where name="mode-button-scheduler" ];
:if ([ :len $Scheduler ] = 0) do={
$LogPrint info $ScriptName ("Creating scheduler mode-button-scheduler, counting presses...");
:log info ($ScriptName . ": Creating scheduler mode-button-scheduler, counting presses...");
/system/scheduler/add name="mode-button-scheduler" interval=3s \
comment=[ :serialize to=json ({ count=1 }) ] \
on-event="/system/script/run mode-button-scheduler;";
} else={
$LogPrint debug $ScriptName ("Updating scheduler mode-button-scheduler...");
:log debug ($ScriptName . ": Updating scheduler mode-button-scheduler...");
:local Presses (([ :deserialize from=json [ /system/scheduler/get $Scheduler comment ] ]->"count") + 1);
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ] \
comment=[ :serialize to=json ({ count=$Presses }) ];
}
} do={
:global ExitOnError; $ExitOnError [ :jobname ] $Err;
:log error ([ :jobname ] . ": " . $Err);
}