Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for subdomain delegation #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions build_bind.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand Down Expand Up @@ -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']);
}

Expand Down Expand Up @@ -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') {
Expand All @@ -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']);
}
Expand Down