Skip to content

Commit 52db853

Browse files
committed
FileManger stuff
1 parent b6dd534 commit 52db853

File tree

11 files changed

+417
-131
lines changed

11 files changed

+417
-131
lines changed

bin/v-check-fs-permission

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# info: open file
3+
# options: USER FILE
4+
#
5+
# The function opens/reads files on the file system
6+
7+
user=$1
8+
src_file=$2
9+
10+
# Checking arguments
11+
if [ -z "$src_file" ]; then
12+
echo "Usage: USER FILE"
13+
exit 1
14+
fi
15+
16+
# Checking vesta user
17+
if [ ! -e "$VESTA/data/users/$user" ]; then
18+
echo "Error: vesta user $user doesn't exist"
19+
exit 3
20+
fi
21+
22+
# Checking user homedir
23+
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
24+
if [ -z $homedir ]; then
25+
echo "Error: user home directory doesn't exist"
26+
exit 12
27+
fi
28+
29+
# Checking path
30+
if [ ! -z "$src_file" ]; then
31+
rpath=$(readlink -f "$src_file")
32+
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
33+
echo "Error: invalid source path $src_file"
34+
exit 2
35+
fi
36+
fi
37+
38+
# Reading file
39+
#sudo -u $user cat "$src_file" 2>/dev/null
40+
#if [ $? -ne 0 ]; then
41+
# echo "Error: file $src_file was not opened"
42+
# exit 3
43+
#fi
44+
45+
# Checking if file has readable permission
46+
if [[ ! -r $src_file ]]
47+
then
48+
# echo "File is readable"
49+
#else
50+
echo "Cannot read file"
51+
fi
52+
53+
# Exiting
54+
exit

web/css/styles.min.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,3 +2787,56 @@ form#vstobjects.suspended {
27872787
text-align: right;
27882788
width: 140px;
27892789
}
2790+
2791+
.description {
2792+
font-weight: normal;
2793+
line-height: 25px;
2794+
padding-bottom: 20px;
2795+
margin-left: 50px;
2796+
}
2797+
.description ul{
2798+
margin-top: 15px;
2799+
list-style: none;
2800+
padding-left: 0;
2801+
}
2802+
2803+
.description li{
2804+
margin: 10px 0;
2805+
}
2806+
2807+
.description a {
2808+
line-height: 30px;
2809+
text-decoration: underline;
2810+
color: #2c9491;
2811+
}
2812+
.description a.purchase {
2813+
color: #86A307;
2814+
background-color: #9fbf0c;
2815+
border-radius: 3px;
2816+
color: #fff;
2817+
font-size: 13px;
2818+
font-weight: bold;
2819+
padding: 7px;
2820+
text-transform: capitalize;
2821+
text-decoration: none;
2822+
}
2823+
.description a.purchase:hover {
2824+
background-color: #c0e60f;
2825+
color: #555;
2826+
}
2827+
.description .licence {
2828+
padding: 20px 0;
2829+
color: #2c9491;
2830+
}
2831+
2832+
.description .licence input {
2833+
margin-left: 17px;
2834+
width: 137px;
2835+
}
2836+
2837+
.description span {
2838+
font-style: italic;
2839+
line-height: 45px;
2840+
padding-top: 20px;
2841+
}
2842+

web/edit/file/index.php

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
55
/*
6+
if (empty($panel)) {
7+
$command = VESTA_CMD."v-list-user '".$user."' 'json'";
8+
exec ($command, $output, $return_var);
9+
if ( $return_var > 0 ) {
10+
header("Location: /error/");
11+
exit;
12+
}
13+
$panel = json_decode(implode('', $output), true);
14+
}
15+
*/
16+
/*
617
// Check user session
718
if ((!isset($_SESSION['user'])) && (!defined('NO_AUTH_REQUIRED'))) {
819
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
@@ -23,13 +34,15 @@
2334
<script src="/js/cheef-editor/ace/mode-ruby.js"></script>
2435
<script src="/js/cheef-editor/jquery-ace.min.js"></script>
2536

37+
<div id="message" style="display:none; position: absoulte;background-color: green; color: white; padding: 10px;"></div>
38+
<div id="error-message" style="display:none; position: absoulte;background-color: red; color: white; padding: 10px;"></div>
39+
2640
<?php
2741

2842
if (!empty($_REQUEST['path'])) {
2943
$content = '';
3044
$path = $_REQUEST['path'];
3145
if (is_readable($path)) {
32-
3346
$image = getimagesize($path) ? true : false;
3447

3548
if ($image) {
@@ -49,8 +62,16 @@
4962
}
5063
}
5164

52-
$content = file_get_contents($path);
53-
$content = $content;
65+
// $content = file_get_contents($path);
66+
// v-open-fs-file
67+
68+
exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var);
69+
if ($return_var != 0) {
70+
print 'Error while opening file'; // todo: handle this more styled
71+
exit;
72+
}
73+
74+
$content = implode("\n", $content);
5475
}
5576
}
5677
else {
@@ -59,18 +80,78 @@
5980

6081
?>
6182

62-
<form method="post">
83+
<form id="edit-file-form" method="post">
84+
<!-- input id="do-backup" type="button" onClick="javascript:void(0);" name="save" value="backup (ctrl+F2)" class="backup" / -->
6385
<input type="submit" name="save" value="Save" class="save" />
6486

6587

6688
<textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?php echo $content ?></textarea>
6789

6890
</form>
69-
<script>
70-
$('.editor').ace({ theme: 'twilight', lang: 'ruby' });
7191

72-
var dcrt = $('#editor').data('ace');
73-
var editor = dcrt.editor.ace;
74-
editor.gotoLine(0);
75-
editor.focus();
92+
<script type="text/javascript" src="/js/hotkeys.js"></script>
93+
<script type="text/javascript">
94+
$('.editor').ace({ theme: 'twilight', lang: 'ruby' });
95+
96+
var dcrt = $('#editor').data('ace');
97+
var editor = dcrt.editor.ace;
98+
editor.gotoLine(0);
99+
editor.focus();
100+
101+
102+
var makeBackup = function() {
103+
var params = {
104+
action: 'backup',
105+
path: '<?= $path ?>'
106+
};
107+
108+
$.ajax({url: "/file_manager/fm_api.php",
109+
method: "POST",
110+
data: params,
111+
dataType: 'JSON',
112+
success: function(reply) {
113+
var fadeTimeout = 3000;
114+
if (reply.result) {
115+
$('#message').text('File backed up as ' + reply.filename);
116+
clearTimeout(window.msg_tmt);
117+
$('#message').show();
118+
window.msg_tmt = setTimeout(function() {$('#message').fadeOut();}, fadeTimeout);
119+
}
120+
else {
121+
$('#error-message').text(reply.message);
122+
clearTimeout(window.errmsg_tmt);
123+
$('#error-message').show();
124+
window.errmsg_tmt = setTimeout(function() {$('#error-message').fadeOut();}, fadeTimeout);
125+
}
126+
}
127+
});
128+
}
129+
130+
$('#do-backup').on('click', function(evt) {
131+
evt.preventDefault();
132+
133+
makeBackup();
134+
});
135+
//
136+
// Shortcuts
137+
//
138+
shortcut.add("Ctrl+s",function() {
139+
var inp = $('<input>').attr({'type': 'hidden', 'name': 'save'}).val('Save');
140+
$('#edit-file-form').append(inp);
141+
$('#edit-file-form').submit();
142+
},{
143+
'type': 'keydown',
144+
'propagate': false,
145+
'disable_in_input': false,
146+
'target': document
147+
});
148+
shortcut.add("Ctrl+F2",function() {
149+
makeBackup();
150+
},{
151+
'type': 'keydown',
152+
'propagate': false,
153+
'disable_in_input': false,
154+
'target': document
155+
});
156+
76157
</script>

web/file_manager/fm_api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
$item = $_REQUEST['item'];
9898
print json_encode($fm->packItem($item, $dir, $target_dir, $filename));
9999
break;
100+
case 'backup':
101+
$path = $_REQUEST['path'];
102+
print json_encode($fm->backupItem($path));
103+
break;
100104
default:
101105
//print json_encode($fm->init());
102106
break;

web/file_manager/fm_core.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,47 @@ function packItem($item, $dir, $target_dir, $filename) {
206206
);
207207
}
208208
}
209+
210+
function backupItem($item) {
211+
212+
$src_item = $this->formatFullPath($item);
213+
214+
$dst_item_name = $item . '~' . date('Ymd_His');
215+
216+
$dst_item = $this->formatFullPath($dst_item_name);
217+
218+
//print VESTA_CMD . "v-add-fs-archive {$this->user} {$item} {$dst_item}";die();
219+
exec (VESTA_CMD . "v-copy-fs-file {$this->user} {$src_item} {$dst_item}", $output, $return_var);
220+
221+
$error = self::check_return_code($return_var, $output);
222+
223+
if (empty($error)) {
224+
return array(
225+
'result' => true,
226+
'filename' => $dst_item_name
227+
);
228+
}
229+
else {
230+
return array(
231+
'result' => false,
232+
'message' => $error
233+
);
234+
}
235+
236+
$error = self::check_return_code($return_var, $output);
237+
238+
if (empty($error)) {
239+
return array(
240+
'result' => true
241+
);
242+
}
243+
else {
244+
return array(
245+
'result' => false,
246+
'message' => $error
247+
);
248+
}
249+
}
209250

210251
function unpackItem($item, $dir, $target_dir, $filename) {
211252
$item = $this->formatFullPath($item);

web/file_manager/upload_file.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
<?php
22

3+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
4+
5+
// todo: set in session?
6+
if (empty($panel)) {
7+
$command = VESTA_CMD."v-list-user '".$user."' 'json'";
8+
exec ($command, $output, $return_var);
9+
if ( $return_var > 0 ) {
10+
header("Location: /error/");
11+
exit;
12+
}
13+
$panel = json_decode(implode('', $output), true);
14+
}
15+
16+
317
// Define a destination
4-
$targetFolder = '/home/admin/'; // Relative to the root
18+
//$targetFolder = '/home/admin/'; // Relative to the root
19+
$targetFolder = $panel[$user]['HOME']; // Relative to the root
520

621
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
722

823
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
9-
$tempFile = $_FILES['Filedata']['tmp_name'];
10-
$targetPath = $targetFolder;
11-
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
12-
13-
// Validate the file type
14-
//$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
15-
//$fileParts = pathinfo($_FILES['Filedata']['name']);
16-
17-
//if (in_array($fileParts['extension'],$fileTypes)) {
18-
move_uploaded_file($tempFile,$targetFile);
19-
echo '1';
20-
//} else {
21-
// echo 'Invalid file type.';
22-
// }
24+
$tempFile = $_FILES['Filedata']['tmp_name'];
25+
$targetPath = $targetFolder;
26+
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
27+
28+
exec (VESTA_CMD . "v-copy-fs-file {$user} {$tempFile} {$targetFile}", $output, $return_var);
29+
30+
$error = self::check_return_code($return_var, $output);
31+
if ($return_var != 0) {
32+
echo '0';
33+
} else {
34+
echo '1';
35+
}
2336
}
2437

2538
?>

0 commit comments

Comments
 (0)