You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-03-27 12:21:48

Ocotaa
Member
Registered: 2022-10-12
Posts: 2

php command exec() return string(0) ""

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

Board footer

Powered by FluxBB