... and i forgot about cd

This commit is contained in:
overflowerror 2014-08-16 21:08:11 +02:00
parent 7c86890c6c
commit c08586161a
2 changed files with 69 additions and 0 deletions

40
backend/cd.php Normal file
View file

@ -0,0 +1,40 @@
<?php
require_once("fileManager.php");
require_once("sessionManager.php");
require_once("config.php");
require_once("userManager.php");
$path = $_GET['path'];
$tmp;
try {
$tmp = fileManager::getFileById(fileManager::getIdByPath($path));
} catch (Exception $e) {
$tmp = array();
$tmp['error'] = $e->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);
?>

View file

@ -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
})