mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-20 21:34:11 -07:00
FileManger stuff
This commit is contained in:
parent
b6dd534b60
commit
52db853acf
11 changed files with 417 additions and 131 deletions
|
@ -97,6 +97,10 @@ 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;
|
||||
default:
|
||||
//print json_encode($fm->init());
|
||||
break;
|
||||
|
|
|
@ -206,6 +206,47 @@ 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,
|
||||
'filename' => $dst_item_name
|
||||
);
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'result' => false,
|
||||
'message' => $error
|
||||
);
|
||||
}
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
|
||||
if (empty($error)) {
|
||||
return array(
|
||||
'result' => true
|
||||
);
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'result' => false,
|
||||
'message' => $error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function unpackItem($item, $dir, $target_dir, $filename) {
|
||||
$item = $this->formatFullPath($item);
|
||||
|
|
|
@ -1,25 +1,38 @@
|
|||
<?php
|
||||
|
||||
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
|
||||
|
||||
// todo: set in session?
|
||||
if (empty($panel)) {
|
||||
$command = VESTA_CMD."v-list-user '".$user."' 'json'";
|
||||
exec ($command, $output, $return_var);
|
||||
if ( $return_var > 0 ) {
|
||||
header("Location: /error/");
|
||||
exit;
|
||||
}
|
||||
$panel = json_decode(implode('', $output), true);
|
||||
}
|
||||
|
||||
|
||||
// Define a destination
|
||||
$targetFolder = '/home/admin/'; // Relative to the root
|
||||
//$targetFolder = '/home/admin/'; // Relative to the root
|
||||
$targetFolder = $panel[$user]['HOME']; // Relative to the root
|
||||
|
||||
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
|
||||
|
||||
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
|
||||
$tempFile = $_FILES['Filedata']['tmp_name'];
|
||||
$targetPath = $targetFolder;
|
||||
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
|
||||
|
||||
// Validate the file type
|
||||
//$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
|
||||
//$fileParts = pathinfo($_FILES['Filedata']['name']);
|
||||
|
||||
//if (in_array($fileParts['extension'],$fileTypes)) {
|
||||
move_uploaded_file($tempFile,$targetFile);
|
||||
echo '1';
|
||||
//} else {
|
||||
// echo 'Invalid file type.';
|
||||
// }
|
||||
$tempFile = $_FILES['Filedata']['tmp_name'];
|
||||
$targetPath = $targetFolder;
|
||||
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
|
||||
|
||||
exec (VESTA_CMD . "v-copy-fs-file {$user} {$tempFile} {$targetFile}", $output, $return_var);
|
||||
|
||||
$error = self::check_return_code($return_var, $output);
|
||||
if ($return_var != 0) {
|
||||
echo '0';
|
||||
} else {
|
||||
echo '1';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue