Skip to content

Commit 4cfd9d0

Browse files
committed
1 parent eb62ea3 commit 4cfd9d0

File tree

6 files changed

+128
-113
lines changed

6 files changed

+128
-113
lines changed

interface/lib/classes/validate_dns.inc.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ function validate_rr(&$rr){
197197
break;
198198
case "MX":
199199
$error .= $this->validate_field($rr['data'], 'Data', $rr['zone'], 0);
200+
$error .= $this->is_integer($rr['aux'], $app->tform->wordbook['aux_txt'], 1);
200201
break;
201202
case "NS":
202203
$error .= $this->validate_field($rr['data'], 'Data', $rr['zone'], 0);
@@ -210,13 +211,12 @@ function validate_rr(&$rr){
210211
break;
211212
case "SRV":
212213
$error .= $this->validate_srv_data($rr['data'], $rr['zone']);
214+
$error .= $this->is_integer($rr['aux'], $app->tform->wordbook['aux_txt'], 1);
213215
break;
214216
case "TXT":
215217
break;
216218
}
217219

218-
$error .= $this->is_integer($rr['aux'], $app->tform->wordbook['aux_txt'], 1);
219-
220220
$error .= $this->is_integer($rr['ttl'], $app->tform->wordbook['ttl_txt']);
221221

222222

@@ -257,4 +257,21 @@ function validate_soa(&$soa){
257257
return $error;
258258
}
259259

260+
function increase_serial($serial){
261+
global $app, $conf;
262+
263+
// increase serial
264+
$serial_date = substr($serial, 0, 8);
265+
$count = intval(substr($serial, 8, 2));
266+
$current_date = date("Ymd");
267+
if($serial_date == $current_date){
268+
$count += 1;
269+
$count = str_pad($count, 2, "0", STR_PAD_LEFT);
270+
$new_serial = $current_date.$count;
271+
} else {
272+
$new_serial = $current_date.'01';
273+
}
274+
return $new_serial;
275+
}
276+
260277
}

interface/web/dns/lib/lang/en_soa.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ $wb["rp_mbox_txt"] = 'RP Mailbox';
1616
$wb["rp_txtref_txt"] = 'RP TXTREF';
1717
$wb["srv_target_txt"] = 'SRV TARGET';
1818
$wb["zone_origin_txt"] = 'Zone Origin';
19+
$wb["yes_txt"] = 'Yes';
20+
$wb["no_txt"] = 'No';
1921
$wb["btn_save_txt"] = 'Save';
2022
$wb["btn_cancel_txt"] = 'Cancel';
2123
$wb["soa_error_empty"] = 'The origin must not be empty!';

interface/web/dns/list/soa.list.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
// Enable auth
4343
$liste["auth"] = "yes";
4444

45-
4645
/*****************************************************
4746
* Suchfelder
4847
*****************************************************/
@@ -132,12 +131,12 @@
132131

133132
$liste["item"][] = array( 'field' => "active",
134133
'datatype' => "VARCHAR",
135-
'formtype' => "TEXT",
134+
'formtype' => "SELECT",
136135
'op' => "=",
137136
'prefix' => "",
138137
'suffix' => "",
139138
'width' => "",
140-
'value' => "");
139+
'value' => array('Y' => 'Yes', 'N' => 'No'));
141140

142141
/*
143142
$liste["item"][] = array( 'field' => "xfer",
@@ -149,5 +148,4 @@
149148
'width' => "",
150149
'value' => "");
151150
*/
152-
153151
?>

interface/web/dns/rr_edit.php

Lines changed: 69 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -61,62 +61,81 @@ function onSubmit() {
6161
$app->uses('validate_dns');
6262
$app->tform->errorMessage .= $app->validate_dns->validate_rr($this->dataRecord);
6363

64-
// update serial
65-
$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$this->dataRecord["zone"]);
66-
$serial = $soa['serial'];
67-
$update = 0;
68-
if($old_record = $app->db->queryOneRecord("SELECT * FROM rr WHERE id = ".$this->dataRecord["id"])){
69-
foreach($old_record as $key => $val){
70-
if($this->dataRecord[$key] != $val) $update += 1;
64+
$increased_serials[] = -1;
65+
if($app->tform->errorMessage == ''){
66+
// update serial
67+
$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$this->dataRecord["zone"]);
68+
$serial = $soa['serial'];
69+
$update = 0;
70+
if($old_record = $app->db->queryOneRecord("SELECT * FROM rr WHERE id = ".$this->dataRecord["id"])){
71+
foreach($old_record as $key => $val){
72+
if($this->dataRecord[$key] != $val) $update += 1;
73+
}
74+
} else { // new record
75+
$update = 1;
7176
}
72-
} else { // new record
73-
$update = 1;
74-
}
75-
if($update > 0){
76-
$serial_date = substr($serial, 0, 8);
77-
$count = intval(substr($serial, 8, 2));
78-
$current_date = date("Ymd");
79-
if($serial_date == $current_date){
80-
$count += 1;
81-
$count = str_pad($count, 2, "0", STR_PAD_LEFT);
82-
$new_serial = $current_date.$count;
83-
} else {
84-
$new_serial = $current_date.'01';
77+
78+
if($update > 0){
79+
$new_serial = $app->validate_dns->increase_serial($serial);
80+
$increased_serials[] = $soa['id'];
81+
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$this->dataRecord["zone"]);
8582
}
86-
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$this->dataRecord["zone"]);
87-
}
8883

89-
// PTR
90-
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
91-
if($this->dataRecord['type'] == 'A' || $this->dataRecord['type'] == 'AAAA'){
92-
list($a, $b, $c, $d) = explode('.', $this->dataRecord['data']);
93-
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
94-
if(substr($this->dataRecord['name'], -1) == '.'){
95-
$ptr_soa_rr_data = $this->dataRecord['name'];
96-
} else {
97-
$ptr_soa_rr_data = $this->dataRecord['name'].(trim($this->dataRecord['name']) == '' ? '' : '.').$soa['origin'];
98-
}
99-
if(!$ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
100-
$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')");
101-
$ptr_soa_id = $app->db->insertID();
102-
$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']."')");
103-
} else {
104-
if($ptr_soa_exist['active'] != 'Y') $app->db->query("UPDATE soa SET active = 'Y' WHERE id = ".$ptr_soa_exist['id']);
105-
if(!$ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR'")){
106-
$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']."')");
107-
// increase serial of PTR SOA
108-
$ptr_soa_serial_date = substr($ptr_soa_exist['serial'], 0, 8);
109-
$ptr_soa_count = intval(substr($ptr_soa_exist['serial'], 8, 2));
110-
$ptr_soa_current_date = date("Ymd");
111-
if($ptr_soa_serial_date == $ptr_soa_current_date){
112-
$ptr_soa_count += 1;
113-
$ptr_soa_count = str_pad($ptr_soa_count, 2, "0", STR_PAD_LEFT);
114-
$ptr_soa_new_serial = $ptr_soa_current_date.$ptr_soa_count;
84+
// PTR
85+
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
86+
if($this->dataRecord['type'] == 'A' || $this->dataRecord['type'] == 'AAAA'){
87+
list($a, $b, $c, $d) = explode('.', $this->dataRecord['data']);
88+
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
89+
if(substr($this->dataRecord['name'], -1) == '.'){
90+
$ptr_soa_rr_data = $this->dataRecord['name'];
91+
} else {
92+
$ptr_soa_rr_data = $this->dataRecord['name'].(trim($this->dataRecord['name']) == '' ? '' : '.').$soa['origin'];
93+
}
94+
95+
if(!$ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$ptr_soa."'")){
96+
$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')");
97+
$ptr_soa_id = $app->db->insertID();
98+
$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']."')");
99+
} else {
100+
if($ptr_soa_exist['active'] != 'Y') $app->db->query("UPDATE soa SET active = 'Y' WHERE id = ".$ptr_soa_exist['id']);
101+
if(!$ptr_soa_rr_exist = $app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$d."' AND type = 'PTR'")){
102+
$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']."')");
103+
// increase serial of PTR SOA
104+
if(!in_array($ptr_soa_exist['id'], $increased_serials)){
105+
$ptr_soa_new_serial = $app->validate_dns->increase_serial($ptr_soa_exist['serial']);
106+
$increased_serials[] = $ptr_soa_exist['id'];
107+
$app->db->query("UPDATE soa SET serial = '".$ptr_soa_new_serial."' WHERE id = ".$ptr_soa_exist['id']);
108+
}
109+
}
110+
}
111+
112+
// if IP address changes, delete/change old PTR record
113+
if(!empty($old_record)){
114+
list($oa, $ob, $oc, $od) = explode('.', $old_record['data']);
115+
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"])){
116+
if(substr($a_rr_with_same_ip['name'], -1) == '.'){
117+
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
118+
} else {
119+
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'].(trim($a_rr_with_same_ip['name']) == '' ? '' : '.').$a_rr_with_same_ip['origin'];
120+
}
121+
$app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
115122
} else {
116-
$ptr_soa_new_serial = $ptr_soa_current_date.'01';
123+
$old_ptr_soa = $oc.'.'.$ob.'.'.$oa.'.in-addr.arpa.';
124+
$old_ptr_soa_exist = $app->db->queryOneRecord("SELECT * FROM soa WHERE origin = '".$old_ptr_soa."'");
125+
$app->db->query("DELETE FROM rr WHERE zone = '".$old_ptr_soa_exist['id']."' AND name = '".$od."' AND type = 'PTR'");
126+
//die("DELETE FROM rr WHERE zone = '".$old_record['zone']."' AND name = '".$od."' AND type = 'PTR'");
127+
if(!$app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$old_ptr_soa_exist['id']."'")){
128+
$app->db->query("DELETE FROM soa WHERE id = ".$old_ptr_soa_exist['id']);
129+
} else {
130+
// increase serial
131+
if(!in_array($old_ptr_soa_exist['id'], $increased_serials)){
132+
$new_serial = $app->validate_dns->increase_serial($old_ptr_soa_exist['serial']);
133+
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$old_ptr_soa_exist['id']);
134+
}
135+
}
117136
}
118-
$app->db->query("UPDATE soa SET serial = '".$ptr_soa_new_serial."' WHERE id = ".$ptr_soa_exist['id']);
119137
}
138+
120139
}
121140
}
122141
}

0 commit comments

Comments
 (0)