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/bin/cat.php | 37 ++++++----- shell/bin/cd.php | 18 +++--- shell/bin/cp.php | 72 +++++++++++---------- shell/bin/editor.php | 50 +++++++-------- shell/bin/grep.php | 52 +++++++++++++++ shell/bin/mkdir.php | 13 ++++ shell/bin/mv.php | 43 ++++++------- shell/bin/php.php | 9 +++ shell/bin/rm.php | 46 ++++++++++--- shell/exec.php | 178 +++++++++++++++++++++++++-------------------------- shell/foobar.txt | 1 - shell/index.php | 62 +++++++++--------- shell/shell.php | 98 ++++++++++++++-------------- shell/shell2.php | 48 -------------- shell/style.css | 82 ++++++++++++------------ 15 files changed, 438 insertions(+), 371 deletions(-) create mode 100644 shell/bin/grep.php create mode 100644 shell/bin/mkdir.php create mode 100644 shell/bin/php.php delete mode 100644 shell/foobar.txt delete mode 100644 shell/shell2.php diff --git a/shell/bin/cat.php b/shell/bin/cat.php index 8778f22..8376ca0 100644 --- a/shell/bin/cat.php +++ b/shell/bin/cat.php @@ -1,15 +1,22 @@ -'; - echo ''; - echo ''."\n"; - echo ''; - echo ''; - } - } -} - +'; + echo ''; + echo ''."\n"; + echo ''; + echo ''; + } + } +} + diff --git a/shell/bin/grep.php b/shell/bin/grep.php new file mode 100644 index 0000000..c73b911 --- /dev/null +++ b/shell/bin/grep.php @@ -0,0 +1,52 @@ + $line_contents) { + if (preg_match($pattern,$line_contents)>0) { + if ( + (self::flag($flags,'r') && !self::flag($flags,'h')) // recursive + || (self::flag($flags,'H')) // or explicit + ) { echo htmlentities($file).': '; } + if (self::flag($flags,'n')) { echo $line_number.': '; } + echo htmlentities($line_contents)."\n"; + } + } + } + + public static function main($args, $env) { + $me = array_shift($args); + $flags = ''; + while (substr($args[0],0,1) == '-') { + $flags .= array_shift($args); + } + $flags = preg_replace('/[ -]/','',$flags); + $pattern = array_shift($args); + foreach ($args as $file) { + if (self::flag($flags,'r')) { self::recurse_grep($pattern, $file, $flags); } + else { self::grep($pattern, $file, $flags); } + } + } +} diff --git a/shell/bin/mkdir.php b/shell/bin/mkdir.php new file mode 100644 index 0000000..565f47a --- /dev/null +++ b/shell/bin/mkdir.php @@ -0,0 +1,13 @@ +2) { - $dest = array_pop($args); - if (!is_dir($dest) { - echo $me.': dest must be a directory: `'.$dest."'\n"; - return 1; - } - foreach ($args as $src) { - rename($src,$dest.'/'.basename($src)); - } - } elseif (count($args)==2) { - rename($args[0],$args[1]); - } else { - echo 'Usage: '.$me." SOURCE [SOURCE2 [SOURCE3 ...]] DEST\n"; - return 1; - } - } -} - +2) { + $dest = array_pop($args); + if (!is_dir($dest)) { + echo $me.': dest must be a directory: `'.$dest."'\n"; + return 1; + } + foreach ($args as $src) { + rename($src,$dest.'/'.basename($src)); + } + } elseif (count($args)==2) { + rename($args[0],$args[1]); + } else { + echo 'Usage: '.$me." SOURCE [SOURCE2 [SOURCE3 ...]] DEST\n"; + return 1; + } + } +} diff --git a/shell/bin/php.php b/shell/bin/php.php new file mode 100644 index 0000000..0e3ba38 --- /dev/null +++ b/shell/bin/php.php @@ -0,0 +1,9 @@ +'; - 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; +} diff --git a/shell/foobar.txt b/shell/foobar.txt deleted file mode 100644 index fd80404..0000000 --- a/shell/foobar.txt +++ /dev/null @@ -1 +0,0 @@ -this is foobar.txt \ No newline at end of file diff --git a/shell/index.php b/shell/index.php index 6d62a65..ce89fec 100644 --- a/shell/index.php +++ b/shell/index.php @@ -1,31 +1,31 @@ -'; -?> - - - - ltShell 3 - - - - -
- - +'; +?> + + + + ltShell 3 + + + + +
+ + diff --git a/shell/shell.php b/shell/shell.php index 499441d..9fd10e6 100644 --- a/shell/shell.php +++ b/shell/shell.php @@ -1,48 +1,50 @@ - -
'; - echo $term; - echo ''; - echo ''; - echo ''; -?>
- - + +
'; + + // Figure out what needs to be displayed on the terminal + if (!isset($_POST['c'])) { $_POST['c'] = ''; } + ob_start(); + if ($_POST['c'] == 'clear') { + lts_chdir('.'); + } else { + if (isset($_POST['stdout'])) { echo htmlentities($_POST['stdout']); } + echo $_POST['c']."\n"; + + lts_shell_exec($_POST['c'],$env); + + echo '$ '; + } + $term = ob_get_contents(); + ob_end_flush(); + + // prompt + echo ''; + echo ''; + echo ''; +?>
+ diff --git a/shell/shell2.php b/shell/shell2.php deleted file mode 100644 index 345064d..0000000 --- a/shell/shell2.php +++ /dev/null @@ -1,48 +0,0 @@ - -
'; - echo $term; - echo ''; - echo ''; - echo ''; -?>
- - diff --git a/shell/style.css b/shell/style.css index 3206cc4..a294994 100644 --- a/shell/style.css +++ b/shell/style.css @@ -1,41 +1,41 @@ -body { - background-color: black; - color: white; -} -.login { - border: solid 2px white; - background: #555555; - position: fixed; - top: 0; right:0; -} -.term { - display:block; -} -.term, .term * { - background-color: black; - color: white; - white-space: pre-wrap; - font-family: monospace; - border: none; - font-size: 1em; -} -.hidden { - display:none; -} -.term input[type=text], -.term input[type=text]:focus { - height:1em; - width: 78em; - margin:0; padding:0; border:none; -} -.editor { - background: #AAAAAA; - padding:2em 1em; - width: 100%; - color: black; - height: 24em; -} -.editor textarea { width: 90%; height: 22em; } -form { - display: inline; -} +body { + background-color: black; + color: white; +} +.login { + border: solid 2px white; + background: #555555; + position: fixed; + top: 0; right:0; +} +.term { + display:block; +} +.term, .term * { + background-color: black; + color: white; + white-space: pre-wrap; + font-family: monospace; + border: none; + font-size: 1em; +} +.hidden { + display:none; +} +.term input[type=text], +.term input[type=text]:focus { + /*height:1em;*/ + width: 78em; + margin:0; padding:0; border:none; +} +.editor { + background: #AAAAAA; + padding:2em 1em; + width: 100%; + color: black; + height: 100%; +} +.editor textarea { width: 90%; height: 22em; } +form { + display: inline; +} -- cgit v1.1-4-g5e80