mirror of
https://github.com/sigmasternchen/webcli
synced 2025-03-15 06:08:54 +00:00
php part of ls... nearly perfect... : )
This commit is contained in:
parent
1f2f978084
commit
ccf3799d72
1 changed files with 53 additions and 0 deletions
53
backend/ls.php
Normal file
53
backend/ls.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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();
|
||||
return json_encode($tmp);
|
||||
exit();
|
||||
}
|
||||
if ($tmp->fileType == "directory") {
|
||||
if (userManager::getRightsOnFile($_SESSION['uid'], $tmp) & 1<<2)
|
||||
$tmp = fileManager::getFilesByParentId($tmp->ID);
|
||||
else {
|
||||
$tmp = array();
|
||||
$tmp['error'] = "cannot open directory " + $path + ": Permission denied";
|
||||
return json_encode($tmp);
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
if (userManager::getRightsOnFile($_SESSION['uid'], fileManager::getFileById($tmp->parentFK)) & 1<<2)
|
||||
$tmp = array($tmp);
|
||||
else {
|
||||
$tmp = array();
|
||||
$tmp['error'] = "cannot open file " + $path + ": Permission denied";
|
||||
return json_encode($tmp);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
for ($i = 0; $i < count($tmp); $i++) {
|
||||
$result[$i] = array();
|
||||
$result[$i]['permission'] = fileManager::getPermissionStringByFile($tmp[$i]);
|
||||
$result[$i]['hardlinks'] = "1"; // not implemented
|
||||
$result[$i]['owner'] = userManager::getUserById($tmp[$i]->userFK)->name;
|
||||
$result[$i]['group'] = userManager::getGroupById($tmp[$i]->groupFK)->name;
|
||||
$result[$i]['size'] = ($tmp[$i]->fileType == "directory" ? SIZE_OF_DIRECTORY : strlen($tmp[$i]->content)) . "";
|
||||
$result[$i]['created'] = $tmp[$i]->created;
|
||||
$result[$i]['changed'] = $tmp[$i]->changed;
|
||||
$result[$i]['name'] = $tmp[$i]->name;
|
||||
}
|
||||
echo json_encode($result);
|
||||
?>
|
Loading…
Reference in a new issue