diff --git a/commands/commands.js b/commands/commands.js index 1398a50..04cb466 100644 --- a/commands/commands.js +++ b/commands/commands.js @@ -1,9 +1,18 @@ -function cd (req, res) { - +function ls (req, res) { + res.json({"response": "dit is totaal een reactie op een ls command :)", "command": "ls"}); +} + +function whoami (req, res){ + res.json({"response": "guest", "command": "whoami"}); +} + +function pwd (req, res, dir){ + res.json({"response": `/home/guest${dir}`}) } - module.exports = { - cd + ls, + whoami, + pwd } \ No newline at end of file diff --git a/httpdocs/index.html b/httpdocs/index.html index 154e9a0..d942a5e 100644 --- a/httpdocs/index.html +++ b/httpdocs/index.html @@ -27,7 +27,7 @@

:

-

~/projects

+

~/

$

diff --git a/httpdocs/public/js/terminal.js b/httpdocs/public/js/terminal.js index f3c9327..08df498 100644 --- a/httpdocs/public/js/terminal.js +++ b/httpdocs/public/js/terminal.js @@ -1,6 +1,6 @@ const terminalContainer = document.getElementById("terminal"); const hostname = `192.168.${Math.floor(Math.random() * 100)}.${Math.floor(Math.random() * 255)}`; -let currentFolder = "~/"; +let currentFolder = "/"; @@ -108,7 +108,7 @@ function createNewTerminalLine(){ let pathPath = document.createElement("h4"); - pathPath.innerHTML = currentFolder; + pathPath.innerHTML = "~"+currentFolder; pathPath.classList.add("pathPath"); diff --git a/server.js b/server.js index 15e067e..e8bb6c9 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,19 @@ 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
and I don't use \n to simulate a line break" + } + } + } + +} + app.get('/', (req, res) => { res.sendFile(documentRoot+"/index.html") @@ -21,8 +34,14 @@ app.get("/execute", (req, res)=> { console.log(`Executed Command: ${formatted_command}`); - if (formatted_command.startsWith("cd")){ - commands.cd(req, res); + 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"})