summaryrefslogtreecommitdiff
path: root/shell/shell.php
blob: 9fd10e61bdec9f23fc177cd08ff5a70d30640777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
if (!isset($LTS)) { die('shell.php may not be accessed directly.'); }
error_reporting(E_ALL);
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']);
}

// Display terminal
?>
<div class="term"><?php
	echo '<form action="'.$_SERVER['PHP_SELF'].'#prompt" method="post">';
		
		// 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 '<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>