diff options
author | Christian Hesse <mail@eworm.de> | 2021-07-08 16:05:11 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-07-08 21:03:31 +0200 |
commit | 6bf8cd5fac77aa5db804c3180777d495b5d2ed26 (patch) | |
tree | d4103c94dd6428613d09089af7c7f0fa7f3c1477 | |
parent | 623fd707c4e9340af35ad11ad09e3a87413423f6 (diff) |
lease-script: implement script order
The order may be important: `collect-wireless-mac` can add a dns name
in notification, thus `dhcp-to-dns` should run first.
-rw-r--r-- | collect-wireless-mac.capsman | 2 | ||||
-rw-r--r-- | collect-wireless-mac.local | 2 | ||||
-rw-r--r-- | collect-wireless-mac.template | 2 | ||||
-rw-r--r-- | dhcp-lease-comment.capsman | 2 | ||||
-rw-r--r-- | dhcp-lease-comment.local | 2 | ||||
-rw-r--r-- | dhcp-lease-comment.template | 2 | ||||
-rw-r--r-- | dhcp-to-dns | 3 | ||||
-rw-r--r-- | doc/lease-script.md | 4 | ||||
-rw-r--r-- | hotspot-to-wpa-cleanup | 2 | ||||
-rw-r--r-- | lease-script | 24 |
10 files changed, 27 insertions, 18 deletions
diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman index 96c204a..18f30d6 100644 --- a/collect-wireless-mac.capsman +++ b/collect-wireless-mac.capsman @@ -6,7 +6,7 @@ # collect wireless mac adresses in access list # https://git.eworm.de/cgit/routeros-scripts/about/doc/collect-wireless-mac.md # -# provides: lease-script, assign +# provides: lease-script, assign, order=40 # # !! Do not edit this file, it is generated from template! diff --git a/collect-wireless-mac.local b/collect-wireless-mac.local index 63cd63c..1e8086e 100644 --- a/collect-wireless-mac.local +++ b/collect-wireless-mac.local @@ -6,7 +6,7 @@ # collect wireless mac adresses in access list # https://git.eworm.de/cgit/routeros-scripts/about/doc/collect-wireless-mac.md # -# provides: lease-script, assign +# provides: lease-script, assign, order=40 # # !! Do not edit this file, it is generated from template! diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template index 3b35fc9..18bab89 100644 --- a/collect-wireless-mac.template +++ b/collect-wireless-mac.template @@ -6,7 +6,7 @@ # collect wireless mac adresses in access list # https://git.eworm.de/cgit/routeros-scripts/about/doc/collect-wireless-mac.md # -# provides: lease-script, assign +# provides: lease-script, assign, order=40 # # !! 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 43697ed..33c1b6a 100644 --- a/dhcp-lease-comment.capsman +++ b/dhcp-lease-comment.capsman @@ -3,7 +3,7 @@ # 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, assign, order=60 # # 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 32adc4c..b05754d 100644 --- a/dhcp-lease-comment.local +++ b/dhcp-lease-comment.local @@ -3,7 +3,7 @@ # 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, assign, order=60 # # 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 3302031..04a6261 100644 --- a/dhcp-lease-comment.template +++ b/dhcp-lease-comment.template @@ -3,7 +3,7 @@ # 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, assign, order=60 # # 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 4fa1621..44fd673 100644 --- a/dhcp-to-dns +++ b/dhcp-to-dns @@ -3,8 +3,7 @@ # 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 +# provides: lease-script, assign, deassign, order=20 # # 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/doc/lease-script.md b/doc/lease-script.md index 55c5430..3d8a29b 100644 --- a/doc/lease-script.md +++ b/doc/lease-script.md @@ -17,10 +17,6 @@ it does: * run [dhcp-to-dns](dhcp-to-dns.md) * run [hotspot-to-wpa](hotspot-to-wpa.md) -Note that installation order influences execution order. You may want to -install `dhcp-to-dns` before `collect-wireless-mac` for dns name in -notification. - Requirements and installation ----------------------------- diff --git a/hotspot-to-wpa-cleanup b/hotspot-to-wpa-cleanup index 34b76c8..c29aa7c 100644 --- a/hotspot-to-wpa-cleanup +++ b/hotspot-to-wpa-cleanup @@ -3,7 +3,7 @@ # Copyright (c) 2021 Christian Hesse <mail@eworm.de> # https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md # -# provides: lease-script, assign +# provides: lease-script, assign, order=80 # # manage and clean up private WPA passphrase after hotspot login # https://git.eworm.de/cgit/routeros-scripts/about/doc/hotspot-to-wpa.md diff --git a/lease-script b/lease-script index 780d122..97d5372 100644 --- a/lease-script +++ b/lease-script @@ -12,6 +12,7 @@ :global IfThenElse; :global LogPrintExit2; +:global ParseKeyValueStore; :if ([ :typeof $leaseActIP ] = "nothing" || \ [ :typeof $leaseActMAC ] = "nothing" || \ @@ -21,18 +22,31 @@ } :local State ([ $IfThenElse ($leaseBound = 0) "de" "" ] . "assign"); +:local RunOrder [ :toarray "" ]; $LogPrintExit2 debug $0 ("DHCP Server " . $leaseServerName . " " . \ $State . "ed lease " . $leaseActIP . " to " . $leaseActMAC) false; -:foreach Script in=[ / system script find where source~("\n# provides: lease-script, " . $State . "\n") ] do={ - :local ScriptName [ / system script get $Script name ]; - :if ([ :len [ / system script job find where script=$ScriptName ] ] < 2) do={ +:foreach Script in=[ / system script find where source~("\n# provides: lease-script, ") ] do={ + :local Name [ / system script get $Script name ]; + :local Store [ / system script get $Script source ]; + + :set Store [ :pick $Store ([ :find $Store "\n# provides: lease-script, " ] + 27) [ :len $Store ] ]; + :set Store [ :pick $Store 0 [ :find $Store "\n" ] ]; + :set Store [ $ParseKeyValueStore $Store ]; + + :if (($Store->$State) = true) do={ + :set ($RunOrder->($Store->"order")) $Name; + } +} + +:foreach Script in=$RunOrder do={ + :if ([ :len [ / system script job find where script=$Script ] ] < 2) do={ :do { - $LogPrintExit2 debug $0 ("Running script: " . $ScriptName) false; + $LogPrintExit2 debug $0 ("Running script: " . $Script) false; / system script run $Script; } on-error={ - $LogPrintExit2 warning $0 ("Running script '" . $ScriptName . "' failed!") false; + $LogPrintExit2 warning $0 ("Running script '" . $Script . "' failed!") false; } } } |