Browse Source

FM changes

Serghey Rodin 10 years ago
parent
commit
d207b7a752

+ 12 - 5
web/download/file/index.php

@@ -1,11 +1,18 @@
 <?php
+include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
+
+$user = $_SESSION['user'];
+if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
+    $user=$_SESSION['look'];
+}
+
 if (!empty($_REQUEST['path'])) {
     $path = $_REQUEST['path'];
-    if (is_readable($path)) {
-        header("Content-disposition: attachment;filename=".basename($path));
-        readfile($path);
-        exit;
-    }
+    header("Content-type: application/octet-stream");
+    header("Content-Transfer-Encoding: binary");
+    header("Content-disposition: attachment;filename=".basename($path));
+    passthru (VESTA_CMD . "v-open-fs-file " . $user . " " . escapeshellarg($path));
+    exit;
 }
 else {
     die('File not found');

+ 42 - 79
web/edit/file/index.php

@@ -1,31 +1,7 @@
 <?php
-session_start();
 
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
-
 $user = $_SESSION['user'];
-/*
-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);
-}
-*/
-
-
-
-/*
-// Check user session
-if ((!isset($_SESSION['user'])) && (!defined('NO_AUTH_REQUIRED'))) {
-    $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
-    header("Location: /login/");
-    exit;
-}
-*/
 
 // Check module activation
 if (!$_SESSION['FILEMANAGER_KEY']) {
@@ -34,6 +10,11 @@ if (!$_SESSION['FILEMANAGER_KEY']) {
     exit;
 }
 
+// Check login_as feature
+if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
+    $user=$_SESSION['look'];
+}
+
 
 ?>
 
@@ -55,66 +36,46 @@ if (!$_SESSION['FILEMANAGER_KEY']) {
     if (!empty($_REQUEST['path'])) {
         $content = '';
         $path = $_REQUEST['path'];
-        if (is_readable($path)) {
-            $image = getimagesize($path) ? true : false;
-            
-            if ($image) {
-                header('Location: /view/file/?path='.$path);
-                exit;
-            }
-            
-            if (!empty($_POST['save'])) {
-                $fn = tempnam ('/tmp', 'vst-save-file-');
-                if ($fn) {
-                    $f = fopen ($fn, 'w+');
-                    fwrite($f, $_POST['contents']);
-                    fclose($f);
-                    
-                    chmod($fn, 0644);
-                    
-                    if ($f) {
-                        //copy($fn, $path);
-                        exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}", $output, $return_var);
-
-                        $error = check_return_code($return_var, $output);
-                        if ($return_var != 0) {
-                            /*var_dump(VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}");
-                            var_dump($path);
-                            var_dump($output);*/
-                            die('<p style="color: white">Error while saving file</p>');//echo '0';
-                        }
+        if (!empty($_POST['save'])) {
+            $fn = tempnam ('/tmp', 'vst-save-file-');
+            if ($fn) {
+                $contents = $_POST['contents'];
+                $contents = preg_replace("/\r/", "", $contents);
+                $f = fopen ($fn, 'w+');
+                fwrite($f, $contents);
+                fclose($f);
+                chmod($fn, 0644);
+
+                if ($f) {
+                    exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}", $output, $return_var);
+                    $error = check_return_code($return_var, $output);
+                    if ($return_var != 0) {
+                        print('<p style="color: white">Error while saving file</p>');
+                        exit;
                     }
-                    unlink($fn);
                 }
+                unlink($fn);
             }
-            
-            // $content = file_get_contents($path);
-            // v-open-fs-file
-            
-
-            //print file_get_contents($path);
-            exec (VESTA_CMD . "v-check-fs-permission {$user} {$path}", $content, $return_var);
+        }
 
-            if ($return_var != 0) {
-                print 'Error while opening file'; // todo: handle this more styled
-                exit;
-            }
+        exec (VESTA_CMD . "v-check-fs-permission {$user} '{$path}'", $content, $return_var);
+        if ($return_var != 0) {
+            var_dump($return_var);
+            var_dump($content);
+            exit;
+            print 'Error while opening file'; // todo: handle this more styled
+            exit;
+        }
 
-            
-            /*exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var);
-            if ($return_var != 0) {
-                print 'Error while opening file'; // todo: handle this more styled
-                exit;
-            }
-            
-            $content = implode("\n", $content);*/
-            $content = file_get_contents($path);
+        exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var);
+        if ($return_var != 0) {
+            print 'Error while opening file'; // todo: handle this more styled
+            exit;
         }
-    }
-    else {
+        $content = implode("\n", $content)."\n";
+    } else {
         $content = '';
     }
-
 ?>
 
 <form id="edit-file-form" method="post">
@@ -131,9 +92,11 @@ if (!$_SESSION['FILEMANAGER_KEY']) {
     $('.editor').ace({ theme: 'twilight', lang: 'ruby' });
 
     var dcrt = $('#editor').data('ace');
-    var editor = dcrt.editor.ace;
-    editor.gotoLine(0);
-    editor.focus();
+    dcrt.editor.ace.getSession().setNewLineMode('unix');
+    var aceInstance = dcrt.editor.ace;
+    aceInstance.gotoLine(0);
+    aceInstance.focus();
+    
 
 
     var makeBackup = function() {

+ 12 - 9
web/file_manager/fm_core.php

@@ -44,9 +44,7 @@ class FileManager {
     
     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(
@@ -76,12 +74,13 @@ class FileManager {
     
     function deleteItem($dir, $item) {
         $dir = $this->formatFullPath($item);
-        if (is_dir($item)) {
+        //if (is_dir($item)) {
+            //var_dump(VESTA_CMD . "v-delete-fs-directory {$this->user} {$dir}");die();
             exec (VESTA_CMD . "v-delete-fs-directory {$this->user} {$dir}", $output, $return_var);
-        }
-        else {
-            exec (VESTA_CMD . "v-delete-fs-file {$this->user} {$dir}", $output, $return_var);
-        }
+        //}
+        //else {
+        //    exec (VESTA_CMD . "v-delete-fs-file {$this->user} {$dir}", $output, $return_var);
+        //}
 
         $error = self::check_return_code($return_var, $output);
         
@@ -189,8 +188,12 @@ class FileManager {
     function packItem($item, $dir, $target_dir, $filename) {
         $item     = $this->formatFullPath($item);
         $dst_item = $this->formatFullPath($target_dir);
-//print VESTA_CMD . "v-add-fs-archive {$this->user} {$item} {$dst_item}";die();
-        exec (VESTA_CMD . "v-add-fs-archive {$this->user} {$item} {$dst_item}", $output, $return_var);
+        
+        $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);
         

+ 18 - 8
web/js/file_manager.js

@@ -99,6 +99,10 @@ FM.showError = function(type, message) {
 
             return;
         }
+        
+        if (ref.find('.results').length > 0) {
+            ref.find('.results').html(message);
+        }
     }
     else {
         FM.popupClose();
@@ -750,7 +754,7 @@ FM.bulkOperation = function(ref) {
 }
 
 FM.checkBulkStatus = function(bulkStatuses, acc) {
-    var status = false;
+    var status = true;
     var msg    = '';
     if (bulkStatuses.length == acc.length) {
         $.each(bulkStatuses, function(i, o) {
@@ -759,18 +763,24 @@ FM.checkBulkStatus = function(bulkStatuses, acc) {
             }
         });
 
-        if (msg == '') {
-            status = true;
+        if (msg != '') {
+            status = false;
         }
     }
 
     if (status == true) {
-        $('#popup .results').html(App.Constants.FM_DONE);
-        $('.controls').html('<p class="ok" onClick="FM.bulkPopupClose();">'+App.Constants.FM_DONE+'</p>');
+        //$('#popup .results').html(App.Constants.FM_DONE);
+        //$('.controls').html('<p class="ok" onClick="FM.bulkPopupClose();">'+App.Constants.FM_DONE+'</p>');
+        FM.popupClose();
+        
+        var box = FM['TAB_' + tab];
+        var tab = FM.getTabLetter(FM.CURRENT_TAB);
+        FM.openAndSync(FM['TAB_' + tab + '_CURRENT_PATH'], box);
     }
     else {
-        $('#popup .results').html(msg);
-        $('.controls').html('<p class="ok" onClick="FM.bulkPopupClose();">'+App.Constants.FM_DONE+'</p>');
+        $('#popup .results').show().html(msg);
+        //$('.controls').html('<p class="ok" onClick="FM.bulkPopupClose();">'+App.Constants.FM_DONE+'</p>');
+        $('#popup .ok').hide();
     }
 }
 
@@ -1249,7 +1259,7 @@ FM.unpackItem = function() {
     
     var tpl = Tpl.get('popup_unpack', 'FM');
     tpl.set(':FILENAME', src.name);
-    tpl.set(':DST_DIRNAME', (dst + '/' + src.name).replace('//', '/'));
+    tpl.set(':DST_DIRNAME', (dst).replace('//', '/'));
     FM.popupOpen(tpl.finalize());
 }
 

+ 3 - 0
web/js/templates.js

@@ -46,6 +46,7 @@ App.Templates.html = {
                         </div>'],
         popup_bulk_remove: ['<div class="confirm-box delete popup-box">\
                             <div class="message">'+App.Constants.FM_CONFIRM_DELETE_BULK+' (~!:NUMBER_OF_ITEMS~!)?</div>\
+                            <div class="results"></div>\
                                 <div class="controls">\
                             <p class="cancel" onClick="FM.popupClose();">'+App.Constants.FM_CANCEL+'</p>\
                             <p class="ok" onClick="FM.bulkRemoveDo();">'+App.Constants.FM_DELETE+'</p>\
@@ -73,6 +74,7 @@ App.Templates.html = {
                         </div>'],*/
         popup_delete: ['<div class="confirm-box delete popup-box">\
                             <div class="message">'+App.Constants.FM_CONFIRM_DELETE+' <span class="title">"~!:FILENAME~!"</span>?</div>\
+                            <div class="warning warning-message"></div>\
                                 <div class="controls">\
                             <p class="cancel" onClick="FM.popupClose();">'+App.Constants.FM_CANCEL+'</p>\
                             <p class="ok" onClick="FM.confirmDelete();">'+App.Constants.FM_DELETE+'</p>\
@@ -84,6 +86,7 @@ App.Templates.html = {
                                 <input type="text" id="copy_dest" value="~!:DST_FILENAME~!" class="new-title">\
                             </div>\
                             <div class="message">'+App.Constants.FM_EXISTING_FILES_WILL_BE_REPLACED+'</div>\
+                           <div class="warning warning-message"></div>\
                                 <div class="controls">\
                             <p class="cancel" onClick="FM.popupClose();">'+App.Constants.FM_CANCEL+'</p>\
                             <p class="ok" onClick="FM.confirmCopyItems();">'+App.Constants.FM_COPY+'</p>\

+ 4 - 3
web/list/directory/index.php

@@ -3,14 +3,15 @@
 include($_SERVER['DOCUMENT_ROOT'] . "/inc/main.php");
 
 
-
-
 if ((!isset($_SESSION['FILEMANAGER_KEY'])) || (empty($_SESSION['FILEMANAGER_KEY']))) {
     header("Location: /filemanager-not-purchased/");
     exit;
 }
 
-
+// Check login_as feature
+if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
+    $user=$_SESSION['look'];
+}
 
 if (empty($panel)) {
     $command = VESTA_CMD."v-list-user '".$user."' 'json'";

+ 3 - 3
web/templates/file_manager/main.php

@@ -25,7 +25,7 @@
             <div class="menu menu-left menu-A">
                 <?php $pre_tab = 'A';include($_SERVER['DOCUMENT_ROOT'].'/templates/file_manager/tab_menu.php'); ?>
             </div>
-            <ul class="listing listing-left"></ul>
+            <ul class="listing listing-left" onClick="FM.setTabActive('.listing-left');"></ul>
         </div>
 
         <div class="window">
@@ -33,7 +33,7 @@
             <div class="menu menu-right menu-B">
                 <?php $pre_tab = 'B';include($_SERVER['DOCUMENT_ROOT'].'/templates/file_manager/tab_menu.php'); ?>
             </div>
-            <ul class="listing listing-right"></ul>
+            <ul class="listing listing-right" onClick="FM.setTabActive('.listing-right');"></ul>
         </div>
         </div>
 
@@ -420,4 +420,4 @@
         });
         </script>
 </body>
-</html>
+</html>

+ 13 - 18
web/upload/UploadHandler.php

@@ -4,19 +4,12 @@
 
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
 
-//$user = $_SESSION['user'];
-
-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);
+// Check login_as feature
+$user = $_SESSION['user'];
+if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
+    $user=$_SESSION['look'];
 }
-$user = array_keys($panel);
-$user = $user[0];
+
 
 define('USERNAME', $user);
 
@@ -478,7 +471,9 @@ class UploadHandler
     }
     
     protected function sanitizeFileName($file) {
-        $file = preg_replace("/[^A-Za-z0-9\._-]+/", '', $file);
+        // (|\\?*<\":>+[]/')
+        // \|\\\?\*\<\"\'\:\>\+\[\]
+        $file = preg_replace("/'/", '', $file);
 
         return $file;
     }
@@ -1140,11 +1135,11 @@ class UploadHandler
                 //    $this->handle_image_file($file_path, $file);
                 //}
             } else {
-                $file->size = $file_size;
-                if (!$content_range && $this->options['discard_aborted_uploads']) {
-                    unlink($file_path);
-                    $file->error = $this->get_error_message('abort');
-                }
+                //$file->size = $file_size;
+                //if (!$content_range && $this->options['discard_aborted_uploads']) {
+                //    unlink($file_path);
+                //    $file->error = $this->get_error_message('abort');
+                //}
             }
             $this->set_additional_file_properties($file);
         }

+ 9 - 10
web/view/file/index.php

@@ -2,18 +2,17 @@
 
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
 
+// Check login_as feature
+$user = $_SESSION['user'];
+if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
+    $user=$_SESSION['look'];
+}
+
 if (!empty($_REQUEST['path'])) {
     $path = $_REQUEST['path'];
-    if (is_readable($path) && !empty($_REQUEST['raw'])) {
-        //print file_get_contents($path);
-        exec (VESTA_CMD . "v-check-fs-permission {$user} {$path}", $content, $return_var);
-
-        if ($return_var != 0) {
-            print 'Error while opening file'; // todo: handle this more styled
-            exit;
-        }
-        header('content-type: image/jpeg'); 
-        print file_get_contents($path);
+    if (!empty($_REQUEST['raw'])) {
+        header('content-type: image/jpeg');
+        passthru (VESTA_CMD . "v-open-fs-file " . $user . " " . escapeshellarg($_REQUEST['path']));
         exit;
     }
 }