From c08586161ac4267772368abfcb8ee0f9c4c29345 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sat, 16 Aug 2014 21:08:11 +0200 Subject: [PATCH] ... and i forgot about cd --- backend/cd.php | 40 +++++++++++++++++++++++++++++++++++++ data/scripts/programs/Cd.js | 29 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 backend/cd.php create mode 100644 data/scripts/programs/Cd.js diff --git a/backend/cd.php b/backend/cd.php new file mode 100644 index 0000000..0e0737d --- /dev/null +++ b/backend/cd.php @@ -0,0 +1,40 @@ +getMessage(); + echo json_encode($tmp); + exit(); + } + + if ($tmp->fileType != "directory") { + $name = $tmp->name; + $tmp = array(); + $tmp['error'] = $name . ": Not a directory"; + echo json_encode($tmp); + exit(); + } + + if (!(userManager::getRightsOnFile($_SESSION['uid'], $tmp) & FILE_FLAG_READ)) { + $name = $tmp->name; + $tmp = array(); + $tmp['error'] = $name . ": Not permitted"; + echo json_encode($tmp); + exit(); + } + + $path = fileManager::getPathById($tmp->ID); + $tmp = array(); + $tmp['path'] = $path; + echo json_encode($tmp); +?> diff --git a/data/scripts/programs/Cd.js b/data/scripts/programs/Cd.js new file mode 100644 index 0000000..a6f99d3 --- /dev/null +++ b/data/scripts/programs/Cd.js @@ -0,0 +1,29 @@ +var Cd = function() { +} +Cd.prototype = new Program(); +Cd.prototype.main = function(args) { + if (args.length != 2) + args[1] = shell.home; + + if (args[1].substring(0, 1) != "/") + args[1] = shell.directory + "/" + args[1]; + + var result = new Request("backend/cd.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); + } + + shell.directory = result.path; + + this.exit(0); +} + +ProgramManager.programs.push({ + command: "cd", + code: Cd +})