From c7ac488520fda2848a3c1f45ba35b99448b90565 Mon Sep 17 00:00:00 2001 From: Christopher Huhn Date: Wed, 31 Oct 2018 16:04:57 +0100 Subject: [PATCH 1/4] Also select NS records from child domains --- build_bind.inc.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/build_bind.inc.php b/build_bind.inc.php index e82ce0c..98bbdb8 100644 --- a/build_bind.inc.php +++ b/build_bind.inc.php @@ -347,9 +347,14 @@ 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']} + OR ( dom.parent_id = {$domain['id']} + AND dns.type = 'NS' + ) + ) ORDER BY type"; From 8f5e9258f1c865b83a5644fcab0e21c334275487 Mon Sep 17 00:00:00 2001 From: Christopher Huhn Date: Thu, 1 Nov 2018 14:13:30 +0100 Subject: [PATCH 2/4] Also SELECT child domains and glue records and handle alien domains in A and NS entries --- build_bind.inc.php | 49 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/build_bind.inc.php b/build_bind.inc.php index 98bbdb8..5936f91 100644 --- a/build_bind.inc.php +++ b/build_bind.inc.php @@ -350,9 +350,18 @@ function build_bind_domain($options="") { SELECT dns.* FROM dns, domains dom WHERE dns.domain_id = dom.id - AND ( domain_id = {$domain['id']} - OR ( dom.parent_id = {$domain['id']} - AND dns.type = 'NS' + 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"; @@ -424,7 +433,20 @@ 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 { + 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']); } @@ -484,7 +506,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') { From 095ae6131a5567be3a482844177ab20abe75bb98 Mon Sep 17 00:00:00 2001 From: Christopher Huhn Date: Thu, 1 Nov 2018 14:59:36 +0100 Subject: [PATCH 3/4] For domains with parent_id the fqdn has to be used here, otherwise name == fqdn --- build_bind.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_bind.inc.php b/build_bind.inc.php index 5936f91..912a317 100644 --- a/build_bind.inc.php +++ b/build_bind.inc.php @@ -542,7 +542,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']); } From cb623047d3e2aef4ef4ad700ef3e4d0d45d73e80 Mon Sep 17 00:00:00 2001 From: Christopher Huhn Date: Thu, 1 Nov 2018 15:57:43 +0100 Subject: [PATCH 4/4] Avoid adding name server A records to reverse zones --- build_bind.inc.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build_bind.inc.php b/build_bind.inc.php index 912a317..6d156d5 100644 --- a/build_bind.inc.php +++ b/build_bind.inc.php @@ -437,6 +437,11 @@ function build_bind_domain($options="") { 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) {