From 1ce5cf6c0010d22bb02f40d014eb9688bc2a9875 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Tue, 17 May 2016 09:12:39 +0200 Subject: [PATCH] various fixes for dns with froxlor-hostname Signed-off-by: Michael Kaufmann (d00p) --- .../dns/function.createDomainZone.php | 107 ++++++++++-------- scripts/classes/class.DnsBase.php | 8 +- scripts/jobs/cron_tasks.inc.dns.10.bind.php | 2 +- scripts/jobs/cron_tasks.inc.dns.20.pdns.php | 2 +- 4 files changed, 68 insertions(+), 51 deletions(-) diff --git a/lib/functions/dns/function.createDomainZone.php b/lib/functions/dns/function.createDomainZone.php index 6d271c02..8a42efb8 100644 --- a/lib/functions/dns/function.createDomainZone.php +++ b/lib/functions/dns/function.createDomainZone.php @@ -16,22 +16,33 @@ */ function createDomainZone($domain_id, $froxlorhostname = false) { - // get domain-name - $dom_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAINS . "` WHERE id = :did"); - $domain = Database::pexecute_first($dom_stmt, array( - 'did' => $domain_id - )); + if (!$froxlorhostname) + { + // get domain-name + $dom_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAINS . "` WHERE id = :did"); + $domain = Database::pexecute_first($dom_stmt, array( + 'did' => $domain_id + )); + } + else + { + $domain = $domain_id; + } if ($domain['isbinddomain'] != '1') { return; } - // select all entries - $sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC"); - Database::pexecute($sel_stmt, array( - 'did' => $domain_id - )); - $dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC); + $dom_entries = array(); + if (!$froxlorhostname) + { + // select all entries + $sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC"); + Database::pexecute($sel_stmt, array( + 'did' => $domain_id + )); + $dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC); + } // check for required records $required_entries = array(); @@ -52,43 +63,46 @@ function createDomainZone($domain_id, $froxlorhostname = false) addRequiredEntry('www', 'AAAA', $required_entries); } - // additional required records for subdomains - $subdomains_stmt = Database::prepare(" - SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` - WHERE `parentdomainid` = :domainid - "); - Database::pexecute($subdomains_stmt, array( - 'domainid' => $domain_id - )); + if (!$froxlorhostname) + { + // additional required records for subdomains + $subdomains_stmt = Database::prepare(" + SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` + WHERE `parentdomainid` = :domainid + "); + Database::pexecute($subdomains_stmt, array( + 'domainid' => $domain_id + )); - while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) { - // Listing domains is enough as there currently is no support for choosing - // different ips for a subdomain => use same IPs as toplevel - addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); - addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); + while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) { + // Listing domains is enough as there currently is no support for choosing + // different ips for a subdomain => use same IPs as toplevel + addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); + addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); - // Check whether to add a www.-prefix - if ($domain['iswildcarddomain'] == '1') { - addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); - addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); - } elseif ($domain['wwwserveralias'] == '1') { - addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); - addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); + // Check whether to add a www.-prefix + if ($domain['iswildcarddomain'] == '1') { + addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); + addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); + } elseif ($domain['wwwserveralias'] == '1') { + addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); + addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); + } } - } - // additional required records for main-but-subdomain-to - $mainbutsub_stmt = Database::prepare(" - SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` - WHERE `ismainbutsubto` = :domainid - "); - Database::pexecute($mainbutsub_stmt, array( - 'domainid' => $domain_id - )); + // additional required records for main-but-subdomain-to + $mainbutsub_stmt = Database::prepare(" + SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` + WHERE `ismainbutsubto` = :domainid + "); + Database::pexecute($mainbutsub_stmt, array( + 'domainid' => $domain_id + )); - while ($mainbutsubtodomain = $mainbutsub_stmt->fetch(PDO::FETCH_ASSOC)) { - // Add NS entry for subdomain-records of "main-but-subdomain-to"-domains, they get their own Zone - addRequiredEntry(str_replace('.' . $domain['domain'], '', $mainbutsubtodomain['domain']), 'NS', $required_entries); + while ($mainbutsubtodomain = $mainbutsub_stmt->fetch(PDO::FETCH_ASSOC)) { + // Add NS entry for subdomain-records of "main-but-subdomain-to"-domains, they get their own Zone + addRequiredEntry(str_replace('.' . $domain['domain'], '', $mainbutsubtodomain['domain']), 'NS', $required_entries); + } } // additional required records for SPF and DKIM if activated @@ -136,6 +150,7 @@ function createDomainZone($domain_id, $froxlorhostname = false) $result_ip_stmt = Database::prepare(" SELECT `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "` GROUP BY `ip` "); + Database::pexecute($result_ip_stmt); } else { $result_ip_stmt = Database::prepare(" SELECT `p`.`ip` AS `ip` @@ -143,10 +158,10 @@ function createDomainZone($domain_id, $froxlorhostname = false) WHERE `di`.`id_domain` = :domainid AND `p`.`id` = `di`.`id_ipandports` GROUP BY `p`.`ip`; "); + Database::pexecute($result_ip_stmt, array( + 'domainid' => $domain_id + )); } - Database::pexecute($result_ip_stmt, array( - 'domainid' => $domain_id - )); $all_ips = $result_ip_stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($all_ips as $ip) { diff --git a/scripts/classes/class.DnsBase.php b/scripts/classes/class.DnsBase.php index 11e06996..ba7a8506 100644 --- a/scripts/classes/class.DnsBase.php +++ b/scripts/classes/class.DnsBase.php @@ -1,11 +1,13 @@ 'none', 'domain' => Settings::Get('system.hostname'), + 'isbinddomain' => '1', 'isemaildomain' => Settings::Get('system.dns_createmailentry'), 'customerid' => 'none', 'loginname' => 'froxlor.panel', @@ -181,5 +184,4 @@ abstract class DnsBase { $this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Dkim-milter reloaded'); } } - -} \ No newline at end of file +} diff --git a/scripts/jobs/cron_tasks.inc.dns.10.bind.php b/scripts/jobs/cron_tasks.inc.dns.10.bind.php index 3e9cff1d..89120e98 100644 --- a/scripts/jobs/cron_tasks.inc.dns.10.bind.php +++ b/scripts/jobs/cron_tasks.inc.dns.10.bind.php @@ -46,7 +46,7 @@ class bind extends DnsBase } // create zone-file $this->_logger->logAction(CRON_ACTION, LOG_DEBUG, 'Generating dns zone for ' . $domain['domain']); - $zone = createDomainZone($domain['id'], $isFroxlorHostname); + $zone = createDomainZone(($domain['id'] == 'none') ? $domain : $domain['id'], $isFroxlorHostname); $zonefile = (string)$zone; $domain['zonefile'] = 'domains/' . $domain['domain'] . '.zone'; $zonefile_name = makeCorrectFile(Settings::Get('system.bindconf_directory') . '/' . $domain['zonefile']); diff --git a/scripts/jobs/cron_tasks.inc.dns.20.pdns.php b/scripts/jobs/cron_tasks.inc.dns.20.pdns.php index 61b11ec1..8352c095 100644 --- a/scripts/jobs/cron_tasks.inc.dns.20.pdns.php +++ b/scripts/jobs/cron_tasks.inc.dns.20.pdns.php @@ -44,7 +44,7 @@ class pdns extends DnsBase } // create zone-file $this->_logger->logAction(CRON_ACTION, LOG_DEBUG, 'Generating dns zone for ' . $domain['domain']); - $zone = createDomainZone($domain['id'], $isFroxlorHostname); + $zone = createDomainZone(($domain['id'] == 'none') ? $domain : $domain['id'], $isFroxlorHostname); $dom_id = $this->_insertZone($zone->origin, $zone->serial); $this->_insertRecords($dom_id, $zone->records);