diff --git a/README.d/12-setup-lease-script.avif b/README.d/12-setup-lease-script.avif index 2a8bcb24..99f9c30c 100644 Binary files a/README.d/12-setup-lease-script.avif and b/README.d/12-setup-lease-script.avif differ diff --git a/README.md b/README.md index b8f5b736..1d67b913 100644 --- a/README.md +++ b/README.md @@ -258,8 +258,8 @@ Some events can run a script. If you want your DHCP hostnames to be available in DNS use `dhcp-to-dns` with the events from dhcp server. For a regular cleanup add a scheduler entry. - $ScriptInstallUpdate dhcp-to-dns,lease-script; - /ip/dhcp-server/set lease-script=lease-script [ find ]; + $ScriptInstallUpdate dhcp-to-dns,dhcpv4-server-lease; + /ip/dhcp-server/set lease-script="dhcpv4-server-lease" [ find ]; /system/scheduler/add name="dhcp-to-dns" interval=5m start-time=startup on-event="/system/script/run dhcp-to-dns;"; ![screenshot: setup lease script](README.d/12-setup-lease-script.avif) @@ -286,6 +286,7 @@ Available scripts * [Use wireless network with daily psk](doc/daily-psk.md) (`daily-psk`) * [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md) (`dhcp-lease-comment`) * [Create DNS records for DHCP leases](doc/dhcp-to-dns.md) (`dhcp-to-dns`) +* [Run other scripts on IPv4 DHCP server lease](doc/dhcpv4-server-lease.md) (`dhcpv4-server-lease`) * [Automatically upgrade firmware and reboot](doc/firmware-upgrade-reboot.md) (`firmware-upgrade-reboot`) * [Download, import and update firewall address-lists](doc/fw-addr-lists.md) (`fw-addr-lists`) * [Wait for global functions und modules](doc/global-wait.md) (`global-wait`) @@ -294,7 +295,6 @@ Available scripts * [Create DNS records for IPSec peers](doc/ipsec-to-dns.md) (`ipsec-to-dns`) * [Update configuration on IPv6 prefix change](doc/ipv6-update.md) (`ipv6-update`) * [Manage IP addresses with bridge status](doc/ip-addr-bridge.md) (`ip-addr-bridge`) -* [Run other scripts on DHCP lease](doc/lease-script.md) (`lease-script`) * [Manage LEDs dark mode](doc/leds-mode.md) (`leds-day-mode`, `leds-night-mode` & `leds-toggle-mode`) * [Forward log messages via notification](doc/log-forward.md) (`log-forward`) * [Mode button with multiple presses](doc/mode-button.md) (`mode-button`) diff --git a/collect-wireless-mac.capsman.rsc b/collect-wireless-mac.capsman.rsc index 8bb33d87..126153a0 100644 --- a/collect-wireless-mac.capsman.rsc +++ b/collect-wireless-mac.capsman.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=40 +# provides: dhcpv4-server-lease, order=40 # requires RouterOS, version=7.19 # # collect wireless mac adresses in access list diff --git a/collect-wireless-mac.local.rsc b/collect-wireless-mac.local.rsc index 9d41d420..f3ede554 100644 --- a/collect-wireless-mac.local.rsc +++ b/collect-wireless-mac.local.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=40 +# provides: dhcpv4-server-lease, order=40 # requires RouterOS, version=7.19 # # collect wireless mac adresses in access list diff --git a/collect-wireless-mac.template.rsc b/collect-wireless-mac.template.rsc index 837726e3..1e1ed139 100644 --- a/collect-wireless-mac.template.rsc +++ b/collect-wireless-mac.template.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=40 +# provides: dhcpv4-server-lease, order=40 # requires RouterOS, version=7.19 # # collect wireless mac adresses in access list diff --git a/collect-wireless-mac.wifi.rsc b/collect-wireless-mac.wifi.rsc index d07ff357..35165a92 100644 --- a/collect-wireless-mac.wifi.rsc +++ b/collect-wireless-mac.wifi.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=40 +# provides: dhcpv4-server-lease, order=40 # requires RouterOS, version=7.19 # # collect wireless mac adresses in access list diff --git a/contrib/telegram.md b/contrib/telegram.md index 36f7bc4e..f84d6dc3 100644 --- a/contrib/telegram.md +++ b/contrib/telegram.md @@ -91,6 +91,10 @@ Notes /save dhcp-to-dns Create DNS records for DHCP leases with [dhcp-to-dns](https://rsc.eworm.de/doc/dhcp-to-dns.md). +#### dhcpv4-server-lease + + /save dhcpv4-server-lease Run other scripts on IPv4 DHCP server lease with [dhcpv4-server-lease](https://rsc.eworm.de/doc/dhcpv4-server-lease.md). + #### firmware-upgrade-reboot /save firmware-upgrade-reboot Automatically upgrade firmware and reboot with [firmware-upgrade-reboot](https://rsc.eworm.de/doc/firmware-upgrade-reboot.md). @@ -123,10 +127,6 @@ Notes /save ip-addr-bridge Manage IP addresses with [ip-addr-bridge](https://rsc.eworm.de/doc/ip-addr-bridge.md). -#### lease-script - - /save lease-script Run other scripts on DHCP lease with [lease-script](https://rsc.eworm.de/doc/lease-script.md). - #### leds-mode /save leds-mode Manage LEDs dark mode with [leds-mode](https://rsc.eworm.de/doc/leds-mode.md). diff --git a/dhcp-lease-comment.capsman.rsc b/dhcp-lease-comment.capsman.rsc index 7fd00a09..d039cb02 100644 --- a/dhcp-lease-comment.capsman.rsc +++ b/dhcp-lease-comment.capsman.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=60 +# provides: dhcpv4-server-lease, order=60 # requires RouterOS, version=7.19 # # update dhcp-server lease comment with infos from access-list diff --git a/dhcp-lease-comment.local.rsc b/dhcp-lease-comment.local.rsc index 7ed6823a..2c5b4efa 100644 --- a/dhcp-lease-comment.local.rsc +++ b/dhcp-lease-comment.local.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=60 +# provides: dhcpv4-server-lease, order=60 # requires RouterOS, version=7.19 # # update dhcp-server lease comment with infos from access-list diff --git a/dhcp-lease-comment.template.rsc b/dhcp-lease-comment.template.rsc index c901de40..a06983f0 100644 --- a/dhcp-lease-comment.template.rsc +++ b/dhcp-lease-comment.template.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=60 +# provides: dhcpv4-server-lease, order=60 # requires RouterOS, version=7.19 # # update dhcp-server lease comment with infos from access-list diff --git a/dhcp-lease-comment.wifi.rsc b/dhcp-lease-comment.wifi.rsc index d481def8..3fea1bf6 100644 --- a/dhcp-lease-comment.wifi.rsc +++ b/dhcp-lease-comment.wifi.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=60 +# provides: dhcpv4-server-lease, order=60 # requires RouterOS, version=7.19 # # update dhcp-server lease comment with infos from access-list diff --git a/dhcp-to-dns.rsc b/dhcp-to-dns.rsc index 70567509..37aaadac 100644 --- a/dhcp-to-dns.rsc +++ b/dhcp-to-dns.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2013-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=20 +# provides: dhcpv4-server-lease, order=20 # requires RouterOS, version=7.19 # # check DHCP leases and add/remove/update DNS entries diff --git a/dhcpv4-server-lease.rsc b/dhcpv4-server-lease.rsc new file mode 100644 index 00000000..899674d1 --- /dev/null +++ b/dhcpv4-server-lease.rsc @@ -0,0 +1,65 @@ +#!rsc by RouterOS +# RouterOS script: dhcpv4-server-lease +# Copyright (c) 2013-2026 Christian Hesse +# https://rsc.eworm.de/COPYING.md +# +# requires RouterOS, version=7.19 +# +# run scripts on IPv4 DHCP server lease +# https://rsc.eworm.de/doc/dhcpv4-server-lease.md + +:local ExitOK false; +:onerror Err { + :global GlobalConfigReady; :global GlobalFunctionsReady; + :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ + do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; + :local ScriptName [ :jobname ]; + + :global Grep; + :global IfThenElse; + :global LogPrint; + :global ParseKeyValueStore; + :global ScriptLock; + + :if ([ :typeof $leaseActIP ] = "nothing" || \ + [ :typeof $leaseActMAC ] = "nothing" || \ + [ :typeof $leaseServerName ] = "nothing" || \ + [ :typeof $leaseBound ] = "nothing") do={ + $LogPrint error $ScriptName ("This script is supposed to run from ip dhcp-server."); + :set ExitOK true; + :error false; + } + + $LogPrint debug $ScriptName ("DHCP Server " . $leaseServerName . " " . [ $IfThenElse ($leaseBound = 0) \ + "de" "" ] . "assigned lease " . $leaseActIP . " to " . $leaseActMAC); + + :if ([ $ScriptLock $ScriptName 10 ] = false) do={ + :set ExitOK true; + :error false; + } + + :if ([ :len [ /system/script/job/find where script=$ScriptName ] ] > 1) do={ + $LogPrint debug $ScriptName ("More invocations are waiting, exiting early."); + :set ExitOK true; + :error true; + } + + :local RunOrder ({}); + :foreach Script in=[ /system/script/find where source~("\n# provides: dhcpv4-server-lease\\b") ] do={ + :local ScriptVal [ /system/script/get $Script ]; + :local Store [ $ParseKeyValueStore [ $Grep ($ScriptVal->"source") ("\23 provides: dhcpv4-server-lease, ") ] ]; + + :set ($RunOrder->($Store->"order" . "-" . $ScriptVal->"name")) ($ScriptVal->"name"); + } + + :foreach Order,Script in=$RunOrder do={ + :onerror Err { + $LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script); + /system/script/run $Script; + } do={ + $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed: " . $Err); + } + } +} do={ + :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} diff --git a/doc/collect-wireless-mac.md b/doc/collect-wireless-mac.md index 9fef2adb..96b314e1 100644 --- a/doc/collect-wireless-mac.md +++ b/doc/collect-wireless-mac.md @@ -64,14 +64,14 @@ Usage and invocation Run this script from a dhcp server as lease-script to collect the MAC address when a new address is leased. You may want to use -[lease-script](lease-script.md). +[dhcpv4-server-lease](dhcpv4-server-lease.md). See also -------- * [Comment DHCP leases with info from access list](dhcp-lease-comment.md) * [Create DNS records for DHCP leases](dhcp-to-dns.md) -* [Run other scripts on DHCP lease](lease-script.md) +* [Run other scripts on IPv4 DHCP server lease](dhcpv4-server-lease.md) --- [⬅️ Go back to main README](../README.md) diff --git a/doc/dhcp-lease-comment.md b/doc/dhcp-lease-comment.md index 2bda80be..1a4e23aa 100644 --- a/doc/dhcp-lease-comment.md +++ b/doc/dhcp-lease-comment.md @@ -50,14 +50,14 @@ Usage and invocation Run this script from a dhcp server as lease-script to update the comment just after a new address is leased. You may want to use -[lease-script](lease-script.md). +[dhcpv4-server-lease](dhcpv4-server-lease.md). See also -------- * [Collect MAC addresses in wireless access list](collect-wireless-mac.md) * [Create DNS records for DHCP leases](dhcp-to-dns.md) -* [Run other scripts on DHCP lease](lease-script.md) +* [Run other scripts on IPv4 DHCP server lease](dhcpv4-server-lease.md) --- [⬅️ Go back to main README](../README.md) diff --git a/doc/dhcp-to-dns.md b/doc/dhcp-to-dns.md index a7e7a680..8c282b00 100644 --- a/doc/dhcp-to-dns.md +++ b/doc/dhcp-to-dns.md @@ -28,7 +28,7 @@ Just install the script: $ScriptInstallUpdate dhcp-to-dns; Then run it from dhcp server as lease script. You may want to use -[lease-script](lease-script.md). +[dhcpv4-server-lease](dhcpv4-server-lease.md). A scheduler cares about cleanup: @@ -102,8 +102,8 @@ See also * [Collect MAC addresses in wireless access list](collect-wireless-mac.md) * [Comment DHCP leases with info from access list](dhcp-lease-comment.md) +* [Run other scripts on IPv4 DHCP server lease](dhcpv4-server-lease.md) * [Create DNS records for IPSec peers](ipsec-to-dns.md) -* [Run other scripts on DHCP lease](lease-script.md) --- [⬅️ Go back to main README](../README.md) diff --git a/doc/dhcpv4-server-lease.md b/doc/dhcpv4-server-lease.md new file mode 100644 index 00000000..e588101d --- /dev/null +++ b/doc/dhcpv4-server-lease.md @@ -0,0 +1,54 @@ +Run other scripts on IPv4 DHCP server lease +=========================================== + +[![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network) +[![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers) +[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.19-yellow?style=flat)](https://mikrotik.com/download/changelogs/) +[![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts) +[![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) + +[⬅️ Go back to main README](../README.md) + +> ℹ️ **Info**: This script can not be used on its own but requires the base +> installation. See [main README](../README.md) for details. + +Description +----------- + +This script is supposed to run from IPv4 DHCP server as lease script. On a +DHCP lease it runs each script containing the following line, where `##` is +a decimal number for ordering: + + # provides: dhcpv4-server-lease, order=## + +Currently it runs if available, in order: + +* [dhcp-to-dns](dhcp-to-dns.md) +* [collect-wireless-mac](collect-wireless-mac.md) +* [dhcp-lease-comment](dhcp-lease-comment.md) +* `hotspot-to-wpa-cleanup`, which is an optional cleanup script + of [hotspot-to-wpa](hotspot-to-wpa.md) + +Requirements and installation +----------------------------- + +Just install the script: + + $ScriptInstallUpdate dhcpv4-server-lease; + +... and add it as `lease-script` to your dhcp server: + + /ip/dhcp-server/set lease-script="dhcpv4-server-lease" [ find ]; + +See also +-------- + +* [Collect MAC addresses in wireless access list](collect-wireless-mac.md) +* [Comment DHCP leases with info from access list](dhcp-lease-comment.md) +* [Create DNS records for DHCP leases](dhcp-to-dns.md) +* [Use WPA network with hotspot credentials](hotspot-to-wpa.md) + +--- +[⬅️ Go back to main README](../README.md) +[⬆️ Go back to top](#top) diff --git a/doc/hotspot-to-wpa.md b/doc/hotspot-to-wpa.md index 22d1dd13..e4e77098 100644 --- a/doc/hotspot-to-wpa.md +++ b/doc/hotspot-to-wpa.md @@ -49,24 +49,24 @@ and add a scheduler. For `wifi`: - $ScriptInstallUpdate hotspot-to-wpa-cleanup.wifi,lease-script; - /system/scheduler/add interval=1d name=hotspot-to-wpa-cleanup on-event="/system/script/run hotspot-to-wpa-cleanup.wifi;" start-time=startup; + $ScriptInstallUpdate hotspot-to-wpa-cleanup.wifi,dhcpv4-server-lease; + /system/scheduler/add interval=1d name="hotspot-to-wpa-cleanup" on-event="/system/script/run hotspot-to-wpa-cleanup.wifi;" start-time=startup; For legacy CAPsMAN: - $ScriptInstallUpdate hotspot-to-wpa-cleanup.capsman,lease-script; - /system/scheduler/add interval=1d name=hotspot-to-wpa-cleanup on-event="/system/script/run hotspot-to-wpa-cleanup.capsman;" start-time=startup; + $ScriptInstallUpdate hotspot-to-wpa-cleanup.capsman,dhcpv4-server-lease; + /system/scheduler/add interval=1d name="hotspot-to-wpa-cleanup" on-event="/system/script/run hotspot-to-wpa-cleanup.capsman;" start-time=startup; And add the lease script and matcher comment to your wpa interfaces' dhcp server. You can add more information to the comment, separated by comma. In this example the server is called `hotspot-to-wpa`. - /ip/dhcp-server/set lease-script=lease-script comment="hotspot-to-wpa=wpa" hotspot-to-wpa; + /ip/dhcp-server/set lease-script="dhcpv4-server-lease" comment="hotspot-to-wpa=wpa" hotspot-to-wpa; You can specify the timeout after which a device is removed from leases and access-list. The default is four weeks. - /ip/dhcp-server/set lease-script=lease-script comment="hotspot-to-wpa=wpa, timeout=2w" hotspot-to-wpa; + /ip/dhcp-server/set lease-script="dhcpv4-server-lease" comment="hotspot-to-wpa=wpa, timeout=2w" hotspot-to-wpa; Configuration ------------- @@ -117,7 +117,7 @@ passphrase from hotspot credentials. See also -------- -* [Run other scripts on DHCP lease](lease-script.md) +* [Run other scripts on IPv4 DHCP server lease](dhcpv4-server-lease.md) --- [⬅️ Go back to main README](../README.md) diff --git a/doc/lease-script.md b/doc/lease-script.md index 6bcf7e13..3cba7045 100644 --- a/doc/lease-script.md +++ b/doc/lease-script.md @@ -1,54 +1 @@ -Run other scripts on DHCP lease -=============================== - -[![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers) -[![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network) -[![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers) -[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.19-yellow?style=flat)](https://mikrotik.com/download/changelogs/) -[![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts) -[![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) - -[⬅️ Go back to main README](../README.md) - -> ℹ️ **Info**: This script can not be used on its own but requires the base -> installation. See [main README](../README.md) for details. - -Description ------------ - -This script is supposed to run from dhcp server as lease script. On a dhcp -lease it runs each script containing the following line, where `##` is a -decimal number for ordering: - - # provides: lease-script, order=## - -Currently it runs if available, in order: - -* [dhcp-to-dns](dhcp-to-dns.md) -* [collect-wireless-mac](collect-wireless-mac.md) -* [dhcp-lease-comment](dhcp-lease-comment.md) -* `hotspot-to-wpa-cleanup`, which is an optional cleanup script - of [hotspot-to-wpa](hotspot-to-wpa.md) - -Requirements and installation ------------------------------ - -Just install the script: - - $ScriptInstallUpdate lease-script; - -... and add it as `lease-script` to your dhcp server: - - /ip/dhcp-server/set lease-script=lease-script [ find ]; - -See also --------- - -* [Collect MAC addresses in wireless access list](collect-wireless-mac.md) -* [Comment DHCP leases with info from access list](dhcp-lease-comment.md) -* [Create DNS records for DHCP leases](dhcp-to-dns.md) -* [Use WPA network with hotspot credentials](hotspot-to-wpa.md) - ---- -[⬅️ Go back to main README](../README.md) -[⬆️ Go back to top](#top) +This script has been renamed. Please see [dhcpv4-server-lease](dhcpv4-server-lease.md). diff --git a/global-functions.rsc b/global-functions.rsc index cb74f991..e45d4363 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -15,7 +15,7 @@ # Git commit id & info, expected configuration version :global CommitId "unknown"; :global CommitInfo "unknown"; -:global ExpectedConfigVersion 139; +:global ExpectedConfigVersion 140; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/hotspot-to-wpa-cleanup.capsman.rsc b/hotspot-to-wpa-cleanup.capsman.rsc index 35275313..6f1ed372 100644 --- a/hotspot-to-wpa-cleanup.capsman.rsc +++ b/hotspot-to-wpa-cleanup.capsman.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2021-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=80 +# provides: dhcpv4-server-lease, order=80 # requires RouterOS, version=7.19 # requires device-mode, hotspot # diff --git a/hotspot-to-wpa-cleanup.template.rsc b/hotspot-to-wpa-cleanup.template.rsc index 398f194f..8986b42d 100644 --- a/hotspot-to-wpa-cleanup.template.rsc +++ b/hotspot-to-wpa-cleanup.template.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2021-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=80 +# provides: dhcpv4-server-lease, order=80 # requires RouterOS, version=7.19 # requires device-mode, hotspot # diff --git a/hotspot-to-wpa-cleanup.wifi.rsc b/hotspot-to-wpa-cleanup.wifi.rsc index 17b9e545..8a5a095c 100644 --- a/hotspot-to-wpa-cleanup.wifi.rsc +++ b/hotspot-to-wpa-cleanup.wifi.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2021-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# provides: lease-script, order=80 +# provides: dhcpv4-server-lease, order=80 # requires RouterOS, version=7.19 # requires device-mode, hotspot # diff --git a/lease-script.rsc b/lease-script.rsc index 991e6fac..2da00ca8 100644 --- a/lease-script.rsc +++ b/lease-script.rsc @@ -1,65 +1,3 @@ #!rsc by RouterOS -# RouterOS script: lease-script -# Copyright (c) 2013-2026 Christian Hesse -# https://rsc.eworm.de/COPYING.md # -# requires RouterOS, version=7.19 -# -# run scripts on DHCP lease -# https://rsc.eworm.de/doc/lease-script.md - -:local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; - :local ScriptName [ :jobname ]; - - :global Grep; - :global IfThenElse; - :global LogPrint; - :global ParseKeyValueStore; - :global ScriptLock; - - :if ([ :typeof $leaseActIP ] = "nothing" || \ - [ :typeof $leaseActMAC ] = "nothing" || \ - [ :typeof $leaseServerName ] = "nothing" || \ - [ :typeof $leaseBound ] = "nothing") do={ - $LogPrint error $ScriptName ("This script is supposed to run from ip dhcp-server."); - :set ExitOK true; - :error false; - } - - $LogPrint debug $ScriptName ("DHCP Server " . $leaseServerName . " " . [ $IfThenElse ($leaseBound = 0) \ - "de" "" ] . "assigned lease " . $leaseActIP . " to " . $leaseActMAC); - - :if ([ $ScriptLock $ScriptName 10 ] = false) do={ - :set ExitOK true; - :error false; - } - - :if ([ :len [ /system/script/job/find where script=$ScriptName ] ] > 1) do={ - $LogPrint debug $ScriptName ("More invocations are waiting, exiting early."); - :set ExitOK true; - :error true; - } - - :local RunOrder ({}); - :foreach Script in=[ /system/script/find where source~("\n# provides: lease-script\\b") ] do={ - :local ScriptVal [ /system/script/get $Script ]; - :local Store [ $ParseKeyValueStore [ $Grep ($ScriptVal->"source") ("\23 provides: lease-script, ") ] ]; - - :set ($RunOrder->($Store->"order" . "-" . $ScriptVal->"name")) ($ScriptVal->"name"); - } - - :foreach Order,Script in=$RunOrder do={ - :onerror Err { - $LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script); - /system/script/run $Script; - } do={ - $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed: " . $Err); - } - } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; -} +# dummy for migration diff --git a/news-and-changes.rsc b/news-and-changes.rsc index 754410ad..48558deb 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -64,6 +64,7 @@ 137="Added support to send notifications via Gotify (gotify.net)."; 138="RouterOS 7.19 is suffering an issue with certificate store. Fixing trust state for all certificates..."; 139="Certificate Authorities will reduce the leaf certificate validity times soon. Thus the defaults for renewal and warning in 'check-certificates' were decreased."; + 140="The scripts 'lease-script' was renamed to 'dhcpv4-server-lease', configuration was updated automatically."; }; # Migration steps to be applied on script updates @@ -74,4 +75,5 @@ 111=":local Rec [ /ip/dns/static/find where comment~\"^managed by dhcp-to-dns for \" ]; :if ([ :len \$Rec ] > 0) do={ /ip/dns/static/remove \$Rec; /system/script/run dhcp-to-dns; };"; 132=":if ([ :len [ /system/script/find where name=\"check-health\" ] ] > 0) do={ :local Code \":local Install \\\"check-health\\\"; :if ([ :len [ /system/health/find where type=\\\"\\\" name~\\\"-state\\\\\\\$\\\" ] ] > 0) do={ :set Install (\\\$Install . \\\",check-health.d/state\\\"); }; :if ([ :len [ /system/health/find where type=\\\"C\\\" ] ] > 0) do={ :set Install (\\\$Install . \\\",check-health.d/temperature\\\"); }; :if ([ :len [ /system/health/find where type=\\\"V\\\" ] ] > 0) do={ :set Install (\\\$Install . \\\",check-health.d/voltage\\\"); }; :global ScriptInstallUpdate; \\\$ScriptInstallUpdate \\\$Install;\"; :global ValidateSyntax; :if ([ \$ValidateSyntax \$Code ] = true) do={ :do { [ :parse \$Code ]; } on-error={ }; }; };"; 138="/certificate/set trusted=yes [ find where trusted=yes ];"; + 140=":if ([ :len [ /system/script/find where name=\"lease-script\" ] ] > 0) do={ /system/script/set name=\"dhcpv4-server-lease\" \"lease-script\"; :global ScriptInstallUpdate; \$ScriptInstallUpdate; /ip/dhcp-server/set lease-script=\"dhcpv4-server-lease\" [ find where lease-script=\"lease-script\" ]; };"; };