aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-06-23 00:53:19 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-06-23 08:38:44 +0200
commit2041390f554e70b72113b7d0b68cc658db1bade6 (patch)
tree6da306711a1bd8d16e338b21d8ad393ebde9b002
parent420986fdfcaee163da10e5e8c6376b6e178c025c (diff)
lease-script: use 'provides' to find lease scripts
-rw-r--r--collect-wireless-mac.capsman2
-rw-r--r--collect-wireless-mac.local2
-rw-r--r--collect-wireless-mac.template2
-rw-r--r--dhcp-lease-comment.capsman2
-rw-r--r--dhcp-lease-comment.local2
-rw-r--r--dhcp-lease-comment.template2
-rw-r--r--dhcp-to-dns3
-rw-r--r--lease-script32
8 files changed, 22 insertions, 25 deletions
diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman
index 4cf8649..8ec6d61 100644
--- a/collect-wireless-mac.capsman
+++ b/collect-wireless-mac.capsman
@@ -6,6 +6,8 @@
# collect wireless mac adresses in access list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/collect-wireless-mac.md
#
+# provides: lease-script assign
+#
# !! Do not edit this file, it is generated from template!
:local 0 "collect-wireless-mac.capsman";
diff --git a/collect-wireless-mac.local b/collect-wireless-mac.local
index a7c26e6..771986e 100644
--- a/collect-wireless-mac.local
+++ b/collect-wireless-mac.local
@@ -6,6 +6,8 @@
# collect wireless mac adresses in access list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/collect-wireless-mac.md
#
+# provides: lease-script assign
+#
# !! Do not edit this file, it is generated from template!
:local 0 "collect-wireless-mac.local";
diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template
index 41cf299..311b72a 100644
--- a/collect-wireless-mac.template
+++ b/collect-wireless-mac.template
@@ -6,6 +6,8 @@
# collect wireless mac adresses in access list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/collect-wireless-mac.md
#
+# provides: lease-script assign
+#
# !! This is just a template! Replace '%PATH%' with 'caps-man'
# !! or 'interface wireless'!
diff --git a/dhcp-lease-comment.capsman b/dhcp-lease-comment.capsman
index 96b1741..e8db68d 100644
--- a/dhcp-lease-comment.capsman
+++ b/dhcp-lease-comment.capsman
@@ -3,6 +3,8 @@
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
+# provides: lease-script assign
+#
# update dhcp-server lease comment with infos from access-list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/dhcp-lease-comment.md
#
diff --git a/dhcp-lease-comment.local b/dhcp-lease-comment.local
index 74de2c8..76972ee 100644
--- a/dhcp-lease-comment.local
+++ b/dhcp-lease-comment.local
@@ -3,6 +3,8 @@
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
+# provides: lease-script assign
+#
# update dhcp-server lease comment with infos from access-list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/dhcp-lease-comment.md
#
diff --git a/dhcp-lease-comment.template b/dhcp-lease-comment.template
index 0e31007..58c349c 100644
--- a/dhcp-lease-comment.template
+++ b/dhcp-lease-comment.template
@@ -3,6 +3,8 @@
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
+# provides: lease-script assign
+#
# update dhcp-server lease comment with infos from access-list
# https://git.eworm.de/cgit/routeros-scripts/about/doc/dhcp-lease-comment.md
#
diff --git a/dhcp-to-dns b/dhcp-to-dns
index bfd6195..32a47cd 100644
--- a/dhcp-to-dns
+++ b/dhcp-to-dns
@@ -3,6 +3,9 @@
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
+# provides: lease-script assign
+# provides: lease-script deassign
+#
# check DHCP leases and add/remove/update DNS entries
# https://git.eworm.de/cgit/routeros-scripts/about/doc/dhcp-to-dns.md
diff --git a/lease-script b/lease-script
index 28f9e20..37d0c39 100644
--- a/lease-script
+++ b/lease-script
@@ -11,6 +11,7 @@
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global LogPrintExit2;
+:global IfThenElse;
:if ([ :typeof $leaseActIP ] = "nothing" || \
[ :typeof $leaseActMAC ] = "nothing" || \
@@ -19,35 +20,16 @@
$LogPrintExit2 error $0 ("This script is supposed to run from ip dhcp-server.") true;
}
-:local Scripts;
-:local ScriptsAssign {
- "dhcp-to-dns";
- "collect-wireless-mac.local";
- "dhcp-lease-comment.local";
- "collect-wireless-mac.capsman";
- "dhcp-lease-comment.capsman"
-}
-:local ScriptsDeAssign {
- "dhcp-to-dns"
-}
-
-:local State "";
-:if ($leaseBound = 0) do={
- :set State "de";
- :set Scripts $ScriptsDeAssign;
-} else={
- :set Scripts $ScriptsAssign;
-}
+:local State ([ $IfThenElse ($leaseBound = 0) "de" "" ] . "assign");
:log debug ("DHCP Server " . $leaseServerName . " " . \
- $State . "assigned lease " . $leaseActIP . " to " . $leaseActMAC);
+ $State . "ed lease " . $leaseActIP . " to " . $leaseActMAC);
# delay a moment to update the lease table, do not run in parallel for de/assign
:delay ((1 + $leaseBound) . "s");
-:foreach Script in=$Scripts do={
- :if ([ :len [ / system script find where name=$Script ] ] > 0) do={
- :log debug ("Running script from lease-script: " . $Script);
- / system script run $Script;
- }
+:foreach Script in=[ / system script find where source~("\n# provides: lease-script " . $State . "\n") ] do={
+ :local ScriptName [ / system script get $Script name ];
+ :log debug ("Running script from lease-script: " . $ScriptName);
+ / system script run $Script;
}