diff --git a/includes/common.php b/includes/common.php index 387cb09ad8..deff57a3de 100644 --- a/includes/common.php +++ b/includes/common.php @@ -21,10 +21,43 @@ function format_number_short($number, $sf) function external_exec($command) { - global $debug; + global $debug , $exec_response; + + $exec_response = array('command' => $command); if ($debug) { echo($command."\n"); } - $output = shell_exec($command); + + $descriptorspec = array( + 0 => array('pipe', 'r'), // stdin + 1 => array('pipe', 'w'), // stdout + 2 => array('pipe', 'w') // stderr + ); + + $process = proc_open($command, $descriptorspec, $pipes); + stream_set_blocking($pipes[2], 0); + if (is_resource($process)) + { + $exec_response['error'] = stream_get_contents($pipes[2]); + if ($exec_response['error']) + { + $output = FALSE; + } else { + $output = stream_get_contents($pipes[1]); + } + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + $exec_response['status'] = proc_close($process); + } else { + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + proc_terminate($process); + $output = FALSE; + $exec_error['error'] = ''; + $exec_response['status'] = -1; + } + if ($debug) { echo($output."\n"); } return $output; diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 708b114d26..56e1c04020 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -47,7 +47,7 @@ function discover_new_device($hostname) function discover_device($device, $options = NULL) { - global $config, $valid; + global $config, $valid, $exec_response; $valid = array(); // Reset $valid array diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index cca6720791..c95a1c5aae 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -89,7 +89,7 @@ function poll_sensor($device, $class, $unit) function poll_device($device, $options) { - global $config, $device, $polled_devices, $db_stats, $memcache; + global $config, $device, $polled_devices, $db_stats, $memcache, $exec_response; $attribs = get_dev_attribs($device['device_id']);