From b571cfe7c7dfc20ae7b356ed34c3c02fdbbe02b2 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 11 Feb 2024 17:33:31 +0100 Subject: [PATCH 1/4] Avoid running checkzone for each rr when deleting a soa, #6647 --- interface/lib/classes/db_mysql.inc.php | 7 ++++--- interface/web/dns/dns_soa_del.php | 5 +++-- server/plugins-available/bind_plugin.inc.php | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php index 9a7cf7129f..2e893e8508 100644 --- a/interface/lib/classes/db_mysql.inc.php +++ b/interface/lib/classes/db_mysql.inc.php @@ -686,7 +686,7 @@ class db } //** Function to fill the datalog with a full differential record. - public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) { + public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false, $options = []) { global $app; // Insert backticks only for incomplete table names. @@ -712,6 +712,7 @@ class db $server_id = (isset($record_old['server_id']) && $record_old['server_id'] > 0)?$record_old['server_id']:0; if(isset($record_new['server_id'])) $server_id = $record_new['server_id']; + $diffrec_full['options'] = $options; if($diff_num > 0) { $diffstr = serialize($diffrec_full); @@ -810,7 +811,7 @@ class db } //** Deletes a record and saves the changes into the datalog - public function datalogDelete($tablename, $index_field, $index_value) { + public function datalogDelete($tablename, $index_field, $index_value, $options = []) { global $app; // Check fields @@ -820,7 +821,7 @@ class db $old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value); $this->query("DELETE FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value); $new_rec = array(); - $this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec); + $this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec, FALSE, $options); return true; } diff --git a/interface/web/dns/dns_soa_del.php b/interface/web/dns/dns_soa_del.php index fee2138f85..2d18a2d4ff 100644 --- a/interface/web/dns/dns_soa_del.php +++ b/interface/web/dns/dns_soa_del.php @@ -55,10 +55,11 @@ class page_action extends tform_actions { if($app->tform->checkPerm($this->id, 'd') == false) $app->error($app->lng('error_no_delete_permission')); - // Delete all records that belog to this zone. + // Delete all records that belong to this zone. $records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE zone = ?", $this->id); + $options = ['deleting_dns_soa' => TRUE]; foreach($records as $rec) { - $app->db->datalogDelete('dns_rr', 'id', $rec['id']); + $app->db->datalogDelete('dns_rr', 'id', $rec['id'], $options); } } diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php index ac71f35cc4..1485fb0f32 100644 --- a/server/plugins-available/bind_plugin.inc.php +++ b/server/plugins-available/bind_plugin.inc.php @@ -352,7 +352,7 @@ class bind_plugin { $loglevel = @($dns_config['disable_bind_log'] === 'y') ? LOGLEVEL_DEBUG : LOGLEVEL_WARN; $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), $loglevel); if(is_array($out) && !empty($out)){ - $app->log('Reason for Bind restart failure: '.implode("\n", $out), $loglevel); + $app->log('Reason for Bind zone check failure: '.implode("\n", $out), $loglevel); $app->dbmaster->datalogError(implode("\n", $out)); } if ($old_zonefile != '') { @@ -524,6 +524,11 @@ class bind_plugin { function rr_delete($event_name, $data) { global $app, $conf; + if (!empty($data['options']['deleting_dns_soa']) && $data['options']['deleting_dns_soa'] == TRUE) { + $app->log("Skipping zone update since it's alse being deleted", LOGLEVEL_DEBUG); + return; + } + //* Get the data of the soa and call soa_update $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['old']['zone']); $data["new"] = $tmp; -- GitLab From 0d83850b962a4b89bf93a1ca024946ea69b288c4 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Wed, 14 Feb 2024 13:29:09 +0100 Subject: [PATCH 2/4] Revert "Avoid running checkzone for each rr when deleting a soa, #6647" This reverts commit b571cfe7c7dfc20ae7b356ed34c3c02fdbbe02b2. Too complex, alterative suggested --- interface/lib/classes/db_mysql.inc.php | 7 +++---- interface/web/dns/dns_soa_del.php | 5 ++--- server/plugins-available/bind_plugin.inc.php | 7 +------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php index 2e893e8508..9a7cf7129f 100644 --- a/interface/lib/classes/db_mysql.inc.php +++ b/interface/lib/classes/db_mysql.inc.php @@ -686,7 +686,7 @@ class db } //** Function to fill the datalog with a full differential record. - public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false, $options = []) { + public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) { global $app; // Insert backticks only for incomplete table names. @@ -712,7 +712,6 @@ class db $server_id = (isset($record_old['server_id']) && $record_old['server_id'] > 0)?$record_old['server_id']:0; if(isset($record_new['server_id'])) $server_id = $record_new['server_id']; - $diffrec_full['options'] = $options; if($diff_num > 0) { $diffstr = serialize($diffrec_full); @@ -811,7 +810,7 @@ class db } //** Deletes a record and saves the changes into the datalog - public function datalogDelete($tablename, $index_field, $index_value, $options = []) { + public function datalogDelete($tablename, $index_field, $index_value) { global $app; // Check fields @@ -821,7 +820,7 @@ class db $old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value); $this->query("DELETE FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value); $new_rec = array(); - $this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec, FALSE, $options); + $this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec); return true; } diff --git a/interface/web/dns/dns_soa_del.php b/interface/web/dns/dns_soa_del.php index 2d18a2d4ff..fee2138f85 100644 --- a/interface/web/dns/dns_soa_del.php +++ b/interface/web/dns/dns_soa_del.php @@ -55,11 +55,10 @@ class page_action extends tform_actions { if($app->tform->checkPerm($this->id, 'd') == false) $app->error($app->lng('error_no_delete_permission')); - // Delete all records that belong to this zone. + // Delete all records that belog to this zone. $records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE zone = ?", $this->id); - $options = ['deleting_dns_soa' => TRUE]; foreach($records as $rec) { - $app->db->datalogDelete('dns_rr', 'id', $rec['id'], $options); + $app->db->datalogDelete('dns_rr', 'id', $rec['id']); } } diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php index 1485fb0f32..ac71f35cc4 100644 --- a/server/plugins-available/bind_plugin.inc.php +++ b/server/plugins-available/bind_plugin.inc.php @@ -352,7 +352,7 @@ class bind_plugin { $loglevel = @($dns_config['disable_bind_log'] === 'y') ? LOGLEVEL_DEBUG : LOGLEVEL_WARN; $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), $loglevel); if(is_array($out) && !empty($out)){ - $app->log('Reason for Bind zone check failure: '.implode("\n", $out), $loglevel); + $app->log('Reason for Bind restart failure: '.implode("\n", $out), $loglevel); $app->dbmaster->datalogError(implode("\n", $out)); } if ($old_zonefile != '') { @@ -524,11 +524,6 @@ class bind_plugin { function rr_delete($event_name, $data) { global $app, $conf; - if (!empty($data['options']['deleting_dns_soa']) && $data['options']['deleting_dns_soa'] == TRUE) { - $app->log("Skipping zone update since it's alse being deleted", LOGLEVEL_DEBUG); - return; - } - //* Get the data of the soa and call soa_update $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['old']['zone']); $data["new"] = $tmp; -- GitLab From 385e219c8a9bb02d4d3fd76fad8c2f41d28f814e Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Wed, 14 Feb 2024 13:31:53 +0100 Subject: [PATCH 3/4] Fix string errors --- interface/web/dns/dns_soa_del.php | 2 +- server/plugins-available/bind_plugin.inc.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/web/dns/dns_soa_del.php b/interface/web/dns/dns_soa_del.php index fee2138f85..2f2b3331c8 100644 --- a/interface/web/dns/dns_soa_del.php +++ b/interface/web/dns/dns_soa_del.php @@ -55,7 +55,7 @@ class page_action extends tform_actions { if($app->tform->checkPerm($this->id, 'd') == false) $app->error($app->lng('error_no_delete_permission')); - // Delete all records that belog to this zone. + // Delete all records that belong to this zone. $records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE zone = ?", $this->id); foreach($records as $rec) { $app->db->datalogDelete('dns_rr', 'id', $rec['id']); diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php index ac71f35cc4..99ae03ace8 100644 --- a/server/plugins-available/bind_plugin.inc.php +++ b/server/plugins-available/bind_plugin.inc.php @@ -352,7 +352,7 @@ class bind_plugin { $loglevel = @($dns_config['disable_bind_log'] === 'y') ? LOGLEVEL_DEBUG : LOGLEVEL_WARN; $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), $loglevel); if(is_array($out) && !empty($out)){ - $app->log('Reason for Bind restart failure: '.implode("\n", $out), $loglevel); + $app->log('Reason for Bind zone check failure: '.implode("\n", $out), $loglevel); $app->dbmaster->datalogError(implode("\n", $out)); } if ($old_zonefile != '') { -- GitLab From eff523095fbaa05a3c502551a0a60b6490dd2544 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Wed, 14 Feb 2024 15:09:06 +0100 Subject: [PATCH 4/4] Avoid running checkzone for each rr when inserting/deleting a soa by deactivating the zone first, #6647 --- interface/lib/classes/dns_wizard.inc.php | 5 ++++- interface/web/dns/dns_import.php | 5 ++++- interface/web/dns/dns_soa_del.php | 2 ++ server/plugins-available/bind_plugin.inc.php | 13 ++++++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/interface/lib/classes/dns_wizard.inc.php b/interface/lib/classes/dns_wizard.inc.php index 9b81748d23..c9c1af2e66 100644 --- a/interface/lib/classes/dns_wizard.inc.php +++ b/interface/lib/classes/dns_wizard.inc.php @@ -268,7 +268,7 @@ class dns_wizard "expire" => $expire, "minimum" => $minimum, "ttl" => $ttl, - "active" => 'Y', + "active" => 'N', // Activated later when all DNS records are added. "xfer" => $xfer, "also_notify" => $also_notify, "update_acl" => $update_acl, @@ -301,6 +301,9 @@ class dns_wizard } } + // Activate the DNS zone. + $app->db->datalogUpdate('dns_soa', array('active' => 'Y'), 'id', $dns_soa_id); + return 'ok'; } else { diff --git a/interface/web/dns/dns_import.php b/interface/web/dns/dns_import.php index d422983c0c..22a5367f6e 100644 --- a/interface/web/dns/dns_import.php +++ b/interface/web/dns/dns_import.php @@ -677,7 +677,7 @@ $error[] = print_r( $soa, true ); "expire" => $soa['expire'], "minimum" => $soa['minimum'], "ttl" => $soa['ttl'], - "active" => 'Y', + "active" => 'N', // Activated later when all DNS records are added. "xfer" => $xfer ); $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id'); @@ -710,6 +710,9 @@ $error[] = print_r( $soa, true ); $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); } + // Activate the DNS zone. + $app->db->datalogUpdate('dns_soa', array('active' => 'Y'), 'id', $dns_soa_id); + $msg[] = $wb['zone_file_successfully_imported_txt']; } elseif (is_array($dns_rr)) { $error[] = $wb['zone_file_import_fail']; diff --git a/interface/web/dns/dns_soa_del.php b/interface/web/dns/dns_soa_del.php index 2f2b3331c8..e04b11620d 100644 --- a/interface/web/dns/dns_soa_del.php +++ b/interface/web/dns/dns_soa_del.php @@ -55,6 +55,8 @@ class page_action extends tform_actions { if($app->tform->checkPerm($this->id, 'd') == false) $app->error($app->lng('error_no_delete_permission')); + $app->db->datalogUpdate('dns_soa', array("active" => 'N'), 'id', $this->id); + // Delete all records that belong to this zone. $records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE zone = ?", $this->id); foreach($records as $rec) { diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php index 99ae03ace8..9be9278269 100644 --- a/server/plugins-available/bind_plugin.inc.php +++ b/server/plugins-available/bind_plugin.inc.php @@ -352,7 +352,7 @@ class bind_plugin { $loglevel = @($dns_config['disable_bind_log'] === 'y') ? LOGLEVEL_DEBUG : LOGLEVEL_WARN; $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), $loglevel); if(is_array($out) && !empty($out)){ - $app->log('Reason for Bind zone check failure: '.implode("\n", $out), $loglevel); + $app->log('Reason for Bind zone check failure: '.implode("\n", $out), $loglevel); $app->dbmaster->datalogError(implode("\n", $out)); } if ($old_zonefile != '') { @@ -505,7 +505,10 @@ class bind_plugin { $data["new"] = $tmp; $data["old"] = $tmp; $this->action = 'update'; - $this->soa_update($event_name, $data); + + if (isset($data['new']['active']) && $data['new']['active'] == 'Y') { + $this->soa_update($event_name, $data); + } } @@ -525,11 +528,15 @@ class bind_plugin { global $app, $conf; //* Get the data of the soa and call soa_update + //* In a singel server setup the record in dns_soa will already be gone ... so this will give an empty array. $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['old']['zone']); $data["new"] = $tmp; $data["old"] = $tmp; $this->action = 'update'; - $this->soa_update($event_name, $data); + + if (isset($data['new']['active']) && $data['new']['active'] == 'Y') { + $this->soa_update($event_name, $data); + } } -- GitLab