mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-07-30 13:11:36 +00:00
Compare commits
77 commits
ce64529c45
...
3a6f5feb4a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a6f5feb4a | ||
|
|
cd9e3feb54 | ||
|
|
3e903b479f | ||
|
|
7de44c9200 | ||
|
|
02a87dae3c | ||
|
|
800a82ba05 | ||
|
|
d54af97513 | ||
|
|
7ab66fc7a9 | ||
|
|
6ffb08066f | ||
|
|
2d04d78b05 | ||
|
|
9b47e6b8a7 | ||
|
|
0a6cad5b2b | ||
|
|
3315ca52c6 | ||
|
|
7eb3c21cfa | ||
|
|
ece7e9a5cd | ||
|
|
c3fc2bf22c | ||
|
|
6bc651d51c | ||
|
|
a0d8f280d9 | ||
|
|
a36a17b444 | ||
|
|
a5b02f27b0 | ||
|
|
a8ba5ee13b | ||
|
|
539fcc3844 | ||
|
|
f5a814df60 | ||
|
|
9559b2e21f | ||
|
|
16cfe335c2 | ||
|
|
6cfde9def4 | ||
|
|
db93e792e6 | ||
|
|
2289d69b01 | ||
|
|
68dfe26198 | ||
|
|
57c954af1d | ||
|
|
f0cc45d2ab | ||
|
|
1be42fc35b | ||
|
|
198b088faa | ||
|
|
dd51fd33e0 | ||
|
|
f1910d0832 | ||
|
|
9d0ad044a3 | ||
|
|
4da0a30210 | ||
|
|
71a4beabac | ||
|
|
83e71ffd5d | ||
|
|
57f713477b | ||
|
|
e92d79b2b7 | ||
|
|
389009453e | ||
|
|
bcb1c77b2f | ||
|
|
d0b8e8f808 | ||
|
|
4c14186e18 | ||
|
|
4ba4b6d16f | ||
|
|
381bb0038a | ||
|
|
363adaaa47 | ||
|
|
b407b08254 | ||
|
|
a88eea6e64 | ||
|
|
53d17d2981 | ||
|
|
d4de082771 | ||
|
|
1b3ce0f834 | ||
|
|
ceafb0ed04 | ||
|
|
add84f32ff | ||
|
|
b065a314af | ||
|
|
942c50aff8 | ||
|
|
03d506d2bf | ||
|
|
5d912bc548 | ||
|
|
6155b6c2a4 | ||
|
|
7717b30c23 | ||
|
|
21a1b32624 | ||
|
|
be629dbfba | ||
|
|
dc7d6c5c74 | ||
|
|
45721186ac | ||
|
|
b9ae49b1bc | ||
|
|
9378d2977a | ||
|
|
f3df68f97d | ||
|
|
5370bc3d0f | ||
|
|
c946c9b9bb | ||
|
|
b6a0293572 | ||
|
|
63d76f031a | ||
|
|
bee12c01ae | ||
|
|
dff5444b1e | ||
|
|
e0bfaddcff | ||
|
|
0e5a30d946 | ||
|
|
b3aa479515 |
5 changed files with 96 additions and 79 deletions
|
|
@ -16,7 +16,7 @@ Mode button with multiple presses
|
|||
Description
|
||||
-----------
|
||||
|
||||
This script extend the functionality of mode button. Instead of just one
|
||||
These scripts 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 script:
|
||||
Just install the scripts:
|
||||
|
||||
$ScriptInstallUpdate mode-button;
|
||||
$ScriptInstallUpdate mode-button,mode-button-scheduler;
|
||||
|
||||
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 143;
|
||||
:global ExpectedConfigVersion 144;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
|||
80
mode-button-scheduler.rsc
Normal file
80
mode-button-scheduler.rsc
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#!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,86 +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 ModeButton;
|
||||
|
||||
:global LogPrint;
|
||||
|
||||
:set ($ModeButton->"count") ($ModeButton->"count" + 1);
|
||||
|
||||
:local Scheduler [ /system/scheduler/find where name="_ModeButtonScheduler" ];
|
||||
:local Scheduler [ /system/scheduler/find where name="mode-button-scheduler" ];
|
||||
|
||||
:if ([ :len $Scheduler ] = 0) do={
|
||||
$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;
|
||||
: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 _ModeButtonScheduler...");
|
||||
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ];
|
||||
: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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@
|
|||
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
|
||||
|
|
@ -79,4 +80,5 @@
|
|||
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