From: hickert Date: Tue, 11 May 2010 13:27:16 +0000 (+0000) Subject: Updated command verifier X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bb036f5f7446fe3f2c71f49a8c7cf642ca8f3fae;p=gosa.git Updated command verifier -Added code from php.net - a comment about large amount result. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18371 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/addons/configViewer/class_commandVerifier.inc b/gosa-core/plugins/addons/configViewer/class_commandVerifier.inc index 92244ca9e..c93fa3368 100644 --- a/gosa-core/plugins/addons/configViewer/class_commandVerifier.inc +++ b/gosa-core/plugins/addons/configViewer/class_commandVerifier.inc @@ -18,36 +18,55 @@ class commandVerifier $output= ""; if(isset($_POST['execute'])){ - $descriptorspec = array(0 => array("pipe", "w"),1 => array("pipe", "w"), 2 => array("pipe", "w")); - $process = proc_open($this->command, $descriptorspec, $pipes); - if (is_resource($process)) { - $send= stream_get_contents($pipes[0]); - $res = trim(htmlentities(stream_get_contents($pipes[1]),ENT_COMPAT,'UTF-8')); - $err = trim(htmlentities(stream_get_contents($pipes[2]),ENT_COMPAT,'UTF-8')); - fclose($pipes[0]); - fclose($pipes[1]); - fclose($pipes[2]); - $code = proc_close($process); - - if(!empty($err)) $err = "
{$err}
"; - if(!empty($res)) $res = "
{$res}
"; - - $output = " - - - - -
Result:$res
Error:$err
Return code:$code
"; + + + $descriptorSpec = array(0 => array("pipe", "r"), + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w')); + $process = proc_open($this->command, $descriptorSpec, $pipes); + $txOff = 0; $txLen = strlen($stdin); + + $stdout = ''; $stdoutDone = FALSE; + $stderr = ''; $stderrDone = FALSE; + stream_set_blocking($pipes[0], 0); // Make stdin/stdout/stderr non-blocking + stream_set_blocking($pipes[1], 0); + stream_set_blocking($pipes[2], 0); + if ($txLen == 0) fclose($pipes[0]); + while (TRUE) { + $rx = array(); // The program's stdout/stderr + if (!$stdoutDone) $rx[] = $pipes[1]; + if (!$stderrDone) $rx[] = $pipes[2]; + foreach ($rx as $r) { + if ($r == $pipes[1]) { + $stdout .= fread($pipes[1], 8192); + if (feof($pipes[1])) { fclose($pipes[1]); $stdoutDone = TRUE; } + } else if ($r == $pipes[2]) { + $stderr .= fread($pipes[2], 8192); + if (feof($pipes[2])) { fclose($pipes[2]); $stderrDone = TRUE; } + } + } + if (!is_resource($process)) break; + if ($txOff >= $txLen && $stdoutDone && $stderrDone) break; } + $code = proc_close($process); + + if(!empty($stdout)) $stdout = "
{$stdout}
"; + if(!empty($stdout)) $stdout = "
{$stdout}
"; + $output = " + + + + +
Result:$stdout
Error:$stdout
Return code:$code
"; } $smarty->assign('value', htmlentities($this->command,ENT_COMPAT,'UTF-8')); $smarty->assign('output', $output); return($smarty->fetch(get_template_path('commandVerifier.tpl', 'TRUE'))); } - function save_object() - { - if(isset($_POST['command'])) $this->command = get_post('command'); +function save_object() +{ + if(isset($_POST['command'])) $this->command = get_post('command'); } function save()