Files
CyberPanel/manageSSL/views.py

324 lines
12 KiB
Python
Raw Normal View History

2017-10-24 19:16:36 +05:00
# -*- coding: utf-8 -*-
2019-12-10 15:09:10 +05:00
2021-03-03 19:11:49 +05:00
from plogical.httpProc import httpProc
2019-11-26 15:03:27 +05:00
from websiteFunctions.models import Websites, ChildDomains
2017-10-24 19:16:36 +05:00
from loginSystem.models import Administrator
from plogical.virtualHostUtilities import virtualHostUtilities
from django.http import HttpResponse
import json
2018-08-18 00:39:10 +05:00
from plogical.acl import ACLManager
2019-03-26 16:19:03 +05:00
from plogical.processUtilities import ProcessUtilities
2019-11-26 15:03:27 +05:00
2017-10-24 19:16:36 +05:00
# Create your views here.
def loadSSLHome(request):
2021-03-03 19:11:49 +05:00
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
proc = httpProc(request, 'manageSSL/index.html',
currentACL, 'admin')
return proc.render()
2017-10-24 19:16:36 +05:00
2019-11-26 15:03:27 +05:00
2017-10-24 19:16:36 +05:00
def manageSSL(request):
2021-03-03 19:11:49 +05:00
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
proc = httpProc(request, 'manageSSL/manageSSL.html',
{'websiteList': websitesName}, 'manageSSL')
return proc.render()
2017-10-24 19:16:36 +05:00
def v2ManageSSL(request):
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
RetStatus, SAVED_CF_Key, SAVED_CF_Email = ACLManager.FetchCloudFlareAPIKeyFromAcme()
from plogical.dnsUtilities import DNS
DNS.ConfigurePowerDNSInAcme()
data = {}
data['SAVED_CF_Key'] = SAVED_CF_Key
data['SAVED_CF_Email'] = SAVED_CF_Email
data['websiteList'] = websitesName
proc = httpProc(request, 'manageSSL/v2ManageSSL.html',
data, 'manageSSL')
return proc.render()
def v2IssueSSL(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(pk=userID)
try:
if request.method == 'POST':
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
elif currentACL['manageSSL'] == 1:
pass
else:
return ACLManager.loadErrorJson('SSL', 0)
data = json.loads(request.body)
virtualHost = data['virtualHost']
if ACLManager.checkOwnership(virtualHost, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
try:
website = ChildDomains.objects.get(domain=virtualHost)
adminEmail = website.master.adminEmail
path = website.path
except:
website = Websites.objects.get(domain=virtualHost)
adminEmail = website.adminEmail
path = "/home/" + virtualHost + "/public_html"
## ssl issue
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " issueSSLv2 --virtualHostName " + virtualHost + " --administratorEmail " + adminEmail + " --path " + path
output = ProcessUtilities.outputExecutioner(execPath)
if output.find("1,") > -1:
## ssl issue ends
website.ssl = 1
website.save()
data_ret = {'status': 1, "SSL": 1,
'error_message': "None", 'sslLogs': output}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'status': 0, "SSL": 0,
'error_message': output, 'sslLogs': output}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, "SSL": 0,
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError:
data_ret = {'status': 0, "SSL": 0,
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2019-11-26 15:03:27 +05:00
2017-10-24 19:16:36 +05:00
def issueSSL(request):
try:
2018-08-18 00:39:10 +05:00
userID = request.session['userID']
admin = Administrator.objects.get(pk=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['manageSSL'] == 1:
pass
else:
return ACLManager.loadErrorJson('SSL', 0)
2017-10-24 19:16:36 +05:00
data = json.loads(request.body)
virtualHost = data['virtualHost']
if ACLManager.checkOwnership(virtualHost, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
try:
website = ChildDomains.objects.get(domain=virtualHost)
2017-12-09 22:30:10 +05:00
adminEmail = website.master.adminEmail
2018-11-08 13:19:36 +05:00
path = website.path
except:
website = Websites.objects.get(domain=virtualHost)
2017-12-09 22:30:10 +05:00
adminEmail = website.adminEmail
path = "/home/" + virtualHost + "/public_html"
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
## ssl issue
2017-10-24 19:16:36 +05:00
2019-12-10 23:04:24 +05:00
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
2017-12-09 22:30:10 +05:00
execPath = execPath + " issueSSL --virtualHostName " + virtualHost + " --administratorEmail " + adminEmail + " --path " + path
2019-03-26 16:19:03 +05:00
output = ProcessUtilities.outputExecutioner(execPath)
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
if output.find("1,None") > -1:
pass
else:
2019-11-26 15:03:27 +05:00
data_ret = {'status': 0, "SSL": 0,
2017-12-09 22:30:10 +05:00
'error_message': output}
2017-10-24 19:16:36 +05:00
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2017-12-09 22:30:10 +05:00
## ssl issue ends
website.ssl = 1
website.save()
2018-11-08 13:19:36 +05:00
data_ret = {'status': 1, "SSL": 1,
2017-12-09 22:30:10 +05:00
'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-11-08 13:19:36 +05:00
data_ret = {'status': 0, "SSL": 0,
2017-10-24 19:16:36 +05:00
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError:
2018-11-08 13:19:36 +05:00
data_ret = {'status': 0, "SSL": 0,
2017-10-24 19:16:36 +05:00
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2019-11-26 15:03:27 +05:00
2017-10-24 19:16:36 +05:00
def sslForHostName(request):
2021-03-03 19:11:49 +05:00
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID, 1)
proc = httpProc(request, 'manageSSL/sslForHostName.html',
{'websiteList': websitesName}, 'hostnameSSL')
return proc.render()
2017-10-24 19:16:36 +05:00
2019-11-26 15:03:27 +05:00
2017-10-24 19:16:36 +05:00
def obtainHostNameSSL(request):
try:
2018-08-18 00:39:10 +05:00
userID = request.session['userID']
2017-10-24 19:16:36 +05:00
try:
2018-08-18 00:39:10 +05:00
if request.method == 'POST':
2017-10-24 19:16:36 +05:00
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['hostnameSSL'] == 1:
pass
else:
return ACLManager.loadErrorJson('SSL', 0)
2017-10-24 19:16:36 +05:00
2018-08-18 00:39:10 +05:00
data = json.loads(request.body)
virtualHost = data['virtualHost']
2017-10-24 19:16:36 +05:00
try:
website = Websites.objects.get(domain=virtualHost)
path = "/home/" + virtualHost + "/public_html"
except:
website = ChildDomains.objects.get(domain=virtualHost)
path = website.path
2017-10-24 19:16:36 +05:00
admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(virtualHost, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
2018-08-18 00:39:10 +05:00
## ssl issue
2017-10-24 19:16:36 +05:00
2019-12-10 23:04:24 +05:00
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
2018-08-18 00:39:10 +05:00
execPath = execPath + " issueSSLForHostName --virtualHostName " + virtualHost + " --path " + path
2019-03-26 16:19:03 +05:00
output = ProcessUtilities.outputExecutioner(execPath)
2018-08-18 00:39:10 +05:00
if output.find("1,None") > -1:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 1, "SSL": 1,
2018-08-18 00:39:10 +05:00
'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 0, "SSL": 0,
2018-08-18 00:39:10 +05:00
'error_message': output}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2017-12-09 22:30:10 +05:00
2018-06-30 15:29:56 +05:00
## ssl issue ends
2017-10-24 19:16:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 0, "SSL": 0,
2017-10-24 19:16:36 +05:00
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 0, "SSL": 0,
2018-04-26 17:59:47 +05:00
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2019-11-26 15:03:27 +05:00
2018-04-26 17:59:47 +05:00
def sslForMailServer(request):
2021-03-03 19:11:49 +05:00
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
2018-04-26 17:59:47 +05:00
2021-03-03 19:11:49 +05:00
websitesName = ACLManager.findAllSites(currentACL, userID)
websitesName = websitesName + ACLManager.findChildDomains(websitesName)
2018-04-26 17:59:47 +05:00
2021-03-03 19:11:49 +05:00
proc = httpProc(request, 'manageSSL/sslForMailServer.html',
{'websiteList': websitesName}, 'mailServerSSL')
return proc.render()
2018-04-26 17:59:47 +05:00
2019-11-26 15:03:27 +05:00
2018-04-26 17:59:47 +05:00
def obtainMailServerSSL(request):
try:
2018-08-18 00:39:10 +05:00
userID = request.session['userID']
2018-04-26 17:59:47 +05:00
try:
2018-08-18 00:39:10 +05:00
if request.method == 'POST':
2018-04-26 17:59:47 +05:00
2018-08-18 00:39:10 +05:00
currentACL = ACLManager.loadedACL(userID)
2018-04-26 17:59:47 +05:00
2018-08-18 00:39:10 +05:00
if currentACL['admin'] == 1:
pass
elif currentACL['mailServerSSL'] == 1:
pass
else:
return ACLManager.loadErrorJson('SSL', 0)
2018-04-26 17:59:47 +05:00
2018-08-18 00:39:10 +05:00
data = json.loads(request.body)
virtualHost = data['virtualHost']
2018-04-26 17:59:47 +05:00
admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(virtualHost, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
2018-08-18 00:39:10 +05:00
path = "/home/" + virtualHost + "/public_html"
## ssl issue
2018-04-26 17:59:47 +05:00
2019-12-10 23:04:24 +05:00
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
2018-08-18 00:39:10 +05:00
execPath = execPath + " issueSSLForMailServer --virtualHostName " + virtualHost + " --path " + path
2019-03-26 16:19:03 +05:00
output = ProcessUtilities.outputExecutioner(execPath)
2018-04-26 17:59:47 +05:00
2018-08-18 00:39:10 +05:00
if output.find("1,None") > -1:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 1, "SSL": 1,
2018-08-18 00:39:10 +05:00
'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2018-04-26 17:59:47 +05:00
else:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 0, "SSL": 0,
2018-08-18 00:39:10 +05:00
'error_message': output}
2018-04-26 17:59:47 +05:00
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2018-08-18 00:39:10 +05:00
## ssl issue ends
2018-04-26 17:59:47 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 0, "SSL": 0,
2018-04-26 17:59:47 +05:00
'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2019-12-10 15:09:10 +05:00
except KeyError as msg:
2018-11-26 02:32:30 +05:00
data_ret = {"status": 0, "SSL": 0,
2017-10-24 19:16:36 +05:00
'error_message': str(msg)}
json_data = json.dumps(data_ret)
2019-11-26 15:03:27 +05:00
return HttpResponse(json_data)