Skip to content

Commit 3dedced

Browse files
committed
1 parent 4cfd9d0 commit 3dedced

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

interface/lib/classes/validate_dns.inc.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ function validate_field($field, $area, $zoneid, $wildcard_allowed = 1){
7676

7777
$parts = explode(".", $field);
7878
$i = 0;
79+
$empty = 0;
7980
foreach ($parts as $part){
8081
$i++;
8182

83+
if(trim($part) == '') $empty += 1;
84+
8285
if(strlen($part) > 63) $error .= $desc." ".$app->tform->wordbook['error_63_characters']."<br>\r\n";
8386

8487
if(strspn($part, $valid_characters) != strlen($part)) $error .= $desc." ".$app->tform->wordbook['error_invalid_characters']."<br>\r\n";
@@ -97,6 +100,12 @@ function validate_field($field, $area, $zoneid, $wildcard_allowed = 1){
97100
}
98101
}
99102

103+
if(substr($field, -1) == '.'){
104+
if($i > 2 && $empty > 1) $error .= $desc." ".$app->tform->wordbook['error_invalid_characters']."<br>\r\n";
105+
} else {
106+
if($empty > 0) $error .= $desc." ".$app->tform->wordbook['error_invalid_characters']."<br>\r\n";
107+
}
108+
100109
if(substr($field, -1) == '.' && $area == 'Name'){
101110
$soa = $app->db->queryOneRecord("SELECT * FROM soa WHERE id = ".$zoneid);
102111
if(substr($field, (strlen($field) - strlen($soa['origin']))) != $soa['origin']) $error .= $desc." ".$app->tform->wordbook['error_out_of_zone']."<br>\r\n";
@@ -176,7 +185,7 @@ function validate_rr(&$rr){
176185
} else {
177186
for($n = 0; $n < 4; $n++){
178187
$q = $ip_parts[$n];
179-
if(!is_numeric($q) || (int)$q < 0 || (int)$q > 255) $error .= $app->tform->wordbook['data_txt']." ".$app->tform->wordbook['error_a']."<br>\r\n";
188+
if(!is_numeric($q) || (int)$q < 0 || (int)$q > 255 || trim($q) !== $q) $error .= $app->tform->wordbook['data_txt']." ".$app->tform->wordbook['error_a']."<br>\r\n";
180189
}
181190
}
182191
$rr['data'] = (int)$ip_parts[0].".".(int)$ip_parts[1].".".(int)$ip_parts[2].".".(int)$ip_parts[3];

interface/web/dns/soa_edit.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,65 @@ function onSubmit() {
108108
} else {
109109
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$update_soa." AND origin NOT LIKE '%.in-addr.arpa.'");
110110
}
111+
$increased_serials[] = $u_soa['id'];
111112
}
112113
}
113114
}
114115
}
115116
}
117+
118+
119+
// PTR
120+
if($conf['auto_create_ptr'] == 1 && trim($conf['default_ns']) != '' && trim($conf['default_mbox']) != ''){
121+
122+
if($soa['active'] = 'Y' && $this->dataRecord['active'][0] == 'N'){
123+
124+
if($soa_rrs = $app->db->queryAllRecords("SELECT * FROM rr WHERE zone = ".$this->dataRecord['id']." AND type = 'A'")){
125+
foreach($soa_rrs as $soa_rr){
126+
if(substr($soa_rr['name'], -1) == '.'){
127+
$fqdn = $soa_rr['name'];
128+
} else {
129+
$fqdn = $soa_rr['name'].(trim($soa_rr['name']) == '' ? '' : '.').$this->dataRecord['origin'];
130+
}
131+
list($a, $b, $c, $d) = explode('.', $soa_rr['data']);
132+
$ptr_soa = $c.'.'.$b.'.'.$a.'.in-addr.arpa.';
133+
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."'")){
134+
############
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']."'")){
136+
if(substr($a_rr_with_same_ip['name'], -1) == '.'){
137+
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'];
138+
} else {
139+
$new_ptr_soa_rr_data = $a_rr_with_same_ip['name'].(trim($a_rr_with_same_ip['name']) == '' ? '' : '.').$a_rr_with_same_ip['origin'];
140+
}
141+
$app->db->query("UPDATE rr SET data = '".$new_ptr_soa_rr_data."' WHERE zone = '".$ptr['id']."' AND name = '".$d."' AND type = 'PTR'");
142+
} else {
143+
$app->db->query("DELETE FROM rr WHERE zone = '".$ptr['id']."' AND name = '".$d."' AND type = 'PTR'");
144+
145+
if(!$app->db->queryOneRecord("SELECT * FROM rr WHERE zone = '".$ptr['id']."'")){
146+
$app->db->query("DELETE FROM soa WHERE id = ".$ptr['id']);
147+
} else {
148+
// increase serial
149+
if(!in_array($ptr['id'], $increased_serials)){
150+
$new_serial = $app->validate_dns->increase_serial($ptr['serial']);
151+
$app->db->query("UPDATE soa SET serial = '".$new_serial."' WHERE id = ".$ptr['id']);
152+
$increased_serials[] = $ptr['id'];
153+
}
154+
}
155+
}
156+
############
157+
}
158+
}
159+
}
160+
161+
/* */
162+
163+
164+
}
165+
166+
if($soa['active'] = 'N' && $this->dataRecord['active'][0] == 'Y'){
167+
168+
}
169+
}
116170
}
117171

118172

0 commit comments

Comments
 (0)