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
16
src/Cli.php
16
src/Cli.php
|
@ -412,17 +412,11 @@ 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');
|
||||||
|
return $password;
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue