Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 9b881cf

Browse files
author
mattpass
committed
Set cwd in session initially and chdir to it always
1 parent c3c829e commit 9b881cf

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/terminal-xhr.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
'll' => 'ls -lvhF',
99
);
1010

11-
// If we have a current working dir in session, change to that dir
12-
if (true === isset($_SESSION['cwd'])) {
13-
chdir($_SESSION['cwd']);
11+
// If we have no cwd set in session, set it now
12+
if (false === isset($_SESSION['cwd'])) {
13+
$_SESSION['cwd'] = $docRoot . $iceRoot;
1414
}
1515

16+
// Change to cwd
17+
chdir($_SESSION['cwd']);
18+
1619
// Get current user and cwd
1720
$user = str_replace("\n", "", shell_exec("whoami"));
1821
$cwd = str_replace("\n", "", shell_exec("pwd"));
@@ -138,9 +141,10 @@ function returnHTMLPromptCommand($cmd) {
138141

139142
// Change to the cwd in session
140143
chdir($_SESSION['cwd']);
144+
141145
// and again ask for current user and working dir
142-
$user = str_replace("\n","",shell_exec("whoami"));
143-
$cwd = str_replace("\n","",shell_exec("pwd"));
146+
$user = str_replace("\n", "", shell_exec("whoami"));
147+
$cwd = str_replace("\n", "", shell_exec("pwd"));
144148

145149
// Finally, output our JSON data
146150
echo json_encode([

terminal.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@
9393

9494
<body onclick="document.getElementById('command').focus()">
9595
<?php
96-
if (true === isset($_SESSION['cwd'])) {
97-
chdir($_SESSION['cwd']);
96+
// If we have no cwd set in session, set it now
97+
if (false === isset($_SESSION['cwd'])) {
98+
$_SESSION['cwd'] = $docRoot . $iceRoot;
9899
}
100+
101+
// Change to cwd
102+
chdir($_SESSION['cwd']);
103+
104+
// Get current user and cwd
99105
$user = str_replace("\n", "", shell_exec("whoami"));
100106
$cwd = str_replace("\n", "", shell_exec("pwd"));
101107
?>

0 commit comments

Comments
 (0)