dhcp-to-dns: use $IfThenElse

This commit is contained in:
Christian Hesse 2020-07-16 21:27:44 +02:00
parent 6dfd8ed41a
commit e709af4c4d

View file

@ -12,15 +12,12 @@
:global PrefixInZone; :global PrefixInZone;
:global CharacterReplace; :global CharacterReplace;
:global IfThenElse;
:global LogPrintExit; :global LogPrintExit;
:local Zone $Domain; :local Zone \
:if ($HostNameInZone = true) do={ ([ $IfThenElse ($PrefixInZone = true) "dhcp." ] . \
:set Zone ($Identity . "." . $Zone); [ $IfThenElse ($HostNameInZone = true) ($Identity . ".") ] . $Domain);
}
:if ($PrefixInZone = true) do={
:set Zone ("dhcp." . $Zone);
}
:local Ttl 5m; :local Ttl 5m;
:local CommentPrefix "managed by dhcp-to-dns for "; :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={ :foreach Lease in=[ / ip dhcp-server lease find where dynamic=yes status=bound ] do={
:local LeaseVal [ / ip dhcp-server lease get $Lease ]; :local LeaseVal [ / ip dhcp-server lease get $Lease ];
:local Comment ($CommentPrefix . $LeaseVal->"mac-address"); :local Comment ($CommentPrefix . $LeaseVal->"mac-address");
:local HostName [ $CharacterReplace ($LeaseVal->"host-name") " " "" ]; :local HostName [ $IfThenElse ([ :len ($LeaseVal->"host-name") ] = 0) \
:if ($HostName = "") do={ [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ] \
:set HostName [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ]; [ $CharacterReplace ($LeaseVal->"host-name") " " "" ] ];
}
:local Fqdn ($HostName . "." . $Zone); :local Fqdn ($HostName . "." . $Zone);
:local DnsRecord [ / ip dns static find where name=$Fqdn ]; :local DnsRecord [ / ip dns static find where name=$Fqdn ];