Skip to content

Commit 3d3f986

Browse files
author
Till Brehm
committed
Implemented: FS#3235 - Allow 'any' value in zone xfer field
1 parent 8433d03 commit 3d3f986

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

interface/lib/classes/validate_dns.inc.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,49 @@ function increase_serial($serial){
283283
}
284284
return $new_serial;
285285
}
286+
287+
function validate_xfer($field_name, $field_value, $validator) {
288+
global $app;
289+
290+
$errorMessage = '';
291+
292+
if($validator['allowempty'] != 'y') $validator['allowempty'] = 'n';
293+
if($validator['allowempty'] == 'y' && $field_value == '') {
294+
//* Do nothing
295+
} elseif ($field_value == 'any') {
296+
//* Do nothing
297+
} else {
298+
//* Check if its a IPv4 or IPv6 address
299+
if(isset($validator['separator']) && $validator['separator'] != '') {
300+
//* When the field may contain several IP addresses, split them by the char defined as separator
301+
$field_value_array = explode($validator['separator'], $field_value);
302+
} else {
303+
$field_value_array[] = $field_value;
304+
}
305+
foreach($field_value_array as $field_value) {
306+
$field_value = trim($field_value);
307+
if(function_exists('filter_var')) {
308+
if(!filter_var($field_value, FILTER_VALIDATE_IP)) {
309+
$errmsg = $validator['errmsg'];
310+
$errorMessage .= $app->tform->lng($errmsg)."<br />\r\n";
311+
}
312+
} else {
313+
//* Check content with regex, if we use php < 5.2
314+
$ip_ok = 0;
315+
if(preg_match("/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i", $field_value)){
316+
$ip_ok = 1;
317+
}
318+
if(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $field_value)){
319+
$ip_ok = 1;
320+
}
321+
if($ip_ok == 0) {
322+
$errmsg = $validator['errmsg'];
323+
$errorMessage .= $app->tform->lng($errmsg)."<br />\r\n";
324+
}
325+
}
326+
}
327+
}
328+
return $errorMessage;
329+
}
286330

287331
}

interface/web/dns/form/dns_soa.tform.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,20 @@
217217
'xfer' => array (
218218
'datatype' => 'VARCHAR',
219219
'formtype' => 'TEXT',
220+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
221+
'class' => 'validate_dns',
222+
'function' => 'validate_xfer',
223+
'allowempty' => 'y',
224+
'separator' => ',',
225+
'errmsg'=> 'xfer_error_regex'),
226+
),
227+
/*
220228
'validators' => array ( 0 => array ( 'type' => 'ISIP',
221229
'allowempty' => 'y',
222230
'separator' => ',',
223231
'errmsg'=> 'xfer_error_regex'),
224232
),
233+
*/
225234
'default' => '',
226235
'value' => '',
227236
'width' => '30',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ $wb['retry_range_error'] = 'Min. Refresh ist 60 Sekunden.';
3434
$wb['expire_range_error'] = 'Min. Expire ist 60 Sekunden.';
3535
$wb['minimum_range_error'] = 'Min. Minimum ist 60 Sekunden.';
3636
$wb['ttl_range_error'] = 'Min. TTL ist 60 Sekunden.';
37-
$wb['xfer_error_regex'] = 'Bitte Beachten: Verwenden Sie eine IP Adresse.';
37+
$wb['xfer_error_regex'] = 'Zonentransfer: Verwenden Sie eine oder mehrere durch Komma getrennte IP Adressen oder das Wort: any.';
3838
?>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $wb["mbox_error_empty"] = 'Email is empty.';
2323
$wb["mbox_error_regex"] = 'Email format invalid.';
2424
$wb["also_notify_txt"] = 'Also Notify';
2525
$wb['also_notify_error_regex'] = 'Also notify: Please use an IP address.';
26-
$wb['xfer_error_regex'] = 'Xfer: Please use an IP address.';
26+
$wb['xfer_error_regex'] = 'Xfer: Please use one or more IP addresses, separated by , or use the keyword: any';
2727
$wb["update_acl_txt"] = 'Update ACL';
2828
$wb['seconds_txt'] = 'Seconds';
2929
$wb['eg_domain_tld'] = 'e.g. domain.tld';

0 commit comments

Comments
 (0)