mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 00:06:09 +01:00
drop certbot
This commit is contained in:
@@ -69,7 +69,6 @@ MIDDLEWARE = [
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
|
||||
@@ -10,7 +10,9 @@ urlpatterns = [
|
||||
|
||||
url(r'^loginAPI', views.loginAPI, name='loginAPI'),
|
||||
|
||||
url(r'^getUserInfo$', views.getUserInfo, name='getUserInfo'),
|
||||
url(r'^changeUserPassAPI', views.changeUserPassAPI, name='changeUserPassAPI'),
|
||||
|
||||
url(r'^changePackageAPI', views.changePackageAPI, name='changePackageAPI'),
|
||||
url(r'^fetchSSHkey', views.fetchSSHkey, name='fetchSSHkey'),
|
||||
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 plogical.virtualHostUtilities import virtualHostUtilities
|
||||
from plogical import hashPassword
|
||||
from plogical.installUtilities import installUtilities
|
||||
from packages.models import Package
|
||||
from baseTemplate.views import renderBase
|
||||
from random import randint
|
||||
from websiteFunctions.models import Websites,ChildDomains
|
||||
from websiteFunctions.models import Websites
|
||||
import os
|
||||
from baseTemplate.models import version
|
||||
import subprocess
|
||||
import shlex
|
||||
import re
|
||||
from plogical.mailUtilities import mailUtilities
|
||||
from plogical.website import WebsiteManager
|
||||
from loginSystem.models import ACL
|
||||
from plogical.acl import ACLManager
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
|
||||
def verifyConn(request):
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
@@ -49,6 +51,46 @@ def createWebsite(request):
|
||||
wm = WebsiteManager()
|
||||
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):
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
@@ -514,6 +556,19 @@ def changeAdminPassword(request):
|
||||
randomFile = data['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)
|
||||
admin = Administrator.objects.get(userName="admin")
|
||||
admin.password = hashPassword.hash_password(adminPass)
|
||||
|
||||
@@ -10,6 +10,9 @@ from websiteFunctions.models import Websites
|
||||
import threading as multi
|
||||
import socket, smtplib
|
||||
import DNS
|
||||
from random import randint
|
||||
import subprocess, shlex
|
||||
|
||||
|
||||
class emailMarketing(multi.Thread):
|
||||
def __init__(self, function, extraArgs):
|
||||
@@ -185,26 +188,42 @@ class emailMarketing(multi.Thread):
|
||||
import re
|
||||
|
||||
message = MIMEMultipart('alternative')
|
||||
message['Subject'] = emailMessage.subject
|
||||
message['From'] = emailMessage.fromEmail
|
||||
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
|
||||
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':
|
||||
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):
|
||||
finalMessage = emailMessage.emailMessage
|
||||
if re.search('<html', messageText, re.IGNORECASE) and re.search('<body', messageText,
|
||||
re.IGNORECASE):
|
||||
finalMessage = messageText
|
||||
|
||||
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')
|
||||
message.attach(html)
|
||||
|
||||
else:
|
||||
finalMessage = emailMessage.emailMessage
|
||||
finalMessage = messageText
|
||||
|
||||
if self.extraArgs['unsubscribeCheck']:
|
||||
finalMessage = finalMessage.replace('{{ unsubscribeCheck }}', removalLink)
|
||||
@@ -212,13 +231,11 @@ class emailMarketing(multi.Thread):
|
||||
html = MIMEText(finalMessage, 'plain')
|
||||
message.attach(html)
|
||||
|
||||
|
||||
|
||||
|
||||
smtpServer.sendmail(message['From'], items.email, message.as_string())
|
||||
sent = sent + 1
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Successfully sent: ' + str(sent) + ' Failed: ' + str(failed))
|
||||
'Successfully sent: ' + str(sent) + ' Failed: ' + str(
|
||||
failed))
|
||||
except BaseException, msg:
|
||||
failed = failed + 1
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
@@ -226,14 +243,14 @@ class emailMarketing(multi.Thread):
|
||||
sent) + ', Failed: ' + str(failed))
|
||||
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"),
|
||||
host=self.extraArgs['host'], totalEmails=totalEmails,
|
||||
sent=sent, failed=failed
|
||||
)
|
||||
emailJob.save()
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],'Email job completed. [200]')
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Email job completed. [200]')
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], str(msg) +'. [404]')
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], str(msg) + '. [404]')
|
||||
return 0
|
||||
@@ -687,7 +687,7 @@ class preFlightsChecks:
|
||||
|
||||
count = 0
|
||||
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"
|
||||
res = subprocess.call(shlex.split(command))
|
||||
|
||||
@@ -707,7 +707,7 @@ class preFlightsChecks:
|
||||
|
||||
count = 0
|
||||
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"
|
||||
|
||||
res = subprocess.call(shlex.split(command))
|
||||
|
||||
@@ -158,7 +158,7 @@ def loadLoginPage(request):
|
||||
firstName="Cyber",lastName="Panel", acl=acl)
|
||||
admin.save()
|
||||
|
||||
vers = version(currentVersion="1.7",build=2)
|
||||
vers = version(currentVersion="1.7",build=3)
|
||||
vers.save()
|
||||
|
||||
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
||||
|
||||
@@ -159,18 +159,24 @@ class sslUtilities:
|
||||
def obtainSSLForADomain(virtualHostName,adminEmail,sslpath, aliasDomain = None):
|
||||
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:
|
||||
|
||||
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName + '/README'
|
||||
if os.path.exists(existingCertPath):
|
||||
return 1
|
||||
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName
|
||||
if not os.path.exists(existingCertPath):
|
||||
command = 'mkdir -p ' + existingCertPath
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
try:
|
||||
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))
|
||||
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName + " and: www." + virtualHostName)
|
||||
|
||||
@@ -181,103 +187,46 @@ class sslUtilities:
|
||||
|
||||
try:
|
||||
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))
|
||||
logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName)
|
||||
except subprocess.CalledProcessError:
|
||||
logging.CyberCPLogFileWriter.writeToFile('Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName)
|
||||
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:
|
||||
|
||||
ipFile = "/etc/cyberpanel/machineIP"
|
||||
f = open(ipFile)
|
||||
ipData = f.read()
|
||||
serverIPAddress = ipData.split('\n', 1)[0]
|
||||
existingCertPath = '/etc/letsencrypt/live/' + virtualHostName
|
||||
if not os.path.exists(existingCertPath):
|
||||
command = 'mkdir -p ' + existingCertPath
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
ipRecords = sslUtilities.getDNSRecords(virtualHostName)
|
||||
|
||||
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:
|
||||
try:
|
||||
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
|
||||
|
||||
output = subprocess.check_output(shlex.split(command))
|
||||
##
|
||||
|
||||
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
|
||||
if output.find('Cert success') > -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [Failed to obtain SSL. [obtainSSLForADomain]]")
|
||||
|
||||
Reference in New Issue
Block a user