From de5cb6329b4e6a4c409d1418f16a3488a53ca953 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Nov 2011 11:29:44 -0500 Subject: This is what was deployed on the lnns server --- shell/exec.php | 178 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 89 insertions(+), 89 deletions(-) (limited to 'shell/exec.php') diff --git a/shell/exec.php b/shell/exec.php index 9c22e5b..0d9c374 100644 --- a/shell/exec.php +++ b/shell/exec.php @@ -1,89 +1,89 @@ -'; - if ($ret == false) { echo 'chdir: unable to change directories: `'.$dir."'\n"; - return $ret; -} - -abstract class prog { public static abstract function main($args, $env); } - -function lts_shell_exec($com, $env) { - if ($env['CWD'] != '') { lts_chdir($env['CWD']); } - if ($com=='') { return 0; } - - $coms = array(); - $stdout_dest = array(); - - // Parse command(s) - $a = 0; $c = 0; $q = ''; - while ($com != '') { - $char = substr($com,0,1); - $com = substr($com,1); - if (substr_count ('\'',$char)!==0) { - if (substr($q,0,1)===$char) { - $q = substr($q,1); - } else { - $q = $char.$q; - } - } elseif ($q != '') { - $coms[$c][$a].=$char; - } elseif (substr_count ($env['IFS'],$char)!==0) { - if (isset($coms[$c][$a])) { - $a++; - } - } elseif ($char==';') { - if (!isset($stdout_dest[$c])) { - $stdout_dest[$c] = '/dev/stdout'; - } - $c++; $a=0; - } elseif ($char=='|') { - $stdout_dest[$c] = '/dev/stdin'; - $c++; $a=0; - } else { - $coms[$c][$a].=$char; - } - } - if (!isset($stdout_dest[$c])) { - $stdout_dest[$c] = '/dev/stdout'; - } - - // execude commands - $ret=0; - foreach ($coms as $key => $args) { - if ($stdout_dest[$key] != '/dev/stdout') { - ob_start(); - } - - lts_exec($args, $env); - - if ($stdout_dest[$key] == '/dev/stdout') { - unset($_POST['stdin']); - } else { - switch ($stdout_dest[$key]) { - case '/dev/stdin': $_POST['stdin']=ob_get_contents(); break; - default: file_put_contents($stdout_dest[$key],ob_get_contents()); break; - } - ob_end_clean(); - } - } - return $ret; -} - -function lts_exec($args, $env) { - if (!class_exists('p_'.$args[0])) { - $file=$env['PATH'].'/'.$args[0].'.php'; - if (file_exists($file)) { - include($file); - } - } - if (class_exists('p_'.$args[0])) { - $ret = call_user_func(array('p_'.$args[0],'main'),$args,$env); - } else { - echo 'lts_exec: command not found: `'.$args[0]."'\n"; - $ret = 1; - } - return $ret; -} - +'; + if ($ret == false) { echo 'chdir: unable to change directories: `'.$dir."'\n"; } + return $ret; +} + +abstract class prog { public static abstract function main($args, $env); } + +function lts_shell_exec($com, $env) { + if ($env['CWD'] != '') { lts_chdir($env['CWD']); } + if ($com=='') { return 0; } + + $coms = array(); + $stdout_dest = array(); + + // Parse command(s) + $a = 0; $c = 0; $q = ''; + while ($com != '') { + $char = substr($com,0,1); + $com = substr($com,1); + if (!isset($coms[$c])) { $coms[$c] = array(); } + if (substr_count ('\'',$char)!==0) { + if (substr($q,0,1)===$char) { + $q = substr($q,1); + } else { + $q = $char.$q; + } + } elseif ($q != '') { + @$coms[$c][$a].=$char; + } elseif (substr_count ($env['IFS'],$char)!==0) { + if (isset($coms[$c][$a])) { + $a++; + } + } elseif ($char==';') { + if (!isset($stdout_dest[$c])) { + $stdout_dest[$c] = '/dev/stdout'; + } + $c++; $a=0; + } elseif ($char=='|') { + $stdout_dest[$c] = '/dev/stdin'; + $c++; $a=0; + } else { + @$coms[$c][$a].=$char; + } + } + if (!isset($stdout_dest[$c])) { + $stdout_dest[$c] = '/dev/stdout'; + } + + // execude commands + $ret=0; + foreach ($coms as $key => $args) { + if ($stdout_dest[$key] != '/dev/stdout') { + ob_start(); + } + + lts_exec($args, $env); + + if ($stdout_dest[$key] == '/dev/stdout') { + unset($_POST['stdin']); + } else { + switch ($stdout_dest[$key]) { + case '/dev/stdin': $_POST['stdin']=ob_get_contents(); break; + default: file_put_contents($stdout_dest[$key],ob_get_contents()); break; + } + ob_end_clean(); + } + } + return $ret; +} + +function lts_exec($args, $env) { + if (!class_exists('p_'.$args[0])) { + $file=$env['PATH'].'/'.$args[0].'.php'; + if (file_exists($file)) { + include($file); + } + } + if (class_exists('p_'.$args[0])) { + $ret = call_user_func(array('p_'.$args[0],'main'),$args,$env); + } else { + echo 'lts_exec: command not found: `'.$args[0]."'\n"; + $ret = 1; + } + return $ret; +} -- cgit v1.2.3