routeros-scripts/lease-script

37 lines
1.3 KiB
Text
Raw Normal View History

#!rsc by RouterOS
2018-07-05 13:29:26 +00:00
# RouterOS script: lease-script
2021-01-01 20:33:52 +00:00
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
2018-07-05 13:29:26 +00:00
#
# run scripts on DHCP lease
2020-03-27 20:47:26 +00:00
# https://git.eworm.de/cgit/routeros-scripts/about/doc/lease-script.md
2018-07-05 13:29:26 +00:00
:local 0 "lease-script";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global IfThenElse;
:global LogPrintExit2;
2020-02-24 19:09:51 +00:00
:if ([ :typeof $leaseActIP ] = "nothing" || \
[ :typeof $leaseActMAC ] = "nothing" || \
[ :typeof $leaseServerName ] = "nothing" || \
[ :typeof $leaseBound ] = "nothing") do={
$LogPrintExit2 error $0 ("This script is supposed to run from ip dhcp-server.") true;
}
:local State ([ $IfThenElse ($leaseBound = 0) "de" "" ] . "assign");
$LogPrintExit2 debug $0 ("DHCP Server " . $leaseServerName . " " . \
$State . "ed lease " . $leaseActIP . " to " . $leaseActMAC) false;
2018-07-05 13:29:26 +00:00
:foreach Script in=[ / system script find where source~("\n# provides: lease-script " . $State . "\n") ] do={
:local ScriptName [ / system script get $Script name ];
2021-06-22 23:37:52 +00:00
:do {
$LogPrintExit2 debug $0 ("Running script: " . $ScriptName) false;
2021-06-22 23:37:52 +00:00
/ system script run $Script;
} on-error={
$LogPrintExit2 warning $0 ("Running script '" . $ScriptName . "' failed!") false;
2021-06-22 23:37:52 +00:00
}
2018-07-05 13:29:26 +00:00
}