Private GIT

Skip to content
Snippets Groups Projects
Commit 94415361 authored by Jelloul Ayeb's avatar Jelloul Ayeb
Browse files

update soa serials of affected domains when deleting records

parent 958602f8
No related branches found
No related tags found
No related merge requests found
...@@ -686,6 +686,27 @@ class PowerDNS extends Common_functions { ...@@ -686,6 +686,27 @@ class PowerDNS extends Common_functions {
return !is_null($record) ? $record : false; return !is_null($record) ? $record : false;
} }
/**
* Searches domains referencing a hostname or ip
*
* @access public
* @param mixed $hostname
* @param mixed $ip
* @return array|boolean
*/
public function search_domains_by_hostname_or_ip ($hostname, $ip) {
// query
$query = "select DISTINCT(`domain_id`) from `records` where `name` = ? or `content` = ? and `type` != 'NS' and `type` != 'SOA';";
// fetch
try { $records = $this->Database_pdns->getObjectsQuery($query, array($hostname, $ip)); }
catch (Exception $e) {
$this->Result->show("danger", _("Error: ").$e->getMessage());
return false;
}
# result
return sizeof($records)>0 ? $records : false;
}
/** /**
* Searches records for specific domainid for type and name values * Searches records for specific domainid for type and name values
* *
...@@ -933,6 +954,9 @@ class PowerDNS extends Common_functions { ...@@ -933,6 +954,9 @@ class PowerDNS extends Common_functions {
* @return void * @return void
*/ */
public function pdns_remove_ip_and_hostname_records ($hostname, $ip) { public function pdns_remove_ip_and_hostname_records ($hostname, $ip) {
// find out which domains are going to need an soa serial update
$domains_records = $this->search_domains_by_hostname_or_ip($hostname, $ip);
// set query // set query
$query = "delete from `records` where (`name` = ? or `content` = ?) and `type` != 'NS' and `type` != 'SOA';"; $query = "delete from `records` where (`name` = ? or `content` = ?) and `type` != 'NS' and `type` != 'SOA';";
...@@ -942,6 +966,14 @@ class PowerDNS extends Common_functions { ...@@ -942,6 +966,14 @@ class PowerDNS extends Common_functions {
$this->Result->show("danger", _("Error: ").$e->getMessage()); $this->Result->show("danger", _("Error: ").$e->getMessage());
return false; return false;
} }
// update soa serial for impacted domains
if($domains_records !== false) {
foreach ($domains_records as $d) {
$this->update_soa_serial ($d->domain_id);
}
}
#result #result
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment