summaryrefslogtreecommitdiff
path: root/shell/exec.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-11-27 11:26:20 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-11-27 11:26:20 -0500
commit76ead734626996f82caddaca57dc2f84243b0947 (patch)
tree32ea6607a7c70de059b4bf376897b64391af2321 /shell/exec.php
parentfb0380f48203a11584773f3db335eaadd9cc6fdf (diff)
This zip file was identified as ltshell-3.6.zip
Diffstat (limited to 'shell/exec.php')
-rw-r--r--shell/exec.php71
1 files changed, 39 insertions, 32 deletions
diff --git a/shell/exec.php b/shell/exec.php
index b842ea8..9c22e5b 100644
--- a/shell/exec.php
+++ b/shell/exec.php
@@ -1,32 +1,27 @@
<?php
-function php_chdir($dir) {
+function lts_chdir($dir) {
$ret = chdir($dir);
echo '<input type="hidden" name="d" value="'.getcwd().'" />';
+ if ($ret == false) { echo 'chdir: unable to change directories: `'.$dir."'\n";
return $ret;
}
abstract class prog { public static abstract function main($args, $env); }
-function php_exec($com, $cwd='') {
- if ($cwd != '') { php_chdir($cwd); }
+function lts_shell_exec($com, $env) {
+ if ($env['CWD'] != '') { lts_chdir($env['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 = '';
+ $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_count ('\'',$char)!==0) {
if (substr($q,0,1)===$char) {
$q = substr($q,1);
} else {
@@ -34,14 +29,16 @@ function php_exec($com, $cwd='') {
}
} elseif ($q != '') {
$coms[$c][$a].=$char;
- } elseif (substr_count ($ifs,$char)!==0) {
+ } elseif (substr_count ($env['IFS'],$char)!==0) {
if (isset($coms[$c][$a])) {
$a++;
}
- } elseif (substr_count (';',$char)!==0) {
- $stdout_dest[$c] = '/dev/stdout';
+ } elseif ($char==';') {
+ if (!isset($stdout_dest[$c])) {
+ $stdout_dest[$c] = '/dev/stdout';
+ }
$c++; $a=0;
- } elseif (substr_count ('|',$char)!==0) {
+ } elseif ($char=='|') {
$stdout_dest[$c] = '/dev/stdin';
$c++; $a=0;
} else {
@@ -52,25 +49,18 @@ function php_exec($com, $cwd='') {
$stdout_dest[$c] = '/dev/stdout';
}
+ // execude commands
$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);
+
+ lts_exec($args, $env);
+
+ if ($stdout_dest[$key] == '/dev/stdout') {
+ unset($_POST['stdin']);
} 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;
@@ -80,3 +70,20 @@ function php_exec($com, $cwd='') {
}
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;
+}
+