53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
const express = require('express')
|
|
const app = express()
|
|
const port = 3000
|
|
|
|
const commands = require("./commands/commands")
|
|
|
|
app.use(express.static("httpdocs/public"))
|
|
|
|
const documentRoot = `${__dirname}/httpdocs`
|
|
|
|
let fileSystem = {
|
|
"guest": {
|
|
"type": "directory",
|
|
"contents": {
|
|
"file.txt": {
|
|
"type": "file",
|
|
"content": "This is the text in the file <br> and I don't use \n to simulate a line break"
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
app.get('/', (req, res) => {
|
|
res.sendFile(documentRoot+"/index.html")
|
|
})
|
|
|
|
app.get("/execute", (req, res)=> {
|
|
const raw_command = req.query.command;
|
|
const formatted_command = String(raw_command).trim();
|
|
|
|
const currentDir = req.query.currentDir
|
|
|
|
console.log(`Executed Command: ${formatted_command}`);
|
|
|
|
if (formatted_command.startsWith("ls")){
|
|
commands.ls(req, res);
|
|
}
|
|
else if (formatted_command.startsWith("whoami")){
|
|
commands.whoami(req, res);
|
|
}
|
|
else if (formatted_command.startsWith("pwd")){
|
|
commands.pwd(req, res, currentDir);
|
|
}
|
|
else {
|
|
res.json({"response": "invalid command"})
|
|
}
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port ${port}`)
|
|
}) |