mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 10:37:42 -07:00
FileManager bugfixes + file permission module
This commit is contained in:
parent
ffec2e7e2d
commit
7fefa20d90
6 changed files with 339 additions and 464 deletions
|
@ -1,359 +1 @@
|
|||
<?php
|
||||
|
||||
//define(MAX_FILES_TO_SORT, 5);
|
||||
//define(LISTING_TIMEOUT, 0.000001);
|
||||
define(LISTING_TIMEOUT, 5);
|
||||
|
||||
|
||||
|
||||
|
||||
//echo 'files: ';
|
||||
//$files = scandir(__DIR__);
|
||||
|
||||
|
||||
//echo '<pre>';
|
||||
//print_r($files);
|
||||
|
||||
|
||||
//$_REQUEST['sort_field'] = 'size';
|
||||
$_REQUEST['sort_field'] = 'name';
|
||||
//$_REQUEST['sort_field'] = 'atime';
|
||||
//$_REQUEST['sort_field'] = 'mtime';
|
||||
$_REQUEST['sort_desc'] = 1;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
+- copy file / dir [ recursive ]
|
||||
+- rename(move) file / dir
|
||||
+- delete file / dir [ recursive ]
|
||||
+- chmod file / dir
|
||||
+- chown file / dir
|
||||
+- create file
|
||||
+- create dir
|
||||
*/
|
||||
|
||||
switch($_REQUEST['action']){
|
||||
case 'copy': fm_copy($_REQUEST['source'], $_REQUEST['dest']); break;
|
||||
case 'rename': fm_rename($_REQUEST['source'], $_REQUEST['dest']); break;
|
||||
case 'delete': fm_delete($_REQUEST['source']); break;
|
||||
case 'chmod': fm_chmod($_REQUEST['source'], $_REQUEST['mode']); break;
|
||||
case 'chown': fm_chown($_REQUEST['source'], $_REQUEST['uid'], $_REQUEST['gid']); break;
|
||||
case 'create_file': fm_create_file($_REQUEST['source'], $_REQUEST['mode'] || FALSE); break;
|
||||
case 'create_dir': fm_create_dir($_REQUEST['source'], $_REQUEST['mode'] || FALSE); break;
|
||||
|
||||
default:
|
||||
$pwd = $_REQUEST['path'] ? $_REQUEST['path'] : __DIR__;
|
||||
$listing = dir_list($pwd, $_REQUEST['sort_field']);
|
||||
$writable = is_writable($pwd);
|
||||
|
||||
$pwd = array_merge(array('/'), explode('/', trim($pwd, '/')));
|
||||
|
||||
include('templates/filemanager.php');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//echo $_GET['sort_field'];
|
||||
|
||||
// if(in_array($_GET['sort_field'], $available_sort_fields)){
|
||||
// echo '1';
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
upload_file
|
||||
|
||||
+ list_dir
|
||||
+- copy file / dir [ recursive ]
|
||||
+- rename(move) file / dir
|
||||
+- delete file / dir [ recursive ]
|
||||
+- chmod file / dir
|
||||
+- chown file / dir
|
||||
+- create file
|
||||
+- create dir
|
||||
|
||||
view file / image
|
||||
download file / image
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function fm_create_file($filename){
|
||||
if(is_file($filename))
|
||||
return array('error' => 'file exists', 'code' => 1);
|
||||
|
||||
return !!fopen($filename, 'w');
|
||||
}
|
||||
|
||||
|
||||
function fm_create_dir($dirname){
|
||||
if(is_dir($filename))
|
||||
return array('error' => 'directory exists', 'code' => 1);
|
||||
|
||||
// TODO set parent directory mode
|
||||
return mkdir($dirname);
|
||||
}
|
||||
|
||||
|
||||
function fm_chown($filename, $recursive = 0, $uid = FALSE, $gid = FALSE){
|
||||
if(is_dir($filename) && $recursive){
|
||||
$dir_handle = opendir($dir);
|
||||
while ($item = readdir($dir_handle)){
|
||||
if (!in_array($item, array('.','..'))){
|
||||
$new_item = $filename.'/'.$item;
|
||||
|
||||
if($uid !== FALSE) chown($new_item, (int)$uid);
|
||||
if($gid !== FALSE) chgrp($new_item, (int)$gid);
|
||||
|
||||
if(is_dir($new_item)){
|
||||
fm_chown($new_item, $recursive, $uid, $gid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if($uid !== FALSE) chown($filename, (int)$uid);
|
||||
if($gid !== FALSE) chgrp($filename, (int)$gid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fm_chmod($filename, $recursive = 0, $mode){
|
||||
if(is_dir($filename) && $recursive){
|
||||
$dir_handle = opendir($dir);
|
||||
while ($item = readdir($dir_handle)){
|
||||
if (!in_array($item, array('.','..'))){
|
||||
$new_item = $filename.'/'.$item;
|
||||
chmod($new_item, octdec($mode));
|
||||
|
||||
if(is_dir($new_item)){
|
||||
fm_chmod($new_item, $recursive, $mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
chmod($filename, octdec($mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fm_delete($filename){
|
||||
if(is_dir($filename)){
|
||||
foreach (
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($filename, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::SELF_FIRST) as $item
|
||||
) {
|
||||
if ($item->isDir()) {
|
||||
rmdir($item);
|
||||
// mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), decoct(fileperms($item->getPerms())));
|
||||
} else {
|
||||
unlink($item);
|
||||
// copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return unlink($filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fm_rename($source, $dest){
|
||||
return rename($source, $dest);
|
||||
}
|
||||
|
||||
|
||||
function fm_copy($source, $dest){
|
||||
if(is_dir($source)){
|
||||
foreach (
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::SELF_FIRST) as $item
|
||||
) {
|
||||
if ($item->isDir()) {
|
||||
// TODO set dir perms
|
||||
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), decoct(fileperms($item->getPerms())));
|
||||
} else {
|
||||
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
return copy($source, $dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function list_dir(){
|
||||
$dir_iterator = new RecursiveDirectoryIterator("/path");
|
||||
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||
// could use CHILD_FIRST if you so wish
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
echo $file, "\n";
|
||||
}
|
||||
|
||||
$size = 0;
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile()) {
|
||||
echo substr($file->getPathname(), 27) . ": " . $file->getSize() . " B; modified " . date("Y-m-d", $file->getMTime()) . "\n";
|
||||
$size += $file->getSize();
|
||||
}
|
||||
}
|
||||
|
||||
echo "\nTotal file size: ", $size, " bytes\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// fast removing directory
|
||||
function rmrf($dir) {
|
||||
|
||||
foreach (glob($dir) as $file) {
|
||||
if (is_dir($file)) {
|
||||
rmrf("$file/*");
|
||||
rmdir($file);
|
||||
} else {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function dir_list($dir, $sort = 0)
|
||||
{
|
||||
$sort_order_for_filename = SORT_ASC;
|
||||
//$available_sort_fields = array('size, type', 'mtime', 'atime', 'owner', 'group');
|
||||
$available_sort_fields = array('name', 'size', 'type', 'mtime', 'atime', 'owner', 'group');
|
||||
$sort_order = SORT_ASC;
|
||||
|
||||
if ($dir[strlen($dir)-1] != '/') $dir .= '/';
|
||||
if (!is_dir($dir)) return array();
|
||||
|
||||
$start = microtime(TRUE);
|
||||
|
||||
$listing = array('dirs' => array(), 'files' => array(), 'dir_names' => array(), 'file_names' => array() ,'count' => 0, 'timeout_exeeded' => 0, 'time' => 0);
|
||||
$dir_handle = opendir($dir);
|
||||
$dir_objects = array();
|
||||
while ($object = readdir($dir_handle)){
|
||||
if (!in_array($object, array('.','..'))){
|
||||
$filename = $dir . $object;
|
||||
$time = microtime(true) - $start;
|
||||
if($time <= LISTING_TIMEOUT){
|
||||
$stats = stat($filename);
|
||||
$mode = explain_mode($stats['mode']);
|
||||
$perms = decoct(fileperms($filename));
|
||||
$item = array(
|
||||
'name' => $object,
|
||||
'size' => $stats['size'],
|
||||
'mode' => array('owner' => $mode['owner'], 'group' => $mode['owner'], 'other' => $mode['owner']),
|
||||
'perms' => decoct($stats['mode']),
|
||||
'type' => $mode['type'],
|
||||
'mtime' => $stats['mtime'],
|
||||
'atime' => $stats['atime'],
|
||||
'mdate_human' => date("Y F d", $stats['mtime']),
|
||||
'mtime_human' => date("H:i:s", $stats['mtime']),
|
||||
'adate_human' => date("Y F d", $stats['atime']),
|
||||
'atime_human' => date("H:i:s", $stats['atime']),
|
||||
'nlink' => $stats['nlink'],
|
||||
'owner' => posix_getpwuid($stats['uid'])['name'],
|
||||
'group' => posix_getgrgid($stats['gid'])['name']
|
||||
);
|
||||
}else{
|
||||
$listing['timeout_exeeded'] = TRUE;
|
||||
if(is_dir($filename)){ $type = 'd';
|
||||
}else{ $type = '-'; }
|
||||
|
||||
$item = array(
|
||||
'name' => $object,
|
||||
'size' => FALSE,
|
||||
'mode' => array('owner' => FALSE, 'group' => FALSE, 'other' => FALSE),
|
||||
'type' => $type,
|
||||
'mtime' => FALSE,
|
||||
'atime' => FALSE,
|
||||
'mdate_human' => FALSE,
|
||||
'mtime_human' => FALSE,
|
||||
'adate_human' => FALSE,
|
||||
'atime_human' => FALSE,
|
||||
'nlink' => FALSE,
|
||||
'owner' => FALSE,
|
||||
'group' => FALSE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$listing['count']++;
|
||||
|
||||
if($item['type'] == 'd'){
|
||||
$listing['dirs'][] = $item;
|
||||
$listing['dir_names'][] = $item['name'];
|
||||
}else{
|
||||
if($sort && !$listing['timeout_exeeded']){
|
||||
$listing[$sort][] = $item[$sort];
|
||||
}
|
||||
$listing['files'][] = $item;
|
||||
$listing['file_names'][] = $item['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$listing['time'] = microtime(TRUE) - $start;
|
||||
|
||||
|
||||
if(!$listing['timeout_exeeded']){
|
||||
if(in_array($_REQUEST['sort_field'], $available_sort_fields)){
|
||||
if($_REQUEST['sort_desc']){
|
||||
$sort_order = SORT_DESC;
|
||||
}
|
||||
array_multisort($listing[$_REQUEST['sort_field']], $sort_order, $listing['file_names'], $sort_order_for_filename, $listing['files']);
|
||||
}
|
||||
array_multisort($listing['dir_names'], $sort_order_for_filename, $listing['dirs']);
|
||||
}
|
||||
|
||||
return $listing;
|
||||
}
|
||||
|
||||
|
||||
function explain_mode($mode)
|
||||
{
|
||||
$info = array();
|
||||
|
||||
if (($mode & 0xC000) == 0xC000) { $info['type'] = 's'; }
|
||||
elseif (($mode & 0xA000) == 0xA000) { $info['type'] = 'l'; }
|
||||
elseif (($mode & 0x8000) == 0x8000) { $info['type'] = '-'; }
|
||||
elseif (($mode & 0x6000) == 0x6000) { $info['type'] = 'b'; }
|
||||
elseif (($mode & 0x4000) == 0x4000) { $info['type'] = 'd'; }
|
||||
elseif (($mode & 0x2000) == 0x2000) { $info['type'] = 'c'; }
|
||||
elseif (($mode & 0x1000) == 0x1000) { $info['type'] = 'p'; }
|
||||
else { $info['type'] = 'u'; }
|
||||
|
||||
$info['owner'] = (($mode & 0x0100) ? 'r' : '-');
|
||||
$info['owner'] .= (($mode & 0x0080) ? 'w' : '-');
|
||||
$info['owner'] .= (($mode & 0x0040) ? (($mode & 0x0800) ? 's' : 'x' ) : (($mode & 0x0800) ? 'S' : '-'));
|
||||
|
||||
// group
|
||||
$info['group'] = (($mode & 0x0020) ? 'r' : '-');
|
||||
$info['group'] .= (($mode & 0x0010) ? 'w' : '-');
|
||||
$info['group'] .= (($mode & 0x0008) ? (($mode & 0x0400) ? 's' : 'x' ) : (($mode & 0x0400) ? 'S' : '-'));
|
||||
|
||||
// other
|
||||
$info['other'] = (($mode & 0x0004) ? 'r' : '-');
|
||||
$info['other'] .= (($mode & 0x0002) ? 'w' : '-');
|
||||
$info['other'] .= (($mode & 0x0001) ? (($mode & 0x0200) ? 't' : 'x' ) : (($mode & 0x0200) ? 'T' : '-'));
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
?>
|
||||
// absolete
|
|
@ -29,18 +29,19 @@ switch ($_REQUEST['action']) {
|
|||
$dir = $_REQUEST['dir'];
|
||||
print json_encode($fm->ls($dir));
|
||||
break;
|
||||
|
||||
case 'check_file_type':
|
||||
$dir = $_REQUEST['dir'];
|
||||
|
||||
print json_encode($fm->checkFileType($dir));
|
||||
break;
|
||||
|
||||
case 'rename_file':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$item = $_REQUEST['item'];
|
||||
$target_name = $_REQUEST['target_name'];
|
||||
|
||||
print json_encode($fm->renameFile($dir, $item, $target_name));
|
||||
break;
|
||||
|
||||
case 'rename_directory':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$item = $_REQUEST['item'];
|
||||
|
@ -48,27 +49,30 @@ switch ($_REQUEST['action']) {
|
|||
|
||||
print json_encode($fm->renameDirectory($dir, $item, $target_name));
|
||||
break;
|
||||
|
||||
case 'delete_files':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$item = $_REQUEST['item'];
|
||||
|
||||
print json_encode($fm->deleteItem($dir, $item));
|
||||
break;
|
||||
|
||||
case 'create_file':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$filename = $_REQUEST['filename'];
|
||||
print json_encode($fm->createFile($dir, $filename));
|
||||
break;
|
||||
|
||||
case 'create_dir':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$dirname = $_REQUEST['dirname'];
|
||||
print json_encode($fm->createDir($dir, $dirname));
|
||||
break;
|
||||
|
||||
|
||||
case 'open_file':
|
||||
$dir = $_REQUEST['dir'];
|
||||
print json_encode($fm->open_file($dir));
|
||||
break;
|
||||
|
||||
case 'copy_file':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$target_dir = $_REQUEST['dir_target'];
|
||||
|
@ -76,6 +80,7 @@ switch ($_REQUEST['action']) {
|
|||
$item = $_REQUEST['item'];
|
||||
print json_encode($fm->copyFile($item, $dir, $target_dir, $filename));
|
||||
break;
|
||||
|
||||
case 'copy_directory':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$target_dir = $_REQUEST['dir_target'];
|
||||
|
@ -83,6 +88,7 @@ switch ($_REQUEST['action']) {
|
|||
$item = $_REQUEST['item'];
|
||||
print json_encode($fm->copyDirectory($item, $dir, $target_dir, $filename));
|
||||
break;
|
||||
|
||||
case 'unpack_item':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$target_dir = $_REQUEST['dir_target'];
|
||||
|
@ -90,6 +96,7 @@ switch ($_REQUEST['action']) {
|
|||
$item = $_REQUEST['item'];
|
||||
print json_encode($fm->unpackItem($item, $dir, $target_dir, $filename));
|
||||
break;
|
||||
|
||||
case 'pack_item':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$target_dir = $_REQUEST['dir_target'];
|
||||
|
@ -97,10 +104,19 @@ switch ($_REQUEST['action']) {
|
|||
$item = $_REQUEST['item'];
|
||||
print json_encode($fm->packItem($item, $dir, $target_dir, $filename));
|
||||
break;
|
||||
|
||||
case 'backup':
|
||||
$path = $_REQUEST['path'];
|
||||
print json_encode($fm->backupItem($path));
|
||||
break;
|
||||
|
||||
case 'chmod_item':
|
||||
$dir = $_REQUEST['dir'];
|
||||
$item = $_REQUEST['item'];
|
||||
$permissions = $_REQUEST['permissions'];
|
||||
print json_encode($fm->chmodItem($dir, $item, $permissions));
|
||||
break;
|
||||
|
||||
default:
|
||||
//print json_encode($fm->init());
|
||||
break;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class FileManager {
|
||||
|
||||
|
||||
protected $delimeter = '|';
|
||||
protected $info_positions = array(
|
||||
'TYPE' => 0,
|
||||
|
@ -13,38 +13,26 @@ class FileManager {
|
|||
'SIZE' => 6,
|
||||
'NAME' => 7
|
||||
);
|
||||
|
||||
|
||||
protected $user = null;
|
||||
public $ROOT_DIR = null;
|
||||
|
||||
|
||||
public function setRootDir($root = null) {
|
||||
if (null != $root) {
|
||||
$root = realpath($root);
|
||||
$root = realpath($root);
|
||||
}
|
||||
$this->ROOT_DIR = $root;
|
||||
}
|
||||
|
||||
|
||||
public function __construct($user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/*public function init() {
|
||||
$path = !empty($_REQUEST['dir']) ? $_REQUEST['dir'] : '';
|
||||
$start_url = !empty($path) ? $this->ROOT_DIR . '/' . $path : $this->ROOT_DIR;
|
||||
$listing = $this->getDirectoryListing($path);
|
||||
|
||||
return $data = array(
|
||||
'result' => true,
|
||||
'ROOT_DIR' => $this->ROOT_DIR,
|
||||
'TAB_A_PATH' => $start_url,
|
||||
'TAB_B_PATH' => $this->ROOT_DIR, // second tab always loads home dir
|
||||
'listing' => $listing
|
||||
);
|
||||
}*/
|
||||
|
||||
|
||||
public function checkFileType($dir) {
|
||||
$dir = $this->formatFullPath($dir);
|
||||
|
||||
exec(VESTA_CMD . "v-get-fs-file-type {$this->user} {$dir}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
|
@ -59,7 +47,7 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function formatFullPath($path_part = '') {
|
||||
if (substr($path_part, 0, strlen($this->ROOT_DIR)) === $this->ROOT_DIR) {
|
||||
$path = $path_part;
|
||||
|
@ -71,13 +59,13 @@ class FileManager {
|
|||
//$path = str_replace(' ', '\ ', $path);
|
||||
return escapeshellarg($path);
|
||||
}
|
||||
|
||||
|
||||
function deleteItem($dir, $item) {
|
||||
$dir = $this->formatFullPath($item);
|
||||
exec (VESTA_CMD . "v-delete-fs-directory {$this->user} {$dir}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -89,29 +77,16 @@ class FileManager {
|
|||
'message' => $error
|
||||
);
|
||||
}
|
||||
|
||||
/*if (is_readable($item)) {
|
||||
unlink($item);
|
||||
}
|
||||
if (is_readable($item)) {
|
||||
return array(
|
||||
'result' => false,
|
||||
'message' => 'item was not deleted'
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'result' => true
|
||||
);*/
|
||||
}
|
||||
|
||||
|
||||
function copyFile($item, $dir, $target_dir, $filename) {
|
||||
$src = $this->formatFullPath($item);
|
||||
$dst = $this->formatFullPath($target_dir);
|
||||
|
||||
|
||||
exec (VESTA_CMD . "v-copy-fs-file {$this->user} {$src} {$dst}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -124,17 +99,15 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function copyDirectory($item, $dir, $target_dir, $filename) {
|
||||
$src = $this->formatFullPath($item);
|
||||
$dst = $this->formatFullPath($target_dir);
|
||||
|
||||
|
||||
exec (VESTA_CMD . "v-copy-fs-directory {$this->user} {$src} {$dst}", $output, $return_var);
|
||||
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -147,25 +120,23 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static function check_return_code($return_var, $output) {
|
||||
if ($return_var != 0) {
|
||||
$error = implode('<br>', $output);
|
||||
return $error;
|
||||
//if (empty($error)) $error = __('Error code:',$return_var);
|
||||
//$_SESSION['error_msg'] = $error;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function createFile($dir, $filename) {
|
||||
$dir = $this->formatFullPath($dir . '/' . $filename);
|
||||
|
||||
exec (VESTA_CMD . "v-add-fs-file {$this->user} {$dir}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -178,19 +149,17 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function packItem($item, $dir, $target_dir, $filename) {
|
||||
$item = $this->formatFullPath($item);
|
||||
$dst_item = $this->formatFullPath($target_dir);
|
||||
|
||||
|
||||
$dst_item = str_replace('.tar.gz', '', $dst_item);
|
||||
|
||||
//$item = str_replace($dir . '/', '', $item);
|
||||
//var_dump(VESTA_CMD . "v-add-fs-archive {$this->user} {$dst_item} {$item}");die();
|
||||
|
||||
exec (VESTA_CMD . "v-add-fs-archive {$this->user} {$dst_item} {$item}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -205,18 +174,16 @@ class FileManager {
|
|||
}
|
||||
|
||||
function backupItem($item) {
|
||||
|
||||
$src_item = $this->formatFullPath($item);
|
||||
|
||||
|
||||
$dst_item_name = $item . '~' . date('Ymd_His');
|
||||
|
||||
$dst_item = $this->formatFullPath($dst_item_name);
|
||||
|
||||
//print VESTA_CMD . "v-add-fs-archive {$this->user} {$item} {$dst_item}";die();
|
||||
exec (VESTA_CMD . "v-copy-fs-file {$this->user} {$src_item} {$dst_item}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true,
|
||||
|
@ -231,7 +198,7 @@ class FileManager {
|
|||
}
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -244,7 +211,7 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function unpackItem($item, $dir, $target_dir, $filename) {
|
||||
$item = $this->formatFullPath($item);
|
||||
$dst_item = $this->formatFullPath($target_dir);
|
||||
|
@ -252,7 +219,7 @@ class FileManager {
|
|||
exec (VESTA_CMD . "v-extract-fs-archive {$this->user} {$item} {$dst_item}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -265,17 +232,15 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function renameFile($dir, $item, $target_name) {
|
||||
$item = $this->formatFullPath($dir . '/' . $item);
|
||||
$dst_item = $this->formatFullPath($dir . '/' . $target_name);
|
||||
|
||||
// var_dump(VESTA_CMD . "v-move-fs-file {$this->user} {$item} {$dst_item}");die();
|
||||
|
||||
exec (VESTA_CMD . "v-move-fs-file {$this->user} {$item} {$dst_item}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -288,6 +253,7 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
function renameDirectory($dir, $item, $target_name) {
|
||||
$item = $this->formatFullPath($dir . $item);
|
||||
$dst_item = $this->formatFullPath($dir . $target_name);
|
||||
|
@ -298,11 +264,10 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
exec (VESTA_CMD . "v-move-fs-directory {$this->user} {$item} {$dst_item}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -315,14 +280,14 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createDir($dir, $dirname) {
|
||||
$dir = $this->formatFullPath($dir . '/' . $dirname);
|
||||
|
||||
exec (VESTA_CMD . "v-add-fs-directory {$this->user} {$dir}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
|
@ -335,14 +300,36 @@ class FileManager {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function chmodItem($dir, $item, $permissions) {
|
||||
$item = $this->formatFullPath($dir . $item);
|
||||
$permissions = escapeshellarg($permissions);
|
||||
|
||||
exec (VESTA_CMD . "v-change-fs-file-permission {$this->user} {$item} {$permissions}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
);
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'result' => false,
|
||||
'message' => $error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getDirectoryListing($dir = '') {
|
||||
$dir = $this->formatFullPath($dir);
|
||||
|
||||
exec (VESTA_CMD . "v-list-fs-directory {$this->user} {$dir}", $output, $return_var);
|
||||
|
||||
return $this->parseListing($output);
|
||||
}
|
||||
|
||||
|
||||
public function ls($dir = '') {
|
||||
$listing = $this->getDirectoryListing($dir);
|
||||
|
||||
|
@ -351,7 +338,7 @@ class FileManager {
|
|||
'listing' => $listing
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function open_file($dir = '') {
|
||||
$listing = $this->getDirectoryListing($dir);
|
||||
|
||||
|
@ -360,14 +347,14 @@ class FileManager {
|
|||
'listing' => $listing
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function parseListing($raw) {
|
||||
$data = array();
|
||||
foreach ($raw as $o) {
|
||||
$info = explode($this->delimeter, $o);
|
||||
$data[] = array(
|
||||
'type' => $info[$this->info_positions['TYPE']],
|
||||
'permissions' => $info[$this->info_positions['PERMISSIONS']],
|
||||
'permissions' => str_pad($info[$this->info_positions['PERMISSIONS']], 3, "0", STR_PAD_LEFT),
|
||||
'date' => $info[$this->info_positions['DATE']],
|
||||
'time' => $info[$this->info_positions['TIME']],
|
||||
'owner' => $info[$this->info_positions['OWNER']],
|
||||
|
@ -376,7 +363,7 @@ class FileManager {
|
|||
'name' => $info[$this->info_positions['NAME']]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue