diff --git a/plist b/plist index 680a54b69..adfb24c63 100644 --- a/plist +++ b/plist @@ -415,6 +415,7 @@ /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/DnsblController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/DotController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/ForwardController.php +/usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/GeneralController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/OverridesController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/OverviewController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/StatsController.php @@ -425,6 +426,7 @@ /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dialogHostOverride.xml /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dnsbl.xml /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/forwarding.xml +/usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/general.xml /usr/local/opnsense/mvc/app/library/Google/API/Drive.php /usr/local/opnsense/mvc/app/library/OPNsense/Auth/API.php /usr/local/opnsense/mvc/app/library/OPNsense/Auth/AuthenticationFactory.php @@ -654,12 +656,14 @@ /usr/local/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.xml /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/ACL/ACL.xml /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/FieldTypes/UnboundDomainField.php +/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/FieldTypes/UnboundInterfaceField.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/FieldTypes/UnboundServerField.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Menu/Menu.xml /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_0.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_1.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_2.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_3.php +/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_5.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.php /usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml /usr/local/opnsense/mvc/app/views/OPNsense/CaptivePortal/clients.volt @@ -718,6 +722,7 @@ /usr/local/opnsense/mvc/app/views/OPNsense/Unbound/advanced.volt /usr/local/opnsense/mvc/app/views/OPNsense/Unbound/dnsbl.volt /usr/local/opnsense/mvc/app/views/OPNsense/Unbound/dot.volt +/usr/local/opnsense/mvc/app/views/OPNsense/Unbound/general.volt /usr/local/opnsense/mvc/app/views/OPNsense/Unbound/overrides.volt /usr/local/opnsense/mvc/app/views/OPNsense/Unbound/overview.volt /usr/local/opnsense/mvc/app/views/OPNsense/Unbound/stats.volt @@ -1952,7 +1957,6 @@ /usr/local/www/services_ntpd_pps.php /usr/local/www/services_opendns.php /usr/local/www/services_router_advertisements.php -/usr/local/www/services_unbound.php /usr/local/www/services_unbound_acls.php /usr/local/www/status_dhcp_leases.php /usr/local/www/status_dhcpv6_leases.php diff --git a/src/etc/inc/plugins.inc.d/dhcpd.inc b/src/etc/inc/plugins.inc.d/dhcpd.inc index 9ddb79990..4389b8299 100644 --- a/src/etc/inc/plugins.inc.d/dhcpd.inc +++ b/src/etc/inc/plugins.inc.d/dhcpd.inc @@ -169,6 +169,8 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = []) /* Process all links which need the router advertise daemon */ $radvdifs = array(); + $unbound_enabled = !empty((string)(new \OPNsense\Unbound\Unbound())->general->enabled); + /* handle manually configured DHCP6 server settings first */ foreach (config_read_array('dhcpdv6') as $dhcpv6if => $dhcpv6ifconf) { if (isset($config['interfaces'][$dhcpv6if]['track6-interface']) && !isset($config['interfaces'][$dhcpv6if]['dhcpd6track6allowoverride'])) { @@ -353,7 +355,7 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = []) $dnslist_tmp = $dhcpv6ifconf['dnsserver']; } elseif (!isset($dhcpv6ifconf['rasamednsasdhcp6']) && !empty($dhcpv6ifconf['radnsserver'][0])) { $dnslist_tmp = $dhcpv6ifconf['radnsserver']; - } elseif (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable'])) { + } elseif (isset($config['dnsmasq']['enable']) || $unbound_enabled) { if (is_ipaddrv6($ifcfgipv6)) { $dnslist_tmp[] = $ifcfgipv6; } else { @@ -448,7 +450,7 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = []) $networkv6 = '::/64'; } - if (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable'])) { + if (isset($config['dnsmasq']['enable']) || $unbound_enabled) { if (is_ipaddrv6($ifcfgipv6)) { $dnslist[] = $ifcfgipv6; } else { @@ -686,6 +688,7 @@ EOPP; $iflist = get_configured_interface_with_descr(); $gwObject = new \OPNsense\Routing\Gateways($ifconfig_details); + $unbound_enabled = !empty((string)(new \OPNsense\Unbound\Unbound())->general->enabled); foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) { if (!isset($dhcpifconf['enable']) || !isset($iflist[$dhcpif])) { @@ -743,7 +746,7 @@ EOPP; if (!empty($newzone['domain-name'])) { $newzone['dns-servers'] = $dhcpifconf['dnsserver']; } - } elseif (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable'])) { + } elseif (isset($config['dnsmasq']['enable']) || $unbound_enabled) { $dnscfg .= " option domain-name-servers {$ifcfgip};"; if (!empty($newzone['domain-name'])) { $newzone['dns-servers'] = [$ifcfgip]; @@ -1409,6 +1412,8 @@ EOD; $ddns_zones = []; $need_ddns_updates = false; + $unbound_enabled = !empty((string)(new \OPNsense\Unbound\Unbound())->general->enabled); + foreach ($dhcpdv6cfg as $dhcpv6if => $dhcpv6ifconf) { if (!isset($dhcpv6ifconf['enable']) || !isset($iflist[$dhcpv6if])) { continue; @@ -1459,7 +1464,7 @@ EOD; if (isset($dhcpv6ifconf['dnsserver'][0])) { $dnscfgv6 .= " option dhcp6.name-servers " . join(",", $dhcpv6ifconf['dnsserver']) . ";"; - } elseif (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable'])) { + } elseif (isset($config['dnsmasq']['enable']) || $unbound_enabled) { $dnscfgv6 .= " option dhcp6.name-servers {$ifcfgipv6};"; } elseif (!empty($dns_arrv6)) { $dnscfgv6 .= " option dhcp6.name-servers " . join(",", $dns_arrv6) . ";"; diff --git a/src/etc/inc/plugins.inc.d/unbound.inc b/src/etc/inc/plugins.inc.d/unbound.inc index 45cfc3374..2e496ca31 100644 --- a/src/etc/inc/plugins.inc.d/unbound.inc +++ b/src/etc/inc/plugins.inc.d/unbound.inc @@ -32,9 +32,8 @@ function unbound_enabled() { - global $config; - - return isset($config['unbound']['enable']); + $mdl = new \OPNsense\Unbound\Unbound(); + return !empty((string)$mdl->general->enabled); } function unbound_configure() @@ -103,11 +102,11 @@ function unbound_optimization() function unbound_service_stop() { - global $config; + $mdl = new \OPNsense\Unbound\Unbound(); mwexec('/usr/local/bin/flock -E 0 -o /tmp/unbound_start.lock true'); - if (empty($config['unbound']['cacheflush'])) { + if (empty((string)$mdl->general->cacheflush)) { if (isvalidpid('/var/run/unbound.pid')) { configd_run('unbound cache dump'); } @@ -115,9 +114,9 @@ function unbound_service_stop() unbound_cache_flush(); } - killbypid('/var/run/unbound_logger.pid', 'TERM', true); - killbypid('/var/run/unbound_dhcpd.pid', 'TERM', true); - killbypid('/var/run/unbound.pid', 'TERM', true); + killbypid('/var/run/unbound_logger.pid'); + killbypid('/var/run/unbound_dhcpd.pid'); + killbypid('/var/run/unbound.pid'); mwexecf('/sbin/umount %s', '/var/unbound/dev', true); mwexecf('/sbin/umount %s', '/var/unbound/usr/local/lib/' . readlink('/usr/local/bin/python3'), true); @@ -126,6 +125,7 @@ function unbound_service_stop() function unbound_generate_config() { global $config; + $general = config_read_array('OPNsense', 'unboundplus', 'general'); $pythonv = readlink('/usr/local/bin/python3'); $python_dir = "/usr/local/lib/{$pythonv}"; @@ -146,17 +146,17 @@ function unbound_generate_config() $anchor_file = ''; $dns64_config = ''; - if (isset($config['unbound']['dns64'])) { - if (!empty($config['unbound']['dns64prefix'])) { - $dns64_config .= "\ndns64-prefix: {$config['unbound']['dns64prefix']}"; + if (!empty($general['dns64'])) { + if (!empty($general['dns64prefix'])) { + $dns64_config .= "\ndns64-prefix: {$general['dns64prefix']}"; } - if (isset($config['unbound']['noarecords'])) { + if (!empty($general['noarecords'])) { $module_config .= 'respip '; $dns64_config .= "\nresponse-ip: 0.0.0.0/0 redirect"; } $module_config .= 'dns64 '; } - if (isset($config['unbound']['dnssec'])) { + if (!empty($general['dnssec'])) { $module_config .= 'validator iterator'; $anchor_file = 'auto-trust-anchor-file: /var/unbound/root.key'; } else { @@ -174,8 +174,8 @@ function unbound_generate_config() } $bindints = ''; - if (!empty($config['unbound']['active_interface'])) { - $active_interfaces = explode(',', $config['unbound']['active_interface']); + if (!empty($general['active_interface'])) { + $active_interfaces = explode(',', $general['active_interface']); $active_interfaces[] = 'lo0'; $addresses = array(); @@ -203,9 +203,9 @@ function unbound_generate_config() $outgoingints = ''; $ifconfig_details = legacy_interfaces_details(); - if (!empty($config['unbound']['outgoing_interface'])) { + if (!empty($general['outgoing_interface'])) { $outgoingints = "# Outgoing interfaces to be used\n"; - $outgoing_interfaces = explode(",", $config['unbound']['outgoing_interface']); + $outgoing_interfaces = explode(",", $general['outgoing_interface']); foreach ($outgoing_interfaces as $outif) { $outip = get_interface_ip($outif, $ifconfig_details); if (!empty($outip)) { @@ -221,12 +221,12 @@ function unbound_generate_config() unbound_add_host_entries($ifconfig_details); unbound_acls_config(); - $port = is_port($config['unbound']['port'] ?? null) ? $config['unbound']['port'] : '53'; + $port = $general['port'] ?? '53'; /* do not touch prefer-ip6 as it is defaulting to 'no' anyway */ $do_ip6 = isset($config['system']['ipv6allow']) ? 'yes' : 'no'; - if (isset($config['unbound']['regdhcp'])) { + if (!empty($general['regdhcp'])) { $include_dhcpleases = 'include: /var/unbound/dhcpleases.conf'; @touch('/var/unbound/dhcpleases.conf'); } else { @@ -352,6 +352,7 @@ function unbound_cache_flush() function unbound_configure_do($verbose = false, $unused = '') { global $config; + $mdl = new \OPNsense\Unbound\Unbound(); unbound_service_stop(); @@ -364,15 +365,14 @@ function unbound_configure_do($verbose = false, $unused = '') unbound_generate_config(); $domain = ''; - - if (isset($config['unbound']['regdhcp'])) { + if (!empty((string)$mdl->general->regdhcp)) { $domain = $config['system']['domain']; - if (isset($config['unbound']['regdhcpdomain'])) { - $domain = $config['unbound']['regdhcpdomain']; + if (!empty((string)$mdl->general->regdhcpdomain)) { + $domain = (string)$mdl->general->regdhcpdomain; } } - if (isset($config['unbound']['stats'])) { + if (isset($config['unbound']['stats'])) { /* XXX */ @touch('/var/unbound/data/stats'); } else { @unlink('/var/unbound/data/stats'); @@ -388,15 +388,13 @@ function unbound_configure_do($verbose = false, $unused = '') function unbound_add_host_entries($ifconfig_details = null) { global $config; + $general = config_read_array('OPNsense', 'unboundplus', 'general'); - $local_zone_type = 'transparent'; $ptr_records = ['127.0.0.1', '::1']; openlog("unbound", LOG_DAEMON, LOG_LOCAL4); - if (!empty($config['unbound']['local_zone_type'])) { - $local_zone_type = $config['unbound']['local_zone_type']; - } + $local_zone_type = $general['local_zone_type'] ?? 'transparent'; $unbound_entries = "local-zone: \"{$config['system']['domain']}\" {$local_zone_type}\n"; @@ -408,13 +406,13 @@ function unbound_add_host_entries($ifconfig_details = null) $unbound_entries .= "local-data: \"localhost AAAA ::1\"\n"; $unbound_entries .= "local-data: \"localhost.{$config['system']['domain']} AAAA ::1\"\n"; - if (!empty($config['unbound']['active_interface'])) { - $interfaces = explode(",", $config['unbound']['active_interface']); + if (!empty($general['active_interface'])) { + $interfaces = explode(",", $general['active_interface']); } else { $interfaces = array_keys(get_configured_interface_with_descr()); } - if (empty($config['unbound']['noregrecords'])) { + if (empty($general['noregrecords'])) { foreach ($interfaces as $interface) { if ($interface == 'lo0' || substr($interface, 0, 4) == 'ovpn') { continue; @@ -442,7 +440,7 @@ function unbound_add_host_entries($ifconfig_details = null) $unbound_entries .= "local-data: \"{$config['system']['hostname']} {$record} {$addr}\"\n"; } - if (empty($config['unbound']['noreglladdr6'])) { + if (empty($general['noreglladdr6'])) { if (!empty($lladdr6)) { /* cannot embed scope */ $lladdr6 = explode('%', $lladdr6)[0]; @@ -457,7 +455,7 @@ function unbound_add_host_entries($ifconfig_details = null) } } - if (isset($config['unbound']['enable_wpad'])) { + if (!empty($general['enable_wpad'])) { $webui_protocol = !empty($config['system']['webgui']['protocol']) ? $config['system']['webgui']['protocol'] : 'https'; $webui_port = !empty($config['system']['webgui']['port']) ? $config['system']['webgui']['port'] : 443; // default domain @@ -537,7 +535,7 @@ function unbound_add_host_entries($ifconfig_details = null) break; } - if (!empty($alias['description']) && isset($config['unbound']['txtsupport'])) { + if (!empty($alias['description']) && !empty($general['txtsupport'])) { $unbound_entries .= "local-data: '{$alias['hostname']}{$alias['domain']} TXT \"" . addslashes($alias['description']) . "\"'\n"; } } @@ -545,7 +543,7 @@ function unbound_add_host_entries($ifconfig_details = null) } } - if (isset($config['unbound']['regdhcpstatic'])) { + if (!empty($general['regdhcpstatic'])) { require_once 'plugins.inc.d/dhcpd.inc'; /* XXX */ foreach (dhcpd_staticmap($config['system']['domain'], $ifconfig_details) as $host) { @@ -560,7 +558,7 @@ function unbound_add_host_entries($ifconfig_details = null) $unbound_entries .= "local-data-ptr: \"{$host['ipaddrv6']} {$host['hostname']}.{$host['domain']}\"\n"; $unbound_entries .= "local-data: \"{$host['hostname']}.{$host['domain']} IN AAAA {$host['ipaddrv6']}\"\n"; } - if (!empty($host['descr']) && isset($config['unbound']['txtsupport'])) { + if (!empty($host['descr']) && !empty($general['txtsupport'])) { $unbound_entries .= "local-data: '{$host['hostname']}.{$host['domain']} TXT \"" . addslashes($host['descr']) . "\"'\n"; } } @@ -575,11 +573,12 @@ function unbound_add_host_entries($ifconfig_details = null) function unbound_acls_subnets() { global $config; + $general = config_read_array('OPNsense', 'unboundplus', 'general'); $any = true; - if (!empty($config['unbound']['active_interface'])) { - $active_interfaces = array_flip(explode(',', $config['unbound']['active_interface'])); + if (!empty($general['active_interface'])) { + $active_interfaces = array_flip(explode(',', $general['active_interface'])); $any = false; } else { $active_interfaces = get_configured_interface_with_descr(); @@ -651,22 +650,3 @@ function unbound_acls_config() file_put_contents('/var/unbound/access_lists.conf', $aclcfg); } - -function unbound_local_zone_types() -{ - return array( - '' => 'transparent', - 'always_nxdomain' => 'always_nxdomain', - 'always_refuse' => 'always_refuse', - 'always_transparent' => 'always_transparent', - 'deny' => 'deny', - 'inform' => 'inform', - 'inform_deny' => 'inform_deny', - 'nodefault' => 'nodefault', - # requires more plumbing: - #'redirect' => 'redirect', - 'refuse' => 'refuse', - 'static' => 'static', - 'typetransparent' => 'typetransparent', - ); -} diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index b9a9a46d9..aa66c76ad 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -202,7 +202,8 @@ function system_resolvconf_generate($verbose = false) $search[] = $syscfg['dnssearchdomain']; } - if (!isset($syscfg['dnslocalhost']) && (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable']))) { + $unbound = new \OPNsense\Unbound\Unbound(); + if (!isset($syscfg['dnslocalhost']) && (isset($config['dnsmasq']['enable']) || !empty((string)$unbound->general->enabled))) { $resolvconf .= "nameserver 127.0.0.1\n"; } diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php index eca989e1c..1e80f781b 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php @@ -36,7 +36,7 @@ class ServiceController extends ApiMutableServiceControllerBase { protected static $internalServiceClass = '\OPNsense\Unbound\Unbound'; protected static $internalServiceTemplate = 'OPNsense/Unbound/*'; - protected static $internalServiceEnabled = 'service_enabled'; + protected static $internalServiceEnabled = 'general.enabled'; protected static $internalServiceName = 'unbound'; public function dnsblAction() @@ -47,4 +47,18 @@ class ServiceController extends ApiMutableServiceControllerBase $response = $backend->configdRun(static::$internalServiceName . ' dnsbl'); return array('status' => $response); } + + /** + * Only used on the general page to account for resolver_configure and dhcp hooks + * since these check if unbound is enabled. + */ + public function reconfigureGeneralAction() + { + $this->sessionClose(); + $backend = new Backend(); + $backend->configdRun('dns reload'); + $result = $this->reconfigureAction(); + $backend->configdRun('dhcpd restart'); + return $result; + } } diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/GeneralController.php b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/GeneralController.php new file mode 100644 index 000000000..72d1ce740 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/GeneralController.php @@ -0,0 +1,40 @@ +view->generalForm = $this->getForm('general'); + $this->view->pick('OPNsense/Unbound/general'); + } +} diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/general.xml b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/general.xml new file mode 100644 index 000000000..45f09e139 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/general.xml @@ -0,0 +1,139 @@ +
diff --git a/src/opnsense/mvc/app/models/OPNsense/Unbound/ACL/ACL.xml b/src/opnsense/mvc/app/models/OPNsense/Unbound/ACL/ACL.xml index c06b73f64..d85b122f2 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Unbound/ACL/ACL.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Unbound/ACL/ACL.xml @@ -2,7 +2,8 @@