Bug fix to CLI and API.

This commit is contained in:
usmannasir
2018-06-11 21:04:55 +05:00
parent 4b13a92eb7
commit b30a1c56e5
7 changed files with 123 additions and 111 deletions

View File

@@ -68,24 +68,6 @@ def createWebsite(request):
externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7] externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7]
try:
website = Websites.objects.get(domain=domain)
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
'error_message': "Website Already Exists"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except:
pass
try:
website = ChildDomains.objects.get(domain=domain)
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
'error_message': "Website Already Exists"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except:
pass
phpSelection = "PHP 7.0" phpSelection = "PHP 7.0"
admin = Administrator.objects.get(userName=adminUser) admin = Administrator.objects.get(userName=adminUser)
@@ -109,40 +91,34 @@ def createWebsite(request):
except BaseException,msg: except BaseException,msg:
pass pass
## Create Configurations ## Create Configurations
numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count()) numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count())
sslpath = "/home/" + domain + "/public_html" sslpath = "/home/" + domain + "/public_html"
## Create Configurations
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " createVirtualHost --virtualHostName " + domain + " --administratorEmail " + adminEmail + " --phpVersion '" + phpSelection + "' --virtualHostUser " + externalApp + " --numberOfSites " + numberOfWebsites + " --ssl " + str( execPath = execPath + " createVirtualHost --virtualHostName " + domain + \
'0') + " --sslPath " + sslpath " --administratorEmail " + adminEmail + " --phpVersion '" + phpSelection + \
"' --virtualHostUser " + externalApp + " --numberOfSites " + numberOfWebsites + \
" --ssl " + str(data['ssl']) + " --sslPath " + sslpath + " --dkimCheck " + str(data['dkimCheck']) \
+ " --openBasedir " + str(data['openBasedir']) + ' --websiteOwner ' + websiteOwner \
+ ' --package ' + packageName
output = subprocess.check_output(shlex.split(execPath)) output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1: if output.find("1,None") > -1:
pass data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else: else:
data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0} data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
## Create Configurations ends here
selectedPackage = Package.objects.get(packageName=packageName)
websiteOwn = Administrator.objects.get(userName=websiteOwner)
website = Websites(admin=websiteOwn, package=selectedPackage, domain=domain, adminEmail=adminEmail,
phpSelection=phpSelection, ssl=0,externalApp=externalApp)
website.save()
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg: except BaseException, msg:
data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0} data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0}
@@ -248,39 +224,19 @@ def deleteWebsite(request):
## Deleting master domain ## Deleting master domain
website = Websites.objects.get(domain=websiteName)
websiteOwner = website.admin
if admin.websites_set.all().count() == 0:
websiteOwner.delete()
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName " + websiteName + " --numberOfSites " + numberOfWebsites execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName " + websiteName + \
" --numberOfSites " + numberOfWebsites
subprocess.check_output(shlex.split(execPath)) subprocess.check_output(shlex.split(execPath))
delWebsite = Websites.objects.get(domain=websiteName)
databases = Databases.objects.filter(website=delWebsite)
childDomains = delWebsite.childdomains_set.all()
## Deleting child domains
for items in childDomains:
numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count())
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName " + items.domain + " --numberOfSites " + numberOfWebsites
subprocess.check_output(shlex.split(execPath))
for items in databases:
mysqlUtilities.deleteDatabase(items.dbName, items.dbUser)
delWebsite.delete()
try:
delZone = Domains.objects.get(name=websiteName)
delZone.delete()
except:
pass
installUtilities.reStartLiteSpeed()
data_ret = {'websiteDeleteStatus': 1, 'error_message': "None"} data_ret = {'websiteDeleteStatus': 1, 'error_message': "None"}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)

View File

@@ -19,11 +19,6 @@ import requests
from baseTemplate.models import version from baseTemplate.models import version
from plogical.virtualHostUtilities import virtualHostUtilities from plogical.virtualHostUtilities import virtualHostUtilities
from random import randint from random import randint
from xml.etree.ElementTree import Element, SubElement
from xml.etree import ElementTree
from xml.dom import minidom
from dns.models import Domains,Records
from mailServer.models import Domains as eDomains
from plogical.mailUtilities import mailUtilities from plogical.mailUtilities import mailUtilities

View File

@@ -38,7 +38,7 @@ class cyberPanel:
def createWebsite(self, package, owner, domainName, email, php, ssl, dkim, openBasedir): def createWebsite(self, package, owner, domainName, email, php, ssl, dkim, openBasedir):
try: try:
externalApp = "".join(re.findall("[a-zA-Z]+", domainName))[:7] externalApp = "".join(re.findall("[a-zA-Z]+", domainName))[:7]
numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count()) numberOfWebsites = Websites.objects.count() + ChildDomains.objects.count()
sslpath = "/home/" + domainName + "/public_html" sslpath = "/home/" + domainName + "/public_html"
phpSelection = 'PHP ' + php phpSelection = 'PHP ' + php
@@ -821,17 +821,17 @@ def main():
return return
if args.ssl: if args.ssl:
ssl = args.ssl ssl = int(args.ssl)
else: else:
ssl = 0 ssl = 0
if args.dkim: if args.dkim:
dkim = args.dkim dkim = int(args.dkim)
else: else:
dkim = 0 dkim = 0
if args.openBasedir: if args.openBasedir:
openBasedir = args.openBasedir openBasedir = int(args.openBasedir)
else: else:
openBasedir = 0 openBasedir = 0
@@ -867,17 +867,17 @@ def main():
return return
if args.ssl: if args.ssl:
ssl = args.ssl ssl = int(args.ssl)
else: else:
ssl = 0 ssl = 0
if args.dkim: if args.dkim:
dkim = args.dkim dkim = int(args.dkim)
else: else:
dkim = 0 dkim = 0
if args.openBasedir: if args.openBasedir:
openBasedir = args.openBasedir openBasedir = int(args.openBasedir)
else: else:
openBasedir = 0 openBasedir = 0

View File

@@ -7,6 +7,8 @@ import os
import shlex import shlex
from firewallUtilities import FirewallUtilities from firewallUtilities import FirewallUtilities
import time import time
import string
import random
# There can not be peace without first a great suffering. # There can not be peace without first a great suffering.
@@ -961,7 +963,7 @@ class preFlightsChecks:
count = 0 count = 0
while(1): while(1):
command = 'wget https://files.phpmyadmin.net/phpMyAdmin/4.7.7/phpMyAdmin-4.7.7-all-languages.zip' command = 'wget https://files.phpmyadmin.net/phpMyAdmin/4.8.1/phpMyAdmin-4.8.1-all-languages.zip'
cmd = shlex.split(command) cmd = shlex.split(command)
res = subprocess.call(cmd) res = subprocess.call(cmd)
@@ -982,7 +984,7 @@ class preFlightsChecks:
count = 0 count = 0
while(1): while(1):
command = 'unzip phpMyAdmin-4.7.7-all-languages.zip' command = 'unzip phpMyAdmin-4.8.1-all-languages.zip'
cmd = shlex.split(command) cmd = shlex.split(command)
res = subprocess.call(cmd) res = subprocess.call(cmd)
@@ -1005,12 +1007,12 @@ class preFlightsChecks:
### ###
os.remove("phpMyAdmin-4.7.7-all-languages.zip") os.remove("phpMyAdmin-4.8.1-all-languages.zip")
count = 0 count = 0
while(1): while(1):
command = 'mv phpMyAdmin-4.7.7-all-languages phpmyadmin' command = 'mv phpMyAdmin-4.8.1-all-languages phpmyadmin'
cmd = shlex.split(command) cmd = shlex.split(command)
@@ -1033,6 +1035,31 @@ class preFlightsChecks:
"[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + "PHPMYAdmin Successfully installed!") "[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + "PHPMYAdmin Successfully installed!")
break break
## Write secret phrase
rString = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(32)])
data = open('phpmyadmin/config.sample.inc.php', 'r').readlines()
writeToFile = open('phpmyadmin/config.inc.php', 'w')
for items in data:
if items.find('blowfish_secret') > -1:
writeToFile.writelines("$cfg['blowfish_secret'] = '" + rString + "'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */\n")
else:
writeToFile.writelines(items)
writeToFile.writelines("$cfg['TempDir'] = '/usr/local/lscp/cyberpanel/phpmyadmin/tmp';\n")
writeToFile.close()
os.mkdir('/usr/local/lscp/cyberpanel/phpmyadmin/tmp')
command = 'chown -R nobody:nobody /usr/local/lscp/cyberpanel/phpmyadmin'
subprocess.call(shlex.split(command))
except OSError, msg: except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [download_install_phpmyadmin]") logging.InstallLog.writeToFile(str(msg) + " [download_install_phpmyadmin]")
return 0 return 0

View File

@@ -239,6 +239,41 @@ class DNS:
auth=1) auth=1)
record.save() record.save()
## TXT Records for mail
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="TXT",
content="v=spf1 a mx ip4:" + ipAddress + " ~all",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name="_dmarc." + topLevelDomain,
type="TXT",
content="v=DMARC1; p=none",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name="_domainkey." + topLevelDomain,
type="TXT",
content="t=y; o=~;",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## Creating sub-domain level record. ## Creating sub-domain level record.
zone = Domains.objects.get(name=topLevelDomain) zone = Domains.objects.get(name=topLevelDomain)
@@ -287,7 +322,7 @@ class DNS:
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile( logging.CyberCPLogFileWriter.writeToFile(
"We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg)) "We had errors while creating DKIM record for: " + domain + ". Error message: " + str(msg))
@staticmethod @staticmethod
def getZoneObject(virtualHostName): def getZoneObject(virtualHostName):
@@ -298,9 +333,23 @@ class DNS:
@staticmethod @staticmethod
def createDNSRecord(zone, name, type, value, priority, ttl): def createDNSRecord(zone, name, type, value, priority, ttl):
try:
if type == 'NS':
if Records.objects.filter(name=name, type=type, content=value).count() == 0:
record = Records(domainOwner=zone,
domain_id=zone.id,
name=name,
type=type,
content=value,
ttl=ttl,
prio=priority,
disabled=0,
auth=1)
record.save()
return
if type == 'NS':
if Records.objects.filter(name=name, type=type, content=value).count() == 0: if Records.objects.filter(name=name, type=type).count() == 0:
record = Records(domainOwner=zone, record = Records(domainOwner=zone,
domain_id=zone.id, domain_id=zone.id,
name=name, name=name,
@@ -311,20 +360,8 @@ class DNS:
disabled=0, disabled=0,
auth=1) auth=1)
record.save() record.save()
return except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDNSRecord]")
if Records.objects.filter(name=name, type=type).count() == 0:
record = Records(domainOwner=zone,
domain_id=zone.id,
name=name,
type=type,
content=value,
ttl=ttl,
prio=priority,
disabled=0,
auth=1)
record.save()
@staticmethod @staticmethod
def deleteDNSZone(virtualHostName): def deleteDNSZone(virtualHostName):

View File

@@ -133,6 +133,11 @@ class mailUtilities:
try: try:
## Generate DKIM Keys ## Generate DKIM Keys
import tldextract
extractDomain = tldextract.extract(virtualHostName)
virtualHostName = extractDomain.domain + '.' + extractDomain.suffix
if os.path.exists("/etc/opendkim/keys/" + virtualHostName): if os.path.exists("/etc/opendkim/keys/" + virtualHostName):
return 1, "None" return 1, "None"

View File

@@ -230,7 +230,6 @@ def submitWebsiteCreation(request):
if admin.type == 1: if admin.type == 1:
pass pass
else: else:
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0, data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
'error_message': "Only administrators are allowed to create websites."} 'error_message': "Only administrators are allowed to create websites."}
@@ -256,17 +255,13 @@ def submitWebsiteCreation(request):
output = subprocess.check_output(shlex.split(execPath)) output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1: if output.find("1,None") > -1:
pass data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else: else:
data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0} data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg: except BaseException, msg:
data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0} data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
@@ -317,17 +312,14 @@ def submitDomainCreation(request):
output = subprocess.check_output(shlex.split(execPath)) output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1: if output.find("1,None") > -1:
pass data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else: else:
data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0} data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg: except BaseException, msg:
data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0} data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)