filemanagerfull

This commit is contained in:
habi
2022-04-05 15:53:07 +05:00
parent f8c38a8c56
commit bcdb0ac595
4 changed files with 592 additions and 363 deletions

View File

@@ -81,9 +81,7 @@
<li id="extractFile" class="nav-item"> <li id="extractFile" class="nav-item">
<a onclick="return false;" ng-click="showExtractionModal()" class="nav-link point-events" href="#"><i class="fa fa-expand" aria-hidden="true"></i> {% trans "Extract" %}</a> <a onclick="return false;" ng-click="showExtractionModal()" class="nav-link point-events" href="#"><i class="fa fa-expand" aria-hidden="true"></i> {% trans "Extract" %}</a>
</li> </li>
<li id="fixPermissions" class="nav-item">
<a onclick="return false;" ng-click="fixPermissions()" class="nav-link point-events" href="#"><i class="fa fa-wrench" aria-hidden="true"></i> {% trans "Fix Permissions" %}</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -113,7 +111,7 @@
</div> </div>
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
<li class="list-group-item"> <li class="list-group-item">
<a href="#" onclick="return false;" ng-click="fetchChilds($event,completeStartingPath,'primary')"> <a href="#" onclick="return false;" ng-click="fetchChilds($event,currentRPath,'primary')">
<i class="fa fa-plus" aria-hidden="true" ></i> <i class="fa fa-plus" aria-hidden="true" ></i>
</a> </a>
<a onclick="return false;" ng-click="fetchForTableSecondary($event,'fromTree',completeStartingPath)" href="#"> <a onclick="return false;" ng-click="fetchForTableSecondary($event,'fromTree',completeStartingPath)" href="#">
@@ -597,97 +595,8 @@
<!--- rename modal --> <!--- rename modal -->
<!-- Permissions modal -->
<div id="showPermissions" 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 "Changing permissions for" %} {$ permissionsPath $} <img ng-hide="changePermissionsLoading" 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">
<table class="table text-center">
<thead id="tableHead">
<tr>
<th scope="col">{% trans "Mode" %}</th>
<th scope="col">{% trans "User" %}</th>
<th scope="col">{% trans "Group" %}</th>
<th scope="col">{% trans "World" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{% trans "Read" %}</td>
<td><input ng-click="updateReadPermissions('userRead')" ng-model="userRead" type="checkbox" class="form-check-input" value=""></td>
<td><input ng-click="updateReadPermissions('groupRead')" ng-model="groupRead" type="checkbox" class="form-check-input" value=""></td>
<td><input ng-click="updateReadPermissions('worldRead')" ng-model="worldRead" type="checkbox" class="form-check-input" value=""></td>
</tr>
<tr>
<td>{% trans "Write" %}</td>
<td><input ng-click="updateWritePermissions('userWrite')" ng-model="userWrite" type="checkbox" class="form-check-input" value=""></td>
<td><input ng-click="updateWritePermissions('groupWrite')" ng-model="groupWrite" type="checkbox" class="form-check-input" value=""></td>
<td><input ng-click="updateWritePermissions('worldWrite')" ng-model="worldWrite" type="checkbox" class="form-check-input" value=""></td>
</tr>
<tr>
<td>{% trans "Execute" %}</td>
<td><input ng-click="updateExecutePermissions('userExecute')" ng-model="userExecute" type="checkbox" class="form-check-input" value=""></td>
<td><input ng-click="updateExecutePermissions('groupExecute')" ng-model="groupExecute" type="checkbox" class="form-check-input" value=""></td>
<td><input ng-click="updateExecutePermissions('worldExecute')" ng-model="worldExecute" type="checkbox" class="form-check-input" value=""></td>
</tr>
<tr>
<td></td>
<td><input ng-model="userPermissions" type="number" class="form-control" readonly></td>
<td><input ng-model="groupPermissions" type="number" class="form-control" readonly></td>
<td><input ng-model="wordlPermissions" type="number" class="form-control" readonly></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button ng-click="changePermissions(0)" type="button" class="btn btn-primary">{% trans "Change Permissions" %}</button>
<button ng-click="changePermissionsRecursively()" type="button" class="btn btn-primary">{% trans "Change Recursively" %}</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>
<!--- 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 -->

View File

@@ -161,6 +161,7 @@ class FileManager:
return "'" + path + "'" return "'" + path + "'"
def changeOwner(self, path): def changeOwner(self, path):
try:
domainName = self.data['domainName'] domainName = self.data['domainName']
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
@@ -169,6 +170,8 @@ class FileManager:
command = "chown -R " + website.externalApp + ':' + website.externalApp + ' ' + self.returnPathEnclosed(path) command = "chown -R " + website.externalApp + ':' + website.externalApp + ' ' + self.returnPathEnclosed(path)
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
except:
print("Permisson not changed")
def listForTable(self): def listForTable(self):
try: try:
@@ -235,7 +238,7 @@ class FileManager:
try: try:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
try:
domainName = self.data['domainName'] domainName = self.data['domainName']
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
@@ -243,6 +246,33 @@ class FileManager:
self.data['completeStartingPath']) self.data['completeStartingPath'])
output = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines() output = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()
counter = 0
for items in output:
try:
currentFile = items.split(' ')
currentFile = [a for a in currentFile if a != '']
if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total':
continue
if len(currentFile) > 9:
fileName = currentFile[8:]
currentFile[-1] = " ".join(fileName)
dirCheck = False
if currentFile[0][0] == 'd':
dirCheck = True
finalData[str(counter)] = [currentFile[-1],
self.data['completeStartingPath'] + '/' + currentFile[-1], dirCheck]
counter = counter + 1
except:
continue
except:
command = "ls -la --group-directories-first " + self.returnPathEnclosed(
self.data['completeStartingPath'])
output = ProcessUtilities.outputExecutioner(command).splitlines()
counter = 0 counter = 0
for items in output: for items in output:
try: try:
@@ -278,7 +308,6 @@ class FileManager:
finalData['status'] = 1 finalData['status'] = 1
try: try:
domainName = self.data['domainName'] domainName = self.data['domainName']
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
homePath = '/home/%s' % (domainName) homePath = '/home/%s' % (domainName)
@@ -288,6 +317,7 @@ class FileManager:
command = "touch " + self.returnPathEnclosed(self.data['fileName']) command = "touch " + self.returnPathEnclosed(self.data['fileName'])
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
self.changeOwner(self.returnPathEnclosed(self.data['fileName']))
except: except:
homePath = '/' homePath = '/'
@@ -296,19 +326,18 @@ class FileManager:
command = "touch " + self.returnPathEnclosed(self.data['fileName']) command = "touch " + self.returnPathEnclosed(self.data['fileName'])
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
self.changeOwner(self.returnPathEnclosed(self.data['fileName'])) self.changeOwner(self.returnPathEnclosed(self.data['fileName']))
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str("......."+msg)) return self.ajaxPre(0, str(msg))
def createNewFolder(self): def createNewFolder(self):
try: try:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
try:
domainName = self.data['domainName'] domainName = self.data['domainName']
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
@@ -321,6 +350,17 @@ class FileManager:
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
self.changeOwner(self.returnPathEnclosed(self.data['folderName'])) self.changeOwner(self.returnPathEnclosed(self.data['folderName']))
except:
homePath = '/'
if self.data['folderName'].find('..') > -1 or self.data['folderName'].find(homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = "mkdir " + self.returnPathEnclosed(self.data['folderName'])
ProcessUtilities.executioner(command)
self.changeOwner(self.returnPathEnclosed(self.data['folderName']))
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -332,9 +372,8 @@ class FileManager:
try: try:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
try: try:
skipTrash = self.data['skipTrash'] skipTrash = self.data['skipTrash']
except: except:
@@ -380,6 +419,44 @@ class FileManager:
command = 'mv %s %s' % (self.returnPathEnclosed(self.data['path'] + '/' + item), trashPath) command = 'mv %s %s' % (self.returnPathEnclosed(self.data['path'] + '/' + item), trashPath)
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
if RemoveOK == 0:
command = 'chattr -R +i %s' % (self.homePath)
ProcessUtilities.executioner(command)
except:
try:
skipTrash = self.data['skipTrash']
except:
skipTrash = False
self.homePath = '/'
RemoveOK = 1
command = 'touch %s/hello.txt' % (self.homePath)
result = ProcessUtilities.outputExecutioner(command)
if result.find('No such file or directory') > -1:
RemoveOK = 0
command = 'chattr -R -i %s' % (self.homePath)
ProcessUtilities.executioner(command)
else:
command = 'rm -f %s/hello.txt' % (self.homePath)
ProcessUtilities.executioner(command)
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!')
if skipTrash:
command = 'rm -rf ' + self.returnPathEnclosed(self.data['path'] + '/' + item)
ProcessUtilities.executioner(command)
if RemoveOK == 0: if RemoveOK == 0:
command = 'chattr -R +i %s' % (self.homePath) command = 'chattr -R +i %s' % (self.homePath)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
@@ -433,6 +510,7 @@ class FileManager:
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
homePath = '/home/%s' % (domainName) homePath = '/home/%s' % (domainName)
@@ -467,6 +545,42 @@ class FileManager:
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
self.changeOwner(self.data['newPath']) self.changeOwner(self.data['newPath'])
except:
homePath = '/'
if self.data['newPath'].find('..') > -1 or self.data['newPath'].find(homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
if len(self.data['fileAndFolders']) == 1:
if (self.data['basePath'] + '/' + self.data['fileAndFolders'][0]).find('..') > -1 or (
self.data['basePath'] + '/' + self.data['fileAndFolders'][0]).find(homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = 'yes| cp -Rf %s %s' % (
self.returnPathEnclosed(self.data['basePath'] + '/' + self.data['fileAndFolders'][0]),
self.data['newPath'])
ProcessUtilities.executioner(command,)
self.changeOwner(self.data['newPath'])
json_data = json.dumps(finalData)
return HttpResponse(json_data)
command = 'mkdir ' + self.returnPathEnclosed(self.data['newPath'])
ProcessUtilities.executioner(command)
for item in self.data['fileAndFolders']:
if (self.data['basePath'] + '/' + item).find('..') > -1 or (
self.data['basePath'] + '/' + item).find(
homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = '%scp -Rf ' % ('yes |') + self.returnPathEnclosed(
self.data['basePath'] + '/' + item) + ' ' + self.returnPathEnclosed(self.data['newPath'])
ProcessUtilities.executioner(command)
self.changeOwner(self.data['newPath'])
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -480,6 +594,7 @@ class FileManager:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
homePath = '/home/%s' % (domainName) homePath = '/home/%s' % (domainName)
@@ -505,6 +620,32 @@ class FileManager:
self.changeOwner(self.data['newPath']) self.changeOwner(self.data['newPath'])
self.fixPermissions(domainName) self.fixPermissions(domainName)
except:
homePath = '/'
command = 'mkdir ' + self.returnPathEnclosed(self.data['newPath'])
ProcessUtilities.executioner(command)
for item in self.data['fileAndFolders']:
if (self.data['basePath'] + '/' + item).find('..') > -1 or (
self.data['basePath'] + '/' + item).find(
homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
if (self.data['newPath'] + '/' + item).find('..') > -1 or (self.data['newPath'] + '/' + item).find(
homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = 'mv ' + self.returnPathEnclosed(
self.data['basePath'] + '/' + item) + ' ' + self.returnPathEnclosed(
self.data['newPath'] + '/' + item)
ProcessUtilities.executioner(command)
self.changeOwner(self.data['newPath'])
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -518,6 +659,7 @@ class FileManager:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
homePath = '/home/%s' % (domainName) homePath = '/home/%s' % (domainName)
@@ -534,6 +676,22 @@ class FileManager:
self.data['basePath'] + '/' + self.data['newFileName']) self.data['basePath'] + '/' + self.data['newFileName'])
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
self.changeOwner(self.data['basePath'] + '/' + self.data['newFileName'])
except:
homePath = '/'
if (self.data['basePath'] + '/' + self.data['existingName']).find('..') > -1 or (
self.data['basePath'] + '/' + self.data['existingName']).find(homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
if (self.data['newFileName']).find('..') > -1 or (self.data['basePath']).find(homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = 'mv ' + self.returnPathEnclosed(
self.data['basePath'] + '/' + self.data['existingName']) + ' ' + self.returnPathEnclosed(
self.data['basePath'] + '/' + self.data['newFileName'])
ProcessUtilities.executioner(command)
self.changeOwner(self.data['basePath'] + '/' + self.data['newFileName']) self.changeOwner(self.data['basePath'] + '/' + self.data['newFileName'])
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
@@ -548,6 +706,7 @@ class FileManager:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
pathCheck = '/home/%s' % (domainName) pathCheck = '/home/%s' % (domainName)
@@ -557,6 +716,15 @@ class FileManager:
command = 'cat ' + self.returnPathEnclosed(self.data['fileName']) command = 'cat ' + self.returnPathEnclosed(self.data['fileName'])
finalData['fileContents'] = ProcessUtilities.outputExecutioner(command, website.externalApp) finalData['fileContents'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
except:
pathCheck = '/'
if self.data['fileName'].find(pathCheck) == -1 or self.data['fileName'].find('..') > -1:
return self.ajaxPre(0, 'Not allowed.')
command = 'cat ' + self.returnPathEnclosed(self.data['fileName'])
finalData['fileContents'] = ProcessUtilities.outputExecutioner(command)
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -569,6 +737,7 @@ class FileManager:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
try:
self.data['home'] = '/home/%s' % (self.data['domainName']) self.data['home'] = '/home/%s' % (self.data['domainName'])
ACLManager.CreateSecureDir() ACLManager.CreateSecureDir()
@@ -588,6 +757,20 @@ class FileManager:
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
os.remove(tempPath) os.remove(tempPath)
except:
self.data['home'] = '/'
ACLManager.CreateSecureDir()
tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', str(randint(1000, 9999)))
writeToFile = open(tempPath, 'wb')
writeToFile.write(self.data['fileContent'].encode('utf-8'))
writeToFile.close()
command = 'cp %s %s' % (tempPath, self.returnPathEnclosed(self.data['fileName']))
ProcessUtilities.executioner(command)
os.remove(tempPath)
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -618,9 +801,11 @@ class FileManager:
except BaseException as msg: except BaseException as msg:
logging.writeToFile('%s. [375:upload]' % (str(msg))) logging.writeToFile('%s. [375:upload]' % (str(msg)))
pathCheck = '/home/%s' % (self.data['domainName'])
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
pathCheck = '/home/%s' % (self.data['domainName'])
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
command = 'ls -la %s' % (self.data['completePath']) command = 'ls -la %s' % (self.data['completePath'])
@@ -642,11 +827,34 @@ class FileManager:
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
self.changeOwner(self.returnPathEnclosed(self.data['completePath'] + '/' + myfile.name)) self.changeOwner(self.returnPathEnclosed(self.data['completePath'] + '/' + myfile.name))
try: try:
os.remove(UploadPath + RanddomFileName) os.remove(UploadPath + RanddomFileName)
except: except:
pass pass
except:
pathCheck = '/'
command = 'ls -la %s' % (self.data['completePath'])
result = ProcessUtilities.outputExecutioner(command)
logging.writeToFile("upload file res %s" % result)
if ACLManager.commandInjectionCheck(self.data['completePath'] + '/' + myfile.name) == 1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
if (self.data['completePath'] + '/' + myfile.name).find(pathCheck) == -1 or (
(self.data['completePath'] + '/' + myfile.name)).find('..') > -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = 'cp ' + self.returnPathEnclosed(
UploadPath + RanddomFileName) + ' ' + self.returnPathEnclosed(
self.data['completePath'] + '/' + myfile.name)
ProcessUtilities.executioner(command)
self.changeOwner(self.returnPathEnclosed(self.data['completePath'] + '/' + myfile.name))
try:
os.remove(UploadPath + RanddomFileName)
except:
pass
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -665,6 +873,9 @@ class FileManager:
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
homePath = '/home/%s' % (domainName) homePath = '/home/%s' % (domainName)
@@ -685,6 +896,26 @@ class FileManager:
ProcessUtilities.executioner(command, website.externalApp) ProcessUtilities.executioner(command, website.externalApp)
self.fixPermissions(domainName) self.fixPermissions(domainName)
except:
homePath = '/'
if self.data['extractionLocation'].find('..') > -1 or self.data['extractionLocation'].find(
homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
if self.data['fileToExtract'].find('..') > -1 or self.data['fileToExtract'].find(homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
if self.data['extractionType'] == 'zip':
command = 'unzip -o ' + self.returnPathEnclosed(
self.data['fileToExtract']) + ' -d ' + self.returnPathEnclosed(self.data['extractionLocation'])
else:
command = 'tar -xf ' + self.returnPathEnclosed(
self.data['fileToExtract']) + ' -C ' + self.returnPathEnclosed(self.data['extractionLocation'])
ProcessUtilities.executioner(command)
json_data = json.dumps(finalData) json_data = json.dumps(finalData)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -698,6 +929,7 @@ class FileManager:
finalData = {} finalData = {}
finalData['status'] = 1 finalData['status'] = 1
domainName = self.data['domainName'] domainName = self.data['domainName']
try:
website = Websites.objects.get(domain=domainName) website = Websites.objects.get(domain=domainName)
if self.data['compressionType'] == 'zip': if self.data['compressionType'] == 'zip':
@@ -723,6 +955,31 @@ class FileManager:
ProcessUtilities.executioner(finalCommand, website.externalApp) ProcessUtilities.executioner(finalCommand, website.externalApp)
self.changeOwner(self.data['compressedFileName'])
except:
if self.data['compressionType'] == 'zip':
compressedFileName = self.returnPathEnclosed(
self.data['basePath'] + '/' + self.data['compressedFileName'] + '.zip')
command = 'zip -r ' + compressedFileName + ' '
else:
compressedFileName = self.returnPathEnclosed(
self.data['basePath'] + '/' + self.data['compressedFileName'] + '.tar.gz')
command = 'tar -czvf ' + compressedFileName + ' '
homePath = '/'
for item in self.data['listOfFiles']:
if (self.data['basePath'] + item).find('..') > -1 or (self.data['basePath'] + item).find(
homePath) == -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
command = '%s%s ' % (command, self.returnPathEnclosed(item))
finalCommand = 'cd %s && %s' % (self.data['basePath'], command)
res = ProcessUtilities.outputExecutioner(finalCommand, "root")
logging.writeToFile("compress file res %s"%res)
self.changeOwner(self.data['compressedFileName']) self.changeOwner(self.data['compressedFileName'])
json_data = json.dumps(finalData) json_data = json.dumps(finalData)

View File

@@ -39,7 +39,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var domainRandomSeed = ""; var domainRandomSeed = "";
$scope.currentRPath = "/"; $scope.currentRPath = "/";
var homeRPathBack = ""; var homeRPathBack = "/";
var homePathBack = "/home/" + domainName; var homePathBack = "/home/" + domainName;
@@ -443,8 +443,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var fileOrFolderNode = document.createTextNode("Folder"); var fileOrFolderNode = document.createTextNode("Folder");
fifthTDNode.appendChild(fileOrFolderNode) fifthTDNode.appendChild(fileOrFolderNode)
} } else {
else {
thNode.appendChild(iNodeFile); thNode.appendChild(iNodeFile);
trNode.appendChild(thNode); trNode.appendChild(thNode);
trNode.addEventListener("click", function () { trNode.addEventListener("click", function () {
@@ -506,12 +505,10 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
} else if (result[0] === "php") { } else if (result[0] === "php") {
aceEditorMode = "ace/mode/php"; aceEditorMode = "ace/mode/php";
editNotRight.style.display = "Block"; editNotRight.style.display = "Block";
} } else if (result[0] === "py") {
else if (result[0] === "py") {
aceEditorMode = "ace/mode/python"; aceEditorMode = "ace/mode/python";
editNotRight.style.display = "Block"; editNotRight.style.display = "Block";
} } else if (result[0] === "txt") {
else if (result[0] === "txt") {
aceEditorMode = ""; aceEditorMode = "";
editNotRight.style.display = "Block"; editNotRight.style.display = "Block";
} else if (result[0] === "htaccess") { } else if (result[0] === "htaccess") {
@@ -527,8 +524,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
editNode.style.pointerEvents = "none"; editNode.style.pointerEvents = "none";
editNotRight.style.display = "None"; editNotRight.style.display = "None";
} }
} } else {
else {
var editNode = document.getElementById("editFile"); var editNode = document.getElementById("editFile");
editNode.style.pointerEvents = "none"; editNode.style.pointerEvents = "none";
} }
@@ -635,13 +631,12 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
url = "/filemanager/controller"; url = "/filemanager/controller";
var completePathToFile = ""; var completePathToFile = "";
if (domainName === "") if (domainName === "") {
{
completePathToFile = "/";
if (functionName === "startPoint") { if (functionName === "startPoint") {
completePathToFile = $scope.currentRPath; completePathToFile = $scope.currentRPath;
} else if (functionName === "doubleClick") { } else if (functionName === "doubleClick") {
$scope.currentRPath = ""
completePathToFile = $scope.currentRPath + "/" + node.innerHTML; completePathToFile = $scope.currentRPath + "/" + node.innerHTML;
} else if (functionName === "homeFetch") { } else if (functionName === "homeFetch") {
completePathToFile = homeRPathBack; completePathToFile = homeRPathBack;
@@ -676,10 +671,6 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
} }
var data = { var data = {
completeStartingPath: completePathToFile, completeStartingPath: completePathToFile,
method: "listForTable", method: "listForTable",
@@ -857,8 +848,20 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
// uploads // uploads
$scope.errorMessage = true; $scope.errorMessage = true;
var uploader;
var uploader = $scope.uploader = new FileUploader({ if (domainName == "") {
uploader = $scope.uploader = new FileUploader({
url: "/filemanager/upload",
headers: {
'X-CSRFToken': getCookie('csrftoken') // X-CSRF-TOKEN is used for Ruby on Rails Tokens
},
formData: [{
"method": "upload",
"home": homeRPathBack
}]
});
} else {
uploader = $scope.uploader = new FileUploader({
url: "/filemanager/upload", url: "/filemanager/upload",
headers: { headers: {
'X-CSRFToken': getCookie('csrftoken') // X-CSRF-TOKEN is used for Ruby on Rails Tokens 'X-CSRFToken': getCookie('csrftoken') // X-CSRF-TOKEN is used for Ruby on Rails Tokens
@@ -869,6 +872,9 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}] }]
}); });
}
uploader.onCompleteItem = function (fileItem, response, status, headers) { uploader.onCompleteItem = function (fileItem, response, status, headers) {
if (response.uploadStatus === 1) { if (response.uploadStatus === 1) {
$scope.errorMessage = true; $scope.errorMessage = true;
@@ -881,10 +887,16 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}; };
uploader.onAfterAddingFile = function (fileItem) { uploader.onAfterAddingFile = function (fileItem) {
var basepath;
if (domainName == "") {
basepath = $scope.currentRPath;
} else {
basepath = $scope.currentPath
}
$scope.errorMessage = true; $scope.errorMessage = true;
fileItem.formData.push( fileItem.formData.push(
{ {
"completePath": $scope.currentPath, "completePath": basepath,
domainRandomSeed: domainRandomSeed, domainRandomSeed: domainRandomSeed,
domainName: domainName domainName: domainName
@@ -914,9 +926,14 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.createNewFolder = function () { $scope.createNewFolder = function () {
$scope.errorMessageFolder = true; var completePathForFolder;
if (domainName === "") {
var completePathForFolder = $scope.currentPath + "/" + $scope.newFolderName; completePathForFolder = $scope.currentRPath + "/" + $scope.newFolderName;
$scope.errorMessageFile = true;
} else {
completePathForFolder = $scope.currentPath + "/" + $scope.newFolderName;
$scope.errorMessageFile = true;
}
if ($scope.newFolderName.length === 0) { if ($scope.newFolderName.length === 0) {
$scope.errorMessageFolder = false; $scope.errorMessageFolder = false;
@@ -982,16 +999,14 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}; };
$scope.createNewFile = function () { $scope.createNewFile = function () {
if(domainName === "") var completePathForFile;
{ if (domainName === "") {
var completePathForFile = $scope.currentRPath + "/" + $scope.newFileName; completePathForFile = $scope.currentRPath + "/" + $scope.newFileName;
$scope.errorMessageFile = true;
} else {
completePathForFile = $scope.currentPath + "/" + $scope.newFileName;
$scope.errorMessageFile = true; $scope.errorMessageFile = true;
} }
else {
var completePathForFile = $scope.currentPath + "/" + $scope.newFileName;
$scope.errorMessageFile = true;
}
if ($scope.newFileName.length === 0) { if ($scope.newFileName.length === 0) {
@@ -1047,16 +1062,26 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}; };
$scope.deleteFolderOrFile = function () { $scope.deleteFolderOrFile = function () {
var pth;
var trash;
if (domainName === "") {
pth = $scope.currentRPath;
trash = true;
} else {
pth = $scope.currentPath;
trash = $scope.skipTrash
}
$scope.deleteLoading = false; $scope.deleteLoading = false;
var data = { var data = {
path: $scope.currentPath, path: pth,
method: "deleteFolderOrFile", method: "deleteFolderOrFile",
fileAndFolders: allFilesAndFolders, fileAndFolders: allFilesAndFolders,
domainRandomSeed: domainRandomSeed, domainRandomSeed: domainRandomSeed,
domainName: domainName, domainName: domainName,
skipTrash: $scope.skipTrash skipTrash: trash
}; };
@@ -1106,12 +1131,19 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
}; };
$scope.startCompression = function () { $scope.startCompression = function () {
var basepathh;
if (domainName === "") {
basepathh = $scope.currentRPath;
} else {
basepathh = $scope.currentPath;
}
$scope.compressionLoading = false; $scope.compressionLoading = false;
var data = { var data = {
home: homePathBack, home: homePathBack,
basePath: $scope.currentPath, basePath: basepathh,
listOfFiles: allFilesAndFolders, listOfFiles: allFilesAndFolders,
compressedFileName: $scope.compressedFileName, compressedFileName: $scope.compressedFileName,
compressionType: $scope.compressionType, compressionType: $scope.compressionType,
@@ -1162,10 +1194,16 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.startExtraction = function () { $scope.startExtraction = function () {
var pathbase;
if (domainName === "") {
pathbase = $scope.currentRPath;
} else {
pathbase = $scope.currentPath;
}
$scope.extractionLoading = false; $scope.extractionLoading = false;
var basePath = $scope.currentPath; var completeFileToExtract = $scope.currentRPath + "/" + allFilesAndFolders[0];
var completeFileToExtract = $scope.currentPath + "/" + allFilesAndFolders[0];
var extractionType = ""; var extractionType = "";
if (findFileExtension(completeFileToExtract) == "gz") { if (findFileExtension(completeFileToExtract) == "gz") {
@@ -1176,7 +1214,7 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
var data = { var data = {
home: homePathBack, home: homePathBack,
basePath: basePath, basePath: pathbase,
fileToExtract: completeFileToExtract, fileToExtract: completeFileToExtract,
extractionType: extractionType, extractionType: extractionType,
extractionLocation: $scope.extractionLocation, extractionLocation: $scope.extractionLocation,
@@ -1236,11 +1274,18 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.startMoving = function () { $scope.startMoving = function () {
var basepth;
if (domainName == "") {
basepth = $scope.currentRPath;
} else {
basepth = $scope.currentPath;
}
$scope.moveLoading = false; $scope.moveLoading = false;
var data = { var data = {
home: homePathBack, home: homePathBack,
basePath: $scope.currentPath, basePath: basepth,
newPath: $scope.pathToMoveTo, newPath: $scope.pathToMoveTo,
fileAndFolders: allFilesAndFolders, fileAndFolders: allFilesAndFolders,
method: 'move', method: 'move',
@@ -1297,12 +1342,19 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.startCopying = function () { $scope.startCopying = function () {
var basepath;
if (domainName == "") {
basepath = $scope.currentRPath;
} else {
basepath = $scope.currentPath;
}
$scope.copyLoading = false; $scope.copyLoading = false;
var data = { var data = {
home: homePathBack, home: homePathBack,
basePath: $scope.currentPath, basePath: basepath,
newPath: $scope.pathToCopyTo, newPath: $scope.pathToCopyTo,
fileAndFolders: allFilesAndFolders, fileAndFolders: allFilesAndFolders,
method: 'copy', method: 'copy',
@@ -1432,10 +1484,17 @@ fileManager.controller('fileManagerCtrl', function ($scope, $http, FileUploader,
$scope.renameFile = function () { $scope.renameFile = function () {
var bpath;
if (domainName === "") {
bpath = $scope.currentRPath;
} else {
bpath = $scope.currentPath;
}
$scope.renameLoading = false; $scope.renameLoading = false;
var data = { var data = {
basePath: $scope.currentPath, basePath: bpath,
existingName: $scope.fileToRename, existingName: $scope.fileToRename,
newFileName: $scope.newFileName, newFileName: $scope.newFileName,
method: 'rename', method: 'rename',

View File

@@ -153,6 +153,8 @@ def upload(request):
data = request.POST data = request.POST
try:
userID = request.session['userID'] userID = request.session['userID']
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
@@ -161,6 +163,8 @@ def upload(request):
pass pass
else: else:
return ACLManager.loadErrorJson() return ACLManager.loadErrorJson()
except:
pass
fm = FM(request, data) fm = FM(request, data)
return fm.upload() return fm.upload()