Skip to content

Commit e7ea7dc

Browse files
committed
1 parent 3dedced commit e7ea7dc

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

interface/lib/classes/validate_dns.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ function increase_serial($serial){
273273
$serial_date = substr($serial, 0, 8);
274274
$count = intval(substr($serial, 8, 2));
275275
$current_date = date("Ymd");
276-
if($serial_date == $current_date){
276+
if($serial_date >= $current_date){
277277
$count += 1;
278278
$count = str_pad($count, 2, "0", STR_PAD_LEFT);
279-
$new_serial = $current_date.$count;
279+
$new_serial = $serial_date.$count;
280280
} else {
281281
$new_serial = $current_date.'01';
282282
}

interface/web/dns/soa_edit.php

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ function onSubmit() {
7171
} else { // new record
7272
$update = 1;
7373
}
74+
if(strlen($this->dataRecord["serial"]) == 10 && intval($this->dataRecord["serial"]) == $this->dataRecord["serial"] && $this->dataRecord["serial"] != $serial){
75+
$update = 0;
76+
$increased_serials[] = $soa['id'];
77+
}
7478
if($update > 0){
7579
$new_serial = $app->validate_dns->increase_serial($serial);
7680
$increased_serials[] = $soa['id'];
@@ -87,12 +91,15 @@ function onSubmit() {
8791
if($soa['origin'] == substr($rr['name'], -(strlen($soa['origin']))) || $soa['origin'] == substr($rr['data'], -(strlen($soa['origin'])))) $update_soas[] = $rr['zone'];
8892
//$update_soas[] = $app->db->queryAllRecords("SELECT DISTINCT zone FROM rr WHERE name LIKE '%".$soa['origin']."' OR data LIKE '%".$soa['origin']."'");
8993

90-
$app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type != 'PTR'");
91-
$app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type != 'PTR'");
94+
$app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type != 'PTR' AND id = ".$rr['id']);
95+
96+
$app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type != 'PTR' AND id = ".$rr['id']);
9297

9398
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
94-
$app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type = 'PTR'");
95-
$app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type = 'PTR'");
99+
$app->db->query("UPDATE rr SET name = '".substr($rr['name'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE name LIKE '%".$soa['origin']."' AND type = 'PTR' AND id = ".$rr['id']);
100+
101+
$app->db->query("UPDATE rr SET data = '".substr($rr['data'], 0, -(strlen($this->dataRecord['origin']))).$this->dataRecord['origin']."' WHERE data LIKE '%".$soa['origin']."' AND type = 'PTR' AND id = ".$rr['id']);
102+
96103
}
97104
}
98105

@@ -132,7 +139,7 @@ function onSubmit() {
132139
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
133140
if($ptr = $app->db->queryOneRecord("SELECT soa.id, soa.serial FROM soa, rr WHERE rr.type = 'PTR' AND rr.data = '".$fqdn."' AND rr.zone = soa.id AND soa.origin = '".$ptr_soa."'")){
134141
############
135-
if($a_rr_with_same_ip = $app->db->queryOneRecord("SELECT rr.*, soa.origin FROM rr, soa WHERE rr.type = 'A' AND rr.data = '".$soa_rr['data']."' AND rr.zone = soa.id AND soa.active = 'Y' AND rr.id != ".$soa_rr["id"]." AND rr.zone != '".$soa_rr['zone']."'")){
142+
if($a_rr_with_same_ip = $app->db->queryOneRecord("SELECT rr.*, soa.origin FROM rr, soa WHERE rr.type = 'A' AND rr.data = '".$soa_rr['data']."' AND rr.zone = soa.id AND soa.active = 'Y' AND rr.id != ".$soa_rr["id"]." AND rr.zone != '".$this->dataRecord['zone']."'")){
136143
if(substr($a_rr_with_same_ip['name'], -1) == '.'){
137144
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
138145
} else {
@@ -165,6 +172,38 @@ function onSubmit() {
165172

166173
if($soa['active'] = 'N' && $this->dataRecord['active'][0] == 'Y'){
167174

175+
if($soa_rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$this->dataRecord['id']." AND type = 'A'")){
176+
foreach($soa_rrs as $soa_rr){
177+
#################
178+
list($a, $b, $c, $d) = explode('.', $soa_rr['data']);
179+
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
180+
if(substr($soa_rr['name'], -1) == '.'){
181+
$ptr_soa_rr_data = $soa_rr['name'];
182+
} else {
183+
$ptr_soa_rr_data = $soa_rr['name'].(trim($soa_rr['name']) == '' ? '' : '.').$this->dataRecord['origin'];
184+
}
185+
186+
if(!$ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
187+
$app->db->query("INSERT INTO soa (origin, ns, mbox, serial, refresh, retry, expire, minimum, ttl, active) VALUES ('".$ptr_soa."', '".trim($conf['default_ns'])."', '".trim($conf['default_mbox'])."', '".date("Ymd").'01'."', '".$conf['default_refresh']."', '".$conf['default_retry']."', '".$conf['default_expire']."', '".$conf['default_minimum_ttl']."', '".$conf['default_ttl']."', 'Y')");
188+
$ptr_soa_id = $app->db->insertID();
189+
$app->db->query("INSERT INTO rr (zone, name, type, data, aux, ttl) VALUES ('".$ptr_soa_id."', '".$d."', 'PTR', '".$ptr_soa_rr_data."', '0', '".$conf['default_ttl']."')");
190+
} else {
191+
if($ptr_soa_exist['active'] != 'Y') $app->db->query("UPDATE soa SET active = 'Y' WHERE id = ".$ptr_soa_exist['id']);
192+
if(!$ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR'")){
193+
$app->db->query("INSERT INTO rr (zone, name, type, data, aux, ttl) VALUES ('".$ptr_soa_exist['id']."', '".$d."', 'PTR', '".$ptr_soa_rr_data."', '0', '".$conf['default_ttl']."')");
194+
// increase serial of PTR SOA
195+
if(!in_array($ptr_soa_exist['id'], $increased_serials)){
196+
$ptr_soa_new_serial = $app->validate_dns->increase_serial($ptr_soa_exist['serial']);
197+
$increased_serials[] = $ptr_soa_exist['id'];
198+
$app->db->query("UPDATE soa SET serial = '".$ptr_soa_new_serial."' WHERE id = ".$ptr_soa_exist['id']);
199+
}
200+
}
201+
}
202+
################
203+
}
204+
}
205+
206+
168207
}
169208
}
170209
}

0 commit comments

Comments
 (0)