From 61c642666540cc68d56bb4eae348afe1db8bf0e1 Mon Sep 17 00:00:00 2001 From: valentijn <120188387+HerpieDerpieee@users.noreply.github.com> Date: Sat, 3 Feb 2024 14:17:58 +0100 Subject: [PATCH] added core linux file system (kinda) --- commands/commands.js | 3 +- filesystem.json | 68 +++++++++++++++++++++++++++++++--- httpdocs/public/js/terminal.js | 7 +++- server.js | 2 +- 4 files changed, 71 insertions(+), 9 deletions(-) diff --git a/commands/commands.js b/commands/commands.js index 4bf4baf..c706191 100644 --- a/commands/commands.js +++ b/commands/commands.js @@ -57,7 +57,7 @@ function cd(req, res, raw_command) { } if (argument === "~" || argument === "~/"){ - req.session.state.directory = `/home/${req.session.state.username}`; + req.session.state.directory = `/home/${req.session.state.username}/`; respondToCommand(req, res, "", req.session.state.directory, command); return; } @@ -114,6 +114,7 @@ function help(req, res) { Here is a list of the available commands:

"help" - shows you this menu
+ "info" - shows you some information about the system
"clear" - clears the screen from previous ran commands
"ls" - shows you the files and directories in your current directory
"cd" - move into a folder you specify, you can use the name of the folder, or you can also use things like ../ to move back one folder
diff --git a/filesystem.json b/filesystem.json index 2534972..caa2cde 100644 --- a/filesystem.json +++ b/filesystem.json @@ -1,16 +1,74 @@ { "/": { - "file1.txt": "this is the content of file1
i like cheese :)", + "bin": "dir", + "etc": "dir", + "home": "dir", + "usr": "dir", + "var": "dir", + "root": "noperms", + "sys": "noperms" + }, + "/home/": { + "guest": "dir" + }, + "/home/guest/": { + "file1.txt": "this is the content of file1
i like cheese :)", "projects": "dir" }, - "/projects/": { + "/home/guest/projects/": { "personal": "dir" }, - "/projects/personal/": { + "/home/guest/projects/personal/": { "discord_bot_builder": "dir" }, - "/projects/personal/discord_bot_builder/": { - "about.txt":"This project is a pesonal project of mine. The goal is that you can easily create discord bots, with commands, to automate some stuff in your discord server!", + "/home/guest/projects/personal/discord_bot_builder/": { + "about.txt": "This project is a personal project of mine. The goal is that you can easily create discord bots, with commands, to automate some stuff in your discord server!", "links.txt": "GitHub: https://github.com/HerpieDerpieee/PS-Discord-BotBuilder/" + }, + + + + + + + + + "/bin/": { + "clear": "executable program", + "ls": "executable program", + "whoami": "executable program", + "cd": "executable program", + "pwd": "executable program", + "cat": "executable program", + "help": "executable program", + "info": "executable program" + }, + "/etc/": { + "passwd": "user account information
root:x:0:0:root:/root:/bin/bash
guest:x:1000:1000::/home/guest:/bin/bash", + "hostname": "HerpDerpOS 1.0.13
", + "hosts": "127.0.0.1 localhost
::1 localhost" + }, + "/usr/": { + "bin": "dir", + "lib": "dir", + "share": "dir" + }, + "/usr/bin/": { + "grep": "executable program", + "find": "executable program" + }, + "/var/": { + "log": "dir", + "www": "dir" + }, + "/var/log/": { + "messages": "system and application messages
...", + "secure": "authentication and authorization logs
..." + }, + "/var/www/": { + "html": "dir" + }, + "/var/www/html/": { + "index.html": "


Welcome to Fedora Server


Hello, World!



" } } \ No newline at end of file diff --git a/httpdocs/public/js/terminal.js b/httpdocs/public/js/terminal.js index d0b517a..57ad792 100644 --- a/httpdocs/public/js/terminal.js +++ b/httpdocs/public/js/terminal.js @@ -85,7 +85,6 @@ function createNewTextLine(text){ terminalContainer.appendChild(commandResponse); } - function createNewTerminalLine(){ let newTerminalLine = document.createElement("div"); newTerminalLine.classList.add("terminalLine"); @@ -103,7 +102,11 @@ function createNewTerminalLine(){ fetch('/currentDir') .then(response => response.text()) .then(data => { - pathPath.innerHTML = "~"+data; + if (data.startsWith("/home/guest")){ + pathPath.innerHTML = "~"+data.split("/home/guest")[1] + } else { + pathPath.innerHTML = data; + } pathPath.classList.add("pathPath"); }) .catch(error => console.error('Error:', error)); diff --git a/server.js b/server.js index 1d72201..dec1de4 100644 --- a/server.js +++ b/server.js @@ -21,7 +21,7 @@ app.get('/', (req, res) => { if (!req.session.state) { req.session.state = { "username": "guest", - "directory": "/" + "directory": `/home/guest/` }; } res.sendFile(documentRoot + "/index.html");