made simple "command" sending
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const hostname = `192.168.${Math.floor(Math.random()*100)}.${Math.floor(Math.random()*255)}`;
|
const hostname = `192.168.${Math.floor(Math.random()*100)}.${Math.floor(Math.random()*255)}`;
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
|
||||||
document.querySelectorAll(".pathText").forEach((element)=> {
|
document.querySelectorAll(".pathText").forEach((element)=> {
|
||||||
@@ -38,15 +39,34 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
|
|
||||||
async function sendCommand(e){
|
async function sendCommand(e){
|
||||||
const command = e.target.value;
|
const command = e.target.value;
|
||||||
console.log("COMMAND SENT: "+command);
|
|
||||||
|
|
||||||
const response = await fetch("/execute")
|
|
||||||
const files = await response.json();
|
|
||||||
|
|
||||||
console.log(files);
|
|
||||||
|
|
||||||
e.target.value = "";
|
e.target.value = "";
|
||||||
resizeInput();
|
resizeInput();
|
||||||
|
|
||||||
|
|
||||||
|
console.log("COMMAND SENT: "+command);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Construct the URL with the command parameter in the query string
|
||||||
|
const url = "/execute?command=" + encodeURIComponent(command);
|
||||||
|
|
||||||
|
// Make a GET request using the fetch API
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Error: ${response.status} - ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the JSON response
|
||||||
|
const files = await response.json();
|
||||||
|
|
||||||
|
// Handle the execution response
|
||||||
|
handleExecutionResponse(files);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error:", error.message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,4 +105,8 @@ function measureTextWidth(text) {
|
|||||||
document.body.removeChild(fakeElement);
|
document.body.removeChild(fakeElement);
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleExecutionResponse(response) {
|
||||||
|
console.log(response);
|
||||||
}
|
}
|
||||||
17
server.js
17
server.js
@@ -12,11 +12,17 @@ app.get('/', (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.get("/execute", (req, res)=> {
|
app.get("/execute", (req, res)=> {
|
||||||
const raw_command = req.body.command;
|
const raw_command = req.query.command;
|
||||||
const formatted_command = toString(raw_command).trim()
|
const formatted_command = String(raw_command).trim();
|
||||||
if (formatted_command.startsWith("ls")){
|
|
||||||
|
|
||||||
}
|
console.log(`Executed Command: ${formatted_command}`);
|
||||||
|
|
||||||
|
if (formatted_command.startsWith("ls")){
|
||||||
|
LS(req, res);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.json({"response": "invalid command"})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
@@ -25,6 +31,7 @@ app.listen(port, () => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function LS () {
|
function LS (req, res) {
|
||||||
|
res.json({"response": "LS IS WEL FICKING EPISCH"});
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user