Commit 1ac520ed authored by Franco Fichtner's avatar Franco Fichtner

system: add nullconsole setting and console rework

(cherry picked from commit f00d4309)
(cherry picked from commit d5969056)
(cherry picked from commit 8e78fd70)
(cherry picked from commit 85e62204)
(cherry picked from commit a7fbf99b)
(cherry picked from commit 6b19b436)
(cherry picked from commit 9bc6342f)
(cherry picked from commit d28b79a9)
(cherry picked from commit 7e4c3cf7)
(cherry picked from commit af8e12f5)
(cherry picked from commit e21aa229)
(cherry picked from commit 8b6d43f5)
(cherry picked from commit 68739fbb)
parent 70588a21
...@@ -1642,9 +1642,11 @@ function system_console_unmute() ...@@ -1642,9 +1642,11 @@ function system_console_unmute()
function system_console_types() function system_console_types()
{ {
return array( return array(
'serial' => array('value' => 'comconsole', 'name' => gettext('Serial Console')), /* sorted by usage */
'video' => array('value' => 'vidconsole', 'name' => gettext('VGA Console')), 'video' => array('value' => 'vidconsole', 'name' => gettext('VGA Console')),
'serial' => array('value' => 'comconsole', 'name' => gettext('Serial Console')),
'efi' => array('value' => 'efi', 'name' => gettext('EFI Console')), 'efi' => array('value' => 'efi', 'name' => gettext('EFI Console')),
'null' => array('value' => 'nullconsole', 'name' => gettext('Mute Console')),
); );
} }
...@@ -1660,16 +1662,7 @@ function system_login_configure($verbose = false) ...@@ -1660,16 +1662,7 @@ function system_login_configure($verbose = false)
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 = isset($config['system']['enableserial']);
// ** serial console - write out /boot.config
if ($serial_enabled) {
@file_put_contents('/boot.config', "-S{$serialspeed} -D\n");
} else {
@unlink('/boot.config');
}
// ** console settings in /boot/loader.conf
$new_boot_config = array(); $new_boot_config = array();
$new_boot_config['comconsole_speed'] = null; $new_boot_config['comconsole_speed'] = null;
$new_boot_config['boot_multicons'] = null; $new_boot_config['boot_multicons'] = null;
...@@ -1687,15 +1680,28 @@ function system_login_configure($verbose = false) ...@@ -1687,15 +1680,28 @@ function system_login_configure($verbose = false)
$console_selection = array_unique($console_selection); $console_selection = array_unique($console_selection);
if ($serial_enabled) { $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) || isset($config['system']['enableserial']);
if (count($console_selection)) {
$new_boot_config['console'] = '"' . implode(',', $console_selection) . '"'; $new_boot_config['console'] = '"' . implode(',', $console_selection) . '"';
$new_boot_config['comconsole_speed'] = '"'.$serialspeed.'"';
$new_boot_config['boot_serial'] = '"YES"';
if (count($console_selection) >= 2) { if (count($console_selection) >= 2) {
$new_boot_config['boot_multicons'] = '"YES"'; $new_boot_config['boot_multicons'] = '"YES"';
} }
} }
if ($serial_enabled) {
@file_put_contents('/boot.config', "-S{$serialspeed} -D\n");
$new_boot_config['comconsole_speed'] = '"'.$serialspeed.'"';
$new_boot_config['boot_serial'] = '"YES"';
} elseif (!$output_enabled) {
@file_put_contents('/boot.config', "-q -m\n");
} else {
@unlink('/boot.config');
}
/* reload static values from rc.loader.d */ /* reload static values from rc.loader.d */
mwexecf('/usr/local/etc/rc.loader'); mwexecf('/usr/local/etc/rc.loader');
...@@ -1715,10 +1721,11 @@ function system_login_configure($verbose = false) ...@@ -1715,10 +1721,11 @@ function system_login_configure($verbose = false)
/* 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 ? 'on secure' : 'off 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';
...@@ -1728,15 +1735,22 @@ function system_login_configure($verbose = false) ...@@ -1728,15 +1735,22 @@ function system_login_configure($verbose = false)
$serial_type = 'al.' . $serialspeed; $serial_type = 'al.' . $serialspeed;
} }
foreach ($etc_ttys_lines as $tty) { foreach ($etc_ttys_lines as $tty) {
if (strpos($tty, 'ttyv0') === 0) {
/* first virtual terminal */ /* first virtual terminal */
fwrite($fd, "ttyv0\t\"/usr/libexec/getty {$console_type}\"\t\t{$terminal_type}\ton secure\n"); if (strpos($tty, 'ttyv0') === 0) {
fwrite($fd, "ttyv0\t\"/usr/libexec/getty {$console_type}\"\t\t{$terminal_type}\t${on_off_secure_v}\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