2017-10-24 19:16:36 +05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
import hashlib
|
|
|
|
|
import json
|
|
|
|
|
from django.shortcuts import render,redirect
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from models import Users
|
|
|
|
|
from loginSystem.models import Administrator
|
|
|
|
|
import plogical.CyberCPLogFileWriter as logging
|
|
|
|
|
from loginSystem.views import loadLoginPage
|
|
|
|
|
from websiteFunctions.models import Websites
|
2017-12-09 22:30:10 +05:00
|
|
|
import subprocess
|
|
|
|
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
|
|
|
|
import shlex
|
2018-06-05 00:53:45 +05:00
|
|
|
from plogical.ftpUtilities import FTPUtilities
|
2018-07-23 22:11:42 +05:00
|
|
|
import os
|
2018-08-18 00:39:10 +05:00
|
|
|
from plogical.acl import ACLManager
|
2017-10-24 19:16:36 +05:00
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
def loadFTPHome(request):
|
|
|
|
|
try:
|
|
|
|
|
val = request.session['userID']
|
|
|
|
|
return render(request,'ftp/index.html')
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
def createFTPAccount(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['createFTPAccount'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
try:
|
|
|
|
|
admin = Administrator.objects.get(pk=userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
|
|
|
|
return render(request, "ftp/createFTPAccount.html", {"status": 0})
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-07-23 22:11:42 +05:00
|
|
|
return render(request, 'ftp/createFTPAccount.html', {'websiteList':websitesName,'admin':admin.userName, "status": 1})
|
2017-10-24 19:16:36 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
return HttpResponse(str(msg))
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
def submitFTPCreation(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['createFTPAccount'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('creatFTPStatus', 0)
|
|
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
userName = data['ftpUserName']
|
|
|
|
|
password = data['ftpPassword']
|
|
|
|
|
path = data['path']
|
2018-06-30 15:29:56 +05:00
|
|
|
domainName = data['ftpDomain']
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
admin = Administrator.objects.get(id=userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
if len(path) > 0:
|
|
|
|
|
pass
|
2017-10-24 19:16:36 +05:00
|
|
|
else:
|
2018-06-05 00:53:45 +05:00
|
|
|
path = 'None'
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/ftpUtilities.py"
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-06-30 15:29:56 +05:00
|
|
|
execPath = execPath + " submitFTPCreation --domainName " + domainName + " --userName " + userName \
|
2018-06-05 00:53:45 +05:00
|
|
|
+ " --password " + password + " --path " + path + " --owner " + admin.userName
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
output = subprocess.check_output(shlex.split(execPath))
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
if output.find("1,None") > -1:
|
|
|
|
|
data_ret = {'creatFTPStatus': 1, 'error_message': 'None'}
|
2017-10-24 19:16:36 +05:00
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
else:
|
2018-06-05 00:53:45 +05:00
|
|
|
data_ret = {'creatFTPStatus': 0, 'error_message': output}
|
2017-10-24 19:16:36 +05:00
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
data_ret = {'creatFTPStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
except KeyError,msg:
|
|
|
|
|
data_ret = {'creatFTPStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
def deleteFTPAccount(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['deleteFTPAccount'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
2018-07-23 22:11:42 +05:00
|
|
|
|
|
|
|
|
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
|
|
|
|
return render(request, "ftp/deleteFTPAccount.html", {"status": 0})
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-07-23 22:11:42 +05:00
|
|
|
return render(request, 'ftp/deleteFTPAccount.html', {'websiteList':websitesName, "status": 1})
|
2017-10-24 19:16:36 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
return HttpResponse(str(msg))
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
def fetchFTPAccounts(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['deleteFTPAccount'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
domain = data['ftpDomain']
|
|
|
|
|
|
|
|
|
|
website = Websites.objects.get(domain=domain)
|
|
|
|
|
|
|
|
|
|
ftpAccounts = website.users_set.all()
|
|
|
|
|
|
|
|
|
|
json_data = "["
|
|
|
|
|
checker = 0
|
|
|
|
|
|
|
|
|
|
for items in ftpAccounts:
|
|
|
|
|
dic = {"userName":items.user}
|
|
|
|
|
|
|
|
|
|
if checker == 0:
|
|
|
|
|
json_data = json_data + json.dumps(dic)
|
|
|
|
|
checker = 1
|
|
|
|
|
else:
|
|
|
|
|
json_data = json_data + ',' + json.dumps(dic)
|
|
|
|
|
|
|
|
|
|
json_data = json_data + ']'
|
|
|
|
|
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
except KeyError,msg:
|
|
|
|
|
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
def submitFTPDelete(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['deleteFTPAccount'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('deleteStatus', 0)
|
2018-06-30 15:29:56 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
data = json.loads(request.body)
|
|
|
|
|
ftpUserName = data['ftpUsername']
|
2018-06-30 15:29:56 +05:00
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
FTPUtilities.submitFTPDeletion(ftpUserName)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
final_json = json.dumps({'deleteStatus': 1, 'error_message': "None"})
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
except KeyError,msg:
|
|
|
|
|
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
def listFTPAccounts(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['listFTPAccounts'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
|
2018-07-23 22:11:42 +05:00
|
|
|
if not os.path.exists('/home/cyberpanel/pureftpd'):
|
|
|
|
|
return render(request, "ftp/listFTPAccounts.html", {"status": 0})
|
|
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
websitesName = ACLManager.findAllSites(currentACL, userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-07-23 22:11:42 +05:00
|
|
|
return render(request, 'ftp/listFTPAccounts.html', {'websiteList':websitesName, "status": 1})
|
2017-10-24 19:16:36 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
|
|
|
|
return HttpResponse(str(msg))
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
def getAllFTPAccounts(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['listFTPAccounts'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('fetchStatus', 0)
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
selectedDomain = data['selectedDomain']
|
|
|
|
|
|
|
|
|
|
domain = Websites.objects.get(domain=selectedDomain)
|
|
|
|
|
|
|
|
|
|
records = Users.objects.filter(domain=domain)
|
|
|
|
|
|
|
|
|
|
json_data = "["
|
|
|
|
|
checker = 0
|
|
|
|
|
|
|
|
|
|
for items in records:
|
|
|
|
|
dic = {'id': items.id,
|
|
|
|
|
'user': items.user,
|
|
|
|
|
'dir': items.dir,
|
|
|
|
|
'quotasize': str(items.quotasize)+"MB",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if checker == 0:
|
|
|
|
|
json_data = json_data + json.dumps(dic)
|
|
|
|
|
checker = 1
|
|
|
|
|
else:
|
|
|
|
|
json_data = json_data + ',' + json.dumps(dic)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json_data = json_data + ']'
|
|
|
|
|
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None","data":json_data})
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
final_dic = {'fetchStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
except KeyError:
|
|
|
|
|
final_dic = {'fetchStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|
|
def changePassword(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
elif currentACL['listFTPAccounts'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
userName = data['ftpUserName']
|
|
|
|
|
password = data['ftpPassword']
|
|
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
FTPUtilities.changeFTPPassword(userName, password)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
|
|
|
|
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
except KeyError,msg:
|
|
|
|
|
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|