routeros-scripts/lease-script
Christian Hesse 71ad56aacc explicitly name the license
Copyright (C) 2013-2020 Christian Hesse <mail@eworm.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

https://www.gnu.org/licenses/#GPL
https://www.gnu.org/licenses/gpl.html
https://www.gnu.org/licenses/gpl.md
2020-06-19 22:17:42 +02:00

49 lines
1.3 KiB
Text

#!rsc
# RouterOS script: lease-script
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# run scripts on DHCP lease
# https://git.eworm.de/cgit/routeros-scripts/about/doc/lease-script.md
:global LogPrintExit;
:if ([ :typeof $leaseActIP ] = "nothing" || \
[ :typeof $leaseActMAC ] = "nothing" || \
[ :typeof $leaseServerName ] = "nothing" || \
[ :typeof $leaseBound ] = "nothing") do={
$LogPrintExit error "This script is supposed to run from ip dhcp-client." 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;
}
:log debug ("DHCP Server " . $leaseServerName . " " . \
$State . "assigned 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 ([ / system script print count-only where name=$Script ] > 0) do={
:log debug ("Running script from lease-script: " . $Script);
/ system script run $Script;
}
}