mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-07-31 13:41:35 +00:00
Compare commits
70 commits
3a6f5feb4a
...
ce64529c45
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce64529c45 | ||
|
|
bbb251ade5 | ||
|
|
5e3070e36b | ||
|
|
c26c63c390 | ||
|
|
1abfc59b73 | ||
|
|
d0821113cc | ||
|
|
d90d8297c9 | ||
|
|
0e53aa7f4c | ||
|
|
1a1b936957 | ||
|
|
1a870c3092 | ||
|
|
1245260299 | ||
|
|
9423d7f1ef | ||
|
|
608045ce31 | ||
|
|
723cacec9f | ||
|
|
37387f5770 | ||
|
|
a68259e863 | ||
|
|
41c2d163a3 | ||
|
|
faa2465bcc | ||
|
|
17a4fd7766 | ||
|
|
5470d97a0d | ||
|
|
2176187257 | ||
|
|
6eddaccba9 | ||
|
|
dff4fb4a8c | ||
|
|
069de4c948 | ||
|
|
0c9c92eb5b | ||
|
|
3eb20152bb | ||
|
|
c1eda113b5 | ||
|
|
4613405037 | ||
|
|
9715f95ef5 | ||
|
|
c8a66955d3 | ||
|
|
9533f21be0 | ||
|
|
7a992f0557 | ||
|
|
3bf40ec73f | ||
|
|
1116585bee | ||
|
|
1826d2fc5b | ||
|
|
df65f7263d | ||
|
|
31e64f6e96 | ||
|
|
f825f484fe | ||
|
|
68a48e00bd | ||
|
|
15e4c93784 | ||
|
|
25608feb0e | ||
|
|
e38af4881d | ||
|
|
847c985cf4 | ||
|
|
fbf346fdd0 | ||
|
|
c096306e59 | ||
|
|
04eb34d8cc | ||
|
|
b2674a4e79 | ||
|
|
eaedb2d5b9 | ||
|
|
d27d7e0ecc | ||
|
|
415c3bc164 | ||
|
|
3e9ec8fa31 | ||
|
|
382057afc3 | ||
|
|
d2f906d9f8 | ||
|
|
0f61c22477 | ||
|
|
8d1a2f2834 | ||
|
|
307afc9a31 | ||
|
|
ff6fc0a7fc | ||
|
|
49c86440ed | ||
|
|
356661c535 | ||
|
|
6f78415c8a | ||
|
|
c2204d55f6 | ||
|
|
46cb8e870e | ||
|
|
0b06740dca | ||
|
|
2f134a2738 | ||
|
|
8c07b9f252 | ||
|
|
0bd7175e78 | ||
|
|
558b02c8bb | ||
|
|
3894b5c7d9 | ||
|
|
f252914622 | ||
|
|
4bc63b575d |
5 changed files with 79 additions and 96 deletions
|
|
@ -16,7 +16,7 @@ Mode button with multiple presses
|
|||
Description
|
||||
-----------
|
||||
|
||||
These scripts extend the functionality of mode button. Instead of just one
|
||||
This script extend the functionality of mode button. Instead of just one
|
||||
you can trigger several actions by pressing the mode button several times.
|
||||
|
||||
The hardware needs to have a mode button, see
|
||||
|
|
@ -39,9 +39,9 @@ Copy this code to terminal to check:
|
|||
Requirements and installation
|
||||
-----------------------------
|
||||
|
||||
Just install the scripts:
|
||||
Just install the script:
|
||||
|
||||
$ScriptInstallUpdate mode-button,mode-button-scheduler;
|
||||
$ScriptInstallUpdate mode-button;
|
||||
|
||||
Then configure the mode button to run `mode-button`:
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
# Git commit id & info, expected configuration version
|
||||
:global CommitId "unknown";
|
||||
:global CommitInfo "unknown";
|
||||
:global ExpectedConfigVersion 144;
|
||||
:global ExpectedConfigVersion 143;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: mode-button-scheduler
|
||||
# Copyright (c) 2018-2026 Christian Hesse <mail@eworm.de>
|
||||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# requires RouterOS, version=7.22
|
||||
# requires device-mode, scheduler
|
||||
#
|
||||
# act on multiple mode and reset button presses
|
||||
# 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 ModeButton;
|
||||
|
||||
:global LogPrint;
|
||||
:global ModeButtonScheduler;
|
||||
:global ValidateSyntax;
|
||||
|
||||
:local LEDInvert do={
|
||||
:global ModeButtonLED;
|
||||
|
||||
:global IfThenElse;
|
||||
|
||||
:local LED [ /system/leds/find where leds=$ModeButtonLED \
|
||||
!disabled type~"^(on|off)\$" interface=[] ];
|
||||
:if ([ :len $LED ] = 0) do={
|
||||
:return false;
|
||||
}
|
||||
/system/leds/set type=[ $IfThenElse ([ get $LED type ] = "on") "off" "on" ] $LED;
|
||||
}
|
||||
|
||||
:local Scheduler [ /system/scheduler/find where name="mode-button-scheduler" ];
|
||||
|
||||
:if ([ :len $Scheduler ] = 0) do={
|
||||
$LogPrint error $ScriptName ("Scheduler does not exist.");
|
||||
:exit;
|
||||
}
|
||||
|
||||
:local Count ([ :deserialize from=json [ /system/scheduler/get $Scheduler comment ] ]->"count");
|
||||
:local Code ($ModeButton->[ :tostr $Count ]);
|
||||
|
||||
/system/scheduler/remove $Scheduler;
|
||||
|
||||
:if ([ :len $Code ] = 0) do={
|
||||
$LogPrint info $ScriptName ("No action defined for " . $Count . " mode-button presses.");
|
||||
:exit;
|
||||
}
|
||||
|
||||
:if ([ $ValidateSyntax $Code ] = false) do={
|
||||
$LogPrint warning $ScriptName \
|
||||
("The code for " . $Count . " mode-button presses failed syntax validation!");
|
||||
:exit;
|
||||
}
|
||||
|
||||
$LogPrint info $ScriptName ("Acting on " . $Count . " mode-button presses: " . $Code);
|
||||
|
||||
:for I from=1 to=$Count do={
|
||||
$LEDInvert;
|
||||
:if ([ /system/routerboard/settings/get silent-boot ] = false) do={
|
||||
:beep length=200ms;
|
||||
}
|
||||
:delay 200ms;
|
||||
$LEDInvert;
|
||||
:delay 200ms;
|
||||
}
|
||||
|
||||
:onerror Err {
|
||||
[ :parse $Code ];
|
||||
} do={
|
||||
$LogPrint warning $ScriptName \
|
||||
("The code for " . $Count . " mode-button presses failed with runtime error: " . $Err);
|
||||
}
|
||||
} do={
|
||||
:global ExitOnError; $ExitOnError [ :jobname ] $Err;
|
||||
}
|
||||
|
|
@ -10,21 +10,86 @@
|
|||
# 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 ];
|
||||
|
||||
:local Scheduler [ /system/scheduler/find where name="mode-button-scheduler" ];
|
||||
:global ModeButton;
|
||||
|
||||
:global LogPrint;
|
||||
|
||||
:set ($ModeButton->"count") ($ModeButton->"count" + 1);
|
||||
|
||||
:local Scheduler [ /system/scheduler/find where name="_ModeButtonScheduler" ];
|
||||
|
||||
:if ([ :len $Scheduler ] = 0) do={
|
||||
: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;";
|
||||
$LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...");
|
||||
:global ModeButtonScheduler do={ :onerror Err {
|
||||
:local FuncName $0;
|
||||
|
||||
:global ModeButton;
|
||||
|
||||
:global LogPrint;
|
||||
:global ModeButtonScheduler;
|
||||
:global ValidateSyntax;
|
||||
|
||||
:local LEDInvert do={
|
||||
:global ModeButtonLED;
|
||||
|
||||
:global IfThenElse;
|
||||
|
||||
:local LED [ /system/leds/find where leds=$ModeButtonLED \
|
||||
!disabled type~"^(on|off)\$" interface=[] ];
|
||||
:if ([ :len $LED ] = 0) do={
|
||||
:return false;
|
||||
}
|
||||
/system/leds/set type=[ $IfThenElse ([ get $LED type ] = "on") "off" "on" ] $LED;
|
||||
}
|
||||
|
||||
:local Count ($ModeButton->"count");
|
||||
:local Code ($ModeButton->[ :tostr $Count ]);
|
||||
|
||||
:set ($ModeButton->"count") 0;
|
||||
:set ModeButtonScheduler;
|
||||
/system/scheduler/remove [ find where name="_ModeButtonScheduler" ];
|
||||
|
||||
:if ([ :len $Code ] > 0) do={
|
||||
:if ([ $ValidateSyntax $Code ] = true) do={
|
||||
$LogPrint info $FuncName ("Acting on " . $Count . " mode-button presses: " . $Code);
|
||||
|
||||
:for I from=1 to=$Count do={
|
||||
$LEDInvert;
|
||||
:if ([ /system/routerboard/settings/get silent-boot ] = false) do={
|
||||
:beep length=200ms;
|
||||
}
|
||||
:delay 200ms;
|
||||
$LEDInvert;
|
||||
:delay 200ms;
|
||||
}
|
||||
|
||||
:onerror Err {
|
||||
[ :parse $Code ];
|
||||
} do={
|
||||
$LogPrint warning $FuncName \
|
||||
("The code for " . $Count . " mode-button presses failed with runtime error: " . $Err);
|
||||
}
|
||||
} else={
|
||||
$LogPrint warning $FuncName \
|
||||
("The code for " . $Count . " mode-button presses failed syntax validation!");
|
||||
}
|
||||
} else={
|
||||
$LogPrint info $FuncName ("No action defined for " . $Count . " mode-button presses.");
|
||||
}
|
||||
} do={
|
||||
:global ExitOnError; $ExitOnError $0 $Err;
|
||||
} }
|
||||
/system/scheduler/add name="_ModeButtonScheduler" \
|
||||
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
|
||||
} else={
|
||||
: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 }) ];
|
||||
$LogPrint debug $ScriptName ("Updating scheduler _ModeButtonScheduler...");
|
||||
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ];
|
||||
}
|
||||
} do={
|
||||
:log error ([ :jobname ] . ": " . $Err);
|
||||
:global ExitOnError; $ExitOnError [ :jobname ] $Err;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@
|
|||
141="Introduced script 'dhcpv6-client-lease' to run several scripts on IPv6 DHCP client lease.";
|
||||
142="Added a setting for 'mod/notification-email' to check availability of certificate chain.";
|
||||
143="Made backup scripts 'backup-email' and 'backup-upload' support date & time in filenames.";
|
||||
144="Split and reworked 'mode-button' for compatibility with RouterOS 7.24, configuration was updated automatically.";
|
||||
};
|
||||
|
||||
# Migration steps to be applied on script updates
|
||||
|
|
@ -80,5 +79,4 @@
|
|||
132=":if ([ :len [ /system/script/find where name=\"check-health\" ] ] > 0) do={ :local Code \":local Install \\\"check-health\\\"; :if ([ :len [ /system/health/find where type=\\\"\\\" name~\\\"-state\\\\\\\$\\\" ] ] > 0) do={ :set Install (\\\$Install . \\\",check-health.d/state\\\"); }; :if ([ :len [ /system/health/find where type=\\\"C\\\" ] ] > 0) do={ :set Install (\\\$Install . \\\",check-health.d/temperature\\\"); }; :if ([ :len [ /system/health/find where type=\\\"V\\\" ] ] > 0) do={ :set Install (\\\$Install . \\\",check-health.d/voltage\\\"); }; :global ScriptInstallUpdate; \\\$ScriptInstallUpdate \\\$Install;\"; :global ValidateSyntax; :if ([ \$ValidateSyntax \$Code ] = true) do={ :do { [ :parse \$Code ]; } on-error={ }; }; };";
|
||||
138="/certificate/set trusted=yes [ find where trusted=yes ];";
|
||||
140=":if ([ :len [ /system/script/find where name=\"lease-script\" ] ] > 0) do={ /system/script/set name=\"dhcpv4-server-lease\" \"lease-script\"; :global ScriptInstallUpdate; \$ScriptInstallUpdate; /ip/dhcp-server/set lease-script=\"dhcpv4-server-lease\" [ find where lease-script=\"lease-script\" ]; };";
|
||||
144=":if ([ :len [ /system/script/find where name=\"mode-button\" ] ] > 0) do={ :global ScriptInstallUpdate; \$ScriptInstallUpdate mode-button-scheduler; };";
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue