From e709af4c4d824560999c9bbd36f7e3504c28e9f6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 16 Jul 2020 21:27:44 +0200 Subject: dhcp-to-dns: use $IfThenElse --- dhcp-to-dns | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/dhcp-to-dns b/dhcp-to-dns index 4496854..352b53f 100644 --- a/dhcp-to-dns +++ b/dhcp-to-dns @@ -12,15 +12,12 @@ :global PrefixInZone; :global CharacterReplace; +:global IfThenElse; :global LogPrintExit; -:local Zone $Domain; -:if ($HostNameInZone = true) do={ - :set Zone ($Identity . "." . $Zone); -} -:if ($PrefixInZone = true) do={ - :set Zone ("dhcp." . $Zone); -} +:local Zone \ + ([ $IfThenElse ($PrefixInZone = true) "dhcp." ] . \ + [ $IfThenElse ($HostNameInZone = true) ($Identity . ".") ] . $Domain); :local Ttl 5m; :local CommentPrefix "managed by dhcp-to-dns for "; @@ -45,10 +42,9 @@ :foreach Lease in=[ / ip dhcp-server lease find where dynamic=yes status=bound ] do={ :local LeaseVal [ / ip dhcp-server lease get $Lease ]; :local Comment ($CommentPrefix . $LeaseVal->"mac-address"); - :local HostName [ $CharacterReplace ($LeaseVal->"host-name") " " "" ]; - :if ($HostName = "") do={ - :set HostName [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ]; - } + :local HostName [ $IfThenElse ([ :len ($LeaseVal->"host-name") ] = 0) \ + [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ] \ + [ $CharacterReplace ($LeaseVal->"host-name") " " "" ] ]; :local Fqdn ($HostName . "." . $Zone); :local DnsRecord [ / ip dns static find where name=$Fqdn ]; -- cgit v1.2.3-54-g00ecf