Commit d28b79a9 authored by Franco Fichtner's avatar Franco Fichtner

system: improve writing etc/ttys even more to disable virtual

parent 1b442b8e
...@@ -1588,7 +1588,6 @@ function system_login_configure() ...@@ -1588,7 +1588,6 @@ function system_login_configure()
configd_run('template reload OPNsense/Auth'); configd_run('template reload OPNsense/Auth');
$serialspeed = (!empty($config['system']['serialspeed']) && is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200'; $serialspeed = (!empty($config['system']['serialspeed']) && is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200';
$serial_enabled = false;
$new_boot_config = array(); $new_boot_config = array();
$new_boot_config['comconsole_speed'] = null; $new_boot_config['comconsole_speed'] = null;
...@@ -1602,13 +1601,14 @@ function system_login_configure() ...@@ -1602,13 +1601,14 @@ function system_login_configure()
foreach (array('primaryconsole', 'secondaryconsole') as $console_order) { foreach (array('primaryconsole', 'secondaryconsole') as $console_order) {
if (!empty($config['system'][$console_order]) && isset($console_types[$config['system'][$console_order]])) { if (!empty($config['system'][$console_order]) && isset($console_types[$config['system'][$console_order]])) {
$console_selection[] = $console_types[$config['system'][$console_order]]['value']; $console_selection[] = $console_types[$config['system'][$console_order]]['value'];
if ($config['system'][$console_order] == 'serial') {
/* make sure serial is enabled when selected, but not by checkbox */
$serial_enabled = true;
}
} }
} }
$output_enabled = count($console_selection) != 1 || in_array('nullconsole', $console_selection);
$virtual_enabled = !count($console_selection) || in_array('vidconsole', $console_selection) ||
in_array('efi', $console_selection);
$serial_enabled = in_array('comconsole', $console_selection);
$console_selection = array_unique($console_selection); $console_selection = array_unique($console_selection);
$new_boot_config['console'] = '"' . implode(',', $console_selection) . '"'; $new_boot_config['console'] = '"' . implode(',', $console_selection) . '"';
if (count($console_selection) >= 2) { if (count($console_selection) >= 2) {
...@@ -1619,7 +1619,7 @@ function system_login_configure() ...@@ -1619,7 +1619,7 @@ function system_login_configure()
@file_put_contents('/boot.config', "-S{$serialspeed} -D\n"); @file_put_contents('/boot.config', "-S{$serialspeed} -D\n");
$new_boot_config['comconsole_speed'] = '"'.$serialspeed.'"'; $new_boot_config['comconsole_speed'] = '"'.$serialspeed.'"';
$new_boot_config['boot_serial'] = '"YES"'; $new_boot_config['boot_serial'] = '"YES"';
} elseif (count($console_selection) == 1 && $console_selection[0] == 'nullconsole') { } elseif (!$output_enabled) {
@file_put_contents('/boot.config', "-q -m\n"); @file_put_contents('/boot.config', "-q -m\n");
} else { } else {
@unlink('/boot.config'); @unlink('/boot.config');
...@@ -1644,10 +1644,11 @@ function system_login_configure() ...@@ -1644,10 +1644,11 @@ function system_login_configure()
/* write merged file back to target location */ /* write merged file back to target location */
@file_put_contents('/boot/loader.conf', $new_loader_conf); @file_put_contents('/boot/loader.conf', $new_loader_conf);
// ** setup /etc/ttys /* setup /etc/ttys */
$etc_ttys_lines = explode("\n", file_get_contents('/etc/ttys')); $etc_ttys_lines = explode("\n", file_get_contents('/etc/ttys'));
$fd = fopen('/etc/ttys', 'w'); $fd = fopen('/etc/ttys', 'w');
$on_off_secure = $serial_enabled ? 'onifconsole secure' : 'off secure'; $on_off_secure_u = $serial_enabled ? 'onifconsole secure' : 'off secure';
$on_off_secure_v = $virtual_enabled ? 'off secure' : 'on secure';
$terminal_type = 'cons25'; /* XXX standard is 'xterm' for virtual, 'vt100' for serial */ $terminal_type = 'cons25'; /* XXX standard is 'xterm' for virtual, 'vt100' for serial */
if (isset($config['system']['disableconsolemenu'])) { if (isset($config['system']['disableconsolemenu'])) {
$console_type = 'Pc'; $console_type = 'Pc';
...@@ -1657,16 +1658,22 @@ function system_login_configure() ...@@ -1657,16 +1658,22 @@ function system_login_configure()
$serial_type = 'al.' . $serialspeed; $serial_type = 'al.' . $serialspeed;
} }
foreach ($etc_ttys_lines as $tty) { foreach ($etc_ttys_lines as $tty) {
/* first virtual terminal */
if (strpos($tty, 'ttyv0') === 0) { if (strpos($tty, 'ttyv0') === 0) {
/* first virtual terminal */ fwrite($fd, "ttyv0\t\"/usr/libexec/getty {$console_type}\"\t\t{$terminal_type}\t${on_off_secure_v}\n");
$on_off_secure2 = count($console_selection) == 1 && $console_selection[0] == 'nullconsole' ? 'off secure' : 'on secure';
fwrite($fd, "ttyv0\t\"/usr/libexec/getty {$console_type}\"\t\t{$terminal_type}\t${on_off_secure2}\n");
continue; continue;
} }
/* all other virtual terminals */
foreach (array('ttyv1', 'ttyv2', 'ttyv3', 'ttyv4', 'ttyv5', 'ttyv6', 'ttyv7') as $virtualport) {
if (strpos($tty, $virtualport) === 0) {
fwrite($fd, "${virtualport}\t\"/usr/libexec/getty {$console_type}\"\t\txterm\t${on_off_secure_v}\n");
continue 2;
}
}
/* each serial terminal */
foreach (array('ttyu0', 'ttyu1', 'ttyu2', 'ttyu3') as $serialport) { foreach (array('ttyu0', 'ttyu1', 'ttyu2', 'ttyu3') as $serialport) {
if (strpos($tty, $serialport) === 0) { if (strpos($tty, $serialport) === 0) {
/* each serial terminal */ fwrite($fd, "{$serialport}\t\"/usr/libexec/getty {$serial_type}\"\t{$terminal_type}\t{$on_off_secure_u}\n");
fwrite($fd, "{$serialport}\t\"/usr/libexec/getty {$serial_type}\"\t{$terminal_type}\t{$on_off_secure}\n");
/* skip to next line in outer loop */ /* skip to next line in outer loop */
continue 2; continue 2;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment