|
1 | 1 | <?php |
2 | | -session_start(); |
3 | 2 |
|
4 | 3 | include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
5 | | - |
6 | 4 | $user = $_SESSION['user']; |
7 | | -/* |
8 | | -if (empty($panel)) { |
9 | | - $command = VESTA_CMD."v-list-user '".$user."' 'json'"; |
10 | | - exec ($command, $output, $return_var); |
11 | | - if ( $return_var > 0 ) { |
12 | | - header("Location: /error/"); |
13 | | - exit; |
14 | | - } |
15 | | - $panel = json_decode(implode('', $output), true); |
16 | | -} |
17 | | -*/ |
18 | | - |
19 | | - |
20 | | - |
21 | | -/* |
22 | | -// Check user session |
23 | | -if ((!isset($_SESSION['user'])) && (!defined('NO_AUTH_REQUIRED'))) { |
24 | | - $_SESSION['request_uri'] = $_SERVER['REQUEST_URI']; |
25 | | - header("Location: /login/"); |
26 | | - exit; |
27 | | -} |
28 | | -*/ |
29 | 5 |
|
30 | 6 | // Check module activation |
31 | 7 | if (!$_SESSION['FILEMANAGER_KEY']) { |
|
34 | 10 | exit; |
35 | 11 | } |
36 | 12 |
|
| 13 | +// Check login_as feature |
| 14 | +if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) { |
| 15 | + $user=$_SESSION['look']; |
| 16 | +} |
| 17 | + |
37 | 18 |
|
38 | 19 | ?> |
39 | 20 |
|
|
55 | 36 | if (!empty($_REQUEST['path'])) { |
56 | 37 | $content = ''; |
57 | 38 | $path = $_REQUEST['path']; |
58 | | - if (is_readable($path)) { |
59 | | - $image = getimagesize($path) ? true : false; |
60 | | - |
61 | | - if ($image) { |
62 | | - header('Location: /view/file/?path='.$path); |
63 | | - exit; |
64 | | - } |
65 | | - |
66 | | - if (!empty($_POST['save'])) { |
67 | | - $fn = tempnam ('/tmp', 'vst-save-file-'); |
68 | | - if ($fn) { |
69 | | - $f = fopen ($fn, 'w+'); |
70 | | - fwrite($f, $_POST['contents']); |
71 | | - fclose($f); |
72 | | - |
73 | | - chmod($fn, 0644); |
74 | | - |
75 | | - if ($f) { |
76 | | - //copy($fn, $path); |
77 | | - exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}", $output, $return_var); |
78 | | - |
79 | | - $error = check_return_code($return_var, $output); |
80 | | - if ($return_var != 0) { |
81 | | - /*var_dump(VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}"); |
82 | | - var_dump($path); |
83 | | - var_dump($output);*/ |
84 | | - die('<p style="color: white">Error while saving file</p>');//echo '0'; |
85 | | - } |
| 39 | + if (!empty($_POST['save'])) { |
| 40 | + $fn = tempnam ('/tmp', 'vst-save-file-'); |
| 41 | + if ($fn) { |
| 42 | + $contents = $_POST['contents']; |
| 43 | + $contents = preg_replace("/\r/", "", $contents); |
| 44 | + $f = fopen ($fn, 'w+'); |
| 45 | + fwrite($f, $contents); |
| 46 | + fclose($f); |
| 47 | + chmod($fn, 0644); |
| 48 | + |
| 49 | + if ($f) { |
| 50 | + exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}", $output, $return_var); |
| 51 | + $error = check_return_code($return_var, $output); |
| 52 | + if ($return_var != 0) { |
| 53 | + print('<p style="color: white">Error while saving file</p>'); |
| 54 | + exit; |
86 | 55 | } |
87 | | - unlink($fn); |
88 | 56 | } |
| 57 | + unlink($fn); |
89 | 58 | } |
90 | | - |
91 | | - // $content = file_get_contents($path); |
92 | | - // v-open-fs-file |
93 | | - |
94 | | - |
95 | | - //print file_get_contents($path); |
96 | | - exec (VESTA_CMD . "v-check-fs-permission {$user} {$path}", $content, $return_var); |
| 59 | + } |
97 | 60 |
|
98 | | - if ($return_var != 0) { |
99 | | - print 'Error while opening file'; // todo: handle this more styled |
100 | | - exit; |
101 | | - } |
| 61 | + exec (VESTA_CMD . "v-check-fs-permission {$user} '{$path}'", $content, $return_var); |
| 62 | + if ($return_var != 0) { |
| 63 | + var_dump($return_var); |
| 64 | + var_dump($content); |
| 65 | + exit; |
| 66 | + print 'Error while opening file'; // todo: handle this more styled |
| 67 | + exit; |
| 68 | + } |
102 | 69 |
|
103 | | - |
104 | | - /*exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var); |
105 | | - if ($return_var != 0) { |
106 | | - print 'Error while opening file'; // todo: handle this more styled |
107 | | - exit; |
108 | | - } |
109 | | - |
110 | | - $content = implode("\n", $content);*/ |
111 | | - $content = file_get_contents($path); |
| 70 | + exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var); |
| 71 | + if ($return_var != 0) { |
| 72 | + print 'Error while opening file'; // todo: handle this more styled |
| 73 | + exit; |
112 | 74 | } |
113 | | - } |
114 | | - else { |
| 75 | + $content = implode("\n", $content)."\n"; |
| 76 | + } else { |
115 | 77 | $content = ''; |
116 | 78 | } |
117 | | - |
118 | 79 | ?> |
119 | 80 |
|
120 | 81 | <form id="edit-file-form" method="post"> |
|
131 | 92 | $('.editor').ace({ theme: 'twilight', lang: 'ruby' }); |
132 | 93 |
|
133 | 94 | var dcrt = $('#editor').data('ace'); |
134 | | - var editor = dcrt.editor.ace; |
135 | | - editor.gotoLine(0); |
136 | | - editor.focus(); |
| 95 | + dcrt.editor.ace.getSession().setNewLineMode('unix'); |
| 96 | + var aceInstance = dcrt.editor.ace; |
| 97 | + aceInstance.gotoLine(0); |
| 98 | + aceInstance.focus(); |
| 99 | + |
137 | 100 |
|
138 | 101 |
|
139 | 102 | var makeBackup = function() { |
|
0 commit comments