diff --git a/backend/cat.php b/backend/cat.php new file mode 100644 index 0000000..04cfdba --- /dev/null +++ b/backend/cat.php @@ -0,0 +1,37 @@ +getMessage(); + echo json_encode($tmp); + exit(); + } + if ($tmp->fileType == "directory") { + $name = $tmp->name; + $tmp = array(); + $tmp['error'] = $name . ": Is a directory"; + echo json_encode($tmp); + exit(); + } + if (!(userManager::getRightsOnFile($_SESSION['uid'], fileManager::getFileById($tmp->parentFK)) & FILE_FLAG_READ)) { + $name = $tmp->name; + $tmp = array(); + $tmp['error'] = $name . ": Permission denied"; + echo json_encode($tmp); + exit(); + } + $result = array(); + $result['name'] = $tmp->name; + $result['content'] = $tmp->content; + echo json_encode($result); +?> diff --git a/data/scripts/programs/Cat.js b/data/scripts/programs/Cat.js new file mode 100644 index 0000000..0a089d9 --- /dev/null +++ b/data/scripts/programs/Cat.js @@ -0,0 +1,35 @@ +var Cat = function() { +} +Cat.prototype = new Program(); +Cat.prototype.main = function(args) { + if (args.length != 2) { + this.output("\033[31m" + args[0] + ": Illegal number of arguments\033[0m\n"); + this.exit(1); + } + + + if (args[1].substring(0, 1) != "/") + args[1] = shell.directory + "/" + args[1]; + + var result = new Request("backend/cat.php"); + result.setData([["path", args[1]]]); + result = result.send(true, ret); + result = JSON.parse(result); + + if (result.error) { + this.output("\033[31m" + args[0] + ": " + result.error + "\033[0m\n"); + this.exit(1); + return; + } + + this.output(result.content); + if (result.content.substring(result.content.length - 1, 1) != "\n") + this.output("\n"); + + this.exit(0); +} + +ProgramManager.programs.push({ + command: "cat", + code: Cat +})