2017-12-09 22:30:10 +05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
from django.shortcuts import render,redirect
|
|
|
|
|
from loginSystem.models import Administrator
|
|
|
|
|
from loginSystem.views import loadLoginPage
|
2018-02-16 00:57:46 +05:00
|
|
|
import plogical.CyberCPLogFileWriter as logging
|
2020-03-06 11:37:08 +05:00
|
|
|
from django.http import HttpResponse
|
2018-02-16 00:57:46 +05:00
|
|
|
import json
|
|
|
|
|
from websiteFunctions.models import Websites
|
2018-08-18 00:39:10 +05:00
|
|
|
from plogical.acl import ACLManager
|
2019-01-28 15:19:59 +05:00
|
|
|
from .filemanager import FileManager as FM
|
2019-06-08 21:41:43 +00:00
|
|
|
from plogical.processUtilities import ProcessUtilities
|
2017-12-09 22:30:10 +05:00
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def loadFileManagerHome(request,domain):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
2018-04-18 15:57:49 +05:00
|
|
|
if Websites.objects.filter(domain=domain).exists():
|
2018-08-21 13:10:40 +05:00
|
|
|
admin = Administrator.objects.get(pk=userID)
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-04-18 15:57:49 +05:00
|
|
|
|
2018-08-21 13:10:40 +05:00
|
|
|
if ACLManager.checkOwnership(domain, admin, currentACL) == 1:
|
2018-11-06 00:19:58 +05:00
|
|
|
return render(request, 'filemanager/index.html', {'domainName': domain})
|
2018-04-18 15:57:49 +05:00
|
|
|
else:
|
2018-08-21 13:10:40 +05:00
|
|
|
return ACLManager.loadError()
|
2018-04-18 15:57:49 +05:00
|
|
|
else:
|
|
|
|
|
return HttpResponse("Domain does not exists.")
|
2017-12-09 22:30:10 +05:00
|
|
|
|
2018-02-16 00:57:46 +05:00
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
def changePermissions(request):
|
|
|
|
|
try:
|
2018-08-21 13:10:40 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
admin = Administrator.objects.get(pk=userID)
|
2018-02-16 00:57:46 +05:00
|
|
|
try:
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
domainName = data['domainName']
|
|
|
|
|
|
2018-08-21 13:10:40 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('permissionsChanged', 0)
|
|
|
|
|
|
2020-03-07 19:01:54 +05:00
|
|
|
fm = FM(request, data)
|
|
|
|
|
fm.fixPermissions(domainName)
|
2020-02-21 17:36:09 +05:00
|
|
|
|
2018-02-16 00:57:46 +05:00
|
|
|
data_ret = {'permissionsChanged': 1, 'error_message': "None"}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-02-16 00:57:46 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
data_ret = {'permissionsChanged': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
except KeyError:
|
2018-02-26 17:50:33 +05:00
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
def downloadFile(request):
|
2018-04-18 15:57:49 +05:00
|
|
|
try:
|
2020-01-12 12:45:35 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
admin = Administrator.objects.get(pk=userID)
|
2020-05-01 12:38:23 +05:00
|
|
|
from urllib.parse import quote
|
|
|
|
|
from django.utils.encoding import iri_to_uri
|
2018-02-26 17:50:33 +05:00
|
|
|
|
2020-04-25 12:43:54 +05:00
|
|
|
fileToDownload = request.build_absolute_uri().split('fileToDownload')[1][1:]
|
2020-05-01 12:38:23 +05:00
|
|
|
fileToDownload = iri_to_uri(fileToDownload)
|
2020-04-25 12:43:54 +05:00
|
|
|
|
2020-01-16 13:55:06 +05:00
|
|
|
domainName = request.GET.get('domainName')
|
2020-01-12 12:45:35 +05:00
|
|
|
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('permissionsChanged', 0)
|
|
|
|
|
|
2020-02-04 19:22:42 +05:00
|
|
|
homePath = '/home/%s' % (domainName)
|
|
|
|
|
|
|
|
|
|
if fileToDownload.find('..') > -1 or fileToDownload.find(homePath) == -1:
|
|
|
|
|
return HttpResponse("Unauthorized access.")
|
|
|
|
|
|
2020-01-12 12:45:35 +05:00
|
|
|
response = HttpResponse(content_type='application/force-download')
|
|
|
|
|
response['Content-Disposition'] = 'attachment; filename=%s' % (fileToDownload.split('/')[-1])
|
|
|
|
|
response['X-LiteSpeed-Location'] = '%s' % (fileToDownload)
|
|
|
|
|
|
2018-04-18 15:57:49 +05:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
def controller(request):
|
2018-04-18 15:57:49 +05:00
|
|
|
try:
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
domainName = data['domainName']
|
2019-01-28 15:19:59 +05:00
|
|
|
method = data['method']
|
2018-02-26 17:50:33 +05:00
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
userID = request.session['userID']
|
2018-08-18 00:39:10 +05:00
|
|
|
admin = Administrator.objects.get(pk=userID)
|
2018-08-21 13:10:40 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-04-18 15:57:49 +05:00
|
|
|
|
2018-08-21 13:10:40 +05:00
|
|
|
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
2019-01-28 15:19:59 +05:00
|
|
|
return ACLManager.loadErrorJson()
|
|
|
|
|
|
|
|
|
|
fm = FM(request, data)
|
|
|
|
|
|
|
|
|
|
if method == 'listForTable':
|
|
|
|
|
return fm.listForTable()
|
|
|
|
|
elif method == 'list':
|
|
|
|
|
return fm.list()
|
|
|
|
|
elif method == 'createNewFile':
|
|
|
|
|
return fm.createNewFile()
|
|
|
|
|
elif method == 'createNewFolder':
|
|
|
|
|
return fm.createNewFolder()
|
|
|
|
|
elif method == 'deleteFolderOrFile':
|
|
|
|
|
return fm.deleteFolderOrFile()
|
2020-08-05 12:13:26 +05:00
|
|
|
elif method == 'restore':
|
|
|
|
|
return fm.restore()
|
2019-01-28 15:19:59 +05:00
|
|
|
elif method == 'copy':
|
|
|
|
|
return fm.copy()
|
|
|
|
|
elif method == 'move':
|
|
|
|
|
return fm.move()
|
|
|
|
|
elif method == 'rename':
|
|
|
|
|
return fm.rename()
|
|
|
|
|
elif method == 'readFileContents':
|
|
|
|
|
return fm.readFileContents()
|
|
|
|
|
elif method == 'writeFileContents':
|
|
|
|
|
return fm.writeFileContents()
|
|
|
|
|
elif method == 'upload':
|
|
|
|
|
return fm.writeFileContents()
|
|
|
|
|
elif method == 'extract':
|
|
|
|
|
return fm.extract()
|
|
|
|
|
elif method == 'compress':
|
|
|
|
|
return fm.compress()
|
2019-02-12 01:57:35 +05:00
|
|
|
elif method == 'changePermissions':
|
|
|
|
|
return fm.changePermissions()
|
2019-01-28 15:19:59 +05:00
|
|
|
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2019-01-28 15:19:59 +05:00
|
|
|
fm = FM(request, None)
|
|
|
|
|
return fm.ajaxPre(0, str(msg))
|
|
|
|
|
|
|
|
|
|
def upload(request):
|
|
|
|
|
try:
|
2018-04-18 15:57:49 +05:00
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
data = request.POST
|
2018-04-18 15:57:49 +05:00
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
admin = Administrator.objects.get(pk=userID)
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-04-18 15:57:49 +05:00
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
if ACLManager.checkOwnership(data['domainName'], admin, currentACL) == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson()
|
2018-04-18 15:57:49 +05:00
|
|
|
|
2019-01-28 15:19:59 +05:00
|
|
|
fm = FM(request, data)
|
|
|
|
|
return fm.upload()
|
2018-04-18 15:57:49 +05:00
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
2020-10-14 12:21:28 +05:00
|
|
|
|
|
|
|
|
def editFile(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
admin = Administrator.objects.get(pk=userID)
|
|
|
|
|
from urllib.parse import quote
|
|
|
|
|
from django.utils.encoding import iri_to_uri
|
|
|
|
|
|
|
|
|
|
domainName = request.GET.get('domainName')
|
|
|
|
|
fileName = request.GET.get('fileName')
|
|
|
|
|
|
2020-10-19 00:05:47 +05:00
|
|
|
try:
|
|
|
|
|
theme = request.GET.get('theme')
|
|
|
|
|
if theme == None:
|
|
|
|
|
theme = 'cobalt'
|
|
|
|
|
except:
|
|
|
|
|
theme = 'cobalt'
|
|
|
|
|
|
2020-10-14 12:21:28 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
|
|
|
|
|
2020-10-18 12:29:14 +05:00
|
|
|
mode = FM.findMode(fileName)
|
|
|
|
|
modeFiles = FM.findModeFiles(mode)
|
2020-10-20 11:51:58 +05:00
|
|
|
additionalOptions = FM.findAdditionalOptions(mode)
|
2020-10-19 00:05:47 +05:00
|
|
|
themeFile = FM.findThemeFile(theme)
|
2020-10-14 12:21:28 +05:00
|
|
|
|
|
|
|
|
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
2020-10-19 00:05:47 +05:00
|
|
|
return render(request, 'filemanager/editFile.html', {'domainName': domainName, 'fileName': fileName,
|
|
|
|
|
'mode': mode, 'modeFiles': modeFiles, 'theme': theme,
|
2020-10-20 11:51:58 +05:00
|
|
|
'themeFile': themeFile, 'additionalOptions': additionalOptions})
|
2020-10-14 12:21:28 +05:00
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|