summaryrefslogtreecommitdiff
path: root/shell/shell2.php
diff options
context:
space:
mode:
Diffstat (limited to 'shell/shell2.php')
-rw-r--r--shell/shell2.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/shell/shell2.php b/shell/shell2.php
new file mode 100644
index 0000000..345064d
--- /dev/null
+++ b/shell/shell2.php
@@ -0,0 +1,48 @@
+<?php if (!isset($LTS)) { die(); }
+
+include('exec.php');
+
+// Set up environment
+$ltshell_dir = dirname(__FILE__);
+$env['PATH'] = $ltshell_dir.'/bin';
+$env['IFS'] = " \t\n";
+if (isset($_POST['d'])) { chdir($_POST['d']); }
+$env['CWD'] = getcwd();
+
+// Check for an incomplete command
+if (isset($_POST['stdout_dest'])) {
+ $_POST['c'] = $_POST['stdout_dest'];
+ unset($_POST['stdout_dest']);
+}
+
+// Figure out what needs to be displayed on the terminal
+ob_start();
+ if ($_POST['c'] == 'clear') {
+ lts_chdir('.');
+ } else {
+ echo htmlentities($_POST['stdout']);
+ echo $_POST['c']."\n";
+
+ lts_shell_exec($_POST['c'],$env);
+
+ echo '$ ';
+ }
+$term = ob_get_contents();
+ob_end_clean();
+
+// Display it
+?>
+<div class="term"><?php
+ echo '<form action="'.$_SERVER['PHP_SELF'].'#prompt" method="post">';
+ echo $term;
+ echo '<input id="prompt" type="text" name="c" />';
+ echo '<textarea name="stdout" class="hidden" readonly="readonly">';
+ // this PCRE is so that only markup from the current
+ // command ends up on the terminal; the rest gets
+ // stripped out
+ echo preg_replace('/<[^>]*>/','',$term);
+ echo '</textarea>';
+ echo '</form>';
+?></div>
+</form>
+<!-- edited -->