do some things

This commit is contained in:
Bruno Rybársky 2022-06-12 09:38:38 +02:00
parent 67c1e35608
commit 204d55d514
81 changed files with 1342 additions and 844 deletions

20
commands/append.js Normal file

@ -0,0 +1,20 @@
"use strict";
exports.__esModule = true;
exports.append = void 0;
function append(args, curdir) {
var buf = "";
if (args.length == 0) {
buf += "append: missing operand\n";
}
else {
if (curdir[args[0]] == undefined) {
curdir[args[0]] = "";
}
for (var i = 1; i < args.length; i++) {
curdir[args[0]] += args[i] + "\n";
}
}
return buf;
}
exports.append = append;
//# sourceMappingURL=append.js.map

1
commands/append.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"append.js","sourceRoot":"","sources":["append.ts"],"names":[],"mappings":";;;AAAA,SAAS,MAAM,CAAC,IAAkB,EAAE,MAAU;IAC1C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,2BAA2B,CAAC;KACtC;SACI;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE;YAC9B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;SACxB;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;SACrC;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,wBAAM"}

@ -0,0 +1,16 @@
function append(args:Array<string>, curdir:any):string {
var buf = "";
if (args.length == 0) {
buf += "append: missing operand\n";
}
else {
if (curdir[args[0]] == undefined) {
curdir[args[0]] = "";
}
for (let i = 1; i < args.length; i++) {
curdir[args[0]] += args[i] + "\n";
}
}
return buf;
}
export { append };

24
commands/cat.js Normal file

@ -0,0 +1,24 @@
"use strict";
exports.__esModule = true;
exports.cat = void 0;
function cat(args, curdir) {
var buf = "";
if (args.length == 0) {
buf += "cat: missing operand\n";
}
else {
var file = args[0];
if (curdir[file] == undefined) {
buf += "cat: " + file + ": No such file or directory\n";
}
else if (typeof curdir[file] == "string") {
buf += curdir[file] + "\n";
}
else {
buf += "cat: " + file + ": Is not a file\n";
}
}
return buf;
}
exports.cat = cat;
//# sourceMappingURL=cat.js.map

1
commands/cat.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"cat.js","sourceRoot":"","sources":["cat.ts"],"names":[],"mappings":";;;AACA,SAAS,GAAG,CAAC,IAAkB,EAAE,MAAU;IACvC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,wBAAwB,CAAC;KACnC;SACI;QACD,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE;YAC3B,GAAG,IAAI,OAAO,GAAG,IAAI,GAAG,+BAA+B,CAAC;SAC3D;aAEI,IAAG,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,QAAQ,EAAE;YACrC,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;SAC9B;aACG;YACA,GAAG,IAAI,OAAO,GAAG,IAAI,GAAG,mBAAmB,CAAC;SAC/C;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,kBAAG"}

@ -0,0 +1,22 @@
import { Socket } from 'socket.io';
function cat(args:Array<string>, curdir:any):string {
var buf = "";
if (args.length == 0) {
buf += "cat: missing operand\n";
}
else {
let file = args[0];
if (curdir[file] == undefined) {
buf += "cat: " + file + ": No such file or directory\n";
}
//check if type string
else if(typeof curdir[file] == "string") {
buf += curdir[file] + "\n";
}
else{
buf += "cat: " + file + ": Is not a file\n";
}
}
return buf;
}
export { cat };

46
commands/cd.js Normal file

@ -0,0 +1,46 @@
"use strict";
exports.__esModule = true;
exports.cd = void 0;
function cd(args, curdir, socket, filesystem, curdirx) {
var buf = "";
if (args.length == 0) {
buf += "Please specify a directory.\n";
}
else {
if (args[0] == "..") {
if (curdirx[socket.id].length > 0) {
var sync = "filesystem[socket.id]";
for (var i = 0; i < curdirx[socket.id].length; i++) {
sync += "['" + curdirx[socket.id][i] + "']";
}
sync += " = curdir[socket.id];";
console.log(sync);
eval(sync);
curdirx[socket.id].pop();
var cmdexec = "curdir[socket.id] = filesystem[socket.id]";
for (var i = 0; i < curdirx[socket.id].length; i++) {
cmdexec += "[(curdirx[socket.id][" + i + "])]";
}
eval(cmdexec);
}
}
else {
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "object") {
curdir[socket.id] = curdir[socket.id][args[0]];
buf += "Changed directory to " + args[0] + "\n";
curdirx[socket.id].push(args[0]);
}
else {
buf += "cd: " + args[0] + ": Is not a directory\n";
}
}
else {
buf += "Directory " + args[0] + " does not exist.\n";
}
}
}
return buf;
}
exports.cd = cd;
//# sourceMappingURL=cd.js.map

1
commands/cd.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"cd.js","sourceRoot":"","sources":["cd.ts"],"names":[],"mappings":";;;AAEA,SAAS,EAAE,CAAC,IAAkB,EAAE,MAAU,EAAE,MAAa,EAAE,UAAc,EAAE,OAAqB;IAC5F,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,+BAA+B,CAAC;KAE1C;SACI;QACD,IAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE;YAIhB,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBAE/B,IAAI,IAAI,GAAG,uBAAuB,CAAC;gBACnC,KAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO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AAC,GAAG,wBAAwB,CAAC;iBACtD;aAEJ;iBACI;gBACD,GAAG,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC;aAExD;SACJ;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,gBAAE"}

@ -0,0 +1,55 @@
import { Socket } from 'socket.io';
function cd(args:Array<string>, curdir:any, socket:Socket, filesystem:any, curdirx:Array<string>):string {
var buf = "";
if (args.length == 0) {
buf += "Please specify a directory.\n";
}
else {
if(args[0] == "..") {
//go up one directory
//recursively scan filesystem until we find curdir and then set curdir to its parent
//check curdirx is not empty
if (curdirx[socket.id].length > 0) {
//pop off last element
var sync = "filesystem[socket.id]";
for(let i = 0; i < curdirx[socket.id].length; i++) {
sync += "['" + curdirx[socket.id][i] + "']";
}
sync += " = curdir[socket.id];";
console.log(sync);
eval(sync);
curdirx[socket.id].pop();
//curdir = filesystem[socket.id][(curdirx[socket.id][0])][(curdirx[socket.id][1])].......;
//i know i shouldnt use eval but I don't know any other way to do this
var cmdexec = "curdir[socket.id] = filesystem[socket.id]";
//syncing = write curdir to a path in the filesystem
for (let i = 0; i < curdirx[socket.id].length; i++) {
cmdexec += "[(curdirx[socket.id][" + i + "])]";
}
eval(cmdexec);
}
}
else {
if (curdir[socket.id][args[0]] != undefined) {
//check if type dict
if (typeof curdir[socket.id][args[0]] == "object") {
curdir[socket.id] = curdir[socket.id][args[0]];
buf += "Changed directory to " + args[0] + "\n";
curdirx[socket.id].push(args[0]);
}
else{
buf += "cd: " + args[0] + ": Is not a directory\n";
}
}
else {
buf += "Directory " + args[0] + " does not exist.\n";
}
}
}
return buf;
}
export { cd };

9
commands/clear.js Normal file

@ -0,0 +1,9 @@
"use strict";
exports.__esModule = true;
exports.clear = void 0;
function clear(buffer) {
buffer = "";
return "";
}
exports.clear = clear;
//# sourceMappingURL=clear.js.map

1
commands/clear.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"clear.js","sourceRoot":"","sources":["clear.ts"],"names":[],"mappings":";;;AAAA,SAAS,KAAK,CAAC,MAAa;IACxB,MAAM,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC;AACd,CAAC;AACQ,sBAAK"}

@ -0,0 +1,5 @@
function clear(buffer:string):string {
buffer = "";
return "";
}
export { clear };

@ -1,367 +1,99 @@
"use strict";
exports.__esModule = true;
exports.resolveCommand = void 0;
var SerAny = require('serialize-anything');
var fs = require('fs');
var append_1 = require("./append");
var cat_1 = require("./cat");
var cd_1 = require("./cd");
var clear_1 = require("./clear");
var cp_1 = require("./cp");
var echo_1 = require("./echo");
var exec_1 = require("./exec");
var help_1 = require("./help");
var loadsess_1 = require("./loadsess");
var ls_1 = require("./ls");
var man_1 = require("./man");
var mkdir_1 = require("./mkdir");
var mv_1 = require("./mv");
var overwrite_1 = require("./overwrite");
var pwd_1 = require("./pwd");
var rm_1 = require("./rm");
var rmdir_1 = require("./rmdir");
var savesess_1 = require("./savesess");
var screenshot_1 = require("./screenshot");
var spam_1 = require("./spam");
var touch_1 = require("./touch");
var wee_1 = require("./wee");
var woo_1 = require("./woo");
function resolveCommand(commandname, socket, args, buffer, sessions, filesystem, curdir, curdirx) {
switch (commandname) {
case "help":
buffer[socket.id] += "Available commands:\n";
buffer[socket.id] += "help - shows this help\n";
buffer[socket.id] += "clear - clears the console\n";
buffer[socket.id] += "exit - exits the console\n";
buffer[socket.id] += "ls - lists the files in the current directory\n";
buffer[socket.id] += "cd - changes the current directory\n";
buffer[socket.id] += "echo - prints the arguments\n";
buffer[socket.id] += "mkdir - creates a new directory\n";
buffer[socket.id] += "cat - prints the contents of a file\n";
buffer[socket.id] += "touch - creates a new file\n";
buffer[socket.id] += "rm - removes a file\n";
buffer[socket.id] += "mv - moves a file\n";
buffer[socket.id] += "cp - copies a file\n";
buffer[socket.id] += "rmdir - removes a directory\n";
buffer[socket.id] += "pwd - prints the current directory\n";
buffer[socket.id] += "exec - executes a file\n";
buffer[socket.id] += "spam - spams the console\n";
buffer[socket.id] += "overwrite - overwrites the file with data\n";
buffer[socket.id] += "append - appends the arguments to a file\n";
buffer[socket.id] += "screenshot - takes a screenshot\n";
buffer[socket.id] += "man - display longer help\n";
buffer[socket.id] += "tree - display directory tree";
buffer[socket.id] += (0, help_1.help)();
break;
case "man":
if (args.length == 0) {
buffer[socket.id] += "Missing arguments";
}
switch (args[0]) {
case "help":
buffer[socket.id] += "Prints the list of available commands\n";
break;
case "clear":
buffer[socket.id] += "Clears the console\n";
break;
case "exit":
buffer[socket.id] += "Exits the console\n";
break;
case "ls":
buffer[socket.id] += "Lists the files in the current directory, also displays if file or directory\n";
break;
case "cd":
buffer[socket.id] += "Changes the current directory\n";
break;
case "echo":
buffer[socket.id] += "Prints the arguments to the console\n";
break;
case "mkdir":
buffer[socket.id] += "Creates a new directory in the current directory\n";
break;
case "cat":
buffer[socket.id] += "Prints the contents of a file out to the console\n";
break;
case "touch":
buffer[socket.id] += "Creates a new file in the current directory\n";
break;
case "rm":
buffer[socket.id] += "Removes a file from the current directory\n";
break;
case "mv":
buffer[socket.id] += "Moves a file from one directory to another\n";
break;
case "cp":
buffer[socket.id] += "Copies a file from one directory to another\n";
break;
case "rmdir":
buffer[socket.id] += "Removes a directory from the current directory\n";
break;
case "pwd":
buffer[socket.id] += "Prints the current directory out to the console\n";
break;
case "exec":
buffer[socket.id] += "Executes a file in the console, you can \'t use \"exit\" and \"exec\" commands\n";
break;
case "spam":
buffer[socket.id] += "Spams the console with a message\n";
break;
case "overwrite":
buffer[socket.id] += "Overwrites a file with from arguments\n";
break;
case "append":
buffer[socket.id] += "Appends the arguments to a file\n";
break;
case "screenshot":
buffer[socket.id] += "Takes a screenshot of the console and saves it to a file\n";
break;
case "man":
buffer[socket.id] += "This manual databank\n";
break;
default:
buffer[socket.id] += "No such command\n";
}
break;
case "savesess":
if (args.length == 2) {
if (args[0] == "kryptic") {
sessions[args[1]] = [];
sessions[args[1]]["buffer"] = buffer[socket.id].slice();
sessions[args[1]]["filesystem"] = JSON.parse(JSON.stringify(filesystem[socket.id]));
sessions[args[1]]["curdir"] = JSON.parse(JSON.stringify(curdir[socket.id]));
var data = SerAny.serialize(sessions);
fs.writeFileSync("./sessions.json", data);
buffer[socket.id] += "Session saved.\n";
}
else {
buffer[socket.id] += "Invalid command.";
}
}
else {
buffer[socket.id] += "Invalid command.";
}
break;
case "loadsess":
if (args.length == 1) {
sessions = SerAny.deserialize(fs.readFileSync("./sessions.json"));
if (sessions[args[0]] != undefined) {
filesystem[socket.id] = sessions[args[0]]["filesystem"];
curdir[socket.id] = sessions[args[0]]["curdir"];
buffer[socket.id] = sessions[args[0]]["buffer"];
buffer[socket.id] += "Session loaded.\n";
}
}
else {
}
break;
case "wee":
buffer[socket.id] += "woo\n";
break;
case "woo":
buffer[socket.id] += "wee\n";
buffer[socket.id] += (0, man_1.man)(args);
break;
case "screenshot":
curdir[socket.id][args[0]] = buffer[socket.id];
buffer[socket.id] += "Screenshot saved to " + args[0] + "\n";
buffer[socket.id] += (0, screenshot_1.screenshot)(args, curdir, buffer, socket);
break;
case "append":
if (args.length == 0) {
buffer[socket.id] += "append: missing operand\n";
}
else {
if (curdir[socket.id][args[0]] == undefined) {
curdir[socket.id][args[0]] = "";
}
for (var i = 1; i < args.length; i++) {
curdir[socket.id][args[0]] += args[i] + "\n";
}
}
break;
case "rm":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
delete curdir[socket.id][args[0]];
buffer[socket.id] += "File " + args[0] + " removed\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a file\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "mv":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
curdir[socket.id][args[1]] = curdir[socket.id][args[0]];
delete curdir[socket.id][args[0]];
buffer[socket.id] += "File " + args[0] + " moved to " + args[1] + "\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a file\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "cp":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
curdir[socket.id][args[1]] = curdir[socket.id][args[0]].slice(0);
buffer[socket.id] += "File " + args[0] + " copied to " + args[1] + "\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a file\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "rmdir":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "object") {
delete curdir[socket.id][args[0]];
buffer[socket.id] += "Directory " + args[0] + " removed\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a directory\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "spam":
for (var i = 0; i < parseInt(args[0]); i++) {
buffer[socket.id] += args.slice(1).join(" ") + "\n";
}
break;
case "touch":
if (args.length == 0) {
buffer[socket.id] += "touch: missing operand\n";
}
else {
curdir[socket.id][args[0]] = "";
}
buffer[socket.id] += (0, append_1.append)(args, curdir[socket.id]);
break;
case "overwrite":
if (args.length == 0) {
buffer[socket.id] += "overwrite: missing operand\n";
}
else {
curdir[socket.id][args[0]] = "";
for (var i = 1; i < args.length; i++) {
curdir[socket.id][args[0]] += args[i] + " ";
}
}
buffer[socket.id] += (0, overwrite_1.overwrite)(args, curdir[socket.id]);
break;
case "cat":
if (args.length == 0) {
buffer[socket.id] += "cat: missing operand\n";
}
else {
var file = args[0];
if (curdir[socket.id][file] == undefined) {
buffer[socket.id] += "cat: " + file + ": No such file or directory\n";
}
else if (typeof curdir[socket.id][file] == "string") {
buffer[socket.id] += curdir[socket.id][file] + "\n";
}
else {
buffer[socket.id] += "cat: " + file + ": Is not a file\n";
}
}
case "rm":
buffer[socket.id] += (0, rm_1.rm)(args, curdir, socket);
break;
case "echo":
buffer[socket.id] += args.join(' ');
buffer[socket.id] += "\n";
case "mv":
buffer[socket.id] += (0, mv_1.mv)(args, curdir[socket.id]);
break;
case "clear":
buffer[socket.id] = "";
break;
case "exit":
buffer[socket.id] = "";
buffer[socket.id] += "Bye!\n";
socket.disconnect();
break;
case "exec":
if (args.length == 0) {
buffer[socket.id] += "exec: missing operand\n";
}
else {
var file = args[0];
if (curdir[socket.id][file] == undefined) {
buffer[socket.id] += "exec: " + file + ": No such file or directory\n";
}
else if (typeof curdir[socket.id][file] == "string") {
var commands = curdir[socket.id][file].split("\n");
for (var i = 0; i < commands.length; i++) {
var exploded = commands[i].split(" ");
var commandx = exploded[0];
var bannedcommands = ["exec", "exit"];
if (!bannedcommands.includes(commandx)) {
var argsx = exploded.slice(1);
resolveCommand(commandx, socket, argsx, buffer, sessions, filesystem, curdir, curdirx);
}
else {
buffer[socket.id] += "Error: " + commandx + " is a restricted command\n";
}
}
}
else {
buffer[socket.id] += "exec: " + file + ": Is not a file\n";
}
}
break;
case "ls":
buffer[socket.id] += "Files in the current directory:\n";
for (var key in curdir[socket.id]) {
if (typeof curdir[socket.id][key] == "string") {
buffer[socket.id] += key + " (file)\n";
}
else if (typeof curdir[socket.id][key] == "object") {
buffer[socket.id] += key + " (directory)\n";
}
else {
buffer[socket.id] += key + " (unknown)\n";
}
}
break;
case "cd":
if (args.length == 0) {
buffer[socket.id] += "Please specify a directory.\n";
}
else {
if (args[0] == "..") {
if (curdirx[socket.id].length > 0) {
var sync = "filesystem[socket.id]";
for (var i = 0; i < curdirx[socket.id].length; i++) {
sync += "['" + curdirx[socket.id][i] + "']";
}
sync += " = curdir[socket.id];";
console.log(sync);
eval(sync);
curdirx[socket.id].pop();
var cmdexec = "curdir[socket.id] = filesystem[socket.id]";
for (var i = 0; i < curdirx[socket.id].length; i++) {
cmdexec += "[(curdirx[socket.id][" + i + "])]";
}
eval(cmdexec);
}
}
else {
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "object") {
curdir[socket.id] = curdir[socket.id][args[0]];
buffer[socket.id] += "Changed directory to " + args[0] + "\n";
curdirx[socket.id].push(args[0]);
}
else {
buffer[socket.id] += "cd: " + args[0] + ": Is not a directory\n";
}
}
else {
buffer[socket.id] += "Directory " + args[0] + " does not exist.\n";
}
}
}
break;
case "pwd":
var curdirasstring = curdirx[socket.id].join("/");
buffer[socket.id] += "Current directory: " + curdirasstring + "\n";
case "cp":
buffer[socket.id] += (0, cp_1.cp)(args, curdir[socket.id]);
break;
case "mkdir":
if (args.length == 0) {
buffer[socket.id] += "Please specify a directory.\n";
}
else {
if (curdir[socket.id][args[0]]) {
buffer[socket.id] += "Directory " + args[0] + " already exists.\n";
}
else {
curdir[socket.id][args[0]] = {};
buffer[socket.id] += "Created directory " + args[0] + "\n";
}
}
buffer[socket.id] += (0, mkdir_1.mkdir)(args, curdir[socket.id]);
break;
case "rmdir":
buffer[socket.id] += (0, rmdir_1.rmdir)(args, curdir, socket);
break;
case "touch":
buffer[socket.id] += (0, touch_1.touch)(args, curdir, socket);
break;
case "cat":
buffer[socket.id] += (0, cat_1.cat)(args, curdir[socket.id]);
break;
case "exec":
buffer[socket.id] += (0, exec_1.exec)(args, curdir, socket, buffer, sessions, filesystem, curdirx);
break;
case "ls":
buffer[socket.id] += (0, ls_1.ls)(curdir[socket.id]);
break;
case "cd":
buffer[socket.id] += (0, cd_1.cd)(args, curdir, socket, filesystem, curdirx);
break;
case "pwd":
buffer[socket.id] += (0, pwd_1.pwd)(curdirx[socket.id]);
break;
case "echo":
buffer[socket.id] += (0, echo_1.echo)(args);
break;
case "clear":
buffer[socket.id] += (0, clear_1.clear)(buffer[socket.id]);
break;
case "savesess":
buffer[socket.id] += (0, savesess_1.savesess)(args, sessions, filesystem, curdir, buffer, socket);
break;
case "loadsess":
buffer[socket.id] += (0, loadsess_1.loadsess)(args, sessions, filesystem[socket.id], curdir[socket.id], buffer[socket.id]);
break;
case "wee":
buffer[socket.id] += (0, wee_1.wee)();
break;
case "woo":
buffer[socket.id] += (0, woo_1.woo)();
break;
case "spam":
buffer[socket.id] += (0, spam_1.spam)(args);
break;
default:
buffer[socket.id] += "Invalid command.\n";

File diff suppressed because one or more lines are too long

@ -1,398 +1,98 @@
import { Socket } from 'socket.io';
const SerAny = require('serialize-anything');
var fs = require('fs');
import { append } from './append';
import { cat } from './cat';
import { cd } from './cd';
import { clear } from './clear';
import { cp } from './cp';
import { echo } from './echo';
import { exec } from './exec';
import { help } from './help';
import { loadsess } from './loadsess';
import { ls } from './ls';
import { man } from './man';
import { mkdir } from './mkdir';
import { mv } from './mv';
import { overwrite } from './overwrite';
import { pwd } from './pwd';
import { rm } from './rm';
import { rmdir } from './rmdir';
import { savesess } from './savesess';
import { screenshot } from './screenshot';
import { spam } from './spam';
import { touch } from './touch';
import { wee } from './wee';
import { woo } from './woo';
function resolveCommand(commandname:string, socket:Socket, args:string[], buffer:{ [id: string]: string }, sessions:any, filesystem:any, curdir:any, curdirx:any) {
switch (commandname) {
case "help":
buffer[socket.id] += "Available commands:\n";
buffer[socket.id] += "help - shows this help\n";
buffer[socket.id] += "clear - clears the console\n";
buffer[socket.id] += "exit - exits the console\n";
buffer[socket.id] += "ls - lists the files in the current directory\n";
buffer[socket.id] += "cd - changes the current directory\n";
buffer[socket.id] += "echo - prints the arguments\n";
buffer[socket.id] += "mkdir - creates a new directory\n";
buffer[socket.id] += "cat - prints the contents of a file\n";
buffer[socket.id] += "touch - creates a new file\n";
buffer[socket.id] += "rm - removes a file\n";
buffer[socket.id] += "mv - moves a file\n";
buffer[socket.id] += "cp - copies a file\n";
buffer[socket.id] += "rmdir - removes a directory\n";
buffer[socket.id] += "pwd - prints the current directory\n";
buffer[socket.id] += "exec - executes a file\n";
buffer[socket.id] += "spam - spams the console\n";
buffer[socket.id] += "overwrite - overwrites the file with data\n";
buffer[socket.id] += "append - appends the arguments to a file\n";
buffer[socket.id] += "screenshot - takes a screenshot\n";
buffer[socket.id] += "man - display longer help\n";
buffer[socket.id] += "tree - display directory tree";
buffer[socket.id] += help();
break;
case "man":
if(args.length == 0){
buffer[socket.id] += "Missing arguments"
}
switch (args[0]){
case "help":
buffer[socket.id] += "Prints the list of available commands\n";
break;
case "clear":
buffer[socket.id] += "Clears the console\n";
break;
case "exit":
buffer[socket.id] += "Exits the console\n";
break;
case "ls":
buffer[socket.id] += "Lists the files in the current directory, also displays if file or directory\n";
break;
case "cd":
buffer[socket.id] += "Changes the current directory\n";
break;
case "echo":
buffer[socket.id] += "Prints the arguments to the console\n";
break;
case "mkdir":
buffer[socket.id] += "Creates a new directory in the current directory\n";
break;
case "cat":
buffer[socket.id] += "Prints the contents of a file out to the console\n";
break;
case "touch":
buffer[socket.id] += "Creates a new file in the current directory\n";
break;
case "rm":
buffer[socket.id] += "Removes a file from the current directory\n";
break;
case "mv":
buffer[socket.id] += "Moves a file from one directory to another\n";
break;
case "cp":
buffer[socket.id] += "Copies a file from one directory to another\n";
break;
case "rmdir":
buffer[socket.id] += "Removes a directory from the current directory\n";
break;
case "pwd":
buffer[socket.id] += "Prints the current directory out to the console\n";
break;
case "exec":
buffer[socket.id] += "Executes a file in the console, you can \'t use \"exit\" and \"exec\" commands\n";
break;
case "spam":
buffer[socket.id] += "Spams the console with a message\n";
break;
case "overwrite":
buffer[socket.id] += "Overwrites a file with from arguments\n";
break;
case "append":
buffer[socket.id] += "Appends the arguments to a file\n";
break;
case "screenshot":
buffer[socket.id] += "Takes a screenshot of the console and saves it to a file\n";
break;
case "man":
buffer[socket.id] += "This manual databank\n"
break
default:
buffer[socket.id] += "No such command\n"
}
break;
case "savesess":
if (args.length == 2) {
if (args[0] == "kryptic") {
sessions[args[1]] = [];
sessions[args[1]]["buffer"] = buffer[socket.id].slice();
sessions[args[1]]["filesystem"] = JSON.parse(JSON.stringify(filesystem[socket.id]));
sessions[args[1]]["curdir"] = JSON.parse(JSON.stringify(curdir[socket.id]));
var data = SerAny.serialize(sessions);
//write all sessions to a single file called sessions.json
fs.writeFileSync("./sessions.json", data);
buffer[socket.id] += "Session saved.\n";
}
else {
buffer[socket.id] += "Invalid command.";
}
}
else {
buffer[socket.id] += "Invalid command.";
}
break;
case "loadsess":
if (args.length == 1) {
sessions = SerAny.deserialize(fs.readFileSync("./sessions.json"));
if(sessions[args[0]] != undefined) {
filesystem[socket.id] = sessions[args[0]]["filesystem"];
curdir[socket.id] = sessions[args[0]]["curdir"];
buffer[socket.id] = sessions[args[0]]["buffer"];
buffer[socket.id] += "Session loaded.\n";
}
}
else {
}
break;
case "wee":
buffer[socket.id] += "woo\n";
break;
case "woo":
buffer[socket.id] += "wee\n";
break;
//implement more commands
buffer[socket.id] += man(args);
break; //implement more commands
case "screenshot":
curdir[socket.id][args[0]] = buffer[socket.id];
buffer[socket.id] += "Screenshot saved to " + args[0] + "\n";
buffer[socket.id] += screenshot(args, curdir, buffer, socket);
break;
case "append":
if (args.length == 0) {
buffer[socket.id] += "append: missing operand\n";
}
else {
if (curdir[socket.id][args[0]] == undefined) {
curdir[socket.id][args[0]] = "";
}
for (let i = 1; i < args.length; i++) {
curdir[socket.id][args[0]] += args[i] + "\n";
}
}
break;
case "rm":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
delete curdir[socket.id][args[0]];
buffer[socket.id] += "File " + args[0] + " removed\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a file\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "mv":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
curdir[socket.id][args[1]] = curdir[socket.id][args[0]];
delete curdir[socket.id][args[0]];
buffer[socket.id] += "File " + args[0] + " moved to " + args[1] + "\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a file\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "cp":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
curdir[socket.id][args[1]] = curdir[socket.id][args[0]].slice(0);
buffer[socket.id] += "File " + args[0] + " copied to " + args[1] + "\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a file\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "rmdir":
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "object") {
delete curdir[socket.id][args[0]];
buffer[socket.id] += "Directory " + args[0] + " removed\n";
}
else {
buffer[socket.id] += "Error: " + args[0] + " is not a directory\n";
}
}
else {
buffer[socket.id] += "Error: " + args[0] + " does not exist\n";
}
break;
case "spam":
//spam arguments times from first argument
for (let i = 0; i < parseInt(args[0]); i++) {
buffer[socket.id] += args.slice(1).join(" ") + "\n";
}
break;
case "touch":
if (args.length == 0) {
buffer[socket.id] += "touch: missing operand\n";
}
else {
curdir[socket.id][args[0]] = "";
}
buffer[socket.id] += append(args, curdir[socket.id]);
break;
case "overwrite":
if (args.length == 0) {
buffer[socket.id] += "overwrite: missing operand\n";
}
else {
curdir[socket.id][args[0]] = "";
for (let i = 1; i < args.length; i++) {
curdir[socket.id][args[0]] += args[i] + " ";
}
}
buffer[socket.id] += overwrite(args, curdir[socket.id]);
break;
case "cat":
if (args.length == 0) {
buffer[socket.id] += "cat: missing operand\n";
}
else {
let file = args[0];
if (curdir[socket.id][file] == undefined) {
buffer[socket.id] += "cat: " + file + ": No such file or directory\n";
}
//check if type string
else if(typeof curdir[socket.id][file] == "string") {
buffer[socket.id] += curdir[socket.id][file] + "\n";
}
else{
buffer[socket.id] += "cat: " + file + ": Is not a file\n";
}
}
case "rm":
buffer[socket.id] += rm(args, curdir, socket);
break;
case "echo":
buffer[socket.id] += args.join(' ');
buffer[socket.id] += "\n";
case "mv":
buffer[socket.id] += mv(args, curdir[socket.id]);
break;
case "clear":
buffer[socket.id] = "";
break;
case "exit":
buffer[socket.id] = "";
buffer[socket.id] += "Bye!\n";
socket.disconnect();
break;
case "exec":
if (args.length == 0) {
buffer[socket.id] += "exec: missing operand\n";
}
else {
let file = args[0];
if (curdir[socket.id][file] == undefined) {
buffer[socket.id] += "exec: " + file + ": No such file or directory\n";
}
//check if type string
else if(typeof curdir[socket.id][file] == "string") {
//split string into array of commands
let commands = curdir[socket.id][file].split("\n");
for (let i = 0; i < commands.length; i++) {
let exploded = commands[i].split(" ");
let commandx = exploded[0];
let bannedcommands = ["exec", "exit"];
if (!bannedcommands.includes(commandx)) {
let argsx = exploded.slice(1);
resolveCommand(commandx, socket, argsx, buffer, sessions, filesystem, curdir, curdirx);
}
else{
buffer[socket.id] += "Error: " + commandx + " is a restricted command\n";
}
}
}
else{
buffer[socket.id] += "exec: " + file + ": Is not a file\n";
}
}
break;
case "ls":
buffer[socket.id] += "Files in the current directory:\n";
//list only first level files
for (var key in curdir[socket.id]) {
//buffer[socket.id] += key + "\n";
//also print if it is a directory or file
if (typeof curdir[socket.id][key] == "string") {
buffer[socket.id] += key + " (file)\n";
}
else if (typeof curdir[socket.id][key] == "object") {
buffer[socket.id] += key + " (directory)\n";
}
else {
buffer[socket.id] += key + " (unknown)\n";
}
}
break;
case "cd":
if (args.length == 0) {
buffer[socket.id] += "Please specify a directory.\n";
}
else {
if(args[0] == "..") {
//go up one directory
//recursively scan filesystem until we find curdir and then set curdir to its parent
//check curdirx is not empty
if (curdirx[socket.id].length > 0) {
//pop off last element
var sync = "filesystem[socket.id]";
for(let i = 0; i < curdirx[socket.id].length; i++) {
sync += "['" + curdirx[socket.id][i] + "']";
}
sync += " = curdir[socket.id];";
console.log(sync);
eval(sync);
curdirx[socket.id].pop();
//curdir = filesystem[socket.id][(curdirx[socket.id][0])][(curdirx[socket.id][1])].......;
//i know i shouldnt use eval but I don't know any other way to do this
var cmdexec = "curdir[socket.id] = filesystem[socket.id]";
//syncing = write curdir to a path in the filesystem
for (let i = 0; i < curdirx[socket.id].length; i++) {
cmdexec += "[(curdirx[socket.id][" + i + "])]";
}
eval(cmdexec);
}
}
else {
if (curdir[socket.id][args[0]] != undefined) {
//check if type dict
if (typeof curdir[socket.id][args[0]] == "object") {
curdir[socket.id] = curdir[socket.id][args[0]];
buffer[socket.id] += "Changed directory to " + args[0] + "\n";
curdirx[socket.id].push(args[0]);
}
else{
buffer[socket.id] += "cd: " + args[0] + ": Is not a directory\n";
}
}
else {
buffer[socket.id] += "Directory " + args[0] + " does not exist.\n";
}
}
}
break;
case "pwd":
var curdirasstring = curdirx[socket.id].join("/");
buffer[socket.id] += "Current directory: " + curdirasstring + "\n";
case "cp":
buffer[socket.id] += cp(args, curdir[socket.id]);
break;
case "mkdir":
if (args.length == 0) {
buffer[socket.id] += "Please specify a directory.\n";
}
else {
if (curdir[socket.id][args[0]]) {
buffer[socket.id] += "Directory " + args[0] + " already exists.\n";
}
else {
curdir[socket.id][args[0]] = {};
buffer[socket.id] += "Created directory " + args[0] + "\n";
}
}
buffer[socket.id] += mkdir(args, curdir[socket.id]);
break;
case "rmdir":
buffer[socket.id] += rmdir(args, curdir, socket);
break;
case "touch":
buffer[socket.id] += touch(args, curdir, socket);
break;
case "cat":
buffer[socket.id] += cat(args, curdir[socket.id]);
break;
case "exec":
buffer[socket.id] += exec(args, curdir, socket, buffer, sessions, filesystem, curdirx);
break;
case "ls":
buffer[socket.id] += ls(curdir[socket.id]);
break;
case "cd":
buffer[socket.id] += cd(args, curdir, socket, filesystem, curdirx);
break;
case "pwd":
buffer[socket.id] += pwd(curdirx[socket.id]);
break;
case "echo":
buffer[socket.id] += echo(args);
break;
case "clear":
buffer[socket.id] += clear(buffer[socket.id]);
break;
case "savesess":
buffer[socket.id] += savesess(args, sessions, filesystem, curdir, buffer, socket);
break;
case "loadsess":
buffer[socket.id] += loadsess(args, sessions, filesystem[socket.id], curdir[socket.id], buffer[socket.id]);
break;
case "wee":
buffer[socket.id] += wee();
break;
case "woo":
buffer[socket.id] += woo();
break;
case "spam":
buffer[socket.id] += spam(args);
break;
//invalid command
default:
buffer[socket.id] += "Invalid command.\n";

26
commands/cp.js Normal file

@ -0,0 +1,26 @@
"use strict";
exports.__esModule = true;
exports.cp = void 0;
function cp(args, curdir) {
var buf = "";
if (args.length == 2) {
if (curdir[args[0]] != undefined) {
if (typeof curdir[args[0]] == "string") {
curdir[args[1]] = curdir[args[0]].slice(0);
buf += "File " + args[0] + " copied to " + args[1] + "\n";
}
else {
buf += "Error: " + args[0] + " is not a file\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
}
else {
buf += "Wrong number of arguments.\n";
}
return buf;
}
exports.cp = cp;
//# sourceMappingURL=cp.js.map

1
commands/cp.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"cp.js","sourceRoot":"","sources":["cp.ts"],"names":[],"mappings":";;;AAAA,SAAS,EAAE,CAAC,IAAkB,EAAE,MAAU;IACtC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAG,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QACjB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE;YAC9B,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE;gBACpC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC3C,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;aAC7D;iBACI;gBACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC;aACnD;SACJ;aACI;YACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;SACpD;KACJ;SACI;QACD,GAAG,IAAI,8BAA8B,CAAC;KACzC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,gBAAE"}

@ -0,0 +1,22 @@
function cp(args:Array<string>, curdir:any):string {
var buf = "";
if(args.length == 2) {
if (curdir[args[0]] != undefined) {
if (typeof curdir[args[0]] == "string") {
curdir[args[1]] = curdir[args[0]].slice(0);
buf += "File " + args[0] + " copied to " + args[1] + "\n";
}
else {
buf += "Error: " + args[0] + " is not a file\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
}
else {
buf += "Wrong number of arguments.\n";
}
return buf;
}
export { cp };

11
commands/echo.js Normal file

@ -0,0 +1,11 @@
"use strict";
exports.__esModule = true;
exports.echo = void 0;
function echo(args) {
var buf = "";
buf += args.join(' ');
buf += "\n";
return buf;
}
exports.echo = echo;
//# sourceMappingURL=echo.js.map

1
commands/echo.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"echo.js","sourceRoot":"","sources":["echo.ts"],"names":[],"mappings":";;;AAAA,SAAS,IAAI,CAAC,IAAmB;IAC7B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,GAAG,IAAI,IAAI,CAAC;IACZ,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,oBAAI"}

@ -0,0 +1,7 @@
function echo(args: Array<string>): string {
var buf = "";
buf += args.join(' ');
buf += "\n";
return buf;
}
export { echo };

37
commands/exec.js Normal file

@ -0,0 +1,37 @@
"use strict";
exports.__esModule = true;
exports.exec = void 0;
var commands_1 = require("./commands");
function exec(args, curdir, socket, buffer, sessions, filesystem, curdirx) {
var buf = "";
if (args.length == 0) {
buf += "exec: missing operand\n";
}
else {
var file = args[0];
if (curdir[socket.id][file] == undefined) {
buf += "exec: " + file + ": No such file or directory\n";
}
else if (typeof curdir[socket.id][file] == "string") {
var commands = curdir[socket.id][file].split("\n");
for (var i = 0; i < commands.length; i++) {
var exploded = commands[i].split(" ");
var commandx = exploded[0];
var bannedcommands = ["exec", "exit"];
if (!bannedcommands.includes(commandx)) {
var argsx = exploded.slice(1);
(0, commands_1.resolveCommand)(commandx, socket, argsx, buffer, sessions, filesystem, curdir, curdirx);
}
else {
buf += "Error: " + commandx + " is a restricted command\n";
}
}
}
else {
buf += "exec: " + file + ": Is not a file\n";
}
}
return buf;
}
exports.exec = exec;
//# sourceMappingURL=exec.js.map

1
commands/exec.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"exec.js","sourceRoot":"","sources":["exec.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAE1C,SAAS,IAAI,CAAC,IAAkB,EAAE,MAAU,EAAE,MAAa,EAAE,MAA+B,EAAE,QAAY,EAAE,UAAc,EAAE,OAAqB;IAC7I,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,yBAAyB,CAAC;KACpC;SACI;QACD,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE;YACtC,GAAG,IAAI,QAAQ,GAAG,IAAI,GAAG,+BAA+B,CAAC;SAC5D;aAEI,IAAG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,QAAQ,EAAE;YAEhD,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACtC,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACtC,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAC3B,IAAI,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBACtC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;oBACpC,IAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBAC9B,IAAA,yBAAc,EAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;iBAC1F;qBACG;oBACA,GAAG,IAAI,SAAS,GAAG,QAAQ,GAAG,4BAA4B,CAAC;iBAC9D;aACJ;SACJ;aACG;YACA,GAAG,IAAI,QAAQ,GAAG,IAAI,GAAG,mBAAmB,CAAC;SAChD;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACO,oBAAI"}

@ -0,0 +1,36 @@
import {resolveCommand} from "./commands";
import {Socket} from "socket.io";
function exec(args:Array<string>, curdir:any, socket:Socket, buffer:{ [id: string]: string }, sessions:any, filesystem:any, curdirx:Array<string>):string {
var buf = "";
if (args.length == 0) {
buf += "exec: missing operand\n";
}
else {
let file = args[0];
if (curdir[socket.id][file] == undefined) {
buf += "exec: " + file + ": No such file or directory\n";
}
//check if type string
else if(typeof curdir[socket.id][file] == "string") {
//split string into array of commands
let commands = curdir[socket.id][file].split("\n");
for (let i = 0; i < commands.length; i++) {
let exploded = commands[i].split(" ");
let commandx = exploded[0];
let bannedcommands = ["exec", "exit"];
if (!bannedcommands.includes(commandx)) {
let argsx = exploded.slice(1);
resolveCommand(commandx, socket, argsx, buffer, sessions, filesystem, curdir, curdirx);
}
else{
buf += "Error: " + commandx + " is a restricted command\n";
}
}
}
else{
buf += "exec: " + file + ": Is not a file\n";
}
}
return buf;
}
export {exec};

29
commands/help.js Normal file

@ -0,0 +1,29 @@
"use strict";
exports.__esModule = true;
exports.help = void 0;
function help() {
var buf = "";
buf += "Available commands:\n";
buf += "help - shows this help\n";
buf += "clear - clears the console\n";
buf += "ls - lists the files in the current directory\n";
buf += "cd - changes the current directory\n";
buf += "echo - prints the arguments\n";
buf += "mkdir - creates a new directory\n";
buf += "cat - prints the contents of a file\n";
buf += "touch - creates a new file\n";
buf += "rm - removes a file\n";
buf += "mv - moves a file\n";
buf += "cp - copies a file\n";
buf += "rmdir - removes a directory\n";
buf += "pwd - prints the current directory\n";
buf += "exec - executes a file\n";
buf += "spam - spams the console\n";
buf += "overwrite - overwrites the file with data\n";
buf += "append - appends the arguments to a file\n";
buf += "screenshot - takes a screenshot\n";
buf += "man - display longer help\n";
return buf;
}
exports.help = help;
//# sourceMappingURL=help.js.map

1
commands/help.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"help.js","sourceRoot":"","sources":["help.ts"],"names":[],"mappings":";;;AAAA,SAAS,IAAI;IACT,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,GAAG,IAAI,uBAAuB,CAAC;IAC/B,GAAG,IAAI,0BAA0B,CAAC;IAClC,GAAG,IAAI,8BAA8B,CAAC;IACtC,GAAG,IAAI,iDAAiD,CAAC;IACzD,GAAG,IAAI,sCAAsC,CAAC;IAC9C,GAAG,IAAI,+BAA+B,CAAC;IACvC,GAAG,IAAI,mCAAmC,CAAC;IAC3C,GAAG,IAAI,uCAAuC,CAAC;IAC/C,GAAG,IAAI,8BAA8B,CAAC;IACtC,GAAG,IAAI,uBAAuB,CAAC;IAC/B,GAAG,IAAI,qBAAqB,CAAC;IAC7B,GAAG,IAAI,sBAAsB,CAAC;IAC9B,GAAG,IAAI,+BAA+B,CAAC;IACvC,GAAG,IAAI,sCAAsC,CAAC;IAC9C,GAAG,IAAI,0BAA0B,CAAC;IAClC,GAAG,IAAI,4BAA4B,CAAC;IACpC,GAAG,IAAI,6CAA6C,CAAC;IACrD,GAAG,IAAI,4CAA4C,CAAC;IACpD,GAAG,IAAI,mCAAmC,CAAC;IAC3C,GAAG,IAAI,6BAA6B,CAAC;IACrC,OAAO,GAAG,CAAC;AACf,CAAC;AACO,oBAAI"}

@ -0,0 +1,25 @@
function help(): string {
var buf = "";
buf += "Available commands:\n";
buf += "help - shows this help\n";
buf += "clear - clears the console\n";
buf += "ls - lists the files in the current directory\n";
buf += "cd - changes the current directory\n";
buf += "echo - prints the arguments\n";
buf += "mkdir - creates a new directory\n";
buf += "cat - prints the contents of a file\n";
buf += "touch - creates a new file\n";
buf += "rm - removes a file\n";
buf += "mv - moves a file\n";
buf += "cp - copies a file\n";
buf += "rmdir - removes a directory\n";
buf += "pwd - prints the current directory\n";
buf += "exec - executes a file\n";
buf += "spam - spams the console\n";
buf += "overwrite - overwrites the file with data\n";
buf += "append - appends the arguments to a file\n";
buf += "screenshot - takes a screenshot\n";
buf += "man - display longer help\n";
return buf;
}
export {help};

23
commands/loadsess.js Normal file

@ -0,0 +1,23 @@
"use strict";
exports.__esModule = true;
exports.loadsess = void 0;
var fs = require('fs');
var SerAny = require('serialize-anything');
function loadsess(args, sessions, filesystem, curdir, buffer) {
var buf = "";
if (args.length == 1) {
sessions = SerAny.deserialize(fs.readFileSync("./sessions.json"));
if (sessions[args[0]] != undefined) {
filesystem = sessions[args[0]]["filesystem"];
curdir = sessions[args[0]]["curdir"];
buffer = sessions[args[0]]["buffer"];
buf += "Session loaded.\n";
}
}
else {
buf += "Wrong number of arguments.";
}
return buf;
}
exports.loadsess = loadsess;
//# sourceMappingURL=loadsess.js.map

1
commands/loadsess.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"loadsess.js","sourceRoot":"","sources":["loadsess.ts"],"names":[],"mappings":";;;AAAA,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,IAAM,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAE7C,SAAS,QAAQ,CAAC,IAAkB,EAAE,QAAY,EAAE,UAAc,EAAE,MAAU,EAAE,MAAa;IACzF,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAClE,IAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE;YAC/B,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;YAC7C,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACrC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACrC,GAAG,IAAI,mBAAmB,CAAC;SAC9B;KACJ;SACI;QACD,GAAG,IAAI,4BAA4B,CAAC;KACvC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,4BAAQ"}

20
commands/loadsess.ts Normal file

@ -0,0 +1,20 @@
var fs = require('fs');
const SerAny = require('serialize-anything');
import { Socket } from 'socket.io';
function loadsess(args:Array<string>, sessions:any, filesystem:any, curdir:any, buffer:string ):string {
var buf = "";
if (args.length == 1) {
sessions = SerAny.deserialize(fs.readFileSync("./sessions.json"));
if(sessions[args[0]] != undefined) {
filesystem = sessions[args[0]]["filesystem"];
curdir = sessions[args[0]]["curdir"];
buffer = sessions[args[0]]["buffer"];
buf += "Session loaded.\n";
}
}
else {
buf += "Wrong number of arguments.";
}
return buf;
}
export { loadsess };

21
commands/ls.js Normal file

@ -0,0 +1,21 @@
"use strict";
exports.__esModule = true;
exports.ls = void 0;
function ls(curdir) {
var buf = "";
buf += "Files in the current directory:\n";
for (var key in curdir) {
if (typeof curdir[key] == "string") {
buf += key + " (file)\n";
}
else if (typeof curdir[key] == "object") {
buf += key + " (directory)\n";
}
else {
buf += key + " (unknown)\n";
}
}
return buf;
}
exports.ls = ls;
//# sourceMappingURL=ls.js.map

1
commands/ls.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"ls.js","sourceRoot":"","sources":["ls.ts"],"names":[],"mappings":";;;AAAA,SAAS,EAAE,CAAC,MAAU;IAClB,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,GAAG,IAAI,mCAAmC,CAAC;IAE3C,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;QAGpB,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE;YAChC,GAAG,IAAI,GAAG,GAAG,WAAW,CAAC;SAC5B;aACI,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE;YACrC,GAAG,IAAI,GAAG,GAAG,gBAAgB,CAAC;SACjC;aACI;YACD,GAAG,IAAI,GAAG,GAAG,cAAc,CAAC;SAC/B;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,gBAAE"}

@ -0,0 +1,20 @@
function ls(curdir:any):string {
var buf = "";
buf += "Files in the current directory:\n";
//list only first level files
for (var key in curdir) {
//buf += key + "\n";
//also print if it is a directory or file
if (typeof curdir[key] == "string") {
buf += key + " (file)\n";
}
else if (typeof curdir[key] == "object") {
buf += key + " (directory)\n";
}
else {
buf += key + " (unknown)\n";
}
}
return buf;
}
export { ls };

73
commands/man.js Normal file

@ -0,0 +1,73 @@
"use strict";
exports.__esModule = true;
exports.man = void 0;
function man(args) {
var buf = "";
if (args.length == 0) {
buf += "Missing arguments";
}
switch (args[0]) {
case "help":
buf += "\'help\' Prints the list of available commands\n";
break;
case "clear":
buf += "\'clear\' Clears the console\n";
break;
case "ls":
buf += "\'ls\' Lists the files in the current directory, also displays if file or directory\n";
break;
case "cd":
buf += "\'cd (dirname/..)\' Changes the current directory\n";
break;
case "echo":
buf += "\'echo (arg1) (arg2) .....\' Prints the arguments to the console\n";
break;
case "mkdir":
buf += "\'mkdir (dirname)\' Creates a new directory in the current directory\n";
break;
case "cat":
buf += "\'cat (filename)\' Prints the contents of a file out to the console\n";
break;
case "touch":
buf += "\'touch (filename)\' Creates a new file in the current directory\n";
break;
case "rm":
buf += "\'rm (filename)\' Removes a file from the current directory\n";
break;
case "mv":
buf += "\'mv (filename from) (filename to)\' Moves a file from one directory to another\n";
break;
case "cp":
buf += "\'cp (filename from) (filename to)\' Copies a file from one directory to another\n";
break;
case "rmdir":
buf += "\'rmdir (dirname)\' Removes a directory from the current directory\n";
break;
case "pwd":
buf += "\'pwd\' Prints the current directory out to the console\n";
break;
case "exec":
buf += "\'exec (filename)\' Executes a file in the console, you can \'t use \"exit\" and \"exec\" commands\n";
break;
case "spam":
buf += "\'spam (number) (arg1) (arg2) .......\' Spams the console with a message from arguments\n";
break;
case "overwrite":
buf += "\'overwrite (filename) (arg1) (arg2) .......\' Overwrites a file with from arguments\n";
break;
case "append":
buf += "\'append (filename) (arg1) (arg2) .......\' Appends the arguments to a file\n";
break;
case "screenshot":
buf += "\'screenshot (filename)\' Takes a screenshot of the console and saves it to a file\n";
break;
case "man":
buf += "\'screenshot (command)\' This manual databank\n";
break;
default:
buf += "No such command\n";
}
return buf;
}
exports.man = man;
//# sourceMappingURL=man.js.map

1
commands/man.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"man.js","sourceRoot":"","sources":["man.ts"],"names":[],"mappings":";;;AAAA,SAAS,GAAG,CAAC,IAAmB;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAG,IAAI,CAAC,MAAM,IAAI,CAAC,EAAC;QAChB,GAAG,IAAI,mBAAmB,CAAA;KAC7B;IACD,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAC;QACZ,KAAK,MAAM;YACP,GAAG,IAAI,kDAAkD,CAAC;YAC1D,MAAM;QACV,KAAK,OAAO;YACR,GAAG,IAAI,gCAAgC,CAAC;YACxC,MAAM;QACV,KAAK,IAAI;YACL,GAAG,IAAI,uFAAuF,CAAC;YAC/F,MAAM;QACV,KAAK,IAAI;YACL,GAAG,IAAI,qDAAqD,CAAC;YAC7D,MAAM;QACV,KAAK,MAAM;YACP,GAAG,IAAI,oEAAoE,CAAC;YAC5E,MAAM;QACV,KAAK,OAAO;YACR,GAAG,IAAI,wEAAwE,CAAC;YAChF,MAAM;QACV,KAAK,KAAK;YACN,GAAG,IAAI,uEAAuE,CAAC;YAC/E,MAAM;QACV,KAAK,OAAO;YACR,GAAG,IAAI,oEAAoE,CAAC;YAC5E,MAAM;QACV,KAAK,IAAI;YACL,GAAG,IAAI,+DAA+D,CAAC;YACvE,MAAM;QACV,KAAK,IAAI;YACL,GAAG,IAAI,mFAAmF,CAAC;YAC3F,MAAM;QACV,KAAK,IAAI;YACL,GAAG,IAAI,oFAAoF,CAAC;YAC5F,MAAM;QACV,KAAK,OAAO;YACR,GAAG,IAAI,sEAAsE,CAAC;YAC9E,MAAM;QACV,KAAK,KAAK;YACN,GAAG,IAAI,2DAA2D,CAAC;YACnE,MAAM;QACV,KAAK,MAAM;YACP,GAAG,IAAI,sGAAsG,CAAC;YAC9G,MAAM;QACV,KAAK,MAAM;YACP,GAAG,IAAI,2FAA2F,CAAC;YACnG,MAAM;QACV,KAAK,WAAW;YACZ,GAAG,IAAI,wFAAwF,CAAC;YAChG,MAAM;QACV,KAAK,QAAQ;YACT,GAAG,IAAI,+EAA+E,CAAC;YACvF,MAAM;QACV,KAAK,YAAY;YACb,GAAG,IAAI,sFAAsF,CAAC;YAC9F,MAAM;QACV,KAAK,KAAK;YACN,GAAG,IAAI,iDAAiD,CAAA;YACxD,MAAK;QACT;YACI,GAAG,IAAI,mBAAmB,CAAA;KACjC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACO,kBAAG"}

@ -0,0 +1,69 @@
function man(args: Array<string>):string{
var buf = "";
if(args.length == 0){
buf += "Missing arguments"
}
switch (args[0]){
case "help":
buf += "\'help\' Prints the list of available commands\n";
break;
case "clear":
buf += "\'clear\' Clears the console\n";
break;
case "ls":
buf += "\'ls\' Lists the files in the current directory, also displays if file or directory\n";
break;
case "cd":
buf += "\'cd (dirname/..)\' Changes the current directory\n";
break;
case "echo":
buf += "\'echo (arg1) (arg2) .....\' Prints the arguments to the console\n";
break;
case "mkdir":
buf += "\'mkdir (dirname)\' Creates a new directory in the current directory\n";
break;
case "cat":
buf += "\'cat (filename)\' Prints the contents of a file out to the console\n";
break;
case "touch":
buf += "\'touch (filename)\' Creates a new file in the current directory\n";
break;
case "rm":
buf += "\'rm (filename)\' Removes a file from the current directory\n";
break;
case "mv":
buf += "\'mv (filename from) (filename to)\' Moves a file from one directory to another\n";
break;
case "cp":
buf += "\'cp (filename from) (filename to)\' Copies a file from one directory to another\n";
break;
case "rmdir":
buf += "\'rmdir (dirname)\' Removes a directory from the current directory\n";
break;
case "pwd":
buf += "\'pwd\' Prints the current directory out to the console\n";
break;
case "exec":
buf += "\'exec (filename)\' Executes a file in the console, you can \'t use \"exit\" and \"exec\" commands\n";
break;
case "spam":
buf += "\'spam (number) (arg1) (arg2) .......\' Spams the console with a message from arguments\n";
break;
case "overwrite":
buf += "\'overwrite (filename) (arg1) (arg2) .......\' Overwrites a file with from arguments\n";
break;
case "append":
buf += "\'append (filename) (arg1) (arg2) .......\' Appends the arguments to a file\n";
break;
case "screenshot":
buf += "\'screenshot (filename)\' Takes a screenshot of the console and saves it to a file\n";
break;
case "man":
buf += "\'screenshot (command)\' This manual databank\n"
break
default:
buf += "No such command\n"
}
return buf;
}
export {man};

21
commands/mkdir.js Normal file

@ -0,0 +1,21 @@
"use strict";
exports.__esModule = true;
exports.mkdir = void 0;
function mkdir(args, curdir) {
var buf = "";
if (args.length == 0) {
buf += "Please specify a directory.\n";
}
else {
if (curdir[args[0]]) {
buf += "Directory " + args[0] + " already exists.\n";
}
else {
curdir[args[0]] = {};
buf += "Created directory " + args[0] + "\n";
}
}
return buf;
}
exports.mkdir = mkdir;
//# sourceMappingURL=mkdir.js.map

1
commands/mkdir.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"mkdir.js","sourceRoot":"","sources":["mkdir.ts"],"names":[],"mappings":";;;AAAA,SAAS,KAAK,CAAC,IAAkB,EAAE,MAAU;IACzC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,+BAA+B,CAAC;KAE1C;SACI;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;YACjB,GAAG,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC;SAExD;aACI;YACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;YACrB,GAAG,IAAI,oBAAoB,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;SAEhD;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,sBAAK"}

@ -0,0 +1,20 @@
function mkdir(args:Array<string>, curdir:any):string {
var buf = "";
if (args.length == 0) {
buf += "Please specify a directory.\n";
}
else {
if (curdir[args[0]]) {
buf += "Directory " + args[0] + " already exists.\n";
}
else {
curdir[args[0]] = {};
buf += "Created directory " + args[0] + "\n";
}
}
return buf;
}
export { mkdir };

27
commands/mv.js Normal file

@ -0,0 +1,27 @@
"use strict";
exports.__esModule = true;
exports.mv = void 0;
function mv(args, curdir) {
var buf = "";
if (args.length == 2) {
if (curdir[args[0]] != undefined) {
if (typeof curdir[args[0]] == "string") {
curdir[args[1]] = curdir[args[0]];
delete curdir[args[0]];
buf += "File " + args[0] + " moved to " + args[1] + "\n";
}
else {
buf += "Error: " + args[0] + " is not a file\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
}
else {
buf += "Wrong number of arguments.\n";
}
return buf;
}
exports.mv = mv;
//# sourceMappingURL=mv.js.map

1
commands/mv.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"mv.js","sourceRoot":"","sources":["mv.ts"],"names":[],"mappings":";;;AAAA,SAAS,EAAE,CAAC,IAAkB,EAAE,MAAU;IACtC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE;YAC9B,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE;gBACpC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvB,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;aAC5D;iBACI;gBACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC;aACnD;SACJ;aACI;YACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;SACpD;KACJ;SACI;QACD,GAAG,IAAI,8BAA8B,CAAC;KACzC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,gBAAE"}

@ -0,0 +1,23 @@
function mv(args:Array<string>, curdir:any){
var buf = "";
if (args.length == 2) {
if (curdir[args[0]] != undefined) {
if (typeof curdir[args[0]] == "string") {
curdir[args[1]] = curdir[args[0]];
delete curdir[args[0]];
buf += "File " + args[0] + " moved to " + args[1] + "\n";
}
else {
buf += "Error: " + args[0] + " is not a file\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
}
else {
buf += "Wrong number of arguments.\n";
}
return buf;
}
export { mv };

19
commands/overwrite.js Normal file

@ -0,0 +1,19 @@
"use strict";
exports.__esModule = true;
exports.overwrite = void 0;
function overwrite(args, curdir) {
var buf = "";
if (args.length == 0) {
buf += "overwrite: missing operand\n";
}
else {
curdir[args[0]] = "";
for (var i = 1; i < args.length; i++) {
curdir[args[0]] += args[i] + " ";
}
buf += "File " + args[0] + " overwritten\n";
}
return buf;
}
exports.overwrite = overwrite;
//# sourceMappingURL=overwrite.js.map

@ -0,0 +1 @@
{"version":3,"file":"overwrite.js","sourceRoot":"","sources":["overwrite.ts"],"names":[],"mappings":";;;AAAA,SAAS,SAAS,CAAC,IAAkB,EAAE,MAAU;IAC7C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,8BAA8B,CAAC;KACzC;SACI;QACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;SACpC;QACD,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;KAC/C;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,8BAAS"}

@ -0,0 +1,15 @@
function overwrite(args:Array<string>, curdir:any){
var buf = "";
if (args.length == 0) {
buf += "overwrite: missing operand\n";
}
else {
curdir[args[0]] = "";
for (let i = 1; i < args.length; i++) {
curdir[args[0]] += args[i] + " ";
}
buf += "File " + args[0] + " overwritten\n";
}
return buf;
}
export { overwrite };

11
commands/pwd.js Normal file

@ -0,0 +1,11 @@
"use strict";
exports.__esModule = true;
exports.pwd = void 0;
function pwd(curdirx) {
var buf = "";
var curdirasstring = curdirx.join("/");
buf += "Current directory: " + curdirasstring + "\n";
return buf;
}
exports.pwd = pwd;
//# sourceMappingURL=pwd.js.map

1
commands/pwd.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"pwd.js","sourceRoot":"","sources":["pwd.ts"],"names":[],"mappings":";;;AAAA,SAAS,GAAG,CAAC,OAAqB;IAC9B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,GAAG,IAAI,qBAAqB,GAAG,cAAc,GAAG,IAAI,CAAC;IACrD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,kBAAG"}

@ -0,0 +1,7 @@
function pwd(curdirx:Array<string>):string {
var buf = "";
var curdirasstring = curdirx.join("/");
buf += "Current directory: " + curdirasstring + "\n";
return buf;
}
export { pwd };

21
commands/rm.js Normal file

@ -0,0 +1,21 @@
"use strict";
exports.__esModule = true;
exports.rm = void 0;
function rm(args, curdir, socket) {
var buf = "";
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
delete curdir[socket.id][args[0]];
buf += "File " + args[0] + " removed\n";
}
else {
buf += "Error: " + args[0] + " is not a file\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
return buf;
}
exports.rm = rm;
//# sourceMappingURL=rm.js.map

1
commands/rm.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"rm.js","sourceRoot":"","sources":["rm.ts"],"names":[],"mappings":";;;AACA,SAAS,EAAE,CAAC,IAAkB,EAAE,MAAU,EAAE,MAAa;IACrD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE;QACzC,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE;YAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;SAC3C;aACI;YACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC;SACnD;KACJ;SACI;QACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;KACpD;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,gBAAE"}

@ -0,0 +1,18 @@
import { Socket } from "socket.io";
function rm(args:Array<string>, curdir:any, socket:Socket):string {
var buf = "";
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "string") {
delete curdir[socket.id][args[0]];
buf += "File " + args[0] + " removed\n";
}
else {
buf += "Error: " + args[0] + " is not a file\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
return buf;
}
export { rm };

21
commands/rmdir.js Normal file

@ -0,0 +1,21 @@
"use strict";
exports.__esModule = true;
exports.rmdir = void 0;
function rmdir(args, curdir, socket) {
var buf = "";
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "object") {
delete curdir[socket.id][args[0]];
buf += "Directory " + args[0] + " removed\n";
}
else {
buf += "Error: " + args[0] + " is not a directory\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
return buf;
}
exports.rmdir = rmdir;
//# sourceMappingURL=rmdir.js.map

1
commands/rmdir.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"rmdir.js","sourceRoot":"","sources":["rmdir.ts"],"names":[],"mappings":";;;AACA,SAAS,KAAK,CAAC,IAAkB,EAAE,MAAU,EAAE,MAAa;IACxD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE;QACzC,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE;YAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,GAAG,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;SAChD;aACI;YACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,uBAAuB,CAAC;SACxD;KACJ;SACI;QACD,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;KACpD;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,sBAAK"}

@ -0,0 +1,18 @@
import {Socket} from "socket.io";
function rmdir(args:Array<string>, curdir:any, socket:Socket):string {
var buf = "";
if (curdir[socket.id][args[0]] != undefined) {
if (typeof curdir[socket.id][args[0]] == "object") {
delete curdir[socket.id][args[0]];
buf += "Directory " + args[0] + " removed\n";
}
else {
buf += "Error: " + args[0] + " is not a directory\n";
}
}
else {
buf += "Error: " + args[0] + " does not exist\n";
}
return buf;
}
export { rmdir };

29
commands/savesess.js Normal file

@ -0,0 +1,29 @@
"use strict";
exports.__esModule = true;
exports.savesess = void 0;
var fs = require('fs');
var SerAny = require('serialize-anything');
function savesess(args, sessions, filesystem, curdir, buffer, socket) {
var buf = "";
var pwd = process.env.PWD || "kryptic";
if (args.length == 2) {
if (args[0] == pwd) {
sessions[args[1]] = [];
sessions[args[1]]["buffer"] = buffer[socket.id].replace(new RegExp(pwd, 'g'), "[REDACTED]");
sessions[args[1]]["filesystem"] = JSON.parse(JSON.stringify(filesystem[socket.id]));
sessions[args[1]]["curdir"] = JSON.parse(JSON.stringify(curdir[socket.id]));
var data = SerAny.serialize(sessions);
fs.writeFileSync("./sessions.json", data);
buf += "Session saved.\n";
}
else {
buf += "Wrong password.";
}
}
else {
buf += "Wrong number of arguments.";
}
return buf;
}
exports.savesess = savesess;
//# sourceMappingURL=savesess.js.map

1
commands/savesess.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"savesess.js","sourceRoot":"","sources":["savesess.ts"],"names":[],"mappings":";;;AAAA,IAA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C;SAC5B;KACJ;SACI;QACD,GAAG,IAAI,4BAA4B,CAAC;KACvC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,4BAAQ"}

31
commands/savesess.ts Normal file

@ -0,0 +1,31 @@
var fs = require('fs');
const SerAny = require('serialize-anything');
import { Socket } from 'socket.io';
function savesess(args:Array<string>, sessions:any, filesystem:any, curdir:any, buffer:{ [id: string]: string }, socket:Socket):string {
var buf = "";
//get password from environment variable or use kryptic
let pwd = process.env.PWD || "kryptic";
if (args.length == 2) {
if (args[0] == pwd) {
sessions[args[1]] = [];
//sessions[args[1]]["buffer"] = buffer[socket.id];
//replace all occurences of passord with [REDACTED]
sessions[args[1]]["buffer"] = buffer[socket.id].replace(new RegExp(pwd, 'g'), "[REDACTED]");
sessions[args[1]]["filesystem"] = JSON.parse(JSON.stringify(filesystem[socket.id]));
sessions[args[1]]["curdir"] = JSON.parse(JSON.stringify(curdir[socket.id]));
var data = SerAny.serialize(sessions);
//write all sessions to a single file called sessions.json
fs.writeFileSync("./sessions.json", data);
buf += "Session saved.\n";
}
else {
buf += "Wrong password.";
}
}
else {
buf += "Wrong number of arguments.";
}
return buf;
}
export { savesess };

11
commands/screenshot.js Normal file

@ -0,0 +1,11 @@
"use strict";
exports.__esModule = true;
exports.screenshot = void 0;
function screenshot(args, curdir, buffer, socket) {
var buf = "";
curdir[socket.id][args[0]] = buffer[socket.id];
buf += "Screenshot saved to " + args[0] + "\n";
return buf;
}
exports.screenshot = screenshot;
//# sourceMappingURL=screenshot.js.map

@ -0,0 +1 @@
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["screenshot.ts"],"names":[],"mappings":";;;AACA,SAAS,UAAU,CAAC,IAAkB,EAAE,MAAU,EAAE,MAA+B,EAAE,MAAa;IAC9F,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/C,GAAG,IAAI,sBAAsB,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC/C,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,gCAAU"}

@ -0,0 +1,8 @@
import {Socket} from 'socket.io';
function screenshot(args:Array<string>, curdir:any, buffer:{ [id: string]: string }, socket:Socket):string {
var buf = "";
curdir[socket.id][args[0]] = buffer[socket.id];
buf += "Screenshot saved to " + args[0] + "\n";
return buf;
}
export { screenshot };

24
commands/spam.js Normal file

@ -0,0 +1,24 @@
"use strict";
exports.__esModule = true;
exports.spam = void 0;
function spam(args) {
var buf = "";
var numtimes = parseInt(args[0]);
if (isNaN(numtimes)) {
buf += "Error: " + args[0] + " is not a number\n";
}
else if (numtimes < 0) {
buf += "Error: " + args[0] + " is negative\n";
}
else if (numtimes > 100) {
buf += "Error: " + args[0] + " is too large\n";
}
else {
for (var i = 0; i < numtimes; i++) {
buf += args.slice(1).join(" ") + "\n";
}
return buf;
}
}
exports.spam = spam;
//# sourceMappingURL=spam.js.map

1
commands/spam.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"spam.js","sourceRoot":"","sources":["spam.ts"],"names":[],"mappings":";;;AAAA,SAAS,IAAI,CAAC,IAAkB;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,IAAG,KAAK,CAAC,QAAQ,CAAC,EAAE;QAChB,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC;KACrD;SACI,IAAI,QAAQ,GAAG,CAAC,EAAE;QACnB,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;KACjD;SACI,IAAK,QAAQ,GAAG,GAAG,EAAE;QACtB,GAAG,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;KAClD;SACI;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE;YAC/B,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;SACzC;QACD,OAAO,GAAG,CAAC;KACd;AACL,CAAC;AACQ,oBAAI"}

@ -0,0 +1,21 @@
function spam(args:Array<string>):string {
var buf = "";
var numtimes = parseInt(args[0]);
if(isNaN(numtimes)) {
buf += "Error: " + args[0] + " is not a number\n";
}
else if (numtimes < 0) {
buf += "Error: " + args[0] + " is negative\n";
}
else if (numtimes > 100) {
buf += "Error: " + args[0] + " is too large\n";
}
else {
//spam arguments times from first argument
for (let i = 0; i < numtimes; i++) {
buf += args.slice(1).join(" ") + "\n";
}
return buf;
}
}
export { spam };

16
commands/touch.js Normal file

@ -0,0 +1,16 @@
"use strict";
exports.__esModule = true;
exports.touch = void 0;
function touch(args, curdir, socket) {
var buf = "";
if (args.length == 0) {
buf += "touch: missing operand\n";
}
else {
curdir[socket.id][args[0]] = "";
buf += "File " + args[0] + " created\n";
}
return buf;
}
exports.touch = touch;
//# sourceMappingURL=touch.js.map

1
commands/touch.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"touch.js","sourceRoot":"","sources":["touch.ts"],"names":[],"mappings":";;;AACA,SAAS,KAAK,CAAC,IAAkB,EAAE,MAAU,EAAE,MAAa;IACxD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,GAAG,IAAI,0BAA0B,CAAC;KACrC;SACI;QACD,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QAChC,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;KAC3C;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,sBAAK"}

@ -0,0 +1,13 @@
import {Socket} from 'socket.io';
function touch(args:Array<string>, curdir:any, socket:Socket):string {
var buf = "";
if (args.length == 0) {
buf += "touch: missing operand\n";
}
else {
curdir[socket.id][args[0]] = "";
buf += "File " + args[0] + " created\n";
}
return buf;
}
export { touch };

10
commands/wee.js Normal file

@ -0,0 +1,10 @@
"use strict";
exports.__esModule = true;
exports.wee = void 0;
function wee() {
var buf = "";
buf += "Woo!\n";
return buf;
}
exports.wee = wee;
//# sourceMappingURL=wee.js.map

1
commands/wee.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"wee.js","sourceRoot":"","sources":["wee.ts"],"names":[],"mappings":";;;AAAA,SAAS,GAAG;IACR,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,GAAG,IAAI,QAAQ,CAAC;IAChB,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,kBAAG"}

6
commands/wee.ts Normal file

@ -0,0 +1,6 @@
function wee(): string {
var buf = "";
buf += "Woo!\n";
return buf;
}
export { wee };

10
commands/woo.js Normal file

@ -0,0 +1,10 @@
"use strict";
exports.__esModule = true;
exports.woo = void 0;
function woo() {
var buf = "";
buf += "Wee!\n";
return buf;
}
exports.woo = woo;
//# sourceMappingURL=woo.js.map

1
commands/woo.js.map Normal file

@ -0,0 +1 @@
{"version":3,"file":"woo.js","sourceRoot":"","sources":["woo.ts"],"names":[],"mappings":";;;AAAA,SAAS,GAAG;IACR,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,GAAG,IAAI,QAAQ,CAAC;IAChB,OAAO,GAAG,CAAC;AACf,CAAC;AACQ,kBAAG"}

6
commands/woo.ts Normal file

@ -0,0 +1,6 @@
function woo(): string {
var buf = "";
buf += "Wee!\n";
return buf;
}
export { woo };

File diff suppressed because one or more lines are too long

@ -9,7 +9,16 @@ var Server = require("socket.io").Server;
var io = new Server(server);
var commands_1 = require("./commands/commands");
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
res.sendFile(__dirname + '/website/index.html');
});
app.get("/script.js", function (req, res) {
res.sendFile(__dirname + '/website/script.js');
});
app.get("/style.css", function (req, res) {
res.sendFile(__dirname + '/website/style.css');
});
app.get("/jquery.js", function (req, res) {
res.sendFile(__dirname + '/website/jquery.js');
});
var buffer = {};
var filesystem = {};

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AACA,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEjC,IAAI,GAAG,GAAG,OAAO,EAAE,CAAC;AACpB,IAAI,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AACpC,IAAI,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;AAC5B,IAAA,MAAM,GAAK,OAAO,CAAC,WAAW,CAAC,OAAzB,CAA0B;AAExC,IAAM,EAAE,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAE9B,gDAAqD;AAErD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAC,GAAW,EAAE,GAAY;IACnC,GAAG,CAAC,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAIL,IAAI,MAAM,GAA6B,EAAE,CAAC;AAE1C,IAAI,UAAU,GAAQ,EAAE,CAAC;AAEzB,IAAI,MAAM,GAAQ,EAAE,CAAC;AAErB,IAAI,QAAQ,GAAQ,EAAE,CAAC;AAEvB,IAAI,OAAO,GAAQ,EAAE,CAAC;AAEtB,SAAS,UAAU,CAAC,MAAa,EAAE,OAAiC;IAChE,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAE9B,IAAI,IAAI,QAAQ,CAAC;IACjB,MAAM,CAAC,I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,CAAC;YACnE,IAAI,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAI,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAEhC,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,UAAS,GAAG;gBACtC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;YAE1B,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,WAAW,GAAG,uBAAuB,GAAG,WAAW,GAAG,IAAI,CAAC,CAAC;YAClG,IAAA,yBAAc,EAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;SACnG;aACG;YAEA,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC;SAC5B;QAED,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AACH,EAAE,CAAC,EAAE,CAAC,YAAY,EAAE,UAAC,MAAa;IAC9B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;IAChB,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}

@ -12,8 +12,21 @@ const io = new Server(server);
import { resolveCommand } from './commands/commands';
app.get('/', (req:Request, res:Response) => {
res.sendFile(__dirname + '/index.html');
});
res.sendFile(__dirname + '/website/index.html');
}
);
app.get("/script.js", (req:Request, res:Response) => {
res.sendFile(__dirname + '/website/script.js');
}
);
app.get("/style.css", (req:Request, res:Response) => {
res.sendFile(__dirname + '/website/style.css');
}
);
app.get("/jquery.js", (req:Request, res:Response) => {
res.sendFile(__dirname + '/website/jquery.js');
}
);
//initialize buffer
//var buffer = [];
//add type for typescript

15
website/index.html Normal file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/socket.io/socket.io.js"></script>
<link rel="stylesheet" href="style.css">
<meta charset="utf-8">
<script src="jquery.js"></script>
<script src="script.js" ></script>
</head>
<body>
<div id="consolecont">
<textarea id="console" readonly></textarea>
</div>
</body>
</html>

2
website/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

75
website/script.js Normal file

@ -0,0 +1,75 @@
function addareacontent(content){
//this appends to the bottom of the console and scrolls to the bottom make sure we start typing at the bottom
var console = document.getElementById("console");
console.innerHTML = content;
console.scrollTop = console.scrollHeight;
}
function resizeit(){
$('#consolecont').css('height', $(window).height() - 10);
let height = ($(window).height() - $('#console').offset().top)*0.96;
$('#console').css('height', height);
$('#rows').val($(window).height() - $('#console').offset().top - 10);
}
$(document).ready(function(){
//fit console to screen
//$('#console').css('height', $(window).height() - $('#console').offset().top - 10);
//account for the input box
let host = 'ws://127.0.0.1:8480';
socket = io.connect(host);
resizeit();
//resize it on window resize
$(window).resize(function(){
resizeit();
});
//on key press on any part of html page
$("#console").keyup(function(e){
//if enter key is pressed
//get the input
e.preventDefault();
//resolve e.code to char
let key = e.which;
//send to server via socket if connected
if (key == 8){
socket.emit('keypress', key);
}
});
$("#console").keypress(function(e){
//if enter key is pressed
//get the input
e.preventDefault();
//resolve e.code to char
let key = e.which;
//send to server via socket if connected
socket.emit('keypress', key);
});
//connect to the server
//on connect
socket.on('connect', function(){
addareacontent("Connected to server");
});
//on disconnect
socket.on('disconnect', function(){
addareacontent("Disconnected from server");
});
//on error
socket.on('error', function(err){
addareacontent("Error: " + err);
});
//on message
socket.on('buffer', function(msg){
addareacontent(msg);
});
})
function flash(){
//if u+2800 is present in the console then replace it with 2588
let console = document.getElementById("console");
if(console.innerHTML.indexOf("\u2800") > -1){
console.innerHTML = console.innerHTML.replace("\u2800", "\u2588");
}
else{
console.innerHTML = console.innerHTML.replace("\u2588", "\u2800");
}
}
setInterval(flash, 500);

23
website/style.css Normal file

@ -0,0 +1,23 @@
.error {
color: red;
}
#console {
background: #000;
width: 99%;
color: #0F0;
margin: 0;
border-color: #00AC00;
}
#consolecont{
width: 100%;
height: 100%;
overflow: auto;
}
body{
width: 100%;
height: 100%;
margin: 0;
}
*{
background-color: #000;
}