various fixes for dns with froxlor-hostname

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-05-17 09:12:39 +02:00
parent f7441df895
commit 1ce5cf6c00
4 changed files with 68 additions and 51 deletions

View File

@@ -16,22 +16,33 @@
*/ */
function createDomainZone($domain_id, $froxlorhostname = false) function createDomainZone($domain_id, $froxlorhostname = false)
{ {
// get domain-name if (!$froxlorhostname)
$dom_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAINS . "` WHERE id = :did"); {
$domain = Database::pexecute_first($dom_stmt, array( // get domain-name
'did' => $domain_id $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') { if ($domain['isbinddomain'] != '1') {
return; return;
} }
// select all entries $dom_entries = array();
$sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC"); if (!$froxlorhostname)
Database::pexecute($sel_stmt, array( {
'did' => $domain_id // select all entries
)); $sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC");
$dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC); Database::pexecute($sel_stmt, array(
'did' => $domain_id
));
$dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC);
}
// check for required records // check for required records
$required_entries = array(); $required_entries = array();
@@ -52,43 +63,46 @@ function createDomainZone($domain_id, $froxlorhostname = false)
addRequiredEntry('www', 'AAAA', $required_entries); addRequiredEntry('www', 'AAAA', $required_entries);
} }
// additional required records for subdomains if (!$froxlorhostname)
$subdomains_stmt = Database::prepare(" {
SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` // additional required records for subdomains
WHERE `parentdomainid` = :domainid $subdomains_stmt = Database::prepare("
"); SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "`
Database::pexecute($subdomains_stmt, array( WHERE `parentdomainid` = :domainid
'domainid' => $domain_id ");
)); Database::pexecute($subdomains_stmt, array(
'domainid' => $domain_id
));
while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) { while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) {
// Listing domains is enough as there currently is no support for choosing // Listing domains is enough as there currently is no support for choosing
// different ips for a subdomain => use same IPs as toplevel // 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']), 'A', $required_entries);
addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
// Check whether to add a www.-prefix // Check whether to add a www.-prefix
if ($domain['iswildcarddomain'] == '1') { if ($domain['iswildcarddomain'] == '1') {
addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
} elseif ($domain['wwwserveralias'] == '1') { } elseif ($domain['wwwserveralias'] == '1') {
addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries); addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries); addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
}
} }
}
// additional required records for main-but-subdomain-to // additional required records for main-but-subdomain-to
$mainbutsub_stmt = Database::prepare(" $mainbutsub_stmt = Database::prepare("
SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `ismainbutsubto` = :domainid WHERE `ismainbutsubto` = :domainid
"); ");
Database::pexecute($mainbutsub_stmt, array( Database::pexecute($mainbutsub_stmt, array(
'domainid' => $domain_id 'domainid' => $domain_id
)); ));
while ($mainbutsubtodomain = $mainbutsub_stmt->fetch(PDO::FETCH_ASSOC)) { 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 // 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); addRequiredEntry(str_replace('.' . $domain['domain'], '', $mainbutsubtodomain['domain']), 'NS', $required_entries);
}
} }
// additional required records for SPF and DKIM if activated // additional required records for SPF and DKIM if activated
@@ -136,6 +150,7 @@ function createDomainZone($domain_id, $froxlorhostname = false)
$result_ip_stmt = Database::prepare(" $result_ip_stmt = Database::prepare("
SELECT `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "` GROUP BY `ip` SELECT `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "` GROUP BY `ip`
"); ");
Database::pexecute($result_ip_stmt);
} else { } else {
$result_ip_stmt = Database::prepare(" $result_ip_stmt = Database::prepare("
SELECT `p`.`ip` AS `ip` 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` WHERE `di`.`id_domain` = :domainid AND `p`.`id` = `di`.`id_ipandports`
GROUP BY `p`.`ip`; 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); $all_ips = $result_ip_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($all_ips as $ip) { foreach ($all_ips as $ip) {

View File

@@ -1,11 +1,13 @@
<?php <?php
/*** /***
* Class DnsBase * Class DnsBase
* *
* Base class for all DNS server configs * Base class for all DNS server configs
* *
*/ */
abstract class DnsBase { abstract class DnsBase
{
protected $_logger = false; protected $_logger = false;
@@ -81,6 +83,7 @@ abstract class DnsBase {
$hostname_arr = array( $hostname_arr = array(
'id' => 'none', 'id' => 'none',
'domain' => Settings::Get('system.hostname'), 'domain' => Settings::Get('system.hostname'),
'isbinddomain' => '1',
'isemaildomain' => Settings::Get('system.dns_createmailentry'), 'isemaildomain' => Settings::Get('system.dns_createmailentry'),
'customerid' => 'none', 'customerid' => 'none',
'loginname' => 'froxlor.panel', 'loginname' => 'froxlor.panel',
@@ -181,5 +184,4 @@ abstract class DnsBase {
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Dkim-milter reloaded'); $this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Dkim-milter reloaded');
} }
} }
} }

View File

@@ -46,7 +46,7 @@ class bind extends DnsBase
} }
// create zone-file // create zone-file
$this->_logger->logAction(CRON_ACTION, LOG_DEBUG, 'Generating dns zone for ' . $domain['domain']); $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; $zonefile = (string)$zone;
$domain['zonefile'] = 'domains/' . $domain['domain'] . '.zone'; $domain['zonefile'] = 'domains/' . $domain['domain'] . '.zone';
$zonefile_name = makeCorrectFile(Settings::Get('system.bindconf_directory') . '/' . $domain['zonefile']); $zonefile_name = makeCorrectFile(Settings::Get('system.bindconf_directory') . '/' . $domain['zonefile']);

View File

@@ -44,7 +44,7 @@ class pdns extends DnsBase
} }
// create zone-file // create zone-file
$this->_logger->logAction(CRON_ACTION, LOG_DEBUG, 'Generating dns zone for ' . $domain['domain']); $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); $dom_id = $this->_insertZone($zone->origin, $zone->serial);
$this->_insertRecords($dom_id, $zone->records); $this->_insertRecords($dom_id, $zone->records);