mirror of
https://github.com/unraid/webgui.git
synced 2026-01-07 18:19:54 -06:00
Refactor getUserShell() for improved clarity and maintainability
- Introduce variable for better code readability - Simplify return logic using the default shell variable - Maintain comprehensive error handling with Throwable
This commit is contained in:
@@ -30,26 +30,25 @@ $run = "$docroot/webGui/scripts/run_cmd";
|
||||
if (!empty($display['tty'])) exec("sed -ri 's/fontSize=[0-9]+/fontSize={$display['tty']}/' /etc/default/ttyd");
|
||||
|
||||
function getUserShell() {
|
||||
$shell = 'bash';
|
||||
$defaultShell = 'bash';
|
||||
|
||||
try {
|
||||
$username = posix_getpwuid(posix_geteuid())['name'];
|
||||
$passwd = file_get_contents('/etc/passwd');
|
||||
$lines = explode("\n", $passwd);
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode(':', $line);
|
||||
if ($parts[0] === $username) {
|
||||
$fullShellPath = end($parts);
|
||||
$shell = basename(trim($fullShellPath));
|
||||
break;
|
||||
}
|
||||
$parts = explode(':', $line);
|
||||
if ($parts[0] === $username) {
|
||||
$fullShellPath = end($parts);
|
||||
return basename(trim($fullShellPath));
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
syslog(LOG_ERR, "Error determining user shell: " . $e->getMessage());
|
||||
} catch (Throwable $t) {
|
||||
syslog(LOG_ERR, 'Error determining user shell: ' . $t->getMessage());
|
||||
return defaultShell;
|
||||
}
|
||||
|
||||
syslog(LOG_INFO, sprintf("User shell determined: %s %s", $username, $shell));
|
||||
|
||||
return $shell;
|
||||
return defaultShell;
|
||||
}
|
||||
|
||||
function wait($name,$cmd) {
|
||||
|
||||
Reference in New Issue
Block a user