diff --git a/build_bind.inc.php b/build_bind.inc.php index e82ce0c..6d156d5 100644 --- a/build_bind.inc.php +++ b/build_bind.inc.php @@ -347,9 +347,23 @@ function build_bind_domain($options="") { // loop through records and display them $q=" - SELECT * - FROM dns - WHERE domain_id = {$domain['id']} + SELECT dns.* + FROM dns, domains dom + WHERE dns.domain_id = dom.id + AND ( domain_id = {$domain['id']} -- direct zone entries + OR ( -- NS records of subdomains: + dom.parent_id = {$domain['id']} AND dns.type = 'NS' + ) OR ( + -- A records for out of zone DNS servers: + dns.id IN ( + SELECT dns_id + FROM dns, domains dom + WHERE dns.domain_id = dom.id + AND dom.parent_id = {$domain['id']} + AND dns.type = 'NS' + ) AND domain_id <> {$domain['id']} + ) + ) ORDER BY type"; @@ -419,7 +433,25 @@ function build_bind_domain($options="") { // Determine A record type if it is IPv6 $dnsrecord['type'] = (strpos($interface['ip_addr_text'],':') ? 'AAAA' : 'A'); - $fqdn = $dnsrecord['name'].$domain['fqdn']; + // check if this is an A record for a child domain: + if ($dns_record['domain_id'] == $domain['id']){ + $fqdn = $dnsrecord['name'].$domain['fqdn']; + } else { + // if this is a reverse zone we don't need glue records - skip + if (preg_match('/.(in-addr|ip6).arpa$/', $domain['fqdn'])) { + continue; + } + + list($status, $rows, $other_domain) = + ona_get_domain_record(array('id' => $dnsrecord['domain_id'])); + if ($status or !$rows) { + printmsg("ERROR => Unable to find domain record!",3); + $self['error'] = "ERROR => Unable to find domain record!"; + return(array(5, $self['error'] . "\n")); + } + $fqdn = $dnsrecord['name'].$other_domain['fqdn']; + } + $text .= sprintf("%-50s %-8s IN %-8s %-30s %s\n" ,$fqdn.'.',$dnsrecord['ttl'],$dnsrecord['type'],$interface['ip_addr_text'],$dnsrecord['notes']); } @@ -479,7 +511,24 @@ function build_bind_domain($options="") { // Get the name info that the cname points to list($status, $rows, $ns) = ona_get_dns_record(array('id' => $dnsrecord['dns_id']), ''); - $text .= sprintf("%-50s %-8s IN %-8s %s.%-30s %s\n" ,$domain['fqdn'].'.',$dnsrecord['ttl'],$dnsrecord['type'],$ns['name'],$ns['domain_fqdn'].'.',$dnsrecord['notes']); + // check if this is an NS record for a child domain: + if ($dnsrecord['domain_id'] == $domain['id']){ + $domain_name = $domain['fqdn']; + } else { + list($status, $rows, $other_domain) = + ona_get_domain_record(array('id' => $dnsrecord['domain_id'])); + if ($status or !$rows) { + printmsg("ERROR => Unable to find domain record!",3); + $self['error'] = "ERROR => Unable to find domain record!"; + return(array(5, $self['error'] . "\n")); + } + $domain_name = $other_domain['fqdn']; + } + + $text .= sprintf("%-50s %-8s IN %-8s %s.%-30s %s\n", + $domain_name.'.', $dnsrecord['ttl'], + $dnsrecord['type'], $ns['name'], + $ns['domain_fqdn'].'.', $dnsrecord['notes']); } if ($dnsrecord['type'] == 'MX') { @@ -498,7 +547,7 @@ function build_bind_domain($options="") { $name = $dnsrecord['name'].$domain['fqdn']; } else { - $name = $domain['name']; + $name = $domain['fqdn']; } $text .= sprintf("%-50s %-8s IN %s %-5s %s.%-30s %s\n" ,$name.'.',$dnsrecord['ttl'],$dnsrecord['type'],$dnsrecord['mx_preference'],$mx['name'],$mx['domain_fqdn'].'.',$dnsrecord['notes']); }