prompt_for_password: remove external bash dependency
This commit is contained in:
parent
fb67ffdf3b
commit
99c350267f
1 changed files with 5 additions and 11 deletions
14
src/Cli.php
14
src/Cli.php
|
@ -412,16 +412,10 @@ Additional parameters:
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function prompt_for_password($prompt=null) {
|
public static function prompt_for_password($prompt=null) {
|
||||||
// Check bash is available
|
print($prompt?_($prompt):I18n::_("Please enter password:"));
|
||||||
$command = "/usr/bin/env bash -c 'echo OK'";
|
system('stty -echo');
|
||||||
if (rtrim(shell_exec($command)) !== 'OK')
|
$password = trim(fgets(STDIN));
|
||||||
Log::fatal(I18n::_("Can't invoke bash. Can't ask password prompt."));
|
system('stty echo');
|
||||||
|
|
||||||
$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";
|
|
||||||
return $password;
|
return $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue