From a519779703195b8f16b86295ca047b01c8c8eebb Mon Sep 17 00:00:00 2001 From: mbfgit Date: Mon, 3 Feb 2014 01:17:25 +0000 Subject: Update reverse zone for dhcp static map Addresses Bug #3323, add PTR records for reverse zone. --- config/bind/bind.inc | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'config/bind') diff --git a/config/bind/bind.inc b/config/bind/bind.inc index ff3728fb..40d626db 100644 --- a/config/bind/bind.inc +++ b/config/bind/bind.inc @@ -438,12 +438,33 @@ EOD; $zone_conf .= "$hostname \t IN $hosttype $hostvalue \t$hostdst\n"; } - if (($zone[regdhcpstatic] == 'on') && is_array($config['dhcpd'])) { - foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) + if (($zone[regdhcpstatic] == 'on') && is_array($config['dhcpd'])) { + foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable'])) foreach ($dhcpifconf['staticmap'] as $host) if ($host['ipaddr'] && $host['hostname']) { - $zone_conf .= "{$host['hostname']}\tIN A\t{$host['ipaddr']}\n"; + if($zonereverso == "on") { + $hostdomain = $dhcpifconf['domain']; + if(strlen($hostdomain) == 0) { + $hostdomain = $config['system']['domain']; + } + if(strlen($hostdomain) != 0) { + $hostdomain .= '.'; + } + $zoneparts = array_reverse(explode('.',$zonename)); + $addressparts = explode('.',$host['ipaddr']); + $addressstart = 0; + while($addressstart < count($zoneparts) && $addressstart < count($addressparts) && $zoneparts[$addressstart] == $addressparts[$addressstart]) { + $addressstart++; + } + $shortaddress=''; + for($addresspointer = count($addressparts)-1; $addresspointer >= $addressstart; $addresspointer--) { + $shortaddress .= (strlen($shortaddress) > 0 ? '.' : '') . $addressparts[$addresspointer]; + } + $zone_conf .= "{$shortaddress}\tIN PTR\t{$host['hostname']}.{$hostdomain}\n"; + } else { + $zone_conf .= "{$host['hostname']}\tIN A\t{$host['ipaddr']}\n"; + } } } if ($zone['customzonerecords']!=""){ -- cgit v1.2.3