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]
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"
admin = Administrator.objects.get(userName=adminUser)
@@ -109,40 +91,34 @@ def createWebsite(request):
except BaseException,msg:
pass
## Create Configurations
numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count())
sslpath = "/home/" + domain + "/public_html"
## Create Configurations
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " createVirtualHost --virtualHostName " + domain + " --administratorEmail " + adminEmail + " --phpVersion '" + phpSelection + "' --virtualHostUser " + externalApp + " --numberOfSites " + numberOfWebsites + " --ssl " + str(
'0') + " --sslPath " + sslpath
execPath = execPath + " createVirtualHost --virtualHostName " + domain + \
" --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))
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:
data_ret = {'createWebSiteStatus': 0, 'error_message': output, "existsStatus": 0}
json_data = json.dumps(data_ret)
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:
data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0}
@@ -248,39 +224,19 @@ def deleteWebsite(request):
## 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 = execPath + " deleteVirtualHostConfigurations --virtualHostName " + websiteName + " --numberOfSites " + numberOfWebsites
execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName " + websiteName + \
" --numberOfSites " + numberOfWebsites
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"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

View File

@@ -19,11 +19,6 @@ import requests
from baseTemplate.models import version
from plogical.virtualHostUtilities import virtualHostUtilities
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

View File

@@ -38,7 +38,7 @@ class cyberPanel:
def createWebsite(self, package, owner, domainName, email, php, ssl, dkim, openBasedir):
try:
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"
phpSelection = 'PHP ' + php
@@ -821,17 +821,17 @@ def main():
return
if args.ssl:
ssl = args.ssl
ssl = int(args.ssl)
else:
ssl = 0
if args.dkim:
dkim = args.dkim
dkim = int(args.dkim)
else:
dkim = 0
if args.openBasedir:
openBasedir = args.openBasedir
openBasedir = int(args.openBasedir)
else:
openBasedir = 0
@@ -867,17 +867,17 @@ def main():
return
if args.ssl:
ssl = args.ssl
ssl = int(args.ssl)
else:
ssl = 0
if args.dkim:
dkim = args.dkim
dkim = int(args.dkim)
else:
dkim = 0
if args.openBasedir:
openBasedir = args.openBasedir
openBasedir = int(args.openBasedir)
else:
openBasedir = 0

View File

@@ -7,6 +7,8 @@ import os
import shlex
from firewallUtilities import FirewallUtilities
import time
import string
import random
# There can not be peace without first a great suffering.
@@ -961,7 +963,7 @@ class preFlightsChecks:
count = 0
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)
res = subprocess.call(cmd)
@@ -982,7 +984,7 @@ class preFlightsChecks:
count = 0
while(1):
command = 'unzip phpMyAdmin-4.7.7-all-languages.zip'
command = 'unzip phpMyAdmin-4.8.1-all-languages.zip'
cmd = shlex.split(command)
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
while(1):
command = 'mv phpMyAdmin-4.7.7-all-languages phpmyadmin'
command = 'mv phpMyAdmin-4.8.1-all-languages phpmyadmin'
cmd = shlex.split(command)
@@ -1033,6 +1035,31 @@ class preFlightsChecks:
"[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + "PHPMYAdmin Successfully installed!")
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:
logging.InstallLog.writeToFile(str(msg) + " [download_install_phpmyadmin]")
return 0

View File

@@ -239,6 +239,41 @@ class DNS:
auth=1)
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.
zone = Domains.objects.get(name=topLevelDomain)
@@ -287,7 +322,7 @@ class DNS:
except BaseException, msg:
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
def getZoneObject(virtualHostName):
@@ -298,7 +333,7 @@ class DNS:
@staticmethod
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,
@@ -325,6 +360,8 @@ class DNS:
disabled=0,
auth=1)
record.save()
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDNSRecord]")
@staticmethod
def deleteDNSZone(virtualHostName):

View File

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

View File

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