diff --git a/include/errors/class_FusionDirectoryError.inc b/include/errors/class_FusionDirectoryError.inc index ba0bcf2d8b9cd331f8b2b5787428733f21f53ac3..673157c14e707ccc4b2ea50697e271efbbb9f5b5 100755 --- a/include/errors/class_FusionDirectoryError.inc +++ b/include/errors/class_FusionDirectoryError.inc @@ -24,10 +24,15 @@ class FusionDirectoryError extends Error { protected $htmlMessage; + protected $code; + protected ?Throwable $previous; public function __construct (string $htmlMessage = '', int $code = 0, Throwable $previous = NULL) { $this->htmlMessage = $htmlMessage; + // Code is present withing the parent class Error, we take it here to avoid calling a creation. + $this->code = $code; + $this->previous = $previous; } public function getHtmlMessage () diff --git a/include/errors/class_SimplePluginError.inc b/include/errors/class_SimplePluginError.inc index f93ed77eda54fa0c2f814ba2ef07324e0cd88c88..93dc38ac12997bb7ed5769fc53b24adf5441b31e 100755 --- a/include/errors/class_SimplePluginError.inc +++ b/include/errors/class_SimplePluginError.inc @@ -30,7 +30,6 @@ class SimplePluginError extends FusionDirectoryError implements \Stringable public function __construct ($origin, string $htmlMessage = '', int $code = 0, Throwable $previous = NULL) { $this->setOrigin($origin); - parent::__construct($htmlMessage, $code, $previous); } diff --git a/include/errors/class_SimplePluginHookError.inc b/include/errors/class_SimplePluginHookError.inc index 7df540ab71a0ba2d04193112ca247299a1e0d16b..dbfd35a9c3ef746c529552ea4c96dbce2269a3ce 100755 --- a/include/errors/class_SimplePluginHookError.inc +++ b/include/errors/class_SimplePluginHookError.inc @@ -28,7 +28,6 @@ class SimplePluginHookError extends SimplePluginError public function __construct ($origin, string $type, string $output = '', int $code = 0, Throwable $previous = NULL) { $this->hookType = $type; - parent::__construct($origin, nl2br('<samp>'.htmlescape($output).'</samp>'), $code, $previous); } diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 3eb098f8f2275c2a0aab5ccf8e82a40d022ea646..96e360307ea50f6411b7114a65627f9c46ed4e01 100755 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -1671,14 +1671,29 @@ class simplePlugin implements SimpleTab $command = templateHandling::parseString($command, $addAttrs, 'escapeshellarg'); logging::debug(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, 'Execute'); - exec($command, $arr, $returnCode); + logging::debug(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, "Processed Command: " . $command); - $command = static::passwordProtect($command); + // Use proc_open instead of exec + $descriptorspec = [ + 1 => ['pipe', 'w'], // stdout + 2 => ['pipe', 'w'] // stderr + ]; - $returnOutput = $arr; + $process = proc_open($command, $descriptorspec, $pipes); + if (is_resource($process)) { + $output = stream_get_contents($pipes[1]); + $errorOutput = stream_get_contents($pipes[2]); + fclose($pipes[1]); + fclose($pipes[2]); + $returnCode = proc_close($process); + + $returnOutput = array_filter(explode("\n", trim($output . "\n" . $errorOutput))); + } - if ($returnCode != 0) { - $str = implode("\n", $arr); + $command = static::passwordProtect($command); + + if ($returnCode !== 0) { + $str = implode("\n", $returnOutput); $str = static::passwordProtect($str); logging::debug(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, 'Execution failed code: ' . $returnCode); logging::debug(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, 'Output: ' . $str); @@ -1688,15 +1703,12 @@ class simplePlugin implements SimpleTab $str, $returnCode ); - } elseif (is_array($arr)) { - $str = implode("\n", $arr); + } elseif (!empty($returnOutput) && $config->get_cfg_value('displayHookOutput', 'FALSE') == 'TRUE') { + $str = implode("\n", $returnOutput); $str = static::passwordProtect($str); logging::debug(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, 'Output: ' . $str); - if (!empty($str) && $config->get_cfg_value('displayHookOutput', 'FALSE') == 'TRUE') { - msg_dialog::display('[' . static::class . ' ' . strtolower((string) $cmd) . 'trigger] ' . $command, htmlescape($str), INFO_DIALOG); - } + msg_dialog::display('[' . static::class . ' ' . strtolower((string) $cmd) . ' trigger] ' . $command, htmlescape($str), INFO_DIALOG); } - unset($arr, $command, $returnCode); } return $messages; }