|
21 | 21 | }
|
22 | 22 |
|
23 | 23 | // Up
|
24 |
| - if (e.keyCode == 38) { |
| 24 | + if (38 === e.keyCode) { |
25 | 25 | // If blank, set a blank line as current
|
26 |
| - if (document.getElementById('command').value == "") { |
| 26 | + if ("" == document.getElementById('command').value) { |
27 | 27 | currentCommand = "";
|
28 | 28 | }
|
29 | 29 | // 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) { |
31 | 31 | // 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); |
34 | 34 | } else {
|
35 |
| - commandHistory[commandHistory.length-1] = "[[ICEcoder]]:"+currentCommand; |
| 35 | + commandHistory[commandHistory.length - 1] = "[[ICEcoder]]:" + currentCommand; |
36 | 36 | }
|
37 | 37 | }
|
38 | 38 | // 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) { |
40 | 40 | currentLine--;
|
41 |
| - document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:",""); |
| 41 | + document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:", ""); |
42 | 42 | }
|
43 | 43 | // Down
|
44 | 44 | // 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) { |
46 | 46 | currentLine++;
|
47 |
| - document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:",""); |
| 47 | + document.getElementById('command').value = commandHistory[currentLine].replace("[[ICEcoder]]:", ""); |
48 | 48 | // Set the current command value to that of the user input
|
49 | 49 | } else {
|
50 | 50 | currentCommand = document.getElementById('command').value;
|
|
54 | 54 | sendCmd = function(command) {
|
55 | 55 | // Send command over XHR for response and display
|
56 | 56 | xhr = parent.ICEcoder.xhrObj();
|
57 |
| - xhr.onreadystatechange=function() { |
58 |
| - if (xhr.readyState==4) { |
| 57 | + xhr.onreadystatechange = function() { |
| 58 | + if (4 === xhr.readyState) { |
59 | 59 | // OK reponse?
|
60 |
| - if (xhr.status==200) { |
| 60 | + if (200 === xhr.status) { |
61 | 61 | // Set the output to also include our response and scroll down to bottom
|
62 | 62 | var newOutput = document.createElement("DIV");
|
63 | 63 | responseText = xhr.responseText;
|
|
70 | 70 | parent.document.getElementById("terminal").contentWindow.document.documentElement.scrollTop = document.getElementById('output').scrollHeight;
|
71 | 71 |
|
72 | 72 | // 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]]:")) { |
74 | 74 | commandHistory.push(document.getElementById('command').value);
|
75 | 75 | } else {
|
76 |
| - commandHistory[commandHistory.length-1] = document.getElementById('command').value; |
| 76 | + commandHistory[commandHistory.length - 1] = document.getElementById('command').value; |
77 | 77 | }
|
78 | 78 |
|
79 | 79 | // Set the current line to be the length of the array and clear the command
|
|
84 | 84 | };
|
85 | 85 |
|
86 | 86 | // 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); |
88 | 88 | xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
89 |
| - xhr.send('command='+encodeURIComponent(command)); |
| 89 | + xhr.send('command=' + encodeURIComponent(command)); |
90 | 90 | }
|
91 | 91 | </script>
|
92 | 92 | </head>
|
|
96 | 96 | if (true === isset($_SESSION['cwd'])) {
|
97 | 97 | chdir($_SESSION['cwd']);
|
98 | 98 | }
|
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")); |
101 | 101 | ?>
|
102 | 102 |
|
103 | 103 | <form name="shell" onsubmit="sendCmd(document.getElementById('command').value); return false" method="POST">
|
|
0 commit comments