* 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"); require_once("services.inc"); if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = array(); if (isset($_GET['savemsg'])) { $savemsg = htmlspecialchars(gettext($_GET['savemsg'])); } $pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']); $pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']); $pconfig['domain'] = $config['system']['domain']; $pconfig['hostname'] = $config['system']['hostname']; $pconfig['language'] = $config['system']['language']; $pconfig['prefer_ipv4'] = isset($config['system']['prefer_ipv4']); $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']); $pconfig['gw_switch_group4'] = isset($config['system']['gw_switch_group4']) ? $config['system']['gw_switch_group4'] : null; $pconfig['gw_switch_group6'] = isset($config['system']['gw_switch_group6']) ? $config['system']['gw_switch_group6'] : null; 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")); 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 '.'."); } $ignore_posted_dnsgw = array(); for ($dnscounter = 1; $dnscounter < 9; $dnscounter++){ $dnsname="dns{$dnscounter}"; $dnsgwname="dns{$dnscounter}gw"; if (!empty($pconfig[$dnsname]) && !is_ipaddr($pconfig[$dnsname])) { $input_errors[] = gettext("A valid IP address must be specified for DNS server $dnscounter."); } elseif (!empty($pconfig[$dnsgwname]) && $pconfig[$dnsgwname] != 'none') { // A real gateway has been selected. if (is_ipaddr($pconfig[$dnsname])) { if ((is_ipaddrv4($pconfig[$dnsname])) && (validate_address_family($pconfig[$dnsname], $pconfig[$dnsgwname]) === false )) { $input_errors[] = gettext("You can not specify IPv6 gateway '{$pconfig[$dnsgwname]}' for IPv4 DNS server '{$pconfig[$dnsname]}'"); } if ((is_ipaddrv6($pconfig[$dnsname])) && (validate_address_family($pconfig[$dnsname], $pconfig[$dnsgwname]) === false )) { $input_errors[] = gettext("You can not specify IPv4 gateway '{$pconfig[$dnsgwname]}' for IPv6 DNS server '{$pconfig[$dnsname]}'"); } } else { // The user selected a gateway but did not provide a DNS address. Be nice and set the gateway back to "none". $ignore_posted_dnsgw[$dnsgwname] = true; } } } /* collect direct attached networks and static routes */ $direct_networks_list = array(); foreach (legacy_interfaces_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++) { $dnsitem = "dns{$dnscounter}"; $dnsgwitem = "dns{$dnscounter}gw"; if (!empty($pconfig[$dnsgwitem])) { if (interface_has_gateway($pconfig[$dnsgwitem])) { foreach ($direct_networks_list as $direct_network) { if (ip_in_subnet($_POST[$dnsitem], $direct_network)) { $input_errors[] = sprintf(gettext("You can not assign a gateway to DNS '%s' server which is on a directly connected network."),$pconfig[$dnsitem]); } } } } } 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']); } if (!empty($pconfig['dnsallowoverride'])) { $config['system']['dnsallowoverride'] = true; } elseif (isset($config['system']['dnsallowoverride'])) { unset($config['system']['dnsallowoverride']); } if ($pconfig['dnslocalhost'] == 'yes') { $config['system']['dnslocalhost'] = true; } elseif (isset($config['system']['dnslocalhost'])) { unset($config['system']['dnslocalhost']); } 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']); } if (!empty($pconfig['gw_switch_group4'])) { $config['system']['gw_switch_group4'] = $pconfig['gw_switch_group4']; } elseif (isset($config['system']['gw_switch_group4'])) { unset($config['system']['gw_switch_group4']); } if (!empty($pconfig['gw_switch_group6'])) { $config['system']['gw_switch_group6'] = $pconfig['gw_switch_group6']; } elseif (isset($config['system']['gw_switch_group6'])) { unset($config['system']['gw_switch_group6']); } $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'; if (!empty($pconfig[$dnsname])) { $config['system']['dnsserver'][] = $pconfig[$dnsname]; } if ($ignore_posted_dnsgw[$dnsgwname]) { $thisdnsgwname = "none"; } else { $thisdnsgwname = $pconfig[$dnsgwname]; } // "Blank" out the settings for this index, then we set them below using the "outdnscounter" index. $config['system'][$dnsgwname] = "none"; $pconfig[$dnsgwname] = "none"; $pconfig[$dnsname] = ""; if (!empty($_POST[$dnsname])) { // Only the non-blank DNS servers were put into the config above. // So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers. // This keeps the DNS server IP and corresponding gateway "lined up" when the user blanks out a DNS server IP in the middle of the list. $outdnscounter++; $outdnsname="dns{$outdnscounter}"; $outdnsgwname="dns{$outdnscounter}gw"; $pconfig[$outdnsname] = $_POST[$dnsname]; if (!empty($_POST[$dnsgwname])) { $config['system'][$outdnsgwname] = $thisdnsgwname; $pconfig[$outdnsgwname] = $thisdnsgwname; } else { // Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens. unset($config['system'][$outdnsgwname]); $pconfig[$outdnsgwname] = ""; } } if ($olddnsgwname != "none" && ($olddnsgwname != $thisdnsgwname || $olddnsservers[$dnscounter-1] != $_POST[$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(); filter_pflog_start(); prefer_ipv4_or_ipv6(); system_hostname_configure(); system_hosts_generate(); system_resolvconf_generate(); plugins_configure('dns'); services_dhcpd_configure(); filter_configure(); header(url_safe('Location: /system_general.php?savemsg=%s', array(get_std_save_message(true)))); exit; } } legacy_html_escape_form_data($pconfig); include("head.inc"); ?>
0) { print_input_errors($input_errors); } if (isset($savemsg)) { print_info_box($savemsg); } ?>
/>
/>
/>
/>
" />