lease-script: use 'provides' to find lease scripts

This commit is contained in:
Christian Hesse 2021-06-23 00:53:19 +02:00
parent 420986fdfc
commit 2041390f55
8 changed files with 22 additions and 25 deletions

View file

@ -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";

View file

@ -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";

View file

@ -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'!

View file

@ -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
#

View file

@ -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
#

View file

@ -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
#

View file

@ -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

View file

@ -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;
}