diff --git a/src/etc/inc/unbound.inc b/src/etc/inc/unbound.inc index 7ab7ed4a3..56a133897 100644 --- a/src/etc/inc/unbound.inc +++ b/src/etc/inc/unbound.inc @@ -518,13 +518,25 @@ function unbound_add_host_entries() { if ($host['host'] != "") $host['host'] = $host['host']."."; if (!$added_item[$current_host]) { - $host_entries .= "local-data-ptr: \"{$host['ip']} {$host['host']}{$host['domain']}\"\n"; - if (is_ipaddrv6($host['ip'])) - $host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN AAAA {$host['ip']}\"\n"; - else - $host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN A {$host['ip']}\"\n"; - if (!empty($host['descr']) && isset($config['unbound']['txtsupport'])) + /* Backwards compatibility for records created before introducing RR types. */ + if (!isset($host['rr'])) { + $host['rr'] = (is_ipaddrv6($host['ip'])) ? 'AAAA' : 'A'; + } + + switch ($host['rr']) { + case 'A': + case 'AAAA': + $host_entries .= "local-data-ptr: \"{$host['ip']} {$host['host']}{$host['domain']}\"\n"; + $host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN {$host['rr']} {$host['ip']}\"\n"; + break; + case 'MX': + $host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN MX {$host['mxprio']} {$host['mx']}\"\n"; + break; + } + + if (!empty($host['descr']) && isset($config['unbound']['txtsupport'])) { $host_entries .= "local-data: '{$host['host']}{$host['domain']} TXT \"".addslashes($host['descr'])."\"'\n"; + } // Do not add duplicate entries $added_item[$current_host] = true; diff --git a/src/www/services_unbound_host_edit.php b/src/www/services_unbound_host_edit.php index 17e5d9488..b62c3575a 100644 --- a/src/www/services_unbound_host_edit.php +++ b/src/www/services_unbound_host_edit.php @@ -58,9 +58,17 @@ if (isset($_POST['id']) && is_numericint($_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'; + } + $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']; } @@ -71,19 +79,48 @@ if ($_POST) { $pconfig = $_POST; /* input validation */ - $reqdfields = explode(" ", "domain ip"); - $reqdfieldsn = array(gettext("Domain"),gettext("IP address")); + $reqdfields = explode(" ", "domain rr"); + $reqdfieldsn = array(gettext("Domain"),gettext("Type")); do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - if (($_POST['host'] && !is_hostname($_POST['host']))) + if (($_POST['host'] && !is_hostname($_POST['host']))) { $input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'."); + } - if (($_POST['domain'] && !is_domain($_POST['domain']))) + if (($_POST['domain'] && !is_domain($_POST['domain']))) { $input_errors[] = gettext("A valid domain must be specified."); + } - if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) - $input_errors[] = gettext("A valid IP address must be specified."); + switch ($_POST['rr']) { + case 'A': /* also: AAAA */ + $reqdfields = explode(" ", "ip"); + $reqdfieldsn = array(gettext("IP address")); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); + + 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")); + + 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(); @@ -136,10 +173,20 @@ if ($_POST) { $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 @@ -175,6 +222,25 @@ include("head.inc"); rowname[2] = "aliasdescription"; rowtype[2] = "textbox"; rowsize[2] = "20"; + + function type_change() { + switch (jQuery('#rr').val()) { + case 'A': + jQuery('#ip').prop('disabled', false); + jQuery('#mxprio').prop('disabled', true); + jQuery('#mx').prop('disabled', true); + break; + case 'MX': + jQuery('#ip').prop('disabled', true); + jQuery('#mxprio').prop('disabled', false); + jQuery('#mx').prop('disabled', false); + break; + default: + jQuery('#ip').prop('disabled', false); + jQuery('#mxprio').prop('disabled', false); + jQuery('#mx').prop('disabled', false); + } + } //]]> @@ -216,13 +282,46 @@ include("head.inc");
| - =$hostent['ip'];?> + =strtoupper($hostent['rr']);?> + | ++ | =htmlspecialchars($hostent['descr']);?> |