prompt_for_password: remove external bash dependency

This commit is contained in:
Benjamin Renard 2024-02-20 21:13:33 +01:00
parent fb67ffdf3b
commit 99c350267f

View file

@ -412,16 +412,10 @@ Additional parameters:
* @return string
*/
public static function prompt_for_password($prompt=null) {
// Check bash is available
$command = "/usr/bin/env bash -c 'echo OK'";
if (rtrim(shell_exec($command)) !== 'OK')
Log::fatal(I18n::_("Can't invoke bash. Can't ask password prompt."));
$command = "/usr/bin/env bash -c 'read -s -p \"";
$command .= addslashes($prompt?_($prompt):I18n::_("Please enter password:"));
$command .= "\" mypassword && echo \$mypassword'";
$password = rtrim(shell_exec($command));
echo "\n";
print($prompt?_($prompt):I18n::_("Please enter password:"));
system('stty -echo');
$password = trim(fgets(STDIN));
system('stty echo');
return $password;
}