mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-07-17 23:01:35 +00:00
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:
parent
198b088faa
commit
68dfe26198
1 changed files with 3 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue