added some commands
:)
This commit is contained in:
@@ -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 = {
|
module.exports = {
|
||||||
cd
|
ls,
|
||||||
|
whoami,
|
||||||
|
pwd
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<div class="terminalLine activeLine">
|
<div class="terminalLine activeLine">
|
||||||
<h4 class="pathText"></h4>
|
<h4 class="pathText"></h4>
|
||||||
<h4 class="pathColon">:</h4>
|
<h4 class="pathColon">:</h4>
|
||||||
<h4 class="pathPath">~/projects</h4>
|
<h4 class="pathPath">~/</h4>
|
||||||
<h4 class="pathDollar">$</h4>
|
<h4 class="pathDollar">$</h4>
|
||||||
<input class="terminalInput" type="text" id="terminalInput" value="">
|
<input class="terminalInput" type="text" id="terminalInput" value="">
|
||||||
<div class="pathBlinky"></div>
|
<div class="pathBlinky"></div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const terminalContainer = document.getElementById("terminal");
|
const terminalContainer = document.getElementById("terminal");
|
||||||
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)}`;
|
||||||
let currentFolder = "~/";
|
let currentFolder = "/";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ function createNewTerminalLine(){
|
|||||||
|
|
||||||
|
|
||||||
let pathPath = document.createElement("h4");
|
let pathPath = document.createElement("h4");
|
||||||
pathPath.innerHTML = currentFolder;
|
pathPath.innerHTML = "~"+currentFolder;
|
||||||
pathPath.classList.add("pathPath");
|
pathPath.classList.add("pathPath");
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
23
server.js
23
server.js
@@ -8,6 +8,19 @@ app.use(express.static("httpdocs/public"))
|
|||||||
|
|
||||||
const documentRoot = `${__dirname}/httpdocs`
|
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) => {
|
app.get('/', (req, res) => {
|
||||||
res.sendFile(documentRoot+"/index.html")
|
res.sendFile(documentRoot+"/index.html")
|
||||||
@@ -21,8 +34,14 @@ app.get("/execute", (req, res)=> {
|
|||||||
|
|
||||||
console.log(`Executed Command: ${formatted_command}`);
|
console.log(`Executed Command: ${formatted_command}`);
|
||||||
|
|
||||||
if (formatted_command.startsWith("cd")){
|
if (formatted_command.startsWith("ls")){
|
||||||
commands.cd(req, res);
|
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 {
|
else {
|
||||||
res.json({"response": "invalid command"})
|
res.json({"response": "invalid command"})
|
||||||
|
|||||||
Reference in New Issue
Block a user