mirror of
https://github.com/sigmasternchen/webcli
synced 2025-03-14 21:58:55 +00:00
cat
This commit is contained in:
parent
a6f804b5d0
commit
e78bc8b928
2 changed files with 72 additions and 0 deletions
37
backend/cat.php
Normal file
37
backend/cat.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?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 . ": 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);
|
||||
?>
|
35
data/scripts/programs/Cat.js
Normal file
35
data/scripts/programs/Cat.js
Normal file
|
@ -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
|
||||
})
|
Loading…
Reference in a new issue