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

Commit 362bbf5

Browse files
author
mattpass
committed
Code tidy in terminal.php
1 parent c19503b commit 362bbf5

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

terminal.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@
2121
}
2222

2323
// Up
24-
if (e.keyCode == 38) {
24+
if (38 === e.keyCode) {
2525
// If blank, set a blank line as current
26-
if (document.getElementById('command').value == "") {
26+
if ("" == document.getElementById('command').value) {
2727
currentCommand = "";
2828
}
2929
// If we have history and the last command in history isn't this one
30-
if (commandHistory[commandHistory.length-1] && commandHistory[commandHistory.length-1].replace("[[ICEcoder]]:") != currentCommand) {
30+
if (commandHistory[commandHistory.length - 1] && commandHistory[commandHistory.length - 1].replace("[[ICEcoder]]:", "") !== currentCommand) {
3131
// Push or append as last item in array with string to indicate temp nature
32-
if (commandHistory[commandHistory.length-1].indexOf("[[ICEcoder]]:") !== 0) {
33-
commandHistory.push("[[ICEcoder]]:"+currentCommand);
32+
if (0 !== commandHistory[commandHistory.length - 1].indexOf("[[ICEcoder]]:")) {
33+
commandHistory.push("[[ICEcoder]]:" + currentCommand);
3434
} else {
35-
commandHistory[commandHistory.length-1] = "[[ICEcoder]]:"+currentCommand;
35+
commandHistory[commandHistory.length - 1] = "[[ICEcoder]]:" + currentCommand;
3636
}
3737
}
3838
// If we have at least some items in history, step back a level and display the previous command
39-
if (currentLine > 0) {
39+
if (0 < currentLine) {
4040
currentLine--;
41-
document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:","");
41+
document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:", "");
4242
}
4343
// Down
4444
// If the current line isn't the last in the array, take a step forward and display the command
45-
} else if(e.keyCode == 40 && currentLine < commandHistory.length-1) {
45+
} else if(40 === e.keyCode && currentLine < commandHistory.length - 1) {
4646
currentLine++;
47-
document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:","");
47+
document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:", "");
4848
// Set the current command value to that of the user input
4949
} else {
5050
currentCommand = document.getElementById('command').value;
@@ -54,10 +54,10 @@
5454
sendCmd = function(command) {
5555
// Send command over XHR for response and display
5656
xhr = parent.ICEcoder.xhrObj();
57-
xhr.onreadystatechange=function() {
58-
if (xhr.readyState==4) {
57+
xhr.onreadystatechange = function() {
58+
if (4 === xhr.readyState) {
5959
// OK reponse?
60-
if (xhr.status==200) {
60+
if (200 === xhr.status) {
6161
// Set the output to also include our response and scroll down to bottom
6262
var newOutput = document.createElement("DIV");
6363
responseText = xhr.responseText;
@@ -70,10 +70,10 @@
7070
parent.document.getElementById("terminal").contentWindow.document.documentElement.scrollTop = document.getElementById('output').scrollHeight;
7171

7272
// Add command onto end of history array or set as last item in array
73-
if (currentLine == 0 || commandHistory[commandHistory.length-1].indexOf("[[ICEcoder]]:") !== 0) {
73+
if (0 === currentLine || 0 !== commandHistory[commandHistory.length - 1].indexOf("[[ICEcoder]]:")) {
7474
commandHistory.push(document.getElementById('command').value);
7575
} else {
76-
commandHistory[commandHistory.length-1] = document.getElementById('command').value;
76+
commandHistory[commandHistory.length - 1] = document.getElementById('command').value;
7777
}
7878

7979
// Set the current line to be the length of the array and clear the command
@@ -84,9 +84,9 @@
8484
};
8585

8686
// Send the XHR request
87-
xhr.open("POST",parent.ICEcoder.iceLoc + "/lib/terminal-xhr.php?csrf="+parent.ICEcoder.csrf,true);
87+
xhr.open("POST", parent.ICEcoder.iceLoc + "/lib/terminal-xhr.php?csrf=" + parent.ICEcoder.csrf, true);
8888
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
89-
xhr.send('command='+encodeURIComponent(command));
89+
xhr.send('command=' + encodeURIComponent(command));
9090
}
9191
</script>
9292
</head>
@@ -96,8 +96,8 @@
9696
if (true === isset($_SESSION['cwd'])) {
9797
chdir($_SESSION['cwd']);
9898
}
99-
$user = str_replace("\n","",shell_exec("whoami"));
100-
$cwd = str_replace("\n","",shell_exec("pwd"));
99+
$user = str_replace("\n", "", shell_exec("whoami"));
100+
$cwd = str_replace("\n", "", shell_exec("pwd"));
101101
?>
102102

103103
<form name="shell" onsubmit="sendCmd(document.getElementById('command').value); return false" method="POST">

0 commit comments

Comments
 (0)