From 2444158bbb7cff67e516f21cb806851640cb2495 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Fri, 12 Aug 2016 09:45:26 +0200 Subject: [PATCH] do not truncate pdns tables, instead just remove entries that are related to froxlor-managed domains; this allows the admin to create custom zones/records in pdns if needed/wanted Signed-off-by: Michael Kaufmann (d00p) --- scripts/jobs/cron_tasks.inc.dns.20.pdns.php | 26 +++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/jobs/cron_tasks.inc.dns.20.pdns.php b/scripts/jobs/cron_tasks.inc.dns.20.pdns.php index 24b128d1..fac7a736 100644 --- a/scripts/jobs/cron_tasks.inc.dns.20.pdns.php +++ b/scripts/jobs/cron_tasks.inc.dns.20.pdns.php @@ -29,11 +29,11 @@ class pdns extends DnsBase // connect to db $this->_connectToPdnsDb(); - // clean up - $this->_clearZoneTables(); - $domains = $this->getDomainList(); + // clean up + $this->_clearZoneTables($domains); + if (empty($domains)) { $this->_logger->logAction(CRON_ACTION, LOG_INFO, 'No domains found for nameserver-config, skipping...'); return; @@ -96,13 +96,25 @@ class pdns extends DnsBase } } - private function _clearZoneTables() + private function _clearZoneTables($domains = null) { $this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Cleaning dns zone entries from database'); - $this->pdns_db->query("TRUNCATE TABLE `records`"); - $this->pdns_db->query("TRUNCATE TABLE `domains`"); - $this->pdns_db->query("TRUNCATE TABLE `domainmetadata`"); + $pdns_domains_stmt = $this->pdns_db->prepare("SELECT `id`, `name` FROM `domains` WHERE `name` = :domain"); + + $del_rec_stmt = $this->pdns_db->prepare("DELETE FROM `records` WHERE `domain_id` = :did"); + $del_meta_stmt = $this->pdns_db->prepare("DELETE FROM `domainmetadata` WHERE `domain_id` = :did"); + $del_dom_stmt = $this->pdns_db->prepare("DELETE FROM `domains` WHERE `id` = :did"); + + foreach ($domains as $domain) + { + $pdns_domains_stmt->execute(array('domain' => $domain['domain'])); + $pdns_domain = $pdns_domains_stmt->fetch(\PDO::FETCH_ASSOC); + + $del_rec_stmt->execute(array('did' => $pdns_domain['id'])); + $del_meta_stmt->execute(array('did' => $pdns_domain['id'])); + $del_dom_stmt->execute(array('did' => $pdns_domain['id'])); + } } private function _insertZone($domainname, $serial = 0)