* Copyright (C) 2014-2015 Deciso B.V. * Copyright (C) 2005-2010 Scott Ullrich * Copyright (C) 2008 Shrew Soft Inc. * Copyright (C) 2007 Bill Marquette * Copyright (C) 2003-2004 Manuel Kasper * 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"); $a_group = &config_read_array('system', 'group'); $a_authmode = auth_get_authserver_list(); $ssh_rekeylimit_choices = [ '' => gettext('System defaults'), 'default 60s' => gettext('60 seconds'), 'default 600s' => gettext('10 minutes'), '512M 60s' => gettext('512MB, 60 seconds'), '512M 600s' => gettext('512MB, 10 minutes'), '512M 1h' => gettext('512MB, 1 hour'), '1G 60s' => gettext('1GB, 60 seconds'), '1G 1h' => gettext('1GB, 1 hour'), ]; if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = []; $pconfig['webguiinterfaces'] = !empty($config['system']['webgui']['interfaces']) ? explode(',', $config['system']['webgui']['interfaces']) : []; $pconfig['authmode'] = !empty($config['system']['webgui']['authmode']) ? explode(',', $config['system']['webgui']['authmode']) : []; $pconfig['session_timeout'] = !empty($config['system']['webgui']['session_timeout']) ? $config['system']['webgui']['session_timeout'] : null; $pconfig['webguiproto'] = $config['system']['webgui']['protocol']; $pconfig['webguiport'] = $config['system']['webgui']['port']; $pconfig['ssl-certref'] = $config['system']['webgui']['ssl-certref']; $pconfig['compression'] = isset($config['system']['webgui']['compression']) ? $config['system']['webgui']['compression'] : null; $pconfig['ssl-ciphers'] = !empty($config['system']['webgui']['ssl-ciphers']) ? explode(':', $config['system']['webgui']['ssl-ciphers']) : []; $pconfig['ssl-hsts'] = isset($config['system']['webgui']['ssl-hsts']); $pconfig['disablehttpredirect'] = isset($config['system']['webgui']['disablehttpredirect']); $pconfig['httpaccesslog'] = isset($config['system']['webgui']['httpaccesslog']); $pconfig['disableconsolemenu'] = isset($config['system']['disableconsolemenu']); $pconfig['usevirtualterminal'] = isset($config['system']['usevirtualterminal']); $pconfig['sudo_allow_wheel'] = $config['system']['sudo_allow_wheel']; $pconfig['sudo_allow_group'] = isset($config['system']['sudo_allow_group']) ? $config['system']['sudo_allow_group'] : null; $pconfig['user_allow_gen_token'] = isset($config['system']['user_allow_gen_token']) ? explode(",", $config['system']['user_allow_gen_token']) : []; $pconfig['nodnsrebindcheck'] = isset($config['system']['webgui']['nodnsrebindcheck']); $pconfig['nohttpreferercheck'] = isset($config['system']['webgui']['nohttpreferercheck']); $pconfig['althostnames'] = $config['system']['webgui']['althostnames'] ?? null; $pconfig['serialspeed'] = $config['system']['serialspeed']; $pconfig['serialusb'] = !empty($config['system']['serialusb']); $pconfig['primaryconsole'] = $config['system']['primaryconsole']; $pconfig['secondaryconsole'] = $config['system']['secondaryconsole'] ?? null; $pconfig['autologout'] = $config['system']['autologout'] ?? null; $pconfig['enablesshd'] = $config['system']['ssh']['enabled'] ?? null; $pconfig['sshport'] = $config['system']['ssh']['port'] ?? null; $pconfig['sshinterfaces'] = !empty($config['system']['ssh']['interfaces']) ? explode(',', $config['system']['ssh']['interfaces']) : []; $pconfig['ssh-kex'] = !empty($config['system']['ssh']['kex']) ? explode(',', $config['system']['ssh']['kex']) : []; $pconfig['ssh-ciphers'] = !empty($config['system']['ssh']['ciphers']) ? explode(',', $config['system']['ssh']['ciphers']) : []; $pconfig['ssh-macs'] = !empty($config['system']['ssh']['macs']) ? explode(',', $config['system']['ssh']['macs']) : []; $pconfig['ssh-keys'] = !empty($config['system']['ssh']['keys']) ? explode(',', $config['system']['ssh']['keys']) : []; $pconfig['ssh-keysig'] = !empty($config['system']['ssh']['keysig']) ? explode(',', $config['system']['ssh']['keysig']) : []; $pconfig['ssh-rekeylimit'] = !empty($config['system']['ssh']['rekeylimit']) ? $config['system']['ssh']['rekeylimit'] : ''; $pconfig['sshpasswordauth'] = isset($config['system']['ssh']['passwordauth']); $pconfig['sshdpermitrootlogin'] = isset($config['system']['ssh']['permitrootlogin']); $pconfig['quietlogin'] = isset($config['system']['webgui']['quietlogin']); $pconfig['deployment'] = $config['system']['deployment'] ?? ''; /* XXX not really a syslog setting */ $pconfig['loglighttpd'] = empty($config['syslog']['nologlighttpd']); /* XXX listtag "fun" */ $pconfig['sshlogingroup'] = !empty($config['system']['ssh']['group'][0]) ? $config['system']['ssh']['group'][0] : null; } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $input_errors = []; $pconfig = $_POST; if (!empty($pconfig['webguiport']) && !is_port($pconfig['webguiport'])) { $input_errors[] = gettext('You must specify a valid web GUI port number.'); } if (empty($pconfig['webguiproto']) || !in_array($pconfig['webguiproto'], ['http', 'https'])) { $input_errors[] = gettext('You must specify a valid web GUI protocol.'); } if (!empty($pconfig['althostnames'])) { $althosts = explode(" ", $pconfig['althostnames']); foreach ($althosts as $ah) { if (!is_hostname($ah)) { $input_errors[] = sprintf(gettext("Alternate hostname %s is not a valid hostname."), htmlspecialchars($ah)); } } } if (!empty($pconfig['sshport']) && !is_port($pconfig['sshport'])) { $input_errors[] = gettext('You must specify a valid SSH port number.'); } if (!empty($pconfig['session_timeout']) && (!is_numeric($pconfig['session_timeout']) || $pconfig['session_timeout'] <= 0)) { $input_errors[] = gettext('Session timeout must be an integer value.'); } if (!empty($pconfig['autologout']) && (!is_numeric($pconfig['autologout']) || $pconfig['autologout'] <= 0)) { $input_errors[] = gettext('Inactivity timeout must be an integer value.'); } if (!empty($pconfig['authmode'])) { foreach ($pconfig['authmode'] as $auth_mode) { if (!isset($a_authmode[$auth_mode])) { $input_errors[] = sprintf(gettext('Authentication server "%s" is invalid.'), $auth_mode); } } } if (!empty($pconfig['ssl-certref'])) { foreach ($config['cert'] as $cert) { if ($cert['refid'] == $pconfig['ssl-certref']) { if (cert_get_purpose($cert['crt'])['server'] == 'No') { $input_errors[] = gettext( sprintf('Certificate %s is not intended for server use.', $cert['descr']) ); break; } } } } if (!empty($pconfig['ssl-ciphers'])) { $ciphers = json_decode(configd_run("system ssl ciphers"), true) ?? []; foreach ($ciphers as $cipher => $settings) { if ($settings['version'] == 'TLSv1.3' && in_array($cipher, $pconfig['ssl-ciphers']) && !in_array('TLS_AES_128_GCM_SHA256', $pconfig['ssl-ciphers'])) { $input_errors[] = gettext('A TLS 1.3-compliant application MUST implement the TLS_AES_128_GCM_SHA256 according to RFC 8446.'); break; } } } if (!empty($pconfig['ssh-rekeylimit']) && !isset($ssh_rekeylimit_choices[$pconfig['ssh-rekeylimit']])) { $input_errors[] = gettext('Invalid rekey limit option.'); } if (count($input_errors) == 0) { $newinterfaces = !empty($pconfig['webguiinterfaces']) ? implode(',', $pconfig['webguiinterfaces']) : ''; $newciphers = !empty($pconfig['ssl-ciphers']) ? implode(':', $pconfig['ssl-ciphers']) : ''; $restart_webgui = $config['system']['webgui']['protocol'] != $pconfig['webguiproto'] || ($config['system']['webgui']['session_timeout'] ?? '') != $pconfig['session_timeout'] || $config['system']['webgui']['port'] != $pconfig['webguiport'] || $config['system']['webgui']['ssl-certref'] != $pconfig['ssl-certref'] || $config['system']['webgui']['compression'] != $pconfig['compression'] || $config['system']['webgui']['ssl-ciphers'] != $newciphers || $config['system']['webgui']['interfaces'] != $newinterfaces || empty($pconfig['httpaccesslog']) != empty($config['system']['webgui']['httpaccesslog']) || empty($pconfig['ssl-hsts']) != empty($config['system']['webgui']['ssl-hsts']) || !empty($pconfig['disablehttpredirect']) != !empty($config['system']['webgui']['disablehttpredirect']) || ($config['system']['deployment'] ?? '') != $pconfig['deployment'] || !empty($config['syslog']['nologlighttpd']) != empty($pconfig['loglighttpd']); $config['system']['webgui']['protocol'] = $pconfig['webguiproto']; $config['system']['webgui']['port'] = $pconfig['webguiport']; $config['system']['webgui']['ssl-certref'] = $pconfig['ssl-certref']; $config['system']['webgui']['ssl-ciphers'] = $newciphers; $config['system']['webgui']['interfaces'] = $newinterfaces; $config['system']['webgui']['compression'] = $pconfig['compression']; if (empty($config['syslog'])) { $config['syslog'] = []; } $config['syslog']['nologlighttpd'] = empty($pconfig['loglighttpd']); if (!empty($pconfig['deployment'])) { $config['system']['deployment'] = $pconfig['deployment']; } elseif (isset($config['system']['deployment'])) { unset($config['system']['deployment']); } if (!empty($pconfig['ssl-hsts'])) { $config['system']['webgui']['ssl-hsts'] = true; } elseif (isset($config['system']['webgui']['ssl-hsts'])) { unset($config['system']['webgui']['ssl-hsts']); } if (!empty($pconfig['session_timeout'])) { $config['system']['webgui']['session_timeout'] = $pconfig['session_timeout']; } elseif (isset($config['system']['webgui']['session_timeout'])) { unset($config['system']['webgui']['session_timeout']); } if (!empty($pconfig['disablehttpredirect'])) { $config['system']['webgui']['disablehttpredirect'] = true; } elseif (isset($config['system']['webgui']['disablehttpredirect'])) { unset($config['system']['webgui']['disablehttpredirect']); } if (!empty($pconfig['httpaccesslog'])) { $config['system']['webgui']['httpaccesslog'] = true; } elseif (isset($config['system']['webgui']['httpaccesslog'])) { unset($config['system']['webgui']['httpaccesslog']); } if (!empty($pconfig['quietlogin'])) { $config['system']['webgui']['quietlogin'] = true; } elseif (isset($config['system']['webgui']['quietlogin'])) { unset($config['system']['webgui']['quietlogin']); } if (!empty($pconfig['disableconsolemenu'])) { $config['system']['disableconsolemenu'] = true; } elseif (isset($config['system']['disableconsolemenu'])) { unset($config['system']['disableconsolemenu']); } if (!empty($pconfig['usevirtualterminal'])) { $config['system']['usevirtualterminal'] = true; } elseif (isset($config['system']['usevirtualterminal'])) { unset($config['system']['usevirtualterminal']); } if (!empty($pconfig['sudo_allow_wheel'])) { $config['system']['sudo_allow_wheel'] = $pconfig['sudo_allow_wheel']; } elseif (isset($config['system']['sudo_allow_wheel'])) { unset($config['system']['sudo_allow_wheel']); } if (is_numeric($pconfig['serialspeed'])) { $config['system']['serialspeed'] = $pconfig['serialspeed']; } elseif (isset($config['system']['serialspeed'])) { unset($config['system']['serialspeed']); } if (!empty($pconfig['serialusb'])) { $config['system']['serialusb'] = true; } elseif (isset($config['system']['serialusb'])) { unset($config['system']['serialusb']); } if (!empty($pconfig['primaryconsole'])) { $config['system']['primaryconsole'] = $pconfig['primaryconsole']; } elseif (isset($config['system']['primaryconsole'])) { unset($config['system']['primaryconsole']); } if (!empty($pconfig['secondaryconsole'])) { $config['system']['secondaryconsole'] = $pconfig['secondaryconsole']; } elseif (isset($config['system']['secondaryconsole'])) { unset($config['system']['secondaryconsole']); } if (!empty($pconfig['nodnsrebindcheck'])) { $config['system']['webgui']['nodnsrebindcheck'] = true; } elseif (isset($config['system']['webgui']['nodnsrebindcheck'])) { unset($config['system']['webgui']['nodnsrebindcheck']); } if (!empty($pconfig['nohttpreferercheck'])) { $config['system']['webgui']['nohttpreferercheck'] = true; } elseif (isset($config['system']['webgui']['nohttpreferercheck'])) { unset($config['system']['webgui']['nohttpreferercheck']); } if (!empty($pconfig['althostnames'])) { $config['system']['webgui']['althostnames'] = $pconfig['althostnames']; } elseif (isset($config['system']['webgui']['althostnames'])) { unset($config['system']['webgui']['althostnames']); } if (!empty($pconfig['authmode'])) { $config['system']['webgui']['authmode'] = implode(',', $pconfig['authmode']); } elseif (isset($config['system']['webgui']['authmode'])) { unset($config['system']['webgui']['authmode']); } if (!empty($pconfig['autologout'])) { $config['system']['autologout'] = $pconfig['autologout']; } elseif (isset($config['system']['autologout'])) { unset($config['system']['autologout']); } if (empty($config['system']['ssh'])) { $config['system']['ssh'] = []; } /* always store setting to prevent installer auto-start */ $config['system']['ssh']['noauto'] = 1; $config['system']['ssh']['interfaces'] = !empty($pconfig['sshinterfaces']) ? implode(',', $pconfig['sshinterfaces']) : null; $config['system']['ssh']['kex'] = !empty($pconfig['ssh-kex']) ? implode(',', $pconfig['ssh-kex']) : null; $config['system']['ssh']['ciphers'] = !empty($pconfig['ssh-ciphers']) ? implode(',', $pconfig['ssh-ciphers']) : null; $config['system']['ssh']['macs'] = !empty($pconfig['ssh-macs']) ? implode(',', $pconfig['ssh-macs']) : null; $config['system']['ssh']['keys'] = !empty($pconfig['ssh-keys']) ? implode(',', $pconfig['ssh-keys']) : null; $config['system']['ssh']['keysig'] = !empty($pconfig['ssh-keysig']) ? implode(',', $pconfig['ssh-keysig']) : null; $config['system']['ssh']['rekeylimit'] = !empty($pconfig['ssh-rekeylimit']) ? $pconfig['ssh-rekeylimit'] : null; if (!empty($pconfig['enablesshd'])) { $config['system']['ssh']['enabled'] = 'enabled'; } elseif (isset($config['system']['ssh']['enabled'])) { unset($config['system']['ssh']['enabled']); } if (!empty($pconfig['sshlogingroup'])) { $config['system']['ssh']['group'] = $pconfig['sshlogingroup']; } elseif (isset($config['system']['ssh']['group'])) { unset($config['system']['ssh']['group']); } if (!empty($pconfig['sudo_allow_group'])) { $config['system']['sudo_allow_group'] = $pconfig['sudo_allow_group']; } elseif (isset($config['system']['sudo_allow_group'])) { unset($config['system']['sudo_allow_group']); } if (!empty($pconfig['user_allow_gen_token'])) { $config['system']['user_allow_gen_token'] = implode(",", $pconfig['user_allow_gen_token']); } elseif (isset($config['system']['user_allow_gen_token'])) { unset($config['system']['user_allow_gen_token']); } if (!empty($pconfig['sshpasswordauth'])) { $config['system']['ssh']['passwordauth'] = true; } elseif (isset($config['system']['ssh']['passwordauth'])) { unset($config['system']['ssh']['passwordauth']); } if (!empty($pconfig['sshport'])) { $config['system']['ssh']['port'] = $pconfig['sshport']; } elseif (isset($config['system']['ssh']['port'])) { unset($config['system']['ssh']['port']); } if (!empty($pconfig['sshdpermitrootlogin'])) { $config['system']['ssh']['permitrootlogin'] = true; } elseif (isset($config['system']['ssh']['permitrootlogin'])) { unset($config['system']['ssh']['permitrootlogin']); } if ($restart_webgui) { $http_host_port = explode("]", $_SERVER['HTTP_HOST']); /* IPv6 address check */ if (strstr($_SERVER['HTTP_HOST'], "]")) { if (count($http_host_port) > 1) { array_pop($http_host_port); $host = str_replace(['[', ']'], '', implode(':', $http_host_port)); $host = "[{$host}]"; } else { $host = str_replace(['[', ']'], '', implode(':', $http_host_port)); $host = "[{$host}]"; } } else { list($host) = explode(":", $_SERVER['HTTP_HOST']); } $prot = $config['system']['webgui']['protocol']; $port = $config['system']['webgui']['port']; if (!empty($port)) { $url = "{$prot}://{$host}:{$port}/system_advanced_admin.php"; } else { $url = "{$prot}://{$host}/system_advanced_admin.php"; } } write_config(); $savemsg = get_std_save_message(); filter_configure(); system_login_configure(); system_resolver_configure(); plugins_configure('dns'); plugins_configure('dhcp'); configd_run('openssh restart', true); if ($restart_webgui) { configd_run('webgui restart 3', true); } } } $a_cert = isset($config['cert']) ? $config['cert'] : []; $interfaces = get_configured_interface_with_descr(); $certs_available = false; if (count($a_cert)) { $certs_available = true; } if (empty($pconfig['webguiproto']) || !$certs_available) { $pconfig['webguiproto'] = "http"; } $sshoptions = json_decode(configd_run('openssh query'), true); legacy_html_escape_form_data($pconfig); legacy_html_escape_form_data($a_group); include("head.inc"); ?>
0) { print_input_errors($input_errors); } if (isset($savemsg)) { print_info_box($savemsg); } ?>
/>     />
','') ?>
/>
/>
/>
/>
/>
/>
/>
/>
/>
/>
/>
/>
/>