Skip to content

Commit 6ecc560

Browse files
committed
1 parent e0b6391 commit 6ecc560

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

interface/web/dns/rr_edit.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ function onSubmit() {
7676
$update = 0;
7777
if($old_record = $app->db->queryOneRecord("SELECT * FROM rr WHERE id = ".$this->dataRecord["id"])){
7878
foreach($old_record as $key => $val){
79-
if($this->dataRecord[$key] != $val) $update += 1;
79+
if($this->dataRecord[$key] != $val && isset($this->dataRecord[$key])) $update += 1;
8080
}
8181
} else { // new record
8282
$update = 1;
8383
}
8484

85-
if($update > 0){
85+
if($update > 0 && !in_array($soa['id'], $increased_serials)){
8686
$new_serial = $app->validate_dns->increase_serial($serial);
8787
$increased_serials[] = $soa['id'];
8888
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$this->dataRecord["zone"]);
@@ -119,24 +119,38 @@ function onSubmit() {
119119
// if IP address changes, delete/change old PTR record
120120
if(!empty($old_record)){
121121
list($oa, $ob, $oc, $od) = explode('.', $old_record['data']);
122-
if($a_rr_with_same_ip = $app->db->queryOneRecord("SELECT rr.*, soa.origin FROM rr, soa WHERE rr.type = 'A' AND rr.data = '".$old_record['data']."' AND rr.zone = soa.id AND soa.active = 'Y' AND rr.id != ".$this->dataRecord["id"])){
122+
123+
if($old_record['data'] == $this->dataRecord['data']){
124+
$a_rr_with_same_ip = $this->dataRecord;
125+
$a_rr_with_same_ip['origin'] = $soa['origin'];
126+
} else {
127+
$a_rr_with_same_ip = $app->db->queryOneRecord("SELECT rr.*, soa.origin FROM rr, soa WHERE rr.type = 'A' AND rr.data = '".$old_record['data']."' AND rr.zone = soa.id AND soa.active = 'Y' AND rr.id != ".$this->dataRecord["id"]);
128+
}
129+
$old_ptr_soa = $oc.'.'.$ob.'.'.$oa.'.in-addr.arpa.';
130+
$old_ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$old_ptr_soa."'");
131+
132+
if($a_rr_with_same_ip){
123133
if(substr($a_rr_with_same_ip['name'], -1) == '.'){
124134
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
125135
} else {
126136
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'].(trim($a_rr_with_same_ip['name']) == '' ? '' : '.').$a_rr_with_same_ip['origin'];
127137
}
128-
$app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
138+
$app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$old_ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
139+
// increase serial
140+
if(!in_array($old_ptr_soa_exist['id'], $increased_serials)){
141+
$new_serial = $app->validate_dns->increase_serial($old_ptr_soa_exist['serial']);
142+
$increased_serials[] = $old_ptr_soa_exist['id'];
143+
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$old_ptr_soa_exist['id']);
144+
}
129145
} else {
130-
$old_ptr_soa = $oc.'.'.$ob.'.'.$oa.'.in-addr.arpa.';
131-
$old_ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$old_ptr_soa."'");
132146
$app->db->query("DELETE FROM rr WHERE zone = '".$old_ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
133-
//die("DELETE FROM rr WHERE zone = '".$old_record['zone']."' AND name = '".$od."' AND type = 'PTR'");
134147
if(!$app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$old_ptr_soa_exist['id']."'")){
135148
$app->db->query("DELETE FROM soa WHERE id = ".$old_ptr_soa_exist['id']);
136149
} else {
137150
// increase serial
138151
if(!in_array($old_ptr_soa_exist['id'], $increased_serials)){
139152
$new_serial = $app->validate_dns->increase_serial($old_ptr_soa_exist['serial']);
153+
$increased_serials[] = $old_ptr_soa_exist['id'];
140154
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$old_ptr_soa_exist['id']);
141155
}
142156
}

interface/web/dns/soa_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function onSubmit() {
7777
$update = 0;
7878
if($soa){
7979
foreach($soa as $key => $val){
80-
if($this->dataRecord[$key] != $val && $key != 'active') $update += 1;
80+
if($this->dataRecord[$key] != $val && $key != 'active' && isset($this->dataRecord[$key])) $update += 1;
8181
}
8282
} else { // new record
8383
$update = 1;

0 commit comments

Comments
 (0)