Usman Nasir
2020-08-05 12:13:26 +05:00
parent 106dfa68aa
commit 9626b94d5d
5 changed files with 229 additions and 52 deletions

View File

@@ -6,6 +6,7 @@ from websiteFunctions.models import Websites
from random import randint
from django.core.files.storage import FileSystemStorage
from plogical.acl import ACLManager
from filemanager.models import Trash
class FileManager:
def __init__(self, request, data):
@@ -172,6 +173,12 @@ class FileManager:
finalData['status'] = 1
domainName = self.data['domainName']
try:
skipTrash = self.data['skipTrash']
except:
skipTrash = False
website = Websites.objects.get(domain=domainName)
self.homePath = '/home/%s' % (domainName)
@@ -180,9 +187,56 @@ class FileManager:
if (self.data['path'] + '/' + item).find('..') > -1 or (self.data['path'] + '/' + item).find(self.homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = 'rm -rf ' + self.returnPathEnclosed(self.data['path'] + '/' + item)
if skipTrash:
command = 'rm -rf ' + self.returnPathEnclosed(self.data['path'] + '/' + item)
ProcessUtilities.executioner(command, website.externalApp)
else:
trashPath = '%s/.trash' % (self.homePath)
command = 'mkdir %s' % (trashPath)
ProcessUtilities.executioner(command, website.externalApp)
Trash(website=website, originalPath=self.returnPathEnclosed(self.data['path']), fileName=self.returnPathEnclosed(item)).save()
command = 'mv %s %s' % (self.returnPathEnclosed(self.data['path'] + '/' + item), trashPath)
ProcessUtilities.executioner(command, website.externalApp)
json_data = json.dumps(finalData)
return HttpResponse(json_data)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def restore(self):
try:
finalData = {}
finalData['status'] = 1
domainName = self.data['domainName']
try:
skipTrash = self.data['skipTrash']
except:
skipTrash = False
website = Websites.objects.get(domain=domainName)
self.homePath = '/home/%s' % (domainName)
for item in self.data['fileAndFolders']:
if (self.data['path'] + '/' + item).find('..') > -1 or (self.data['path'] + '/' + item).find(self.homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
trashPath = '%s/.trash' % (self.homePath)
tItem = Trash.objects.get(website=website, fileName=self.returnPathEnclosed(item))
command = 'mv %s %s' % (self.returnPathEnclosed(trashPath + '/' + item), tItem.originalPath)
ProcessUtilities.executioner(command, website.externalApp)
tItem.delete()
json_data = json.dumps(finalData)
return HttpResponse(json_data)

View File

@@ -42,6 +42,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.currentPath = "/home/" + domainName;
$scope.startingPath = domainName;
$scope.completeStartingPath = "/home/" + domainName;
var trashPath = homePathBack + '/.trash'
$scope.editDisable = true;
// disable loading image on tree loading
@@ -218,7 +219,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
}
function prepareChildNodeUL() {
// text nodes are created
@@ -305,7 +305,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var tableBody = document.getElementById("tableBodyFiles");
var getFileName = tableBody.firstChild.firstChild.innerHTML;
allFilesAndFolders = []
allFilesAndFolders = [];
var collectionOfA = tableBody.getElementsByTagName("tr");
@@ -340,7 +340,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";
@@ -375,19 +375,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
/*
<tr>
<th scope="row"><i class="fa fa-folder" aria-hidden="true"></i></th>
<td>public_html</td>
<td>26KB</td>
<td>26 Oct</td>
<td>775</td>
<td>Folder/File</td>
</tr>
*/
function createTR(fileName, fileSize, lastModified, permissions, dirCheck) {
// text nodes are created
@@ -396,10 +383,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var lastModifiedNode = document.createTextNode(lastModified);
var permissionsNode = document.createTextNode(permissions);
//
var iNodeFolder = document.createElement('i');
iNodeFolder.setAttribute('class', 'fa fa-folder');
iNodeFolder.setAttribute('aria-hidden', 'true');
@@ -454,7 +439,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var fileOrFolderNode = document.createTextNode("Folder");
fifthTDNode.appendChild(fileOrFolderNode)
} else {
}
else {
thNode.appendChild(iNodeFile);
trNode.appendChild(thNode);
trNode.addEventListener("click", function () {
@@ -485,6 +471,14 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.buttonActivator = function () {
// for restore button
if($scope.currentPath === trashPath) {
var restoreBTN = document.getElementById("restoreRight");
restoreBTN.style.display = "block";
}else{
var restoreBTN = document.getElementById("restoreRight");
restoreBTN.style.display = "none";
}
// for edit button
if (allFilesAndFolders.length === 1) {
var editNode = document.getElementById("editFile");
@@ -507,7 +501,12 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
} else if (result[0] === "php") {
aceEditorMode = "ace/mode/php";
editNotRight.style.display = "Block";
} else if (result[0] === "txt") {
}
else if (result[0] === "py") {
aceEditorMode = "ace/mode/python";
editNotRight.style.display = "Block";
}
else if (result[0] === "txt") {
aceEditorMode = "";
editNotRight.style.display = "Block";
} else if (result[0] === "htaccess") {
@@ -523,7 +522,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
editNode.style.pointerEvents = "none";
editNotRight.style.display = "None";
}
} else {
}
else {
var editNode = document.getElementById("editFile");
editNode.style.pointerEvents = "none";
}
@@ -1385,7 +1385,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
};
$scope.renameFile = function () {
$scope.renameLoading = false;
@@ -1494,13 +1493,11 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.groupPermissions = 0;
$scope.wordlPermissions = 0;
$scope.showPermissionsModal = function () {
$('#showPermissions').modal('show');
$scope.permissionsPath = allFilesAndFolders[0];
};
$scope.updateReadPermissions = function (value) {
switch (value) {
@@ -1618,7 +1615,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
};
$scope.changePermissionsRecursively = function () {
$scope.changePermissions(1);
};
@@ -1670,5 +1666,53 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
};
///
//
$scope.cyberPanelLoading = true;
$scope.showRestoreModal = function () {
$scope.createSuccess = true;
$scope.errorMessageFolder = true;
$scope.newFolderName = "";
$('#showRestore').modal('show');
};
$scope.restoreFinal = function () {
$scope.cyberPanelLoading = false;
var data = {
path: $scope.currentPath,
method: "restore",
fileAndFolders: allFilesAndFolders,
domainRandomSeed: domainRandomSeed,
domainName: domainName,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberPanelLoading = true;
if (response.data.status === 1) {
$('#showRestore').modal('hide');
var notification = alertify.notify('Successfully restored to its original location!', 'success', 5, function () {
});
$scope.fetchForTableSecondary(null, 'refresh');
} else {
var notification = alertify.notify('Files/Folders can not be restored', 'error', 5, function () {
console.log('dismissed');
});
}
}
function cantLoadInitialDatas(response) {
}
};
});

View File

@@ -662,6 +662,37 @@
<!--- Permissions modal -->
<!--- Restore modal -->
<div id="showRestore" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div id="htmlEditorLable" class="modal-header">
<h5 class="modal-title" >{% trans "Confirm Restore!" %} <img ng-hide="cyberPanelLoading" src="{% static 'filemanager/images/loadingSmall.gif' %}"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="/">
<div class="form-group">
<small class="form-text text-muted">{% trans "This will restore file to its original location." %}</small>
</div>
</form>
<p>Are you sure?</p>
</div>
<div class="modal-footer">
<button ng-click="restoreFinal()" type="button" class="btn btn-primary">{% trans "Restore" %}</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>
<!--- Restore modal -->
@@ -704,6 +735,7 @@
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showCompressionModal()" href="#"><li class="list-group-item"><i class="fa fa-compress" aria-hidden="true"></i> {% trans "Compress" %}</li></a>
<a style="border-bottom: 1px solid #007bff;" id="extractOnRight" onclick="return false;" ng-click="showExtractionModal()" href="#"><li class="list-group-item"><i class="fa fa-expand" aria-hidden="true"></i> {% trans "Extract" %}</li></a>
<a style="border-bottom: 1px solid #007bff;" id="editOnRight" onclick="return false;" ng-click="showHTMLEditorModal()" href="#"><li class="list-group-item"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> {% trans "Edit" %}</li></a>
<a style="border-bottom: 1px solid #007bff;" id="restoreRight" onclick="return false;" ng-click="showRestoreModal()" href="#"><li class="list-group-item"><i class="fa fa-window-restore" aria-hidden="true"></i> {% trans "Restore" %}</li></a>
</ul>
</div>

View File

@@ -120,6 +120,8 @@ def controller(request):
return fm.createNewFolder()
elif method == 'deleteFolderOrFile':
return fm.deleteFolderOrFile()
elif method == 'restore':
return fm.restore()
elif method == 'copy':
return fm.copy()
elif method == 'move':

View File

@@ -42,6 +42,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.currentPath = "/home/" + domainName;
$scope.startingPath = domainName;
$scope.completeStartingPath = "/home/" + domainName;
var trashPath = homePathBack + '/.trash'
$scope.editDisable = true;
// disable loading image on tree loading
@@ -218,7 +219,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
}
function prepareChildNodeUL() {
// text nodes are created
@@ -305,7 +305,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var tableBody = document.getElementById("tableBodyFiles");
var getFileName = tableBody.firstChild.firstChild.innerHTML;
allFilesAndFolders = []
allFilesAndFolders = [];
var collectionOfA = tableBody.getElementsByTagName("tr");
@@ -340,7 +340,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";
@@ -375,19 +375,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
/*
<tr>
<th scope="row"><i class="fa fa-folder" aria-hidden="true"></i></th>
<td>public_html</td>
<td>26KB</td>
<td>26 Oct</td>
<td>775</td>
<td>Folder/File</td>
</tr>
*/
function createTR(fileName, fileSize, lastModified, permissions, dirCheck) {
// text nodes are created
@@ -396,10 +383,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var lastModifiedNode = document.createTextNode(lastModified);
var permissionsNode = document.createTextNode(permissions);
//
var iNodeFolder = document.createElement('i');
iNodeFolder.setAttribute('class', 'fa fa-folder');
iNodeFolder.setAttribute('aria-hidden', 'true');
@@ -454,7 +439,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var fileOrFolderNode = document.createTextNode("Folder");
fifthTDNode.appendChild(fileOrFolderNode)
} else {
}
else {
thNode.appendChild(iNodeFile);
trNode.appendChild(thNode);
trNode.addEventListener("click", function () {
@@ -485,6 +471,14 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.buttonActivator = function () {
// for restore button
if($scope.currentPath === trashPath) {
var restoreBTN = document.getElementById("restoreRight");
restoreBTN.style.display = "block";
}else{
var restoreBTN = document.getElementById("restoreRight");
restoreBTN.style.display = "none";
}
// for edit button
if (allFilesAndFolders.length === 1) {
var editNode = document.getElementById("editFile");
@@ -507,7 +501,12 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
} else if (result[0] === "php") {
aceEditorMode = "ace/mode/php";
editNotRight.style.display = "Block";
} else if (result[0] === "txt") {
}
else if (result[0] === "py") {
aceEditorMode = "ace/mode/python";
editNotRight.style.display = "Block";
}
else if (result[0] === "txt") {
aceEditorMode = "";
editNotRight.style.display = "Block";
} else if (result[0] === "htaccess") {
@@ -523,7 +522,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
editNode.style.pointerEvents = "none";
editNotRight.style.display = "None";
}
} else {
}
else {
var editNode = document.getElementById("editFile");
editNode.style.pointerEvents = "none";
}
@@ -1007,7 +1007,8 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
method: "deleteFolderOrFile",
fileAndFolders: allFilesAndFolders,
domainRandomSeed: domainRandomSeed,
domainName: domainName
domainName: domainName,
skipTrash: $scope.skipTrash
};
@@ -1384,7 +1385,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
};
$scope.renameFile = function () {
$scope.renameLoading = false;
@@ -1493,13 +1493,11 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.groupPermissions = 0;
$scope.wordlPermissions = 0;
$scope.showPermissionsModal = function () {
$('#showPermissions').modal('show');
$scope.permissionsPath = allFilesAndFolders[0];
};
$scope.updateReadPermissions = function (value) {
switch (value) {
@@ -1617,7 +1615,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}
};
$scope.changePermissionsRecursively = function () {
$scope.changePermissions(1);
};
@@ -1669,5 +1666,53 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
};
///
//
$scope.cyberPanelLoading = true;
$scope.showRestoreModal = function () {
$scope.createSuccess = true;
$scope.errorMessageFolder = true;
$scope.newFolderName = "";
$('#showRestore').modal('show');
};
$scope.restoreFinal = function () {
$scope.cyberPanelLoading = false;
var data = {
path: $scope.currentPath,
method: "restore",
fileAndFolders: allFilesAndFolders,
domainRandomSeed: domainRandomSeed,
domainName: domainName,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberPanelLoading = true;
if (response.data.status === 1) {
$('#showRestore').modal('hide');
var notification = alertify.notify('Successfully restored to its original location!', 'success', 5, function () {
});
$scope.fetchForTableSecondary(null, 'refresh');
} else {
var notification = alertify.notify('Files/Folders can not be restored', 'error', 5, function () {
console.log('dismissed');
});
}
}
function cantLoadInitialDatas(response) {
}
};
});