diff --git a/src/www/services_unbound_host_edit.php b/src/www/services_unbound_host_edit.php index ce4c9bb58..9a310b931 100644 --- a/src/www/services_unbound_host_edit.php +++ b/src/www/services_unbound_host_edit.php @@ -1,406 +1,278 @@ - Copyright (C) 2014-2015 Deciso B.V. - Copyright (C) 2014 Warren Baker - Copyright (C) 2003-2004 Bob Zoller and Manuel Kasper . - All rights reserved. + Copyright (C) 2015 Manuel Faux + Copyright (C) 2014-2016 Deciso B.V. + Copyright (C) 2014 Warren Baker + Copyright (C) 2003-2004 Bob Zoller and Manuel Kasper . + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once("services.inc"); require_once("interfaces.inc"); -$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound_overrides.php'); function hostcmp($a, $b) { - return strcasecmp($a['host'], $b['host']); + return strcasecmp($a['host'], $b['host']); } -function hosts_sort() -{ - global $config; - - if (!isset($config['unbound']['hosts'])) { - return; - } - - usort($config['unbound']['hosts'], "hostcmp"); +if (empty($config['unbound']['hosts']) || !is_array($config['unbound']['hosts'])) { + $config['unbound']['hosts'] = array(); } - -if (!is_array($config['unbound']['hosts'])) - $config['unbound']['hosts'] = array(); - $a_hosts = &$config['unbound']['hosts']; -if (is_numericint($_GET['id'])) - $id = $_GET['id']; -if (isset($_POST['id']) && is_numericint($_POST['id'])) - $id = $_POST['id']; +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['id']) && !empty($a_hosts[$_GET['id']])) { + $id = $_GET['id']; + } + $pconfig = array(); + foreach (array('rr', 'host', 'domain', 'ip', 'mxprio', 'mx', 'descr') as $fieldname) { + if (isset($id) && !empty($a_hosts[$id][$fieldname])) { + $pconfig[$fieldname] = $a_hosts[$id][$fieldname]; + } else { + $pconfig[$fieldname] = null; + } + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['id']) && !empty($a_hosts[$_POST['id']])) { + $id = $_POST['id']; + } -if (isset($id) && $a_hosts[$id]) { -/* Backwards compatibility for records created before introducing different RR types. */ - if (!isset($a_hosts[$id]['rr'])) { - $a_hosts[$id]['rr'] = 'A'; - } + $input_errors = array(); + $pconfig = $_POST; - $pconfig['host'] = $a_hosts[$id]['host']; - $pconfig['domain'] = $a_hosts[$id]['domain']; - $pconfig['rr'] = $a_hosts[$id]['rr']; - $pconfig['ip'] = $a_hosts[$id]['ip']; - $pconfig['mxprio'] = $a_hosts[$id]['mxprio']; - $pconfig['mx'] = $a_hosts[$id]['mx']; - $pconfig['descr'] = $a_hosts[$id]['descr']; - $pconfig['aliases'] = $a_hosts[$id]['aliases']; -} + /* input validation */ + $reqdfields = explode(" ", "domain rr"); + $reqdfieldsn = array(gettext("Domain"),gettext("Type")); -if ($_POST) { + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); - unset($input_errors); - $pconfig = $_POST; + if (!empty($pconfig['host']) && !is_hostname($pconfig['host'])) { + $input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'."); + } - /* input validation */ - $reqdfields = explode(" ", "domain rr"); - $reqdfieldsn = array(gettext("Domain"),gettext("Type")); + if (!empty($pconfig['domain']) && !is_domain($pconfig['domain'])) { + $input_errors[] = gettext("A valid domain must be specified."); + } - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); + switch ($pconfig['rr']) { + case 'A': /* also: AAAA */ + $reqdfields = explode(" ", "ip"); + $reqdfieldsn = array(gettext("IP address")); + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); - if (($_POST['host'] && !is_hostname($_POST['host']))) { - $input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'."); - } + if (!empty($pconfig['ip']) && !is_ipaddr($pconfig['ip'])) { + $input_errors[] = gettext("A valid IP address must be specified."); + } + break; + case 'MX': + $reqdfields = explode(" ", "mxprio mx"); + $reqdfieldsn = array(gettext("MX Priority"), gettext("MX Host")); + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); - if (($_POST['domain'] && !is_domain($_POST['domain']))) { - $input_errors[] = gettext("A valid domain must be specified."); - } + if (!empty($pconfig['mxprio']) && !is_numericint($pconfig['mxprio'])) { + $input_errors[] = gettext("A valid MX priority must be specified."); + } - switch ($_POST['rr']) { - case 'A': /* also: AAAA */ - $reqdfields = explode(" ", "ip"); - $reqdfieldsn = array(gettext("IP address")); + if (!empty($pconfig['mx']) && !is_domain($pconfig['mx'])) { + $input_errors[] = gettext("A valid MX host must be specified."); + } + break; + default: + $input_errors[] = gettext("A valid resource record type must be specified."); + break; + } + if (count($input_errors) == 0) { + $hostent = array(); + $hostent['host'] = $pconfig['host']; + $hostent['domain'] = $pconfig['domain']; + /* Destinguish between A and AAAA by parsing the passed IP address */ + $hostent['rr'] = $pconfig['rr'] == "A" && is_ipaddrv6($pconfig['ip']) ? "AAA" : $pconfig['rr']; + $hostent['ip'] = $pconfig['ip']; + $hostent['mxprio'] = $pconfig['mxprio']; + $hostent['mx'] = $pconfig['mx']; + $hostent['descr'] = $pconfig['descr']; - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); + if (isset($id)) { + $a_hosts[$id] = $hostent; + } else { + $a_hosts[] = $hostent; + } - if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) { - $input_errors[] = gettext("A valid IP address must be specified."); - } - break; - case 'MX': - $reqdfields = explode(" ", "mxprio mx"); - $reqdfieldsn = array(gettext("MX Priority"), gettext("MX Host")); + usort($a_hosts, "hostcmp"); + mark_subsystem_dirty('unbound'); + write_config(); + header("Location: services_unbound_overrides.php"); + exit; + } - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - if (($_POST['mxprio'] && !is_numericint($_POST['mxprio']))) { - $input_errors[] = gettext("A valid MX priority must be specified."); - } - - if (($_POST['mx'] && !is_domain($_POST['mx']))) { - $input_errors[] = gettext("A valid MX host must be specified."); - } - break; - default: - $input_errors[] = gettext("A valid resource record type must be specified."); - break; - } - - /* collect aliases */ - $aliases = array(); - foreach ($_POST as $key => $value) { - $entry = ''; - if (!substr_compare('aliashost', $key, 0, 9)) { - $entry = substr($key, 9); - $field = 'host'; - } - elseif (!substr_compare('aliasdomain', $key, 0, 11)) { - $entry = substr($key, 11); - $field = 'domain'; - } - elseif (!substr_compare('aliasdescription', $key, 0, 16)) { - $entry = substr($key, 16); - $field = 'description'; - } - if (ctype_digit($entry)) { - $aliases[$entry][$field] = $value; - } - } - $pconfig['aliases']['item'] = $aliases; - - /* validate aliases */ - foreach ($aliases as $idx => $alias) { - $aliasreqdfields = array('aliasdomain' . $idx); - $aliasreqdfieldsn = array(gettext("Alias Domain")); - - var_dump(array('fields' => $aliasreqdfields, 'names' => $aliasreqdfieldsn, 'alias' => $alias)); - do_input_validation($_POST, $aliasreqdfields, $aliasreqdfieldsn, $input_errors); - if (($alias['host'] && !is_hostname($alias['host']))) - $input_errors[] = gettext("Hostnames in alias list can only contain the characters A-Z, 0-9 and '-'."); - if (($alias['domain'] && !is_domain($alias['domain']))) - $input_errors[] = gettext("A valid domain must be specified in alias list."); - } - - if (!$input_errors) { - $hostent = array(); - $hostent['host'] = $_POST['host']; - $hostent['domain'] = $_POST['domain']; - $hostent['rr'] = $_POST['rr']; - $hostent['ip'] = $_POST['ip']; - $hostent['mxprio'] = $_POST['mxprio']; - $hostent['mx'] = $_POST['mx']; - $hostent['descr'] = $_POST['descr']; - $hostent['aliases']['item'] = $aliases; - - /* Destinguish between A and AAAA by parsing the passed IP address */ - if ($_POST['rr'] == 'A') { - if (is_ipaddrv6($_POST['ip'])) { - $hostent['rr'] = 'AAAA'; - } - } - - if (isset($id) && $a_hosts[$id]) - $a_hosts[$id] = $hostent; - else - $a_hosts[] = $hostent; - hosts_sort(); - - 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); ?> - -
- -
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
-
-
-
- -
- A AAAA
-
-
-
- 192.168.100.100 fd00:abcd::1
-
-
-
- 10
-
-
-
- mail.example.com
-
-
- -
- - - - - - - - - - - - - - - - - - - -
-
- -
-
- - - - - - - -
- - -
  - " /> - " onclick="window.location.href=''" /> - - - -
-
-
-
-
-
-
-
- + + +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
  + " /> + " onclick="window.location.href=''" /> + + + +
+
+
+
+
+
+
+