'; return $ret; } abstract class prog { public static abstract function main($args, $env); } function php_exec($com, $cwd='') { if ($cwd != '') { php_chdir($cwd); } if ($com=='') { return 0; } $root = dirname(__FILE__); $ifs=' '; $path = $root.'/bin'; $env = array('IFS' => $ifs, 'PATH' => $path); $coms = array(); $stdout_dest = array(); $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 ($ifs,$char)!==0) { if (isset($coms[$c][$a])) { $a++; } } elseif (substr_count (';',$char)!==0) { $stdout_dest[$c] = '/dev/stdout'; $c++; $a=0; } elseif (substr_count ('|',$char)!==0) { $stdout_dest[$c] = '/dev/stdin'; $c++; $a=0; } else { $coms[$c][$a].=$char; } } if (!isset($stdout_dest[$c])) { $stdout_dest[$c] = '/dev/stdout'; } $ret=0; if (!isset($_POST['stdin'])) { $_POST['stdin']=''; } foreach ($coms as $key => $args) { if ($stdout_dest[$key] != '/dev/stdout') { ob_start(); } if (!class_exists('p_'.$args[0])) { $file=$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);//main($args,$env); } else { echo 'sh: command not found: `'.$args[0]."'\n"; $ret = 1; } if ($stdout_dest[$key] != '/dev/stdout') { 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; }