remove domain from pdns database if removed or updated so nameserver is disabled (remove) or update of db triggered when isemaildomain option is disabled, fixes #581
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -1038,9 +1038,13 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
$speciallogfile = $result['speciallogfile'];
|
||||
}
|
||||
|
||||
if ($isbinddomain != $result['isbinddomain'] || $zonefile != $result['zonefile'] || $dkim != $result['dkim']) {
|
||||
if ($isbinddomain != $result['isbinddomain'] || $zonefile != $result['zonefile'] || $dkim != $result['dkim'] || $isemaildomain != $result['isemaildomain']) {
|
||||
inserttask('4');
|
||||
}
|
||||
// check whether nameserver has been disabled, #581
|
||||
if ($isbinddomain != $result['isbinddomain'] && $isbinddomain == 0) {
|
||||
inserttask('11', $result['domain']);
|
||||
}
|
||||
|
||||
if ($isemaildomain == '0' && $result['isemaildomain'] == '1') {
|
||||
$del_stmt = Database::prepare("
|
||||
@@ -1499,6 +1503,9 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
|
||||
triggerLetsEncryptCSRForAliasDestinationDomain($result['aliasdomain'], $this->logger());
|
||||
|
||||
// remove domains DNS from powerDNS if used, #581
|
||||
inserttask('11', $result['domain']);
|
||||
|
||||
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] deleted domain/subdomains (#" . $result['id'] . ")");
|
||||
updateCounters();
|
||||
inserttask('1');
|
||||
|
||||
127
lib/classes/dns/class.PowerDNS.php
Normal file
127
lib/classes/dns/class.PowerDNS.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2016 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2016-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
*
|
||||
*/
|
||||
class PowerDNS
|
||||
{
|
||||
|
||||
private static $pdns_db = null;
|
||||
|
||||
private static function connectToPdnsDb()
|
||||
{
|
||||
// get froxlor pdns config
|
||||
$cf = Settings::Get('system.bindconf_directory') . '/froxlor/pdns_froxlor.conf';
|
||||
$config = makeCorrectFile($cf);
|
||||
|
||||
if (! file_exists($config)) {
|
||||
die('PowerDNS configuration file (' . $config . ') not found. Did you go through the configuration templates?' . PHP_EOL);
|
||||
}
|
||||
$lines = file($config);
|
||||
$mysql_data = array();
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (strtolower(substr($line, 0, 6)) == 'gmysql') {
|
||||
$namevalue = explode("=", $line);
|
||||
$mysql_data[$namevalue[0]] = $namevalue[1];
|
||||
}
|
||||
}
|
||||
|
||||
// build up connection string
|
||||
$driver = 'mysql';
|
||||
$dsn = $driver . ":";
|
||||
$options = array(
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET names utf8,sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'
|
||||
);
|
||||
$attributes = array(
|
||||
'ATTR_ERRMODE' => 'ERRMODE_EXCEPTION'
|
||||
);
|
||||
$dbconf = array();
|
||||
|
||||
$dbconf["dsn"] = array(
|
||||
'dbname' => $mysql_data["gmysql-dbname"],
|
||||
'charset' => 'utf8'
|
||||
);
|
||||
|
||||
if (isset($mysql_data['gmysql-socket']) && ! empty($mysql_data['gmysql-socket'])) {
|
||||
$dbconf["dsn"]['unix_socket'] = makeCorrectFile($mysql_data['gmysql-socket']);
|
||||
} else {
|
||||
$dbconf["dsn"]['host'] = $mysql_data['gmysql-host'];
|
||||
$dbconf["dsn"]['port'] = $mysql_data['gmysql-port'];
|
||||
}
|
||||
|
||||
// add options to dsn-string
|
||||
foreach ($dbconf["dsn"] as $k => $v) {
|
||||
$dsn .= $k . "=" . $v . ";";
|
||||
}
|
||||
|
||||
// clean up
|
||||
unset($dbconf);
|
||||
|
||||
// try to connect
|
||||
try {
|
||||
self::$pdns_db = new PDO($dsn, $mysql_data['gmysql-user'], $mysql_data['gmysql-password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
// set attributes
|
||||
foreach ($attributes as $k => $v) {
|
||||
self::$pdns_db->setAttribute(constant("PDO::" . $k), constant("PDO::" . $v));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get pdo database connection to powerdns database
|
||||
*
|
||||
* @return PDO
|
||||
*/
|
||||
public static function getDB()
|
||||
{
|
||||
if (! isset(self::$pdns_db) || (self::$pdns_db instanceof PDO) == false) {
|
||||
self::connectToPdnsDb();
|
||||
}
|
||||
return self::$pdns_db;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove all records and entries of a given domain
|
||||
*
|
||||
* @param array $domain
|
||||
*/
|
||||
public static function cleanDomainZone($domain = null)
|
||||
{
|
||||
if (is_array($domain) && isset($domain['domain'])) {
|
||||
$pdns_domains_stmt = self::getDB()->prepare("SELECT `id`, `name` FROM `domains` WHERE `name` = :domain");
|
||||
$del_rec_stmt = self::getDB()->prepare("DELETE FROM `records` WHERE `domain_id` = :did");
|
||||
$del_meta_stmt = self::getDB()->prepare("DELETE FROM `domainmetadata` WHERE `domain_id` = :did");
|
||||
$del_dom_stmt = self::getDB()->prepare("DELETE FROM `domains` WHERE `id` = :did");
|
||||
|
||||
$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']
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,27 +20,26 @@
|
||||
/**
|
||||
* Inserts a task into the PANEL_TASKS-Table
|
||||
*
|
||||
* @param int Type of task
|
||||
* @param string Parameter 1
|
||||
* @param string Parameter 2
|
||||
* @param string Parameter 3
|
||||
* @param
|
||||
* int Type of task
|
||||
* @param
|
||||
* string Parameter 1
|
||||
* @param
|
||||
* string Parameter 2
|
||||
* @param
|
||||
* string Parameter 3
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
*/
|
||||
function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '') {
|
||||
function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '')
|
||||
{
|
||||
|
||||
// prepare the insert-statement
|
||||
$ins_stmt = Database::prepare("
|
||||
INSERT INTO `" . TABLE_PANEL_TASKS . "` SET `type` = :type, `data` = :data
|
||||
");
|
||||
|
||||
if ($type == '1'
|
||||
|| $type == '3'
|
||||
|| $type == '4'
|
||||
|| $type == '5'
|
||||
|| $type == '10'
|
||||
|| $type == '99'
|
||||
) {
|
||||
if ($type == '1' || $type == '3' || $type == '4' || $type == '5' || $type == '10' || $type == '99') {
|
||||
// 4 = bind -> if bind disabled -> no task
|
||||
if ($type == '4' && Settings::Get('system.bind_enable') == '0') {
|
||||
return;
|
||||
@@ -54,57 +53,65 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|
||||
$del_stmt = Database::prepare("
|
||||
DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = :type
|
||||
");
|
||||
Database::pexecute($del_stmt, array('type' => $type));
|
||||
Database::pexecute($del_stmt, array(
|
||||
'type' => $type
|
||||
));
|
||||
|
||||
// insert the new task
|
||||
Database::pexecute($ins_stmt, array('type' => $type, 'data' => ''));
|
||||
|
||||
} elseif ($type == '2'
|
||||
&& $param1 != ''
|
||||
&& $param2 != ''
|
||||
&& $param3 != ''
|
||||
&& ($param4 == 0 || $param4 == 1)
|
||||
) {
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => $type,
|
||||
'data' => ''
|
||||
));
|
||||
} elseif ($type == '2' && $param1 != '' && $param2 != '' && $param3 != '' && ($param4 == 0 || $param4 == 1)) {
|
||||
$data = array();
|
||||
$data['loginname'] = $param1;
|
||||
$data['uid'] = $param2;
|
||||
$data['gid'] = $param3;
|
||||
$data['store_defaultindex'] = $param4;
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array('type' => '2', 'data' => $data));
|
||||
|
||||
} elseif ($type == '6'
|
||||
&& $param1 != ''
|
||||
) {
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => '2',
|
||||
'data' => $data
|
||||
));
|
||||
} elseif ($type == '6' && $param1 != '') {
|
||||
$data = array();
|
||||
$data['loginname'] = $param1;
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array('type' => '6', 'data' => $data));
|
||||
|
||||
} elseif ($type == '7'
|
||||
&& $param1 != ''
|
||||
&& $param2 != ''
|
||||
) {
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => '6',
|
||||
'data' => $data
|
||||
));
|
||||
} elseif ($type == '7' && $param1 != '' && $param2 != '') {
|
||||
$data = array();
|
||||
$data['loginname'] = $param1;
|
||||
$data['email'] = $param2;
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array('type' => '7', 'data' => $data));
|
||||
|
||||
} elseif ($type == '8'
|
||||
&& $param1 != ''
|
||||
&& $param2 != ''
|
||||
) {
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => '7',
|
||||
'data' => $data
|
||||
));
|
||||
} elseif ($type == '8' && $param1 != '' && $param2 != '') {
|
||||
$data = array();
|
||||
$data['loginname'] = $param1;
|
||||
$data['homedir'] = $param2;
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array('type' => '8', 'data' => $data));
|
||||
|
||||
} elseif ($type == '20'
|
||||
&& is_array($param1)
|
||||
) {
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => '8',
|
||||
'data' => $data
|
||||
));
|
||||
} elseif ($type == '11' && $param1 != '') {
|
||||
$data = array();
|
||||
$data['domain'] = $param1;
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => '11',
|
||||
'data' => $data
|
||||
));
|
||||
} elseif ($type == '20' && is_array($param1)) {
|
||||
$data = json_encode($param1);
|
||||
Database::pexecute($ins_stmt, array('type' => '20', 'data' => $data));
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'type' => '20',
|
||||
'data' => $data
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user