mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 16:26:12 +01:00
drop certbot
This commit is contained in:
@@ -69,7 +69,6 @@ MIDDLEWARE = [
|
|||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.locale.LocaleMiddleware',
|
'django.middleware.locale.LocaleMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ urlpatterns = [
|
|||||||
|
|
||||||
url(r'^loginAPI', views.loginAPI, name='loginAPI'),
|
url(r'^loginAPI', views.loginAPI, name='loginAPI'),
|
||||||
|
|
||||||
|
url(r'^getUserInfo$', views.getUserInfo, name='getUserInfo'),
|
||||||
url(r'^changeUserPassAPI', views.changeUserPassAPI, name='changeUserPassAPI'),
|
url(r'^changeUserPassAPI', views.changeUserPassAPI, name='changeUserPassAPI'),
|
||||||
|
|
||||||
url(r'^changePackageAPI', views.changePackageAPI, name='changePackageAPI'),
|
url(r'^changePackageAPI', views.changePackageAPI, name='changePackageAPI'),
|
||||||
url(r'^fetchSSHkey', views.fetchSSHkey, name='fetchSSHkey'),
|
url(r'^fetchSSHkey', views.fetchSSHkey, name='fetchSSHkey'),
|
||||||
url(r'^remoteTransfer', views.remoteTransfer, name='remoteTransfer'),
|
url(r'^remoteTransfer', views.remoteTransfer, name='remoteTransfer'),
|
||||||
|
|||||||
61
api/views.py
61
api/views.py
@@ -6,21 +6,23 @@ from django.http import HttpResponse
|
|||||||
from loginSystem.models import Administrator
|
from loginSystem.models import Administrator
|
||||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||||
from plogical import hashPassword
|
from plogical import hashPassword
|
||||||
from plogical.installUtilities import installUtilities
|
|
||||||
from packages.models import Package
|
from packages.models import Package
|
||||||
from baseTemplate.views import renderBase
|
from baseTemplate.views import renderBase
|
||||||
from random import randint
|
from random import randint
|
||||||
from websiteFunctions.models import Websites,ChildDomains
|
from websiteFunctions.models import Websites
|
||||||
import os
|
import os
|
||||||
from baseTemplate.models import version
|
from baseTemplate.models import version
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
import re
|
|
||||||
from plogical.mailUtilities import mailUtilities
|
from plogical.mailUtilities import mailUtilities
|
||||||
from plogical.website import WebsiteManager
|
from plogical.website import WebsiteManager
|
||||||
|
from loginSystem.models import ACL
|
||||||
|
from plogical.acl import ACLManager
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def verifyConn(request):
|
def verifyConn(request):
|
||||||
try:
|
try:
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -49,6 +51,46 @@ def createWebsite(request):
|
|||||||
wm = WebsiteManager()
|
wm = WebsiteManager()
|
||||||
return wm.createWebsiteAPI(json.loads(request.body))
|
return wm.createWebsiteAPI(json.loads(request.body))
|
||||||
|
|
||||||
|
def getUserInfo(request):
|
||||||
|
try:
|
||||||
|
if request.method == 'POST':
|
||||||
|
|
||||||
|
data = json.loads(request.body)
|
||||||
|
|
||||||
|
adminUser = data['adminUser']
|
||||||
|
adminPass = data['adminPass']
|
||||||
|
username = data['username']
|
||||||
|
|
||||||
|
admin = Administrator.objects.get(userName=adminUser)
|
||||||
|
|
||||||
|
if hashPassword.check_password(admin.password, adminPass):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
data_ret = {"status": 0,
|
||||||
|
'error_message': "Could not authorize access to API"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
try:
|
||||||
|
user = Administrator.objects.get(userName=username)
|
||||||
|
data_ret = {'status': 0,
|
||||||
|
'firstName': user.firstName,
|
||||||
|
'lastName': user.lastName,
|
||||||
|
'email': user.email,
|
||||||
|
'adminStatus': user.acl.adminStatus,
|
||||||
|
'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
except:
|
||||||
|
data_ret = {'status': 0, 'error_message': "User does not exists."}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def changeUserPassAPI(request):
|
def changeUserPassAPI(request):
|
||||||
try:
|
try:
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -514,6 +556,19 @@ def changeAdminPassword(request):
|
|||||||
randomFile = data['randomFile']
|
randomFile = data['randomFile']
|
||||||
|
|
||||||
if os.path.exists(randomFile):
|
if os.path.exists(randomFile):
|
||||||
|
numberOfAdministrator = Administrator.objects.count()
|
||||||
|
if numberOfAdministrator == 0:
|
||||||
|
ACLManager.createDefaultACLs()
|
||||||
|
acl = ACL.objects.get(name='admin')
|
||||||
|
email = 'usman@cyberpersons.com'
|
||||||
|
admin = Administrator(userName="admin", password=adminPass, type=1, email=email,
|
||||||
|
firstName="Cyber", lastName="Panel", acl=acl)
|
||||||
|
admin.save()
|
||||||
|
data_ret = {"changed": 1,
|
||||||
|
'error_message': "None"}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
os.remove(randomFile)
|
os.remove(randomFile)
|
||||||
admin = Administrator.objects.get(userName="admin")
|
admin = Administrator.objects.get(userName="admin")
|
||||||
admin.password = hashPassword.hash_password(adminPass)
|
admin.password = hashPassword.hash_password(adminPass)
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ from websiteFunctions.models import Websites
|
|||||||
import threading as multi
|
import threading as multi
|
||||||
import socket, smtplib
|
import socket, smtplib
|
||||||
import DNS
|
import DNS
|
||||||
|
from random import randint
|
||||||
|
import subprocess, shlex
|
||||||
|
|
||||||
|
|
||||||
class emailMarketing(multi.Thread):
|
class emailMarketing(multi.Thread):
|
||||||
def __init__(self, function, extraArgs):
|
def __init__(self, function, extraArgs):
|
||||||
@@ -185,26 +188,42 @@ class emailMarketing(multi.Thread):
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
message = MIMEMultipart('alternative')
|
message = MIMEMultipart('alternative')
|
||||||
message['Subject'] = emailMessage.subject
|
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||||
message['From'] = emailMessage.fromEmail
|
|
||||||
|
|
||||||
for items in allEmails:
|
for items in allEmails:
|
||||||
|
message = MIMEMultipart('alternative')
|
||||||
|
message['Subject'] = emailMessage.subject
|
||||||
|
message['From'] = emailMessage.fromName + ' ' + emailMessage.fromEmail
|
||||||
|
message['reply-to'] = emailMessage.replyTo
|
||||||
if (items.verificationStatus == 'Verified' or self.extraArgs['verificationCheck']) and not items.verificationStatus == 'REMOVED':
|
if (items.verificationStatus == 'Verified' or self.extraArgs['verificationCheck']) and not items.verificationStatus == 'REMOVED':
|
||||||
try:
|
try:
|
||||||
|
|
||||||
removalLink = "https://" + ipAddress + ":8090/emailMarketing/remove/" + self.extraArgs['listName'] + "/" + items.email
|
removalLink = "https:\/\/" + ipAddress + ":8090\/emailMarketing\/remove\/" + self.extraArgs[
|
||||||
|
'listName'] + "\/" + items.email
|
||||||
|
messageText = str(emailMessage.emailMessage)
|
||||||
|
message['To'] = items.email
|
||||||
|
|
||||||
if re.search('<html', emailMessage.emailMessage, re.IGNORECASE) and re.search('<body', emailMessage.emailMessage, re.IGNORECASE):
|
if re.search('<html', messageText, re.IGNORECASE) and re.search('<body', messageText,
|
||||||
finalMessage = emailMessage.emailMessage
|
re.IGNORECASE):
|
||||||
|
finalMessage = messageText
|
||||||
|
|
||||||
if self.extraArgs['unsubscribeCheck']:
|
if self.extraArgs['unsubscribeCheck']:
|
||||||
finalMessage = finalMessage.replace('{{ unsubscribeCheck }}', removalLink)
|
messageFile = open(tempPath, 'w')
|
||||||
|
messageFile.write(messageText)
|
||||||
|
messageFile.close()
|
||||||
|
|
||||||
|
command = "sudo sed -i 's/{{ unsubscribeCheck }}/" + removalLink + "/g' " + tempPath
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
messageFile = open(tempPath, 'r')
|
||||||
|
finalMessage = messageFile.read()
|
||||||
|
messageFile.close()
|
||||||
|
|
||||||
html = MIMEText(finalMessage, 'html')
|
html = MIMEText(finalMessage, 'html')
|
||||||
message.attach(html)
|
message.attach(html)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
finalMessage = emailMessage.emailMessage
|
finalMessage = messageText
|
||||||
|
|
||||||
if self.extraArgs['unsubscribeCheck']:
|
if self.extraArgs['unsubscribeCheck']:
|
||||||
finalMessage = finalMessage.replace('{{ unsubscribeCheck }}', removalLink)
|
finalMessage = finalMessage.replace('{{ unsubscribeCheck }}', removalLink)
|
||||||
@@ -212,13 +231,11 @@ class emailMarketing(multi.Thread):
|
|||||||
html = MIMEText(finalMessage, 'plain')
|
html = MIMEText(finalMessage, 'plain')
|
||||||
message.attach(html)
|
message.attach(html)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
smtpServer.sendmail(message['From'], items.email, message.as_string())
|
smtpServer.sendmail(message['From'], items.email, message.as_string())
|
||||||
sent = sent + 1
|
sent = sent + 1
|
||||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
'Successfully sent: ' + str(sent) + ' Failed: ' + str(failed))
|
'Successfully sent: ' + str(sent) + ' Failed: ' + str(
|
||||||
|
failed))
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
failed = failed + 1
|
failed = failed + 1
|
||||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
@@ -226,14 +243,14 @@ class emailMarketing(multi.Thread):
|
|||||||
sent) + ', Failed: ' + str(failed))
|
sent) + ', Failed: ' + str(failed))
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||||
|
|
||||||
|
emailJob = EmailJobs(owner=emailMessage, date=time.strftime("%I-%M-%S-%a-%b-%Y"),
|
||||||
|
host=self.extraArgs['host'], totalEmails=totalEmails,
|
||||||
|
sent=sent, failed=failed
|
||||||
|
)
|
||||||
|
emailJob.save()
|
||||||
|
|
||||||
emailJob = EmailJobs(owner=emailMessage, date=time.strftime("%I-%M-%S-%a-%b-%Y"),
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
host=self.extraArgs['host'], totalEmails=totalEmails,
|
'Email job completed. [200]')
|
||||||
sent=sent, failed=failed
|
|
||||||
)
|
|
||||||
emailJob.save()
|
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],'Email job completed. [200]')
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], str(msg) +'. [404]')
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], str(msg) + '. [404]')
|
||||||
return 0
|
return 0
|
||||||
@@ -687,7 +687,7 @@ class preFlightsChecks:
|
|||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
while (1):
|
while (1):
|
||||||
command = "wget http://cyberpanel.net/CyberPanel.1.7.2.tar.gz"
|
command = "wget http://cyberpanel.net/CyberPanel.1.7.3.tar.gz"
|
||||||
#command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz"
|
#command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz"
|
||||||
res = subprocess.call(shlex.split(command))
|
res = subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
@@ -707,7 +707,7 @@ class preFlightsChecks:
|
|||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
while(1):
|
while(1):
|
||||||
command = "tar zxf CyberPanel.1.7.2.tar.gz"
|
command = "tar zxf CyberPanel.1.7.3.tar.gz"
|
||||||
#command = "tar zxf CyberPanelTemp.tar.gz"
|
#command = "tar zxf CyberPanelTemp.tar.gz"
|
||||||
|
|
||||||
res = subprocess.call(shlex.split(command))
|
res = subprocess.call(shlex.split(command))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ def loadLoginPage(request):
|
|||||||
firstName="Cyber",lastName="Panel", acl=acl)
|
firstName="Cyber",lastName="Panel", acl=acl)
|
||||||
admin.save()
|
admin.save()
|
||||||
|
|
||||||
vers = version(currentVersion="1.7",build=2)
|
vers = version(currentVersion="1.7",build=3)
|
||||||
vers.save()
|
vers.save()
|
||||||
|
|
||||||
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
||||||
|
|||||||
@@ -159,18 +159,24 @@ class sslUtilities:
|
|||||||
def obtainSSLForADomain(virtualHostName,adminEmail,sslpath, aliasDomain = None):
|
def obtainSSLForADomain(virtualHostName,adminEmail,sslpath, aliasDomain = None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
## Obtaining Server IP
|
if not os.path.exists('/root/.acme.sh/acme.sh'):
|
||||||
|
command = 'wget -O - https://get.acme.sh | sh'
|
||||||
|
subprocess.call(command, shell=True)
|
||||||
|
|
||||||
if aliasDomain == None:
|
if aliasDomain == None:
|
||||||
|
|
||||||
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName + '/README'
|
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName
|
||||||
if os.path.exists(existingCertPath):
|
if not os.path.exists(existingCertPath):
|
||||||
return 1
|
command = 'mkdir -p ' + existingCertPath
|
||||||
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Trying to obtain SSL for: " + virtualHostName + " and: www." + virtualHostName)
|
logging.CyberCPLogFileWriter.writeToFile("Trying to obtain SSL for: " + virtualHostName + " and: www." + virtualHostName)
|
||||||
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d www." + virtualHostName
|
command = "/root/.acme.sh/acme.sh --issue -d " + virtualHostName + " -d www." + virtualHostName \
|
||||||
|
+ ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \
|
||||||
|
+ ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w ' + sslpath + ' --force'
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(command))
|
output = subprocess.check_output(shlex.split(command))
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName + " and: www." + virtualHostName)
|
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName + " and: www." + virtualHostName)
|
||||||
|
|
||||||
@@ -181,103 +187,46 @@ class sslUtilities:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Trying to obtain SSL for: " + virtualHostName)
|
logging.CyberCPLogFileWriter.writeToFile("Trying to obtain SSL for: " + virtualHostName)
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName
|
command = "/root/.acme.sh/acme.sh --issue -d " + virtualHostName + ' --cert-file ' + existingCertPath \
|
||||||
|
+ '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \
|
||||||
|
+ ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w ' + sslpath + ' --force'
|
||||||
output = subprocess.check_output(shlex.split(command))
|
output = subprocess.check_output(shlex.split(command))
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName)
|
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
logging.CyberCPLogFileWriter.writeToFile('Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName)
|
logging.CyberCPLogFileWriter.writeToFile('Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
##
|
|
||||||
|
|
||||||
if output.find('Congratulations!') > -1:
|
|
||||||
|
|
||||||
return 1
|
|
||||||
|
|
||||||
elif output.find('no action taken.') > -1:
|
|
||||||
|
|
||||||
return 1
|
|
||||||
elif output.find('Failed authorization procedure') > -1:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
'Failed authorization procedure for ' + virtualHostName + " while issuing Let's Encrypt SSL.")
|
|
||||||
return 0
|
|
||||||
elif output.find('Too many SSL requests for this domain, please try to get SSL at later time.') > -1:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
'Too many SSL requests for ' + virtualHostName + " please try to get SSL at later time.")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
ipFile = "/etc/cyberpanel/machineIP"
|
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName
|
||||||
f = open(ipFile)
|
if not os.path.exists(existingCertPath):
|
||||||
ipData = f.read()
|
command = 'mkdir -p ' + existingCertPath
|
||||||
serverIPAddress = ipData.split('\n', 1)[0]
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
ipRecords = sslUtilities.getDNSRecords(virtualHostName)
|
try:
|
||||||
|
|
||||||
if ipRecords[0] == 1:
|
|
||||||
|
|
||||||
if serverIPAddress == ipRecords[1] and serverIPAddress == ipRecords[2]:
|
|
||||||
|
|
||||||
ipRecordsAlias = sslUtilities.getDNSRecords(aliasDomain)
|
|
||||||
|
|
||||||
if serverIPAddress == ipRecordsAlias[1] and serverIPAddress == ipRecordsAlias[2]:
|
|
||||||
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d www." + virtualHostName + " -d " + aliasDomain + " -d www." + aliasDomain
|
|
||||||
|
|
||||||
else:
|
|
||||||
if serverIPAddress == ipRecordsAlias[2]:
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d www." + virtualHostName + " -d " + aliasDomain
|
|
||||||
else:
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d www." + virtualHostName
|
|
||||||
|
|
||||||
else:
|
|
||||||
if serverIPAddress == ipRecords[2]:
|
|
||||||
|
|
||||||
ipRecordsAlias = sslUtilities.getDNSRecords(aliasDomain)
|
|
||||||
|
|
||||||
if serverIPAddress == ipRecordsAlias[1] and serverIPAddress == ipRecordsAlias[2]:
|
|
||||||
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d " + aliasDomain + " -d www." + aliasDomain
|
|
||||||
|
|
||||||
else:
|
|
||||||
if serverIPAddress == ipRecordsAlias[2]:
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d " + aliasDomain
|
|
||||||
else:
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName
|
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
"SSL is issued without 'www' due to DNS error for domain : " + virtualHostName)
|
|
||||||
else:
|
|
||||||
|
|
||||||
ipRecordsAlias = sslUtilities.getDNSRecords(aliasDomain)
|
|
||||||
|
|
||||||
if serverIPAddress == ipRecordsAlias[1] and serverIPAddress == ipRecordsAlias[2]:
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + aliasDomain + " -d www." + aliasDomain
|
|
||||||
else:
|
|
||||||
if serverIPAddress == ipRecordsAlias[2]:
|
|
||||||
command = "/usr/local/CyberCP/bin/certbot certonly -n --expand --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + aliasDomain
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
"Failed to obtain DNS records for " + virtualHostName + ", issuing self signed certificate.")
|
"Trying to obtain SSL for: " + virtualHostName + ", www." + virtualHostName + ", " + aliasDomain + " and www." + aliasDomain + ",")
|
||||||
|
|
||||||
|
command = "/root/.acme.sh/acme.sh --issue -d " + virtualHostName + " -d www." + virtualHostName \
|
||||||
|
+ ' -d ' + aliasDomain + ' -d www.' + aliasDomain\
|
||||||
|
+ ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \
|
||||||
|
+ ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w ' + sslpath + ' --force'
|
||||||
|
|
||||||
|
output = subprocess.check_output(shlex.split(command))
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
|
"Successfully obtained SSL for: " + virtualHostName + ", www." + virtualHostName + ", " + aliasDomain + "and www." + aliasDomain + ",")
|
||||||
|
|
||||||
|
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
|
"Failed to obtain SSL for: " + virtualHostName + ", www." + virtualHostName + ", " + aliasDomain + "and www." + aliasDomain + ",")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(command))
|
##
|
||||||
|
|
||||||
if output.find('Congratulations!') > -1:
|
if output.find('Cert success') > -1:
|
||||||
return 1
|
return 1
|
||||||
elif output.find('no action taken.') > -1:
|
else:
|
||||||
return 1
|
return 0
|
||||||
elif output.find('Failed authorization procedure') > -1:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
'Failed authorization procedure for ' + virtualHostName + " while issuing Let's Encrypt SSL.")
|
|
||||||
return 0
|
|
||||||
elif output.find('Too many SSL requests for this domain, please try to get SSL at later time.') > -1:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
'Too many SSL requests for ' + virtualHostName + " please try to get SSL at later time.")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except BaseException,msg:
|
except BaseException,msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [Failed to obtain SSL. [obtainSSLForADomain]]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [Failed to obtain SSL. [obtainSSLForADomain]]")
|
||||||
|
|||||||
Reference in New Issue
Block a user