-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux.js
28 lines (26 loc) · 891 Bytes
/
linux.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import fs from "fs";
// Import execFile
import { execFile } from "child_process";
export default function linux_callback(request, response) {
const command = request.query?.commandChooser;
let content = "";
if (command) {
content = fs.readFileSync("public/linux.html", "utf8");
// Convert exec to execFile
execFile(command, (error, stdout, stderr) => {
if (error || stderr) {
content = content.replace(">", "> " + (error ? error + "<br/>" : "") + stderr);
} else {
content = content.replace(">", "> " + stdout);
}
response.send(content);
});
} else {
try {
content = fs.readFileSync("public/linux.html", "utf8");
} catch (e) {
console.log("Error:", e.stack);
}
response.send(content);
}
}