Sfoglia il codice sorgente

File Manager stuff

Serghey Rodin 10 anni fa
parent
commit
55eb1ec16a

+ 40 - 0
bin/v-get-fs-file-type

@@ -0,0 +1,40 @@
+#!/bin/bash
+# info: get file type
+# options: USER FILE
+#
+# The function shows file type
+
+user=$1
+path=$2
+
+# Checking arguments
+if [ -z "$path" ]; then
+    echo "Usage: USER FILE"
+    exit 1
+fi
+
+# Checking vesta user
+if [ ! -e "$VESTA/data/users/$user" ]; then
+    echo "Error: vesta user $user doesn't exist"
+    exit 3
+fi
+
+# Checking user homedir
+homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
+if [ -z $homedir ]; then
+    echo "Error: user home directory doesn't exist"
+    exit 12
+fi
+
+# Checking path
+rpath=$(readlink -f "$path")
+if [ -z "$(echo $rpath |grep $homedir)" ]; then
+    echo "Error: invalid path $path"
+    exit 2
+fi
+
+# Listing file type
+sudo -u $user file -i -b $path 2>/dev/null
+
+# Exiting
+exit $?

+ 5 - 0
web/file_manager/fm_api.php

@@ -31,6 +31,11 @@ switch ($_REQUEST['action']) {
         $dir = $_REQUEST['dir'];
         $dir = $_REQUEST['dir'];
         print json_encode($fm->ls($dir));
         print json_encode($fm->ls($dir));
         break;
         break;
+    case 'check_file_type':
+        $dir = $_REQUEST['dir'];
+        
+        print json_encode($fm->checkFileType($dir));
+        break;
     case 'rename_file':
     case 'rename_file':
         $dir = $_REQUEST['dir'];
         $dir = $_REQUEST['dir'];
         $item = $_REQUEST['item'];
         $item = $_REQUEST['item'];

+ 20 - 0
web/file_manager/fm_core.php

@@ -42,6 +42,26 @@ class FileManager {
         );
         );
     }*/
     }*/
     
     
+    public function checkFileType($dir) {
+        $dir = $this->formatFullPath($dir);
+
+        exec(VESTA_CMD . "v-delete-fs-file {$this->user} {$dir}", $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
+            );
+        }
+    }
+    
     public function formatFullPath($path_part = '') {
     public function formatFullPath($path_part = '') {
         if (substr($path_part, 0, strlen($this->ROOT_DIR)) === $this->ROOT_DIR) {
         if (substr($path_part, 0, strlen($this->ROOT_DIR)) === $this->ROOT_DIR) {
             $path = $path_part;
             $path = $path_part;

+ 64 - 10
web/js/file_manager.js

@@ -164,12 +164,26 @@ FM.setSecondInactive = function(index, box) {
     FM.BG_TAB  = box;
     FM.BG_TAB  = box;
 }
 }
 
 
+FM.goToTop = function() {
+    var tab = FM.getTabLetter(FM.CURRENT_TAB);
+    var index = 0;
+
+    FM.setActive(index, FM.CURRENT_TAB);
+}
+
+FM.goToBottom = function() {
+    var tab = FM.getTabLetter(FM.CURRENT_TAB);
+    var index = $(FM.CURRENT_TAB).find('.dir').length - 1;
+
+    FM.setActive(index, FM.CURRENT_TAB);
+}
+
 FM.goUp = function() {
 FM.goUp = function() {
     var tab = FM.getTabLetter(FM.CURRENT_TAB);
     var tab = FM.getTabLetter(FM.CURRENT_TAB);
     var index = FM['CURRENT_' + tab + '_LINE'];
     var index = FM['CURRENT_' + tab + '_LINE'];
     index -= 1;
     index -= 1;
     if (index < 0) {
     if (index < 0) {
-        index = $(FM.CURRENT_TAB).find('li').length - 1;
+        index = $(FM.CURRENT_TAB).find('li.dir').length - 1;
     }
     }
     
     
     FM.setActive(index, FM.CURRENT_TAB);
     FM.setActive(index, FM.CURRENT_TAB);
@@ -179,7 +193,7 @@ FM.goDown = function() {
     var tab = FM.getTabLetter(FM.CURRENT_TAB);
     var tab = FM.getTabLetter(FM.CURRENT_TAB);
     var index = FM['CURRENT_' + tab + '_LINE'];
     var index = FM['CURRENT_' + tab + '_LINE'];
     index += 1;
     index += 1;
-    if (index > ($(FM.CURRENT_TAB).find('li').length - 1)) {
+    if (index > ($(FM.CURRENT_TAB).find('li.dir').length - 1)) {
         index = 0;
         index = 0;
     }
     }
     
     
@@ -196,6 +210,7 @@ FM.open = function(dir, box, callback) {
         'dir': dir
         'dir': dir
     };
     };
     App.Ajax.request('cd', params, function(reply) {
     App.Ajax.request('cd', params, function(reply) {
+        var tab = FM.getTabLetter(FM.CURRENT_TAB);
         FM.preselectedItems[tab] = [];
         FM.preselectedItems[tab] = [];
         if (reply.result == true) {
         if (reply.result == true) {
             var html = FM.generate_listing(reply.listing, box);
             var html = FM.generate_listing(reply.listing, box);
@@ -216,6 +231,9 @@ FM.open = function(dir, box, callback) {
         var url = '/list/directory/?dir_a='+path_a+'&dir_b='+path_b;
         var url = '/list/directory/?dir_a='+path_a+'&dir_b='+path_b;
         history.pushState({}, null, url);
         history.pushState({}, null, url);
         
         
+        if (FM['CURRENT_' + tab + '_LINE'] == -1) {
+           FM.setActive(0, FM.CURRENT_TAB);
+        }
     });
     });
 }
 }
 
 
@@ -401,7 +419,7 @@ FM.openFile = function(dir, box, elm) {
     
     
     var elm = $(elm).hasClass('dir') ? $(elm) : $(elm).closest('.dir');
     var elm = $(elm).hasClass('dir') ? $(elm) : $(elm).closest('.dir');
     var src = $.parseJSON($(elm).find('.source').val());
     var src = $.parseJSON($(elm).find('.source').val());
-    console.log(elm);
+
     if (FM.isItemPseudo(src)) {
     if (FM.isItemPseudo(src)) {
         FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
         FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
     }
     }
@@ -552,7 +570,7 @@ FM.fotoramaOpen = function(tab, img_index) {
     });
     });
 
 
     $('.fotorama').on('fotorama:fullscreenexit', function (e, fotorama) {
     $('.fotorama').on('fotorama:fullscreenexit', function (e, fotorama) {
-	$('.fotorama').data('fotorama').destroy();
+    $('.fotorama').data('fotorama').destroy();
     });
     });
 
 
     $('.fotorama').fotorama().data('fotorama').requestFullScreen();
     $('.fotorama').fotorama().data('fotorama').requestFullScreen();
@@ -587,7 +605,7 @@ FM.checkBulkStatus = function(bulkStatuses, acc) {
     }
     }
 
 
     if (status == true) {
     if (status == true) {
-        $('#popup .results').html(msg);
+        $('#popup .results').html('Done');
         $('.controls p').replaceWith('<p class="ok" onClick="FM.bulkPopupClose();">close</p>');
         $('.controls p').replaceWith('<p class="ok" onClick="FM.bulkPopupClose();">close</p>');
     }
     }
     else {
     else {
@@ -637,7 +655,7 @@ FM.bulkCopy = function() {
         var cfr_html = '';
         var cfr_html = '';
         
         
         $.each(acc, function(i, o) {
         $.each(acc, function(i, o) {
-            var ref = $(o).parents('.dir');
+            var ref = $(o);
             var src = $(ref).find('.source').val();
             var src = $(ref).find('.source').val();
             src = $.parseJSON(src);
             src = $.parseJSON(src);
           
           
@@ -654,7 +672,7 @@ FM.bulkCopy = function() {
         
         
         var bulkStatuses = [];
         var bulkStatuses = [];
         $.each(acc, function(i, o) {
         $.each(acc, function(i, o) {
-            var ref = $(o).parents('.dir');
+            var ref = $(o);
             var src = $(ref).find('.source').val();
             var src = $(ref).find('.source').val();
             src = $.parseJSON(src);
             src = $.parseJSON(src);
           
           
@@ -712,7 +730,7 @@ FM.bulkRemove = function() {
         var cfr_html = '';
         var cfr_html = '';
         
         
         $.each(acc, function(i, o) {
         $.each(acc, function(i, o) {
-            var ref = $(o).parents('.dir');
+            var ref = $(o);
             var src = $(ref).find('.source').val();
             var src = $(ref).find('.source').val();
             src = $.parseJSON(src);
             src = $.parseJSON(src);
           
           
@@ -729,7 +747,7 @@ FM.bulkRemove = function() {
         
         
         var bulkStatuses = [];
         var bulkStatuses = [];
         $.each(acc, function(i, o) {
         $.each(acc, function(i, o) {
-            var ref = $(o).parents('.dir');
+            var ref = $(o);
             var src = $(ref).find('.source').val();
             var src = $(ref).find('.source').val();
             src = $.parseJSON(src);
             src = $.parseJSON(src);
           
           
@@ -784,6 +802,10 @@ FM.toggleAllItemsSelected = function() {
         $(box).find('.dir').removeClass('selected');
         $(box).find('.dir').removeClass('selected');
         var index = FM['CURRENT_' + tab + '_LINE'];
         var index = FM['CURRENT_' + tab + '_LINE'];
         $(box).find('.dir:eq(' + index + ')').addClass('selected');
         $(box).find('.dir:eq(' + index + ')').addClass('selected');
+        
+        $(FM.preselectedItems[tab]).each(function(i, index) {
+            $(box).find('.dir:eq(' + index + ')').addClass('selected');
+        });
     }
     }
     else {
     else {
         $(box).find('.dir').addClass('selected');
         $(box).find('.dir').addClass('selected');
@@ -1010,6 +1032,10 @@ FM.setTabActive = function(box, action) {
     if (FM.CURRENT_TAB == FM.TAB_A) {
     if (FM.CURRENT_TAB == FM.TAB_A) {
         $(FM.TAB_B).find('.selected').addClass('selected-inactive').removeClass('selected');
         $(FM.TAB_B).find('.selected').addClass('selected-inactive').removeClass('selected');
         $(FM.TAB_A).find('.selected-inactive').addClass('selected').removeClass('selected-inactive');
         $(FM.TAB_A).find('.selected-inactive').addClass('selected').removeClass('selected-inactive');
+
+        if ($(FM.TAB_A).find('.selected-inactive').length == 0 && $(FM.TAB_A).find('.selected').length == 0) {
+            
+        }
     }
     }
     else {
     else {
         $(FM.TAB_A).find('.selected').addClass('selected-inactive').removeClass('selected');
         $(FM.TAB_A).find('.selected').addClass('selected-inactive').removeClass('selected');
@@ -1277,7 +1303,7 @@ FM.confirmCopyItems = function () {
     App.Ajax.request(action, params, function(reply) {
     App.Ajax.request(action, params, function(reply) {
         if (reply.result == true) {
         if (reply.result == true) {
             FM.popupClose();
             FM.popupClose();
-            FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
+            // FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
             FM.open(FM['TAB_' + opposite_tab + '_CURRENT_PATH'], FM['TAB_' + opposite_tab]);
             FM.open(FM['TAB_' + opposite_tab + '_CURRENT_PATH'], FM['TAB_' + opposite_tab]);
         }
         }
         else {
         else {
@@ -1638,6 +1664,11 @@ $(document).ready(function() {
     
     
     shortcut.add("Left",function() {
     shortcut.add("Left",function() {
         FM.setTabActive(FM.TAB_A);
         FM.setTabActive(FM.TAB_A);
+        
+        var tab = FM.getTabLetter(FM.CURRENT_TAB);
+        if (FM['CURRENT_' + tab + '_LINE'] == -1) {
+           FM.setActive(0, FM.CURRENT_TAB);
+        }
     },{
     },{
         'type':             'keydown',
         'type':             'keydown',
         'propagate':        false,
         'propagate':        false,
@@ -1647,6 +1678,29 @@ $(document).ready(function() {
     
     
     shortcut.add("Right",function() {
     shortcut.add("Right",function() {
         FM.setTabActive(FM.TAB_B);
         FM.setTabActive(FM.TAB_B);
+        
+        var tab = FM.getTabLetter(FM.CURRENT_TAB);
+        if (FM['CURRENT_' + tab + '_LINE'] == -1) {
+           FM.setActive(0, FM.CURRENT_TAB);
+        }
+    },{
+        'type':             'keydown',
+        'propagate':        false,
+        'disable_in_input': false,
+        'target':           document
+    });
+    
+    shortcut.add("Home",function() {
+        FM.goToTop();
+    },{
+        'type':             'keydown',
+        'propagate':        false,
+        'disable_in_input': false,
+        'target':           document
+    });
+    
+    shortcut.add("End",function() {
+        FM.goToBottom();
     },{
     },{
         'type':             'keydown',
         'type':             'keydown',
         'propagate':        false,
         'propagate':        false,

+ 2 - 2
web/js/templates.js

@@ -24,9 +24,9 @@ App.Templates.html = {
                         <span class="size-value">~!:SIZE_VALUE~!</span>\
                         <span class="size-value">~!:SIZE_VALUE~!</span>\
                         <span class="date">~!:DATE~!</span>\
                         <span class="date">~!:DATE~!</span>\
                         <span class="time">~!:TIME~!</span>\
                         <span class="time">~!:TIME~!</span>\
-                        <span class="subcontext-control ~!:SUBMENU_CLASS~!" onClick="FM.toggleSubContextMenu(this)">&#8226;&#8226;&#8226;&nbsp;\
+                        <!-- span class="subcontext-control ~!:SUBMENU_CLASS~!" onClick="FM.toggleSubContextMenu(this)">&#8226;&#8226;&#8226;&nbsp;\
                         <ul class="subcontext-menu subcontext-menu-hidden"><li onClick="FM.downloadFileFromSubcontext(this);">Download</li><li onClick="FM.editFileFromSubcontext(this);">Edit</li></ul>\
                         <ul class="subcontext-menu subcontext-menu-hidden"><li onClick="FM.downloadFileFromSubcontext(this);">Download</li><li onClick="FM.editFileFromSubcontext(this);">Edit</li></ul>\
-                        </span>\
+                        </span -->\
                     </li>'],
                     </li>'],
         popup_alert: ['<div class="confirm-box alarm popup-box">\
         popup_alert: ['<div class="confirm-box alarm popup-box">\
                             <div class="message">~!:TEXT~!</div>\
                             <div class="message">~!:TEXT~!</div>\