import {resolveCommand} from "./commands"; import {Socket} from "socket.io"; function exec(args:Array, curdir:any, socket:Socket, buffer:{ [id: string]: string }, sessions:any, filesystem:any, curdirx:Array):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};