Fix #3647 and other improvements:

- Remove auto_login(), now gettytab is a constant file
- Add reload_ttys(), that will send a SIGHUP to init and make it reload
  /etc/ttys
- Change serial speed on /etc/ttys when necessary
- Change console and serial auto_login on /etc/ttys when necessary
- Change default type from cons25 to xterm
This commit is contained in:
Renato Botelho 2014-07-01 13:37:42 -03:00
parent 6f9a191d76
commit edb4b65732
4 changed files with 30 additions and 91 deletions

View File

@ -902,78 +902,6 @@ function reload_all_sync() {
send_event("service restart webgui");
}
function auto_login() {
global $config;
if(isset($config['system']['disableconsolemenu']))
$status = false;
else
$status = true;
$gettytab = file_get_contents("/etc/gettytab");
$getty_split = explode("\n", $gettytab);
$getty_update_needed = false;
$getty_search_str = ":ht:np:sp#115200";
$getty_al_str = ":al=root:";
$getty_al_search_str = $getty_search_str . $getty_al_str;
/* Check if gettytab is already OK, if so then do not rewrite it. */
foreach($getty_split as $gs) {
if(stristr($gs, $getty_search_str)) {
if($status == true) {
if(!stristr($gs, $getty_al_search_str)) {
$getty_update_needed = true;
}
} else {
if(stristr($gs, $getty_al_search_str)) {
$getty_update_needed = true;
}
}
}
}
if (!$getty_update_needed) {
return;
}
conf_mount_rw();
$fd = false;
$tries = 0;
while (!$fd && $tries < 100) {
$fd = fopen("/etc/gettytab", "w");
$tries++;
}
if (!$fd) {
conf_mount_ro();
if ($status) {
log_error(gettext("Enabling auto login was not possible."));
} else {
log_error(gettext("Disabling auto login was not possible."));
}
return;
}
foreach($getty_split as $gs) {
if(stristr($gs, $getty_search_str)) {
if($status == true) {
fwrite($fd, " ".$getty_al_search_str."\n");
} else {
fwrite($fd, " ".$getty_search_str."\n");
}
} else {
fwrite($fd, "{$gs}\n");
}
}
fclose($fd);
if ($status) {
log_error(gettext("Enabled console auto login, console menu is NOT password protected."));
} else {
log_error(gettext("Disabled console auto login, console menu is password protected."));
}
conf_mount_ro();
}
function setup_serial_port($when="save", $path="") {
global $g, $config;
conf_mount_rw();
@ -1047,24 +975,35 @@ function setup_serial_port($when="save", $path="") {
$ttys = file_get_contents("/etc/ttys");
$ttys_split = explode("\n", $ttys);
$fd = fopen("/etc/ttys", "w");
foreach($ttys_split as $tty) {
if(stristr($tty, "ttyd0") or stristr($tty, "ttyu0")) {
if(isset($config['system']['enableserial']) || $g['enableserial_force']) {
fwrite($fd, "ttyu0 \"/usr/libexec/getty bootupcli\" cons25 on secure\n");
} else {
fwrite($fd, "ttyu0 \"/usr/libexec/getty bootupcli\" cons25 off secure\n");
}
} else {
fwrite($fd, $tty . "\n");
}
$on_off = ((isset($config['system']['enableserial']) || $g['enableserial_force']) ? 'on' : 'off');
if (isset($config['system']['disableconsolemenu'])) {
$console_type = 'Pc';
$serial_type = 'std.' . $serialspeed;
} else {
$console_type = 'al.Pc';
$serial_type = 'al.' . $serialspeed;
}
foreach($ttys_split as $tty) {
if (stristr($tty, "ttyv0"))
fwrite($fd, "ttyv0 \"/usr/libexec/getty {$console_type}\" xterm on secure\n");
else if (stristr($tty, "ttyu0"))
fwrite($fd, "ttyu0 \"/usr/libexec/getty {$seral_type}\" xterm {$on_off} secure\n");
else
fwrite($fd, $tty . "\n");
}
unset($on_off, $console_type, $serial_type);
fclose($fd);
auto_login();
reload_ttys();
conf_mount_ro();
return;
}
function reload_ttys() {
// Send a HUP signal to init will make it reload /etc/ttys
posix_kill(1, SIGHUP);
}
function print_value_list($list, $count = 10, $separator = ",") {
$list = implode($separator, array_slice($list, 0, $count));
if(count($list) < $count) {

View File

@ -393,7 +393,7 @@ function post_cvssync_commands() {
/* lock down console if necessary */
echo "===> Locking down the console if needed...\n";
auto_login();
reload_ttys();
echo "===> Signaling PHP and Lighty restart...";
$fd = fopen("/tmp/restart_lighty", "w");

View File

@ -61,19 +61,19 @@ function rescue_detect_keypress() {
}
// If R or I was pressed do our logic here
if (in_array($key, array("r", "R"))) {
putenv("TERM=cons25");
putenv("TERM=xterm");
echo "\n\nRecovery mode selected...\n";
passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
passthru("/usr/bin/env TERM=xterm /bin/tcsh -c /scripts/lua_installer_rescue");
} elseif (in_array($key, array("i", "I"))) {
putenv("TERM=cons25");
putenv("TERM=xterm");
echo "\n\nInstaller mode selected...\n";
passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
passthru("/usr/bin/env TERM=xterm /bin/tcsh -c /scripts/lua_installer");
if(file_exists("/tmp/install_complete")) {
passthru("/etc/rc.reboot");
exit;
}
} elseif (in_array($key, array("!", "~"))) {
putenv("TERM=cons25");
putenv("TERM=xterm");
echo "\n\nRecovery shell selected...\n";
echo "\n";
touch("/tmp/donotbootup");
@ -375,7 +375,7 @@ services_snmpd_configure();
system_set_harddisk_standby();
/* lock down console if necessary */
auto_login();
reload_ttys();
/* load graphing functions */
enable_rrd_graphing();

View File

@ -161,7 +161,7 @@ case ${opmode} in
;;
99)
if [ -e /dev/ukbd0 ]; then
env TERM=cons25 /scripts/lua_installer
env TERM=xterm /scripts/lua_installer
else
/scripts/lua_installer
fi