mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
Merge pull request #329 from DrDoof/feat/cmd-output
httpd: answer /cmd with what the command printed, and show it in the console tab
This commit is contained in:
7 files changed
+63
-6
No files matched your search
@@ -88,6 +88,8 @@
|
||||
<input style="width:20%;" class="action" id="cmd_sub" onclick="cmdSub();" type="button" data-i18n="sys_send_cmd" value="Send Command"><br/>
|
||||
<br/><br/>
|
||||
<span data-i18n="sys_console_warn">Be careful when entering console commands, you can lock yourself out!</span><br/>
|
||||
<br/>
|
||||
<pre id="console_out" style="height:22em;overflow:auto;white-space:pre-wrap;border:1px solid;padding:0.5em;"></pre>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
+16
-2
@@ -35,14 +35,28 @@ async function ipSub() {
|
||||
}
|
||||
|
||||
async function cmdSub() {
|
||||
var cmd = document.getElementById('console_cmd').value;
|
||||
const input = document.getElementById('console_cmd');
|
||||
const out = document.getElementById('console_out');
|
||||
const cmd = input.value;
|
||||
try {
|
||||
const response = await fetch('/cmd', {
|
||||
method: 'POST',
|
||||
body: cmd
|
||||
});
|
||||
console.log('Completed!', response);
|
||||
if (response.status == 401) {
|
||||
window.location.href = 'login.html';
|
||||
return;
|
||||
}
|
||||
let text = await response.text();
|
||||
if (text != "" && !text.endsWith("\n"))
|
||||
text += "\n";
|
||||
if (out.textContent.length > 20000)
|
||||
out.textContent = out.textContent.slice(-16000);
|
||||
out.textContent += "> " + cmd + "\n" + text;
|
||||
out.scrollTop = out.scrollHeight;
|
||||
input.value = "";
|
||||
} catch(err) {
|
||||
out.textContent += "> " + cmd + "\n" + err + "\n";
|
||||
console.error(`Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user