function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input) { //dprint("<hr>$dir <hr> "); global $gbl, $sgbl, $login, $ghtml; global $global_shell_out, $global_shell_error, $global_shell_ret; global $global_dontlogshell; $path = "{$sgbl->__path_lxmisc}"; $fename = tempnam($sgbl->__path_tmp, "system_errr"); $execcmd = null; if ($username !== '__system__') { $execcmd = "{$path} -u {$username}"; chmod($path, 0700); } $oldpath = null; if ($dir) { lxfile_mkdir($dir); $oldpath = getcwd(); chdir($dir); } $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $fename, "a")); os_set_path(); $process = proc_open("{$cmd}", $descriptorspec, $pipes); $out = null; if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to $fename if ($input) { fwrite($pipes[0], $input); } fclose($pipes[0]); while (!feof($pipes[1])) { $out .= fgets($pipes[1], 1024); } fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $ret = proc_close($process); } $err = lfile_get_contents($fename); unlink($fename); $tcwd = getcwd(); if ($ret) { log_shell_error("{$err}: [({$username}:{$tcwd}) {$cmd}]"); } if ($global_dontlogshell) { log_log("other_cmd", "{$ret}: {$err} [({$username}:{$tcwd}) {$cmd}]"); } else { log_shell("{$ret}: {$err} [({$username}:{$tcwd}) {$cmd}]"); } $global_shell_ret = $ret; $global_shell_out = $out; $global_shell_error = $err; if ($oldpath) { chdir($oldpath); } }
function recursively_remove($directory) { $directory = trim($directory); if ($directory[strlen($directory) - 1] === '/') { $string = "{$directory}: Directory ends in a slash. Will not recursively delete"; dprint(' <br> ' . $string . "<br> "); log_shell_error($string); return; } lxfile_rm_rec($directory); }
function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input) { global $gbl, $sgbl, $login, $ghtml; global $global_shell_out, $global_shell_error, $global_shell_ret; dprint("<hr> {$dir} <br> {$cmd} <hr> "); $path = "{$sgbl->__path_lxmisc}"; $fename = tempnam($sgbl->__path_tmp, "system_errr"); $execcmd = null; /* if ($username !== '__system__') { $execcmd = "$path -u $username"; } */ os_set_path(); $sh = new COM("Wscript.shell"); if ($dir) { if (!csa($dir, ':')) { $dir = getcwd() . "/{$dir}"; } $sh->currentDirectory = $dir; } $out = null; $ret = 0; $err = null; dprint("\n ** mmmmmm {$dir} {$cmd} **\n"); $cmdobject = $sh->Exec($cmd); if ($input) { $cmdobject->StdIn->Write($input); } $out = $cmdobject->StdOut->ReadAll(); $err = $cmdobject->StdErr->ReadAll(); $ret = 0; $sh->currentDirectory = $sgbl->__path_program_htmlbase; /* function ReadAllFromAny($ret) { if (!($ret->StdOut->AtEndOfStream)){ $Ret=$ret->StdOut->ReadAll(); return $Ret; } if (!($ret->StdErr->AtEndOfStream)){ $Ret="STDERR: ".$ret->StdErr->ReadAll(); return $Ret; } return -1; }*/ if ($ret) { log_shell_error("{$err}: [({$username}:{$dir}) {$cmd}]"); } log_shell("{$ret}: {$err} [({$username}:{$dir}) {$cmd}]"); $global_shell_ret = $ret; $global_shell_out = $out; $global_shell_error = $err; }