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

@@ -15,23 +15,34 @@
* *
*/ */
function createDomainZone($domain_id, $froxlorhostname = false) function createDomainZone($domain_id, $froxlorhostname = false)
{
if (!$froxlorhostname)
{ {
// get domain-name // get domain-name
$dom_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAINS . "` WHERE id = :did"); $dom_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAINS . "` WHERE id = :did");
$domain = Database::pexecute_first($dom_stmt, array( $domain = Database::pexecute_first($dom_stmt, array(
'did' => $domain_id 'did' => $domain_id
)); ));
}
else
{
$domain = $domain_id;
}
if ($domain['isbinddomain'] != '1') { if ($domain['isbinddomain'] != '1') {
return; return;
} }
$dom_entries = array();
if (!$froxlorhostname)
{
// select all entries // select all entries
$sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC"); $sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_DOMAIN_DNS . "` WHERE domain_id = :did ORDER BY id ASC");
Database::pexecute($sel_stmt, array( Database::pexecute($sel_stmt, array(
'did' => $domain_id 'did' => $domain_id
)); ));
$dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC); $dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC);
}
// check for required records // check for required records
$required_entries = array(); $required_entries = array();
@@ -52,6 +63,8 @@ function createDomainZone($domain_id, $froxlorhostname = false)
addRequiredEntry('www', 'AAAA', $required_entries); addRequiredEntry('www', 'AAAA', $required_entries);
} }
if (!$froxlorhostname)
{
// additional required records for subdomains // additional required records for subdomains
$subdomains_stmt = Database::prepare(" $subdomains_stmt = Database::prepare("
SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "`
@@ -90,6 +103,7 @@ function createDomainZone($domain_id, $froxlorhostname = false)
// 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
if ($domain['isemaildomain'] == '1') { if ($domain['isemaildomain'] == '1') {
@@ -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( Database::pexecute($result_ip_stmt, array(
'domainid' => $domain_id '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);