From 12353e8f74058d196b4fa3bb7810951280edc721 Mon Sep 17 00:00:00 2001 From: Manuel Faux Date: Thu, 10 Dec 2015 18:38:10 +0100 Subject: [PATCH 1/6] unbound: Separated DNS overrides from General settings Put Host and Domain Overrides to separate configuration section of unbound DNS resolver. --- .../app/models/OPNsense/Base/Menu/Menu.xml | 5 +- src/www/services_unbound.php | 153 ----------- .../services_unbound_domainoverride_edit.php | 4 +- src/www/services_unbound_host_edit.php | 4 +- src/www/services_unbound_overrides.php | 241 ++++++++++++++++++ 5 files changed, 248 insertions(+), 159 deletions(-) create mode 100644 src/www/services_unbound_overrides.php diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml index 34eef0c74..e90ad6241 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml @@ -235,10 +235,11 @@ - + + - + diff --git a/src/www/services_unbound.php b/src/www/services_unbound.php index 22c18b25f..a28c415e1 100644 --- a/src/www/services_unbound.php +++ b/src/www/services_unbound.php @@ -38,14 +38,6 @@ if (!is_array($config['unbound'])) $config['unbound'] = array(); $a_unboundcfg =& $config['unbound']; -if (!is_array($config['unbound']['hosts'])) - $config['unbound']['hosts'] = array(); -$a_hosts =& $config['unbound']['hosts']; - -if (!is_array($config['unbound']['domainoverrides'])) - $config['unbound']['domainoverrides'] = array(); -$a_domainOverrides = &$config['unbound']['domainoverrides']; - if (isset($config['unbound']['enable'])) $pconfig['enable'] = true; if (isset($config['unbound']['dnssec'])) @@ -141,26 +133,6 @@ if ($_POST) { } } -if ($_GET['act'] == "del") { - if ($_GET['type'] == 'host') { - if ($a_hosts[$_GET['id']]) { - unset($a_hosts[$_GET['id']]); - write_config(); - mark_subsystem_dirty('unbound'); - header("Location: services_unbound.php"); - exit; - } - } elseif ($_GET['type'] == 'doverride') { - if ($a_domainOverrides[$_GET['id']]) { - unset($a_domainOverrides[$_GET['id']]); - write_config(); - mark_subsystem_dirty('unbound'); - header("Location: services_unbound.php"); - exit; - } - } -} - $closehead = false; $pgtitle = array(gettext('Services'), gettext('DNS Resolver'), gettext('General')); include_once("head.inc"); @@ -361,131 +333,6 @@ function show_advanced_dns() { -
- -
- -
-

-
- -
- - -
-
-
- - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-
-   - -   - -   - -   - - - - - - -
')" class="btn btn-default btn-xs">
-
- -
-
-
- -
- -
- -
- -
-

-
- -
-

-
- -
-
- - - - - - - - - - - - - - - - - - - - -
- - - - - -
-
-   - -   - -   - - - - - - -
')" class="btn btn-default btn-xs">
-
-
-
-
-
diff --git a/src/www/services_unbound_domainoverride_edit.php b/src/www/services_unbound_domainoverride_edit.php index 4c40a6fc7..dfa13b323 100644 --- a/src/www/services_unbound_domainoverride_edit.php +++ b/src/www/services_unbound_domainoverride_edit.php @@ -31,7 +31,7 @@ require_once("guiconfig.inc"); require_once("services.inc"); require_once("interfaces.inc"); -$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound.php'); +$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound_overrides.php'); if (!is_array($config['unbound']['domainoverrides'])) $config['unbound']['domainoverrides'] = array(); @@ -95,7 +95,7 @@ if ($_POST) { write_config(); - header("Location: services_unbound.php"); + header("Location: services_unbound_overrides.php"); exit; } } diff --git a/src/www/services_unbound_host_edit.php b/src/www/services_unbound_host_edit.php index d2396fb99..17e5d9488 100644 --- a/src/www/services_unbound_host_edit.php +++ b/src/www/services_unbound_host_edit.php @@ -32,7 +32,7 @@ require_once("guiconfig.inc"); require_once("services.inc"); require_once("interfaces.inc"); -$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound.php'); +$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound_overrides.php'); function hostcmp($a, $b) { return strcasecmp($a['host'], $b['host']); @@ -150,7 +150,7 @@ if ($_POST) { write_config(); - header("Location: services_unbound.php"); + header("Location: services_unbound_overrides.php"); exit; } } diff --git a/src/www/services_unbound_overrides.php b/src/www/services_unbound_overrides.php new file mode 100644 index 000000000..dffc2a6f5 --- /dev/null +++ b/src/www/services_unbound_overrides.php @@ -0,0 +1,241 @@ + + + + + + +
+
+
+ + 0) print_input_errors($input_errors); ?> + +
+ " . gettext("You must apply the changes in order for them to take effect."));?>
+ + +
+ +
+ +
+ +
+

+
+ +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+   + +   + +   + +   + + + + + + +
')" class="btn btn-default btn-xs">
+
+ +
+
+
+ +
+ +
+ +
+ +
+

+
+ +
+

+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+   + +   + +   + + + + + + +
')" class="btn btn-default btn-xs">
+
+
+
+
+
+
+ +
+
+
+ + + + From 75ce22549fa6d819e4d24ad1af771a7bac9b1cdc Mon Sep 17 00:00:00 2001 From: Manuel Faux Date: Thu, 10 Dec 2015 18:47:29 +0100 Subject: [PATCH 2/6] unbound: fixed UX on domain overrides Added double click to edit domain override entry. --- src/www/services_unbound_overrides.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/www/services_unbound_overrides.php b/src/www/services_unbound_overrides.php index dffc2a6f5..6b2e06395 100644 --- a/src/www/services_unbound_overrides.php +++ b/src/www/services_unbound_overrides.php @@ -200,13 +200,13 @@ include_once("head.inc"); - +   - +   - +   From c632424ec759996f77bea2592352ea243950ec02 Mon Sep 17 00:00:00 2001 From: Manuel Faux Date: Thu, 10 Dec 2015 23:25:45 +0100 Subject: [PATCH 3/6] unbound: Added different DNS RRs to be overwritten Added the possibility to overwrite MX records by unbound DNS resolver. --- src/etc/inc/unbound.inc | 24 +++-- src/www/services_unbound_host_edit.php | 118 +++++++++++++++++++++++-- src/www/services_unbound_overrides.php | 32 ++++++- 3 files changed, 158 insertions(+), 16 deletions(-) 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"); - + + + +
+ A AAAA
+ + + +

192.168.100.100 fd00:abcd::1
+ + + +
+
+ 10
+ + + + + +
+
+ mail.example.com
+ + @@ -306,4 +405,9 @@ include("head.inc"); + diff --git a/src/www/services_unbound_overrides.php b/src/www/services_unbound_overrides.php index 6b2e06395..2c4227771 100644 --- a/src/www/services_unbound_overrides.php +++ b/src/www/services_unbound_overrides.php @@ -41,6 +41,13 @@ if (!is_array($config['unbound']['hosts'])) $config['unbound']['hosts'] = array(); $a_hosts =& $config['unbound']['hosts']; +/* Backwards compatibility for records created before introducing RR types. */ +foreach ($a_hosts as $i => $hostent) { + if (!isset($hostent['rr'])) { + $a_hosts[$i]['rr'] = (is_ipaddrv6($hostent['ip'])) ? 'AAAA' : 'A'; + } +} + if (!is_array($config['unbound']['domainoverrides'])) $config['unbound']['domainoverrides'] = array(); $a_domainOverrides = &$config['unbound']['domainoverrides']; @@ -112,6 +119,7 @@ include_once("head.inc");
+
@@ -119,8 +127,9 @@ include_once("head.inc"); - - + + + @@ -142,7 +151,24 @@ include_once("head.inc");   +
-   +   + +   From 920217e1044fb03066e3f8cf5abde0f285d3d669 Mon Sep 17 00:00:00 2001 From: Manuel Faux Date: Fri, 11 Dec 2015 14:35:57 +0100 Subject: [PATCH 4/6] unbound: Corrected copyright notes --- src/etc/inc/unbound.inc | 1 + src/www/services_unbound_host_edit.php | 1 + src/www/services_unbound_overrides.php | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/etc/inc/unbound.inc b/src/etc/inc/unbound.inc index 56a133897..79cce8a9d 100644 --- a/src/etc/inc/unbound.inc +++ b/src/etc/inc/unbound.inc @@ -1,6 +1,7 @@ Copyright (C) 2014 Warren Baker All rights reserved. diff --git a/src/www/services_unbound_host_edit.php b/src/www/services_unbound_host_edit.php index 6830b0a1b..15df83633 100644 --- a/src/www/services_unbound_host_edit.php +++ b/src/www/services_unbound_host_edit.php @@ -1,6 +1,7 @@ Copyright (C) 2014-2015 Deciso B.V. Copyright (C) 2014 Warren Baker Copyright (C) 2003-2004 Bob Zoller and Manuel Kasper . diff --git a/src/www/services_unbound_overrides.php b/src/www/services_unbound_overrides.php index 2c4227771..8233560c8 100644 --- a/src/www/services_unbound_overrides.php +++ b/src/www/services_unbound_overrides.php @@ -1,7 +1,9 @@ Copyright (C) 2014-2015 Deciso B.V. + Copyright (C) 2014 Warren Baker All rights reserved. Redistribution and use in source and binary forms, with or without From 23c805dc544dbcdff3fa4055facd58d95f84996d Mon Sep 17 00:00:00 2001 From: Manuel Faux Date: Fri, 11 Dec 2015 14:37:53 +0100 Subject: [PATCH 5/6] unbound: Fixed inconsistent code formatting --- src/www/services_unbound_host_edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www/services_unbound_host_edit.php b/src/www/services_unbound_host_edit.php index 15df83633..c27c34a1c 100644 --- a/src/www/services_unbound_host_edit.php +++ b/src/www/services_unbound_host_edit.php @@ -104,7 +104,7 @@ if ($_POST) { $input_errors[] = gettext("A valid IP address must be specified."); } break; - case 'MX': + case 'MX': $reqdfields = explode(" ", "mxprio mx"); $reqdfieldsn = array(gettext("MX Priority"), gettext("MX Host")); From 57b8d60d59f6034da9247ad3c47b05423374b0a5 Mon Sep 17 00:00:00 2001 From: Manuel Faux Date: Fri, 8 Jan 2016 08:55:54 +0100 Subject: [PATCH 6/6] unbound: removed no-duplicate host restriction Previously it was not possible to add two host override entries for the same host-domain combination. Technically this restriction does not exist neither within unbound nor DNS. --- src/etc/inc/unbound.inc | 41 +++++++++++--------------- src/www/services_unbound_host_edit.php | 12 -------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/etc/inc/unbound.inc b/src/etc/inc/unbound.inc index 79cce8a9d..d114d821f 100644 --- a/src/etc/inc/unbound.inc +++ b/src/etc/inc/unbound.inc @@ -515,32 +515,27 @@ function unbound_add_host_entries() { $host_entries = ""; $added_item = array(); foreach($config['unbound']['hosts'] as $host) { - $current_host = $host['host']; - if ($host['host'] != "") + if ($host['host'] != "") { $host['host'] = $host['host']."."; - if (!$added_item[$current_host]) { - /* Backwards compatibility for records created before introducing RR types. */ - if (!isset($host['rr'])) { - $host['rr'] = (is_ipaddrv6($host['ip'])) ? 'AAAA' : 'A'; - } + } + /* 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; - } + 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; + if (!empty($host['descr']) && isset($config['unbound']['txtsupport'])) { + $host_entries .= "local-data: '{$host['host']}{$host['domain']} TXT \"".addslashes($host['descr'])."\"'\n"; } } $unbound_entries .= $host_entries; diff --git a/src/www/services_unbound_host_edit.php b/src/www/services_unbound_host_edit.php index c27c34a1c..bbdfad1e9 100644 --- a/src/www/services_unbound_host_edit.php +++ b/src/www/services_unbound_host_edit.php @@ -158,18 +158,6 @@ if ($_POST) { $input_errors[] = gettext("A valid domain must be specified in alias list."); } - /* check for overlaps */ - foreach ($a_hosts as $hostent) { - if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent)) - continue; - - if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain']) - && ((is_ipaddrv4($hostent['ip']) && is_ipaddrv4($_POST['ip'])) || (is_ipaddrv6($hostent['ip']) && is_ipaddrv6($_POST['ip'])))) { - $input_errors[] = gettext("This host/domain already exists."); - break; - } - } - if (!$input_errors) { $hostent = array(); $hostent['host'] = $_POST['host'];