* All rights reserved. * * 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. * * 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. */ require_once("guiconfig.inc"); require_once("filter.inc"); require_once("system.inc"); require_once("interfaces.inc"); $all_intf_details = legacy_interfaces_details(); $a_gateways = (new \OPNsense\Routing\Gateways())->gatewaysIndexedByName(); if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = array(); if (isset($_GET['savemsg'])) { $savemsg = htmlspecialchars(gettext($_GET['savemsg'])); } $pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']); if (!empty($config['system']['dnsallowoverride_exclude'])) { $pconfig['dnsallowoverride_exclude'] = explode(',', $config['system']['dnsallowoverride_exclude']); } else { $pconfig['dnsallowoverride_exclude'] = []; } $pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']); $pconfig['dnssearchdomain'] = $config['system']['dnssearchdomain'] ?? null; $pconfig['domain'] = $config['system']['domain']; $pconfig['hostname'] = $config['system']['hostname']; $pconfig['language'] = $config['system']['language']; $pconfig['prefer_ipv4'] = isset($config['system']['prefer_ipv4']); $pconfig['store_intermediate_certs'] = isset($config['system']['store_intermediate_certs']); $pconfig['theme'] = $config['theme'] ?? ''; $pconfig['timezone'] = empty($config['system']['timezone']) ? 'Etc/UTC' : $config['system']['timezone']; $pconfig['gw_switch_default'] = isset($config['system']['gw_switch_default']); for ($dnscounter = 1; $dnscounter < 9; $dnscounter++) { $dnsname = "dns{$dnscounter}"; $pconfig[$dnsname] = !empty($config['system']['dnsserver'][$dnscounter - 1]) ? $config['system']['dnsserver'][$dnscounter - 1] : null; $dnsgwname= "dns{$dnscounter}gw"; $pconfig[$dnsgwname] = !empty($config['system'][$dnsgwname]) ? $config['system'][$dnsgwname] : 'none'; } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $input_errors = array(); $pconfig = $_POST; /* input validation */ $reqdfields = explode(" ", "hostname domain"); $reqdfieldsn = array(gettext("Hostname"),gettext("Domain")); if (empty($pconfig['dnsallowoverride_exclude'])) { $pconfig['dnsallowoverride_exclude'] = []; } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); if (!empty($pconfig['hostname']) && !is_hostname($pconfig['hostname'])) { $input_errors[] = gettext("The hostname may only contain the characters a-z, 0-9 and '-'."); } if (!empty($pconfig['domain']) && !is_domain($pconfig['domain'])) { $input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'."); } if (!empty($pconfig['dnssearchdomain']) && !is_domain($pconfig['dnssearchdomain'], true)) { $input_errors[] = gettext("A search domain may only contain the characters a-z, 0-9, '-' and '.'."); } /* collect direct attached networks and static routes */ $direct_networks_list = array(); foreach ($all_intf_details as $ifname => $ifcnf) { foreach ($ifcnf['ipv4'] as $addr) { $direct_networks_list[] = gen_subnet($addr['ipaddr'], $addr['subnetbits']) . "/{$addr['subnetbits']}"; } foreach ($ifcnf['ipv6'] as $addr) { $direct_networks_list[] = gen_subnetv6($addr['ipaddr'], $addr['subnetbits']) . "/{$addr['subnetbits']}"; } } foreach (get_staticroutes() as $netent) { $direct_networks_list[] = $netent['network']; } for ($dnscounter = 1; $dnscounter < 9; $dnscounter++) { $dnsname = "dns{$dnscounter}"; $dnsgwname = "dns{$dnscounter}gw"; if (!empty($pconfig[$dnsname]) && !is_ipaddr($pconfig[$dnsname])) { $input_errors[] = sprintf(gettext('A valid IP address must be specified for DNS server "%s".'), $dnscounter); continue; } if (!empty($pconfig[$dnsgwname]) && $pconfig[$dnsgwname] != 'none') { if (is_ipaddr($pconfig[$dnsname])) { if (is_ipaddrv4($pconfig[$dnsname]) && $a_gateways[$pconfig[$dnsgwname]]['ipprotocol'] != 'inet') { $input_errors[] = gettext("You can not specify IPv6 gateway '{$pconfig[$dnsgwname]}' for IPv4 DNS server '{$pconfig[$dnsname]}'"); continue; } if (is_ipaddrv6($pconfig[$dnsname]) && $a_gateways[$pconfig[$dnsgwname]]['ipprotocol'] != 'inet6') { $input_errors[] = gettext("You can not specify IPv4 gateway '{$pconfig[$dnsgwname]}' for IPv6 DNS server '{$pconfig[$dnsname]}'"); continue; } } else { $input_errors[] = sprintf(gettext('A valid IP address must be specified for DNS server "%s".'), $dnscounter); continue; } $af = is_ipaddrv6($pconfig[$dnsname]) ? 'inet6' : 'inet'; foreach ($direct_networks_list as $direct_network) { if ($af == 'inet' && !is_subnetv4($direct_network)) { continue; } elseif ($af == 'inet6' && !is_subnetv6($direct_network)) { continue; } if (ip_in_subnet($pconfig[$dnsname], $direct_network)) { $input_errors[] = sprintf(gettext('You can not assign a gateway to DNS server "%s" which is on a directly connected network.'), $pconfig[$dnsname]); break; } } } } if (count($input_errors) == 0) { $config['system']['domain'] = $pconfig['domain']; $config['system']['hostname'] = $pconfig['hostname']; $config['system']['language'] = $pconfig['language']; $config['system']['timezone'] = $pconfig['timezone']; $config['theme'] = $pconfig['theme']; if (!empty($pconfig['prefer_ipv4'])) { $config['system']['prefer_ipv4'] = true; } elseif (isset($config['system']['prefer_ipv4'])) { unset($config['system']['prefer_ipv4']); } $sync_trust = !empty($pconfig['store_intermediate_certs']) !== isset($config['system']['store_intermediate_certs']); $config['system']['store_intermediate_certs'] = !empty($pconfig['store_intermediate_certs']); if (!empty($pconfig['dnsallowoverride'])) { $config['system']['dnsallowoverride'] = true; $config['system']['dnsallowoverride_exclude'] = implode(',', $pconfig['dnsallowoverride_exclude']); } elseif (isset($config['system']['dnsallowoverride'])) { unset($config['system']['dnsallowoverride']); if (isset($config['system']['dnsallowoverride_exclude'])) { unset($config['system']['dnsallowoverride_exclude']); } } if ($pconfig['dnslocalhost'] == 'yes') { $config['system']['dnslocalhost'] = true; } elseif (isset($config['system']['dnslocalhost'])) { unset($config['system']['dnslocalhost']); } if (!empty($pconfig['dnssearchdomain'])) { $config['system']['dnssearchdomain'] = $pconfig['dnssearchdomain']; } elseif (isset($config['system']['dnssearchdomain'])) { unset($config['system']['dnssearchdomain']); } if (!empty($pconfig['gw_switch_default'])) { $config['system']['gw_switch_default'] = true; } elseif (isset($config['system']['gw_switch_default'])) { unset($config['system']['gw_switch_default']); } $olddnsservers = $config['system']['dnsserver']; $config['system']['dnsserver'] = array(); $outdnscounter = 0; for ($dnscounter = 1; $dnscounter < 9; $dnscounter++) { $dnsname="dns{$dnscounter}"; $dnsgwname="dns{$dnscounter}gw"; $olddnsgwname = !empty($config['system'][$dnsgwname]) ? $config['system'][$dnsgwname] : 'none'; $thisdnsgwname = $pconfig[$dnsgwname]; if (!empty($pconfig[$dnsname])) { $config['system']['dnsserver'][] = $pconfig[$dnsname]; } $config['system'][$dnsgwname] = "none"; if (!empty($pconfig[$dnsgwname])) { // The indexes used to save the item don't have to correspond to the ones in the config, but since // we always redirect after save, the configuration content is read after a successful change. $outdnscounter++; $outdnsgwname="dns{$outdnscounter}gw"; $config['system'][$outdnsgwname] = $thisdnsgwname; } if ($olddnsgwname != "none" && ($olddnsgwname != $thisdnsgwname || $olddnsservers[$dnscounter-1] != $pconfig[$dnsname])) { // A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed. // Remove the route. Later calls will add the correct new route if needed. if (is_ipaddrv4($olddnsservers[$dnscounter-1])) { mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1])); } else { if (is_ipaddrv6($olddnsservers[$dnscounter-1])) { mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1])); } } } } write_config(); /* time zone change first */ system_timezone_configure(); if ($sync_trust) { /* * FreeBSD trust store integration is slow so we need * to avoid processing when setting is unchanged. */ system_trust_configure(); } system_hostname_configure(); system_resolver_configure(); plugins_configure('dns'); plugins_configure('dhcp'); filter_configure(); header(url_safe('Location: /system_general.php?savemsg=%s', array('The changes have been applied successfully.'))); exit; } } legacy_html_escape_form_data($a_gateways); legacy_html_escape_form_data($pconfig); include("head.inc"); ?>
0) { print_input_errors($input_errors); } if (isset($savemsg)) { print_info_box($savemsg); } ?>
/>
/>
/>
/>
/>