From 2c480edec4eab49c3d875d05220c3d150f0bde2a Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Mon, 26 Feb 2018 17:50:33 +0500 Subject: [PATCH] Download files via Filemanager, post_max_size added to PHP Basic! --- .../static/filemanager/js/fileManager.js | 80 ++++++++++++++++++- filemanager/templates/filemanager/index.html | 1 + filemanager/urls.py | 1 + filemanager/views.py | 20 ++++- managePHP/static/managePHP/managePHP.js | 4 +- .../templates/managePHP/editPHPConfig.html | 7 ++ managePHP/views.py | 8 +- plogical/phpUtilities.py | 7 +- static/backup/backup.js | 2 +- static/filemanager/js/fileManager.js | 80 ++++++++++++++++++- static/managePHP/managePHP.js | 4 +- 11 files changed, 197 insertions(+), 17 deletions(-) diff --git a/filemanager/static/filemanager/js/fileManager.js b/filemanager/static/filemanager/js/fileManager.js index a5fc1671b..9db45bcf1 100755 --- a/filemanager/static/filemanager/js/fileManager.js +++ b/filemanager/static/filemanager/js/fileManager.js @@ -350,7 +350,9 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { 26KB 26 Oct 775 + Folder/File + */ function createTR(fileName,fileSize,lastModified,permissions,dirCheck){ @@ -381,6 +383,9 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { var secondTDNode = document.createElement('td'); var thirdTDNode = document.createElement('td'); var forthTDNode = document.createElement('td'); + var fifthTDNode = document.createElement('td'); + + fifthTDNode.style.display = "none"; // @@ -405,18 +410,29 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { trNode.addEventListener("dblclick", function(){ $scope.fetchForTableSecondary(firstTDNode,"doubleClick");}); trNode.addEventListener("click", function(){ addFileOrFolderToList(trNode);}); trNode.addEventListener("contextmenu", function(event){$scope.rightClickCallBack(event,trNode);}); + + // Hidden td to represent file or folder + + var fileOrFolderNode = document.createTextNode("Folder"); + fifthTDNode.appendChild(fileOrFolderNode) } else{ thNode.appendChild(iNodeFile); trNode.appendChild(thNode); trNode.addEventListener("click", function(){ addFileOrFolderToList(trNode);}); trNode.addEventListener("contextmenu", function(event){ $scope.rightClickCallBack(event,trNode); }); + + // Hidden td to represent file or folder + + var fileOrFolderNode = document.createTextNode("File"); + fifthTDNode.appendChild(fileOrFolderNode) } trNode.appendChild(firstTDNode); trNode.appendChild(secondTDNode); trNode.appendChild(thirdTDNode); trNode.appendChild(forthTDNode); + trNode.appendChild(fifthTDNode); return trNode; @@ -1131,7 +1147,7 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { // right click settings - var rightClickNode = document.getElementById("rightClick") + var rightClickNode = document.getElementById("rightClick"); rightClickNode.style.display = "none"; $scope.rightClickCallBack = function (event,trNode) { @@ -1146,6 +1162,19 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { 'left': event.pageX }); + // If we want to enable download for this node + + var downloadOnRight = document.getElementById("downloadOnRight"); + + if(trNode.lastChild.innerHTML === "File"){ + downloadOnRight.style.display = "Block"; + }else{ + downloadOnRight.style.display = "none"; + } + + + + $scope.addFileOrFolderToListForRightClick(trNode); } @@ -1154,7 +1183,7 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { var check = 1; var getFileName = nodeName.getElementsByTagName('td')[0].innerHTML; - if(nodeName.style.backgroundColor == "aliceblue") { + if(nodeName.style.backgroundColor === "aliceblue") { var tempArray = []; nodeName.style.background = "None"; @@ -1236,7 +1265,7 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { }; - // fix permissions + // Fix permissions $scope.fixPermissions = function() { @@ -1248,7 +1277,6 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { }; - $http.post(url, data).then(ListInitialDatas, cantLoadInitialDatas); function ListInitialDatas(response) { @@ -1270,6 +1298,50 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { }; + // Download files + + $scope.downloadFile = function() { + + url = "/filemanager/downloadFile"; + + var data = { + fileToDownload: $scope.currentPath + "/" + allFilesAndFolders[0] + }; + + + $http.post(url, data).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + var blob = new Blob([response.data]); + + //IE case + if (!!window.navigator.msSaveBlob){ + window.navigator.msSaveBlob(blob, allFilesAndFolders[0]); + return; + } + + //create blob and url + var url = URL.createObjectURL(blob); + + //create invisible acnhor, to specify the file name + var a = document.createElement('a'); + document.body.appendChild(a); + a.style = "display: none"; + a.href = url; + a.download = allFilesAndFolders[0]; + a.click(); + + setTimeout(function(){ + URL.revokeObjectURL(url); + document.body.removeChild(a); + }, 100); + } + + function cantLoadInitialDatas(response) {} + + }; + diff --git a/filemanager/templates/filemanager/index.html b/filemanager/templates/filemanager/index.html index 4d3efcddd..f6dad04ea 100644 --- a/filemanager/templates/filemanager/index.html +++ b/filemanager/templates/filemanager/index.html @@ -634,6 +634,7 @@
+
+ +
+ +
+
+
diff --git a/managePHP/views.py b/managePHP/views.py index 1755d83eb..d41d09599 100644 --- a/managePHP/views.py +++ b/managePHP/views.py @@ -2000,6 +2000,8 @@ def getCurrentPHPConfig(request): upload_max_filesize = re.findall(r"[A-Za-z0-9_]+", items)[1] if items.find("max_input_time")>-1 and items.find("=")>-1: max_input_time = re.findall(r"[A-Za-z0-9_]+", items)[1] + if items.find("post_max_size") > -1 and items.find("=") > -1: + post_max_size = re.findall(r"[A-Za-z0-9_]+", items)[1] @@ -2011,7 +2013,8 @@ def getCurrentPHPConfig(request): 'memory_limit': memory_limit, 'max_execution_time': max_execution_time, 'upload_max_filesize': upload_max_filesize, - 'max_input_time': max_input_time} + 'max_input_time': max_input_time, + 'post_max_size':post_max_size} final_json = json.dumps(final_dic) @@ -2046,6 +2049,7 @@ def savePHPConfigBasic(request): max_execution_time = data['max_execution_time'] upload_max_filesize = data['upload_max_filesize'] max_input_time = data['max_input_time'] + post_max_size = data['post_max_size'] if allow_url_fopen == True: allow_url_fopen = "allow_url_fopen = On" @@ -2086,7 +2090,7 @@ def savePHPConfigBasic(request): execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/phpUtilities.py" - execPath = execPath + " savePHPConfigBasic --phpVers " + phpVers + " --allow_url_fopen '" + allow_url_fopen + "' --display_errors '" + display_errors + "' --file_uploads '" + file_uploads + "' --allow_url_include '" + allow_url_include + "' --memory_limit " + memory_limit+ " --max_execution_time " + max_execution_time + " --upload_max_filesize " + upload_max_filesize + " --max_input_time " + max_input_time + execPath = execPath + " savePHPConfigBasic --phpVers " + phpVers + " --allow_url_fopen '" + allow_url_fopen + "' --display_errors '" + display_errors + "' --file_uploads '" + file_uploads + "' --allow_url_include '" + allow_url_include + "' --memory_limit " + memory_limit+ " --max_execution_time " + max_execution_time + " --upload_max_filesize " + upload_max_filesize + " --max_input_time " + max_input_time + " --post_max_size " + post_max_size diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index c1be38cfa..71759d98d 100644 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -78,7 +78,7 @@ class phpUtilities: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]") @staticmethod - def savePHPConfigBasic(phpVers,allow_url_fopen,display_errors,file_uploads,allow_url_include,memory_limit,max_execution_time,upload_max_filesize,max_input_time): + def savePHPConfigBasic(phpVers,allow_url_fopen,display_errors,file_uploads,allow_url_include,memory_limit,max_execution_time,upload_max_filesize,max_input_time,post_max_size): try: path = "/usr/local/lsws/ls" + phpVers + "/etc/php.ini" @@ -109,6 +109,8 @@ class phpUtilities: elif items.find("max_input_time") > -1 and items.find("=") > -1: writeToFile.writelines("max_input_time = " + max_input_time + "\n") + elif items.find("post_max_size") > -1 and items.find("=") > -1: + writeToFile.writelines("post_max_size = " + post_max_size + "\n") else: writeToFile.writelines(items) @@ -155,6 +157,7 @@ def main(): parser.add_argument("--max_execution_time", help="Memory Hard Limit (bytes) for PHP!") parser.add_argument("--upload_max_filesize", help="Process Soft Limit for PHP!") parser.add_argument("--max_input_time", help="Process Hard Limit for PHP!") + parser.add_argument("--post_max_size", help="Process Hard Limit for PHP!") ## Litespeed Tuning Arguments @@ -165,7 +168,7 @@ def main(): if args.function == "savePHPConfigBasic": phpUtilities.savePHPConfigBasic(args.phpVers, args.allow_url_fopen, args.display_errors, args.file_uploads, args.allow_url_include, args.memory_limit, - args.max_execution_time, args.upload_max_filesize, args.max_input_time) + args.max_execution_time, args.upload_max_filesize, args.max_input_time, args.post_max_size) elif args.function == "savePHPConfigAdvance": phpUtilities.savePHPConfigAdvance(args.phpVers, args.tempPath) diff --git a/static/backup/backup.js b/static/backup/backup.js index 5f42d380a..b83f9bcce 100644 --- a/static/backup/backup.js +++ b/static/backup/backup.js @@ -1267,7 +1267,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { $timeout.cancel(); // Start the restore of remote backups that are transferred to local server - + remoteBackupRestore(); } } diff --git a/static/filemanager/js/fileManager.js b/static/filemanager/js/fileManager.js index a5fc1671b..9db45bcf1 100644 --- a/static/filemanager/js/fileManager.js +++ b/static/filemanager/js/fileManager.js @@ -350,7 +350,9 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { 26KB 26 Oct 775 + Folder/File + */ function createTR(fileName,fileSize,lastModified,permissions,dirCheck){ @@ -381,6 +383,9 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { var secondTDNode = document.createElement('td'); var thirdTDNode = document.createElement('td'); var forthTDNode = document.createElement('td'); + var fifthTDNode = document.createElement('td'); + + fifthTDNode.style.display = "none"; // @@ -405,18 +410,29 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { trNode.addEventListener("dblclick", function(){ $scope.fetchForTableSecondary(firstTDNode,"doubleClick");}); trNode.addEventListener("click", function(){ addFileOrFolderToList(trNode);}); trNode.addEventListener("contextmenu", function(event){$scope.rightClickCallBack(event,trNode);}); + + // Hidden td to represent file or folder + + var fileOrFolderNode = document.createTextNode("Folder"); + fifthTDNode.appendChild(fileOrFolderNode) } else{ thNode.appendChild(iNodeFile); trNode.appendChild(thNode); trNode.addEventListener("click", function(){ addFileOrFolderToList(trNode);}); trNode.addEventListener("contextmenu", function(event){ $scope.rightClickCallBack(event,trNode); }); + + // Hidden td to represent file or folder + + var fileOrFolderNode = document.createTextNode("File"); + fifthTDNode.appendChild(fileOrFolderNode) } trNode.appendChild(firstTDNode); trNode.appendChild(secondTDNode); trNode.appendChild(thirdTDNode); trNode.appendChild(forthTDNode); + trNode.appendChild(fifthTDNode); return trNode; @@ -1131,7 +1147,7 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { // right click settings - var rightClickNode = document.getElementById("rightClick") + var rightClickNode = document.getElementById("rightClick"); rightClickNode.style.display = "none"; $scope.rightClickCallBack = function (event,trNode) { @@ -1146,6 +1162,19 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { 'left': event.pageX }); + // If we want to enable download for this node + + var downloadOnRight = document.getElementById("downloadOnRight"); + + if(trNode.lastChild.innerHTML === "File"){ + downloadOnRight.style.display = "Block"; + }else{ + downloadOnRight.style.display = "none"; + } + + + + $scope.addFileOrFolderToListForRightClick(trNode); } @@ -1154,7 +1183,7 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { var check = 1; var getFileName = nodeName.getElementsByTagName('td')[0].innerHTML; - if(nodeName.style.backgroundColor == "aliceblue") { + if(nodeName.style.backgroundColor === "aliceblue") { var tempArray = []; nodeName.style.background = "None"; @@ -1236,7 +1265,7 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { }; - // fix permissions + // Fix permissions $scope.fixPermissions = function() { @@ -1248,7 +1277,6 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { }; - $http.post(url, data).then(ListInitialDatas, cantLoadInitialDatas); function ListInitialDatas(response) { @@ -1270,6 +1298,50 @@ fileManager.controller('fileManagerCtrl', function($scope,$http,FileUploader) { }; + // Download files + + $scope.downloadFile = function() { + + url = "/filemanager/downloadFile"; + + var data = { + fileToDownload: $scope.currentPath + "/" + allFilesAndFolders[0] + }; + + + $http.post(url, data).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + var blob = new Blob([response.data]); + + //IE case + if (!!window.navigator.msSaveBlob){ + window.navigator.msSaveBlob(blob, allFilesAndFolders[0]); + return; + } + + //create blob and url + var url = URL.createObjectURL(blob); + + //create invisible acnhor, to specify the file name + var a = document.createElement('a'); + document.body.appendChild(a); + a.style = "display: none"; + a.href = url; + a.download = allFilesAndFolders[0]; + a.click(); + + setTimeout(function(){ + URL.revokeObjectURL(url); + document.body.removeChild(a); + }, 100); + } + + function cantLoadInitialDatas(response) {} + + }; + diff --git a/static/managePHP/managePHP.js b/static/managePHP/managePHP.js index 77d49025e..f15425925 100644 --- a/static/managePHP/managePHP.js +++ b/static/managePHP/managePHP.js @@ -362,6 +362,7 @@ app.controller('editPHPConfig', function($scope,$http,$timeout) { $scope.max_execution_time = response.data.max_execution_time; $scope.upload_max_filesize = response.data.upload_max_filesize; $scope.max_input_time = response.data.max_input_time; + $scope.post_max_size = response.data.post_max_size; $scope.phpDetailsBox = false; @@ -407,6 +408,7 @@ app.controller('editPHPConfig', function($scope,$http,$timeout) { max_execution_time:$scope.max_execution_time, upload_max_filesize:$scope.upload_max_filesize, max_input_time:$scope.max_input_time, + post_max_size: $scope.post_max_size, }; var config = { @@ -423,7 +425,7 @@ app.controller('editPHPConfig', function($scope,$http,$timeout) { function ListInitialDatas(response) { - if(response.data.saveStatus == 1){ + if(response.data.saveStatus === 1){ $scope.detailsSaved = false; $scope.loadingPHP = true;