diff --git a/src/www/services_unbound_domainoverride_edit.php b/src/www/services_unbound_domainoverride_edit.php index 3c5e474a7..da5a631d9 100644 --- a/src/www/services_unbound_domainoverride_edit.php +++ b/src/www/services_unbound_domainoverride_edit.php @@ -1,7 +1,7 @@ and Manuel Kasper . All rights reserved. @@ -32,150 +32,140 @@ require_once("guiconfig.inc"); require_once("services.inc"); require_once("interfaces.inc"); -$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound_overrides.php'); - -if (!is_array($config['unbound']['domainoverrides'])) - $config['unbound']['domainoverrides'] = array(); +if (empty($config['unbound']['domainoverrides']) || !is_array($config['unbound']['domainoverrides'])) { + $config['unbound']['domainoverrides'] = array(); +} $a_domainOverrides = &$config['unbound']['domainoverrides']; -if (is_numericint($_GET['id'])) - $id = $_GET['id']; -if (isset($_POST['id']) && is_numericint($_POST['id'])) - $id = $_POST['id']; -if (isset($id) && $a_domainOverrides[$id]) { - $pconfig['domain'] = $a_domainOverrides[$id]['domain']; - $pconfig['ip'] = $a_domainOverrides[$id]['ip']; - $pconfig['descr'] = $a_domainOverrides[$id]['descr']; -} - -if ($_POST) { - - unset($input_errors); +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['id']) && !empty($a_domainOverrides[$_GET['id']])) { + $id = $_GET['id']; + } + $pconfig = array(); + $pconfig['domain'] = isset($id) && !empty($a_domainOverrides[$id]['domain']) ? $a_domainOverrides[$id]['domain'] : null; + $pconfig['ip'] = isset($id) && !empty($a_domainOverrides[$id]['ip']) ? $a_domainOverrides[$id]['ip'] : null; + $pconfig['descr'] = isset($id) && !empty($a_domainOverrides[$id]['descr']) ? $a_domainOverrides[$id]['descr'] : null; +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_GET['id']) && !empty($a_domainOverrides[$_POST['id']])) { + $id = $_POST['id']; + } + $input_errors= array(); $pconfig = $_POST; /* input validation */ $reqdfields = explode(" ", "domain ip"); $reqdfieldsn = array(gettext("Domain"),gettext("IP address")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - function String_Begins_With($needle, $haystack) { - return (substr($haystack, 0, strlen($needle))==$needle); - } - - if (String_Begins_With(_msdcs, $_POST['domain'])) { - $subdomainstr = substr($_POST['domain'], 7); - if ($subdomainstr && !is_domain($subdomainstr)) + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + if (!empty($pconfig['domain']) && substr($pconfig['domain'], 0, 6) == '_msdcs') { + $subdomainstr = substr($pconfig['domain'], 7); + if ($subdomainstr && !is_domain($subdomainstr)) { $input_errors[] = gettext("A valid domain must be specified after _msdcs."); - } elseif ($_POST['domain'] && !is_domain($_POST['domain'])) + } + } elseif (!empty($pconfig['domain']) && !is_domain($_POST['domain'])) { $input_errors[] = gettext("A valid domain must be specified."); - - if ($_POST['ip']) { - if (strpos($_POST['ip'],'@') !== false) { - $ip_details = explode("@", $_POST['ip']); - if (!is_ipaddr($ip_details[0]) && !is_port($ip_details[1])) - $input_errors[] = gettext("A valid IP address and port must be specified, for example 192.168.100.10@5353."); - } else if (!is_ipaddr($_POST['ip'])) - $input_errors[] = gettext("A valid IP address must be specified, for example 192.168.100.10."); } - if (!$input_errors) { - $doment = array(); - $doment['domain'] = $_POST['domain']; - $doment['ip'] = $_POST['ip']; - $doment['descr'] = $_POST['descr']; + if (!empty($pconfig['ip'])) { + if (strpos($pconfig['ip'],'@') !== false) { + $ip_details = explode("@", $pconfig['ip']); + if (!is_ipaddr($ip_details[0]) && !is_port($ip_details[1])) { + $input_errors[] = gettext("A valid IP address and port must be specified, for example 192.168.100.10@5353."); + } + } elseif (!is_ipaddr($pconfig['ip'])) { + $input_errors[] = gettext("A valid IP address must be specified, for example 192.168.100.10."); + } + } - if (isset($id) && $a_domainOverrides[$id]) + if (count($input_errors) == 0) { + $doment = array(); + $doment['domain'] = $pconfig['domain']; + $doment['ip'] = $pconfig['ip']; + $doment['descr'] = $pconfig['descr']; + + if (isset($id)) { $a_domainOverrides[$id] = $doment; - else + } else { $a_domainOverrides[] = $doment; + } mark_subsystem_dirty('unbound'); - write_config(); - header("Location: services_unbound_overrides.php"); exit; } } $service_hook = 'unbound'; - +legacy_html_escape_form_data($pconfig); include("head.inc"); - ?> - - - - - -
- -
- -
- - 0) print_input_errors($input_errors); ?> - -
- -
- -
- -
- - - - - - - - - - - - - - - - - - -
-
- -
- mycompany.localdomain 1.168.192.in-addr.arpa -
-
-
- -
- 192.168.100.100
-
-
-
-
- - - -
  - " /> - " onclick="window.location.href=''" /> - - - -
-
-
-
-
-
-
-
- + +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
  + " /> + " onclick="window.location.href=''" /> + + + +
+
+
+
+
+
+
+