You are not logged in.
Pages: 1
Hello,
I'm trying to create a plugin that executes some system commands with the exec() command in php.
When I run the command from a separate script and get the result back to display, it works fine. However, when I execute the same command from a plugin, I get an empty string as a result which blocks me because I have to use this result to execute the other commands. I tried to modify my first command but it does not work. Since it works with a script but not with a plugin, I think the problem is with GLPI.
For information, the commands used come from a NPM package. It is the Bitwarden CLI package which allows to use the Bitwarden solution with a command line interface.
Here is the code from the script:
$session_token = exec("bw login [mail] [password] --raw");
var_dump($session_token);
Here is the code from the plugin:
static function authentication(){
global $CFG_GLPI;
// Retrieving configured values from the DB :
$config = new PluginBitwardenConfig();
$config->getFromDB(1);
// Decryption of the password retrieved from the DB :
$account_passwd =(new GLPIKey())->decrypt($config->fields["account_passwd"]);
// Login to Bitwarden CLI using email & password :
$session_token = exec("bw login [mail] [password] --raw", $output, $rcode);
// We retrieve the session token here
var_dump($session_token); //return empty string
var_dump($output); //return empty array
var_dump($rcode); //return 1 (true)
var_dump($config["email"]); //Creating an error to stop the plugin and force it to display errors and warnings
//Test of the session token :
//If session token is empty or NULL then the login did not go well.
//Else, the login did go well and we return the session token
if(!isset($session_token)||($session_token == "")){
echo "Login failed : wrong email or password, verify your plugin configuration";
return NULL;
}
else{
return $session_token;
}
}
I would like to know if someone has an idea to solve this problem.
That's it for the explanations. I hope I was clear in my approach. If you have any questions for further clarification, don't hesitate.
Offline
Pages: 1