workaround for passthru() being disabled

This commit is contained in:
divinity76 2022-07-12 19:14:55 +02:00 committed by GitHub
commit 1a081dfdbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,14 +26,24 @@ if ($_GET['type'] == 'access') $type = 'access';
if ($_GET['type'] == 'error') $type = 'error';
$cmd = implode(" ", array(
escapeshellarg(VESTA_CMD . "v-list-web-domain-" . $type . "log"),
escapeshellarg($user),
escapeshellarg($v_domain),
"5000",
));
passthru($cmd, $return_var);
if(is_callable("passthru")){
passthru($cmd, $return_var);
} else{
// passthru is disabled, workaround it by writing the output to a file then reading the file.
// this is slower than passthru, but avoids running out of RAM...
$passthru_is_disabled_workaround_handle = tmpfile();
$passthru_is_disabled_workaround_file = stream_get_meta_data($passthru_is_disabled_workaround_handle)['uri'];
exec ($cmd . " > " . escapeshellarg($passthru_is_disabled_workaround_file), $output, $return_var);
readfile($passthru_is_disabled_workaround_file);
fclose($passthru_is_disabled_workaround_handle); // fclose(tmpfile()) automatically deletes the file, unlink is not required :)
}
if ($return_var != 0) {
$errstr = "Internal server error: command returned non-zero: {$return_var}: {$cmd}";
echo $errstr;