2019-01-28 15:19:59 +05:00
|
|
|
from django.shortcuts import HttpResponse
|
|
|
|
|
import json
|
|
|
|
|
import subprocess, shlex
|
|
|
|
|
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
|
|
|
|
from plogical.processUtilities import ProcessUtilities
|
|
|
|
|
from websiteFunctions.models import Websites
|
|
|
|
|
from random import randint
|
|
|
|
|
from django.core.files.storage import FileSystemStorage
|
2019-04-28 22:01:36 +05:00
|
|
|
import HTMLParser
|
2019-07-16 23:23:16 +05:00
|
|
|
import os
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
class FileManager:
|
|
|
|
|
def __init__(self, request, data):
|
|
|
|
|
self.request = request
|
|
|
|
|
self.data = data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ajaxPre(self, status, errorMessage):
|
|
|
|
|
final_dic = {'status': status, 'error_message': errorMessage, 'uploadStatus': status}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|
|
def returnPathEnclosed(self, path):
|
2019-04-28 22:01:36 +05:00
|
|
|
htmlParser = HTMLParser.HTMLParser()
|
|
|
|
|
path = htmlParser.unescape(path)
|
2019-07-16 23:23:16 +05:00
|
|
|
return path
|
2019-01-28 15:19:59 +05:00
|
|
|
return "'" + path + "'"
|
|
|
|
|
|
|
|
|
|
def changeOwner(self, path):
|
|
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-03-12 14:47:58 +05:00
|
|
|
|
|
|
|
|
if path.find('..') > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = "chown -R " + website.externalApp + ':' + website.externalApp + ' ' + self.returnPathEnclosed(path)
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
def listForTable(self):
|
|
|
|
|
try:
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
if not self.data['completeStartingPath'].find(self.data['home']) > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to browse this path, going back home!')
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = "ls -la --group-directories-first " + self.returnPathEnclosed(
|
2019-04-15 15:54:23 +05:00
|
|
|
self.data['completeStartingPath'])
|
2019-07-16 23:23:16 +05:00
|
|
|
output = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
|
for items in output:
|
2019-02-09 14:01:43 +05:00
|
|
|
try:
|
|
|
|
|
currentFile = items.split(' ')
|
|
|
|
|
currentFile = filter(lambda a: a != '', currentFile)
|
|
|
|
|
if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total':
|
|
|
|
|
continue
|
2019-04-15 15:54:23 +05:00
|
|
|
|
|
|
|
|
if len(currentFile) > 9:
|
|
|
|
|
fileName = currentFile[8:]
|
|
|
|
|
currentFile[-1] = " ".join(fileName)
|
|
|
|
|
|
2019-02-09 14:01:43 +05:00
|
|
|
dirCheck = 0
|
|
|
|
|
if currentFile[0][0] == 'd':
|
|
|
|
|
dirCheck = 1
|
|
|
|
|
|
2019-04-15 15:54:23 +05:00
|
|
|
size = str(int(int(currentFile[4]) / float(1024)))
|
2019-02-09 14:01:43 +05:00
|
|
|
lastModified = currentFile[5] + ' ' + currentFile[6] + ' ' + currentFile[7]
|
2019-04-15 15:54:23 +05:00
|
|
|
finalData[str(counter)] = [currentFile[-1], currentFile[-1], lastModified, size, currentFile[0],
|
|
|
|
|
dirCheck]
|
2019-02-09 14:01:43 +05:00
|
|
|
counter = counter + 1
|
2019-04-15 15:54:23 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.writeToFile(str(msg))
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def list(self):
|
|
|
|
|
try:
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
|
|
|
|
command = "ls -la --group-directories-first " + self.returnPathEnclosed(
|
2019-04-15 15:54:23 +05:00
|
|
|
self.data['completeStartingPath'])
|
2019-07-16 23:23:16 +05:00
|
|
|
output = ProcessUtilities.outputExecutioner(command, website.externalApp).splitlines()
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
|
for items in output:
|
2019-02-09 14:01:43 +05:00
|
|
|
try:
|
|
|
|
|
currentFile = items.split(' ')
|
|
|
|
|
currentFile = filter(lambda a: a != '', currentFile)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-02-09 14:01:43 +05:00
|
|
|
if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total':
|
|
|
|
|
continue
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-04-15 15:54:23 +05:00
|
|
|
if len(currentFile) > 9:
|
|
|
|
|
fileName = currentFile[8:]
|
|
|
|
|
currentFile[-1] = " ".join(fileName)
|
|
|
|
|
|
2019-02-09 14:01:43 +05:00
|
|
|
dirCheck = False
|
|
|
|
|
if currentFile[0][0] == 'd':
|
|
|
|
|
dirCheck = True
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-04-15 15:54:23 +05:00
|
|
|
finalData[str(counter)] = [currentFile[-1],
|
|
|
|
|
self.data['completeStartingPath'] + '/' + currentFile[-1], dirCheck]
|
2019-02-09 14:01:43 +05:00
|
|
|
counter = counter + 1
|
|
|
|
|
except:
|
|
|
|
|
continue
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def createNewFile(self):
|
|
|
|
|
try:
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
2019-03-12 14:47:58 +05:00
|
|
|
if self.data['fileName'].find('..') > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
2019-04-15 15:54:23 +05:00
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = "touch " + self.returnPathEnclosed(self.data['fileName'])
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-04-15 15:54:23 +05:00
|
|
|
self.changeOwner(self.returnPathEnclosed(self.data['fileName']))
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def createNewFolder(self):
|
|
|
|
|
try:
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = "mkdir " + self.returnPathEnclosed(self.data['folderName'])
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-04-15 15:54:23 +05:00
|
|
|
self.changeOwner(self.returnPathEnclosed(self.data['folderName']))
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def deleteFolderOrFile(self):
|
|
|
|
|
try:
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
for item in self.data['fileAndFolders']:
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'rm -rf ' + self.returnPathEnclosed(self.data['path'] + '/' + item)
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def copy(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
if not self.data['newPath'].find(self.data['home']) > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'mkdir ' + self.returnPathEnclosed(self.data['newPath'])
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
for item in self.data['fileAndFolders']:
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'cp -R ' + self.returnPathEnclosed(self.data['basePath'] + '/' + item) + ' ' + self.returnPathEnclosed(self.data['newPath'] + '/' + item)
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
self.changeOwner(self.data['newPath'])
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def move(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
if not self.data['newPath'].find(self.data['home']) > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'mkdir ' + self.returnPathEnclosed(self.data['newPath'])
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
for item in self.data['fileAndFolders']:
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'mv ' + self.returnPathEnclosed(self.data['basePath'] + '/' + item) + ' ' + self.returnPathEnclosed(self.data['newPath'] + '/' + item)
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
self.changeOwner(self.data['newPath'])
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def rename(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-03-12 14:47:58 +05:00
|
|
|
if self.data['newFileName'].find('..') > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'mv ' + self.returnPathEnclosed(self.data['basePath'] + '/' + self.data['existingName']) + ' ' + self.returnPathEnclosed(self.data['basePath'] + '/' + self.data['newFileName'])
|
|
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
self.changeOwner(self.data['basePath'] + '/' + self.data['newFileName'])
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def readFileContents(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'cat ' + self.returnPathEnclosed(self.data['fileName'])
|
|
|
|
|
finalData['fileContents'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def writeFileContents(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
2019-07-16 23:23:16 +05:00
|
|
|
self.data['home'] = '/home/%s' % (self.data['domainName'])
|
|
|
|
|
|
|
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
writeToFile = open(tempPath, 'w')
|
|
|
|
|
writeToFile.write(self.data['fileContent'])
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
if os.path.islink(self.data['fileName']):
|
|
|
|
|
return self.ajaxPre(0, 'File exists and is symlink.')
|
|
|
|
|
|
|
|
|
|
if not self.data['fileName'].find(self.data['home']) > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
|
|
|
|
command = 'mv ' + tempPath + ' ' + self.returnPathEnclosed(self.data['fileName'])
|
2019-01-28 15:19:59 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2019-07-16 23:23:16 +05:00
|
|
|
|
|
|
|
|
command = 'chown %s:%s %s' % (website.externalApp, website.externalApp, self.data['fileName'])
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
self.changeOwner(self.data['fileName'])
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def upload(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['uploadStatus'] = 1
|
|
|
|
|
finalData['answer'] = 'File transfer completed.'
|
|
|
|
|
|
|
|
|
|
myfile = self.request.FILES['file']
|
|
|
|
|
fs = FileSystemStorage()
|
|
|
|
|
filename = fs.save(myfile.name, myfile)
|
|
|
|
|
finalData['fileName'] = fs.url(filename)
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
if not self.data['completePath'].find(self.data['home']) > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
|
|
|
|
command = 'mv ' + self.returnPathEnclosed('/home/cyberpanel/media/' + myfile.name) + ' ' + self.returnPathEnclosed(self.data['completePath'] + '/' + myfile.name)
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
|
|
|
|
command = 'chown %s:%s %s' % (website.externalApp, website.externalApp, self.data['completePath'] + '/' + myfile.name)
|
2019-01-28 15:19:59 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
self.changeOwner(self.data['completePath'] + '/' + myfile.name)
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def extract(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
if not self.data['extractionLocation'].find(self.data['home']) > -1:
|
|
|
|
|
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')
|
|
|
|
|
|
|
|
|
|
if self.data['extractionType'] == 'zip':
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'unzip -o ' + self.returnPathEnclosed(self.data['fileToExtract']) + ' -d ' + self.returnPathEnclosed(self.data['extractionLocation'])
|
2019-01-28 15:19:59 +05:00
|
|
|
else:
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'tar -xf ' + self.returnPathEnclosed(self.data['fileToExtract']) + ' -C ' + self.returnPathEnclosed(self.data['extractionLocation'])
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
self.changeOwner(self.data['extractionLocation'])
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def compress(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.data['compressionType'] == 'zip':
|
|
|
|
|
compressedFileName = self.returnPathEnclosed(self.data['basePath'] + '/' + self.data['compressedFileName'] + '.zip')
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'zip -r ' + compressedFileName + ' '
|
2019-01-28 15:19:59 +05:00
|
|
|
else:
|
|
|
|
|
compressedFileName = self.returnPathEnclosed(
|
|
|
|
|
self.data['basePath'] + '/' + self.data['compressedFileName'] + '.tar.gz')
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'tar -czvf ' + compressedFileName + ' '
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
for item in self.data['listOfFiles']:
|
2019-08-29 17:05:46 +05:00
|
|
|
command = '%s%s ' % (command, self.returnPathEnclosed(item))
|
2019-01-28 15:19:59 +05:00
|
|
|
|
2019-08-29 17:05:46 +05:00
|
|
|
|
|
|
|
|
finalCommand = 'cd %s && %s' % (self.data['basePath'], command)
|
|
|
|
|
|
|
|
|
|
ProcessUtilities.executioner(finalCommand, website.externalApp)
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
self.changeOwner(self.data['compressedFileName'])
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-02-12 01:57:35 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def changePermissions(self):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
finalData = {}
|
|
|
|
|
finalData['status'] = 1
|
2019-07-16 23:23:16 +05:00
|
|
|
domainName = self.data['domainName']
|
|
|
|
|
website = Websites.objects.get(domain=domainName)
|
2019-02-12 01:57:35 +05:00
|
|
|
|
|
|
|
|
if self.data['recursive'] == 1:
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'chmod -R ' + self.data['newPermissions'] + ' ' + self.returnPathEnclosed(
|
2019-02-12 01:57:35 +05:00
|
|
|
self.data['basePath'] + '/' + self.data['permissionsPath'])
|
|
|
|
|
else:
|
2019-07-16 23:23:16 +05:00
|
|
|
command = 'chmod ' + self.data['newPermissions'] + ' ' + self.returnPathEnclosed(
|
2019-02-12 01:57:35 +05:00
|
|
|
self.data['basePath'] + '/' + self.data['permissionsPath'])
|
|
|
|
|
|
|
|
|
|
|
2019-07-16 23:23:16 +05:00
|
|
|
ProcessUtilities.executioner(command, website.externalApp)
|
2019-02-12 01:57:35 +05:00
|
|
|
|
|
|
|
|
json_data = json.dumps(finalData)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
return self.ajaxPre(0, str(msg))
|