mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-04-16 10:09:37 +00:00
Compare commits
2 commits
4fbfb181d9
...
c2d458fa71
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2d458fa71 | ||
|
|
0e833b1d87 |
8 changed files with 138 additions and 5 deletions
|
|
@ -283,6 +283,7 @@ Available scripts
|
|||
* [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`)
|
||||
* [Run other scripts on IPv6 DHCP client lease](doc/dhcpv6-client-lease.md) (`dhcpv6-client-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`)
|
||||
|
|
|
|||
60
dhcpv6-client-lease.rsc
Normal file
60
dhcpv6-client-lease.rsc
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: dhcpv6-client-lease
|
||||
# Copyright (c) 2026 Christian Hesse <mail@eworm.de>
|
||||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# requires RouterOS, version=7.22
|
||||
#
|
||||
# run scripts on IPv6 DHCP client lease
|
||||
# https://rsc.eworm.de/doc/dhcpv6-client-lease.md
|
||||
|
||||
: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 LogPrint;
|
||||
:global ParseKeyValueStore;
|
||||
:global ScriptLock;
|
||||
|
||||
:if ([ $ScriptLock $ScriptName 10 ] = false) do={
|
||||
:exit;
|
||||
}
|
||||
|
||||
:if (([ :typeof $"na-address" ] = "nothing" || [ :typeof $"na-valid" ] = "nothing") && \
|
||||
([ :typeof $"pd-prefix" ] = "nothing" || [ :typeof $"pd-valid" ] = "nothing")) do={
|
||||
$LogPrint error $ScriptName ("This script is supposed to run from ipv6 dhcp-client.");
|
||||
:exit;
|
||||
}
|
||||
|
||||
:global DHCPv6ClientLeaseVars {
|
||||
"na-address"=$"na-address";
|
||||
"na-valid"=$"na-valid";
|
||||
"pd-prefix"=$"pd-prefix";
|
||||
"pd-valid"=$"pd-valid";
|
||||
"options"=$"options" };
|
||||
|
||||
:local RunOrder ({});
|
||||
:foreach Script in=[ /system/script/find where source~("\n# provides: dhcpv6-client-lease\\b") ] do={
|
||||
:local ScriptVal [ /system/script/get $Script ];
|
||||
:local Store [ $ParseKeyValueStore [ $Grep ($ScriptVal->"source") ("\23 provides: dhcpv6-client-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);
|
||||
}
|
||||
}
|
||||
|
||||
:set DHCPv6ClientLeaseVars;
|
||||
} do={
|
||||
:global DHCPv6ClientLeaseVars; :set DHCPv6ClientLeaseVars;
|
||||
:global ExitOnError; $ExitOnError [ :jobname ] $Err;
|
||||
}
|
||||
65
doc/dhcpv6-client-lease.md
Normal file
65
doc/dhcpv6-client-lease.md
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
Run other scripts on IPv6 DHCP client lease
|
||||
===========================================
|
||||
|
||||
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
||||
[](https://github.com/eworm-de/routeros-scripts/network)
|
||||
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||
[](https://mikrotik.com/download/changelogs/)
|
||||
[](https://t.me/routeros_scripts)
|
||||
[](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 IPv6 DHCP client as lease script. On a
|
||||
DHCP leasse it runs each script containing the following line, where `##` is
|
||||
a decimal number for ordering:
|
||||
|
||||
# provides: dhcpv6-client-lease, order=##
|
||||
|
||||
The lease script is started with some variables injected, but these are not
|
||||
available in child scripts. However this script makes these variables
|
||||
available with a global variable. This code is required in child script:
|
||||
|
||||
:global EitherOr;
|
||||
|
||||
:global DHCPv6ClientLeaseVars;
|
||||
|
||||
:local NaAddress [ $EitherOr $"na-address" ($DHCPv6ClientLeaseVars->"na-address") ];
|
||||
:local NaValid [ $EitherOr $"na-valid" ($DHCPv6ClientLeaseVars->"na-valid") ];
|
||||
:local PdPrefix [ $EitherOr $"pd-prefix" ($DHCPv6ClientLeaseVars->"pd-prefix") ];
|
||||
:local PdValid [ $EitherOr $"pd-valid" ($DHCPv6ClientLeaseVars->"pd-valid") ];
|
||||
:local Options [ $EitherOr $"options" ($DHCPv6ClientLeaseVars->"options") ];
|
||||
|
||||
The values are available under different name then, use `$PdPrefix` instead
|
||||
of `$"pd-prefix"`, and so on. The resulting script supports both, being a
|
||||
lease script itself or being run as child.
|
||||
|
||||
Currently it runs if available, in order:
|
||||
|
||||
* [ipv6-update](ipv6-update.md)
|
||||
|
||||
Requirements and installation
|
||||
-----------------------------
|
||||
|
||||
Just install the script:
|
||||
|
||||
$ScriptInstallUpdate dhcpv6-client-lease;
|
||||
|
||||
... and add it as `lease-script` to your dhcp client:
|
||||
|
||||
/ipv6/dhcp-client/set lease-script="dhcpv6-client-lease" [ find ];
|
||||
|
||||
See also
|
||||
--------
|
||||
|
||||
* [Update configuration on IPv6 prefix change](ipv6-update.md)
|
||||
|
||||
---
|
||||
[⬅️ Go back to main README](../README.md)
|
||||
[⬆️ Go back to top](#top)
|
||||
|
|
@ -77,6 +77,7 @@ start with "`ipv6-pool-`" and actual pool name, followed by a comma,
|
|||
See also
|
||||
--------
|
||||
|
||||
* [Run other scripts on IPv6 DHCP client lease](dhcpv6-client-lease.md)
|
||||
* [Run scripts on ppp connection](ppp-on-up.md)
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ Just install the script:
|
|||
See also
|
||||
--------
|
||||
|
||||
* [Run other scripts on IPv6 DHCP client lease](dhcpv6-client-lease.md)
|
||||
* [Update configuration on IPv6 prefix change](ipv6-update.md)
|
||||
* [Update tunnelbroker configuration](update-tunnelbroker.md)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
# Git commit id & info, expected configuration version
|
||||
:global CommitId "unknown";
|
||||
:global CommitInfo "unknown";
|
||||
:global ExpectedConfigVersion 140;
|
||||
:global ExpectedConfigVersion 141;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# requires RouterOS, version=7.22
|
||||
# provides: dhcpv6-client-lease, order=40
|
||||
#
|
||||
# update firewall and dns settings on IPv6 prefix change
|
||||
# https://rsc.eworm.de/doc/ipv6-update.md
|
||||
|
|
@ -14,14 +15,17 @@
|
|||
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
|
||||
:local ScriptName [ :jobname ];
|
||||
|
||||
:global EitherOr;
|
||||
:global LogPrint;
|
||||
:global ParseKeyValueStore;
|
||||
:global ScriptLock;
|
||||
|
||||
:local NaAddress $"na-address";
|
||||
:local NaValid $"na-valid";
|
||||
:local PdPrefix $"pd-prefix";
|
||||
:local PdValid $"pd-valid";
|
||||
:global DHCPv6ClientLeaseVars;
|
||||
|
||||
:local NaAddress [ $EitherOr $"na-address" ($DHCPv6ClientLeaseVars->"na-address") ];
|
||||
:local NaValid [ $EitherOr $"na-valid" ($DHCPv6ClientLeaseVars->"na-valid") ];
|
||||
:local PdPrefix [ $EitherOr $"pd-prefix" ($DHCPv6ClientLeaseVars->"pd-prefix") ];
|
||||
:local PdValid [ $EitherOr $"pd-valid" ($DHCPv6ClientLeaseVars->"pd-valid") ];
|
||||
|
||||
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||
:exit;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
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.";
|
||||
141="Introduced script 'dhcpv6-client-lease' to run several scripts on IPv6 DHCP client lease.";
|
||||
};
|
||||
|
||||
# Migration steps to be applied on script updates
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue