Cli: add prompt_for_password() helper method

This commit is contained in:
Benjamin Renard 2023-02-28 01:44:43 +01:00
parent f79be675fb
commit d546bebe49
7 changed files with 97 additions and 51 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2023-02-28 01:28+0100\n"
"POT-Creation-Date: 2023-02-28 01:45+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Benjamin Renard <brenard@zionetrix.net>\n"
"Language-Team: \n"
@ -118,6 +118,16 @@ msgstr ""
"Port d'écoute spécifié invalide. Il doit s'agir d'un entier positif entre 1 "
"et 65535."
#: Cli.php:354
msgid "Can't invoke bash. Can't ask password prompt."
msgstr ""
"Impossible d'utiliser bash. Impossible de demander à l'utilisateur de saisir "
"un mot de passe."
#: Cli.php:357
msgid "Please enter password:"
msgstr "Merci de saisir le mot de passe :"
#: Db.php:74
msgid "Unable to connect to the database."
msgstr "Impossible de se connecter à la base de données."
@ -130,11 +140,11 @@ msgstr "Nom d'utilisateur ou mot de passe invalide."
msgid "Sign in"
msgstr "Connexion"
#: Auth/Http.php:34 Url.php:176
#: Auth/Http.php:34 Url.php:177
msgid "Authentication required"
msgstr "Authentification requise"
#: Auth/Http.php:115 Auth/Http.php:118 Url.php:180
#: Auth/Http.php:115 Auth/Http.php:118 Url.php:181
msgid "Access denied"
msgstr "Accès interdit"
@ -182,19 +192,19 @@ msgstr "Aucun template spécifié."
msgid "An error occurred while displaying this page."
msgstr "Une erreur est survenue en affichant cette page."
#: Url.php:172
#: Url.php:173
msgid "Bad request"
msgstr "Mauvaise requête"
#: Url.php:173
#: Url.php:174
msgid "Invalid request."
msgstr "Requête invalide."
#: Url.php:177
#: Url.php:178
msgid "You have to be authenticated to access to this page."
msgstr "Vous devez être authentifié pour accéder à cette page."
#: Url.php:181
#: Url.php:182
msgid ""
"You do not have access to this application. If you think this is an error, "
"please contact support."
@ -202,25 +212,25 @@ msgstr ""
"Vous n'avez pas accès à cette application. Si vous pensez qu'il s'agit d'une "
"erreur, merci de prendre contact avec le support."
#: Url.php:184
#: Url.php:185
msgid "Whoops ! Page not found"
msgstr "Oups ! Page introuvable"
#: Url.php:185
#: Url.php:186
msgid "The requested page can not be found."
msgstr "La page demandée est introuvable."
#: Url.php:193
#: Url.php:194
msgid "Error"
msgstr "Erreur"
#: Url.php:194
#: Url.php:195
msgid "An unknown error occurred. If problem persist, please contact support."
msgstr ""
"Une erreur inconnue est survenue. Si le problème persiste, merci de prendre "
"contact avec le support."
#: Url.php:257
#: Url.php:258
msgid ""
"Unable to determine the requested page. If the problem persists, please "
"contact support."
@ -228,7 +238,7 @@ msgstr ""
"Impossible de déterminer la page demandée. Si le problème persiste, merci de "
"prendre contact avec le support."
#: Url.php:411
#: Url.php:412
msgid ""
"Unable to determine the requested page (loop detected). If the problem "
"persists, please contact support."
@ -236,15 +246,15 @@ msgstr ""
"Impossible de déterminer la page demandée (boucle détectée). Si le problème "
"persiste, merci de prendre contact avec le support."
#: Url.php:441
#: Url.php:442
msgid "This request cannot be processed."
msgstr "Cette requête ne peut être traitée."
#: Url.php:451
#: Url.php:452
msgid "Authentication required but fail to authenticate you."
msgstr "Authentification requise mais impossible pour vous authentifier."
#: Url.php:460
#: Url.php:461
msgid "This request could not be processed correctly."
msgstr "Cette requête n'a put être traitée correctement."

View file

@ -1,7 +1,7 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2023-02-28 01:28+0100\n"
"PO-Revision-Date: 2023-02-28 01:28+0100\n"
"POT-Creation-Date: 2023-02-28 01:45+0100\n"
"PO-Revision-Date: 2023-02-28 01:45+0100\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

View file

@ -1,7 +1,7 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2023-02-28 01:28+0100\n"
"PO-Revision-Date: 2023-02-28 01:28+0100\n"
"POT-Creation-Date: 2023-02-28 01:45+0100\n"
"PO-Revision-Date: 2023-02-28 01:45+0100\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@ -98,6 +98,14 @@ msgid ""
"65535."
msgstr ""
#: Cli.php:354
msgid "Can't invoke bash. Can't ask password prompt."
msgstr ""
#: Cli.php:357
msgid "Please enter password:"
msgstr ""
#: Db.php:74
msgid "Unable to connect to the database."
msgstr ""
@ -110,11 +118,11 @@ msgstr ""
msgid "Sign in"
msgstr ""
#: Auth/Http.php:34 Url.php:176
#: Auth/Http.php:34 Url.php:177
msgid "Authentication required"
msgstr ""
#: Auth/Http.php:115 Auth/Http.php:118 Url.php:180
#: Auth/Http.php:115 Auth/Http.php:118 Url.php:181
msgid "Access denied"
msgstr ""
@ -156,61 +164,61 @@ msgstr ""
msgid "An error occurred while displaying this page."
msgstr ""
#: Url.php:172
#: Url.php:173
msgid "Bad request"
msgstr ""
#: Url.php:173
#: Url.php:174
msgid "Invalid request."
msgstr ""
#: Url.php:177
#: Url.php:178
msgid "You have to be authenticated to access to this page."
msgstr ""
#: Url.php:181
#: Url.php:182
msgid ""
"You do not have access to this application. If you think this is an error, "
"please contact support."
msgstr ""
#: Url.php:184
#: Url.php:185
msgid "Whoops ! Page not found"
msgstr ""
#: Url.php:185
#: Url.php:186
msgid "The requested page can not be found."
msgstr ""
#: Url.php:193
#: Url.php:194
msgid "Error"
msgstr ""
#: Url.php:194
#: Url.php:195
msgid "An unknown error occurred. If problem persist, please contact support."
msgstr ""
#: Url.php:257
#: Url.php:258
msgid ""
"Unable to determine the requested page. If the problem persists, please "
"contact support."
msgstr ""
#: Url.php:411
#: Url.php:412
msgid ""
"Unable to determine the requested page (loop detected). If the problem "
"persists, please contact support."
msgstr ""
#: Url.php:441
#: Url.php:442
msgid "This request cannot be processed."
msgstr ""
#: Url.php:451
#: Url.php:452
msgid "Authentication required but fail to authenticate you."
msgstr ""
#: Url.php:460
#: Url.php:461
msgid "This request could not be processed correctly."
msgstr ""

View file

@ -90,6 +90,14 @@ msgid ""
"65535."
msgstr ""
#: Cli.php:354
msgid "Can't invoke bash. Can't ask password prompt."
msgstr ""
#: Cli.php:357
msgid "Please enter password:"
msgstr ""
#: Db.php:74
msgid "Unable to connect to the database."
msgstr ""
@ -102,11 +110,11 @@ msgstr ""
msgid "Sign in"
msgstr ""
#: Auth/Http.php:34 Url.php:176
#: Auth/Http.php:34 Url.php:177
msgid "Authentication required"
msgstr ""
#: Auth/Http.php:115 Auth/Http.php:118 Url.php:180
#: Auth/Http.php:115 Auth/Http.php:118 Url.php:181
msgid "Access denied"
msgstr ""
@ -148,61 +156,61 @@ msgstr ""
msgid "An error occurred while displaying this page."
msgstr ""
#: Url.php:172
#: Url.php:173
msgid "Bad request"
msgstr ""
#: Url.php:173
#: Url.php:174
msgid "Invalid request."
msgstr ""
#: Url.php:177
#: Url.php:178
msgid "You have to be authenticated to access to this page."
msgstr ""
#: Url.php:181
#: Url.php:182
msgid ""
"You do not have access to this application. If you think this is an error, "
"please contact support."
msgstr ""
#: Url.php:184
#: Url.php:185
msgid "Whoops ! Page not found"
msgstr ""
#: Url.php:185
#: Url.php:186
msgid "The requested page can not be found."
msgstr ""
#: Url.php:193
#: Url.php:194
msgid "Error"
msgstr ""
#: Url.php:194
#: Url.php:195
msgid "An unknown error occurred. If problem persist, please contact support."
msgstr ""
#: Url.php:257
#: Url.php:258
msgid ""
"Unable to determine the requested page. If the problem persists, please "
"contact support."
msgstr ""
#: Url.php:411
#: Url.php:412
msgid ""
"Unable to determine the requested page (loop detected). If the problem "
"persists, please contact support."
msgstr ""
#: Url.php:441
#: Url.php:442
msgid "This request cannot be processed."
msgstr ""
#: Url.php:451
#: Url.php:452
msgid "Authentication required but fail to authenticate you."
msgstr ""
#: Url.php:460
#: Url.php:461
msgid "This request could not be processed correctly."
msgstr ""

View file

@ -341,4 +341,24 @@ class Cli {
exit($exit_code);
}
/**
* Helper method to ask user to enter a password
* Note: this method use the bash binary and a fatal error will be trigger if it's not available.
* @param string|null $prompt The prompt message (optional)
* @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";
return $password;
}
}