From ee94024dcaa59333f03d90f342e550a5f3ab40f2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 13 Apr 2023 00:32:13 +0200 Subject: dhcp-to-dns: get domain from dhcp server's network definition --- dhcp-to-dns.rsc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'dhcp-to-dns.rsc') diff --git a/dhcp-to-dns.rsc b/dhcp-to-dns.rsc index d310a73..b15511e 100644 --- a/dhcp-to-dns.rsc +++ b/dhcp-to-dns.rsc @@ -13,10 +13,7 @@ :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } :global Domain; -:global HostNameInZone; :global Identity; -:global PrefixInZone; -:global ServerNameInZone; :global CharacterReplace; :global EitherOr; @@ -27,9 +24,6 @@ $ScriptLock $0 false 10; -:local Zone \ - ([ $IfThenElse ($PrefixInZone = true) "dhcp." ] . \ - [ $IfThenElse ($HostNameInZone = true) ($Identity . ".") ] . $Domain); :local Ttl 5m; :local CommentPrefix ("managed by " . $0 . " for "); :local CommentString ("--- " . $0 . " above ---"); @@ -70,7 +64,14 @@ $ScriptLock $0 false 10; :local Comment ($CommentPrefix . $LeaseVal->"mac-address"); :local MacDash [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ]; :local HostName [ $CharacterReplace [ $EitherOr ([ $ParseKeyValueStore ($LeaseVal->"comment") ]->"hostname") ($LeaseVal->"host-name") ] " " "" ]; - :local NetDomain ([ $IfThenElse ($ServerNameInZone = true) ($LeaseVal->"server" . ".") ] . $Zone); + :local Network [ /ip/dhcp-server/network/find where ($LeaseVal->"address") in address ]; + :local NetworkVal; + :if ([ :len $Network ] > 0) do={ + :set NetworkVal [ /ip/dhcp-server/network/get ($Network->0) ]; + } + :local NetworkInfo [ $ParseKeyValueStore ($NetworkVal->"comment") ]; + :local NetDomain ([ $IfThenElse ([ :len ($NetworkInfo->"name-extra") ] > 0) ($NetworkInfo->"name-extra" . ".") ] . \ + [ $EitherOr [ $EitherOr ($NetworkInfo->"domain") ($NetworkVal->"domain") ] $Domain ]); :local DnsRecord [ /ip/dns/static/find where comment=$Comment (!type or type=A) ]; :if ([ :len $DnsRecord ] > 0) do={ -- cgit v1.2.3-54-g00ecf