mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
Initial Command Line Interface.
This commit is contained in:
0
cli/__init__.py
Normal file
0
cli/__init__.py
Normal file
28
cli/cliLogger.py
Normal file
28
cli/cliLogger.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
class cliLogger:
|
||||||
|
fileName = "/home/cyberpanel/error-logs.txt"
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def writeforCLI(message, level, method):
|
||||||
|
try:
|
||||||
|
file = open(cliLogger.fileName, 'a')
|
||||||
|
file.writelines("[" + time.strftime(
|
||||||
|
"%I-%M-%S-%a-%b-%Y") + "] [" + level + ":" + method + "] " + message + "\n")
|
||||||
|
file.close()
|
||||||
|
file.close()
|
||||||
|
except IOError:
|
||||||
|
return "Can not write to error file!"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def readLastNFiles(numberOfLines,fileName):
|
||||||
|
try:
|
||||||
|
|
||||||
|
lastFewLines = subprocess.check_output(["tail", "-n",str(numberOfLines),fileName])
|
||||||
|
|
||||||
|
return lastFewLines
|
||||||
|
|
||||||
|
except subprocess.CalledProcessError,msg:
|
||||||
|
return "File was empty"
|
||||||
123
cli/cyberPanel.py
Executable file
123
cli/cyberPanel.py
Executable file
@@ -0,0 +1,123 @@
|
|||||||
|
#!/usr/bin/env python2.7
|
||||||
|
import os,sys
|
||||||
|
sys.path.append('/usr/local/CyberCP')
|
||||||
|
import django
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
|
import argparse
|
||||||
|
from inspect import stack
|
||||||
|
from cliLogger import cliLogger as logger
|
||||||
|
import json
|
||||||
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||||
|
import re
|
||||||
|
from websiteFunctions.models import Websites, ChildDomains
|
||||||
|
from plogical.vhost import vhost
|
||||||
|
|
||||||
|
class cyberPanel:
|
||||||
|
def printStatus(self, operationStatus, errorMessage):
|
||||||
|
data = json.dumps({'success': operationStatus,
|
||||||
|
'errorMessage': errorMessage
|
||||||
|
})
|
||||||
|
|
||||||
|
print data
|
||||||
|
|
||||||
|
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())
|
||||||
|
sslpath = "/home/" + domainName + "/public_html"
|
||||||
|
phpSelection = 'PHP ' + php
|
||||||
|
|
||||||
|
result = virtualHostUtilities.createVirtualHost(domainName, email, phpSelection, externalApp, numberOfWebsites, ssl, sslpath, dkim,
|
||||||
|
openBasedir, owner, package)
|
||||||
|
|
||||||
|
if result[0] == 1:
|
||||||
|
self.printStatus(1,'None')
|
||||||
|
else:
|
||||||
|
self.printStatus(0, result[1])
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
logger.writeforCLI(str(msg), "Error", stack()[0][3])
|
||||||
|
self.printStatus(0, str(msg))
|
||||||
|
|
||||||
|
def deleteWebsite(self, domainName):
|
||||||
|
try:
|
||||||
|
|
||||||
|
numberOfWebsites = Websites.objects.count() + ChildDomains.objects.count()
|
||||||
|
vhost.deleteVirtualHostConfigurations(domainName, numberOfWebsites)
|
||||||
|
self.printStatus(1, 'None')
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
logger.writeforCLI(str(msg), "Error", stack()[0][3])
|
||||||
|
print 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='CyberPanel Command Line Interface!')
|
||||||
|
parser.add_argument('function', help='Specific a operation to perform!')
|
||||||
|
|
||||||
|
|
||||||
|
## Website creation arguemtns
|
||||||
|
parser.add_argument('--package', help='Select a package for website.')
|
||||||
|
parser.add_argument('--owner', help='Select a website owner.')
|
||||||
|
parser.add_argument('--domainName', help='Domain name!')
|
||||||
|
parser.add_argument('--email', help='Administrator email.')
|
||||||
|
parser.add_argument('--php', help='Administrator email.')
|
||||||
|
parser.add_argument('--ssl', help='Weather to obtain SSL.')
|
||||||
|
parser.add_argument('--dkim', help='DKIM Signing')
|
||||||
|
parser.add_argument('--openBasedir', help='To enable or disable open_basedir protection for domain.')
|
||||||
|
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.function == "createWebsite":
|
||||||
|
|
||||||
|
completeCommandExample = 'cyberpanel createWebsite --package Detault --owner admin --domainName cyberpanel.net --email support@cyberpanel.net --php 5.6'
|
||||||
|
|
||||||
|
if not args.package:
|
||||||
|
print "\n\nPlease enter the package name. For example:\n\n" + completeCommandExample + "\n\n"
|
||||||
|
|
||||||
|
if not args.owner:
|
||||||
|
print "\n\nPlease enter the owner name. For example:\n\n" + completeCommandExample + "\n\n"
|
||||||
|
|
||||||
|
if not args.domainName:
|
||||||
|
print "\n\nPlease enter the domain name. For example:\n\n" + completeCommandExample + "\n\n"
|
||||||
|
|
||||||
|
if not args.email:
|
||||||
|
print "\n\nPlease enter the email. For example:\n\n" + completeCommandExample + "\n\n"
|
||||||
|
|
||||||
|
if not args.php:
|
||||||
|
print "\n\nPlease enter the PHP version such as 5.6 for PHP version 5.6. For example:\n\n" + completeCommandExample + "\n\n"
|
||||||
|
|
||||||
|
if args.ssl:
|
||||||
|
ssl = args.ssl
|
||||||
|
else:
|
||||||
|
ssl = 0
|
||||||
|
|
||||||
|
if args.dkim:
|
||||||
|
dkim = args.dkim
|
||||||
|
else:
|
||||||
|
dkim = 0
|
||||||
|
|
||||||
|
if args.openBasedir:
|
||||||
|
openBasedir = args.openBasedir
|
||||||
|
else:
|
||||||
|
openBasedir = 0
|
||||||
|
|
||||||
|
cyberpanel = cyberPanel()
|
||||||
|
cyberpanel.createWebsite(args.package, args.owner, args.domainName, args.email, args.php, ssl, dkim, openBasedir)
|
||||||
|
elif args.function == "deleteWebsite":
|
||||||
|
|
||||||
|
completeCommandExample = 'cyberpanel deleteWebsite --domainName cyberpanel.net'
|
||||||
|
|
||||||
|
if not args.domainName:
|
||||||
|
print "\n\nPlease enter the domain to delete. For example:\n\n" + completeCommandExample + "\n\n"
|
||||||
|
return
|
||||||
|
|
||||||
|
cyberpanel = cyberPanel()
|
||||||
|
cyberpanel.deleteWebsite(args.domainName)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
20
dns/views.py
20
dns/views.py
@@ -593,26 +593,6 @@ def submitZoneDeletion(request):
|
|||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
def createDNSRecord(request, zone, name, type, value, priority, ttl):
|
|
||||||
try:
|
|
||||||
val = request.session['userID']
|
|
||||||
|
|
||||||
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()
|
|
||||||
except KeyError,msg:
|
|
||||||
final_dic = {'add_status': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
|
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2669,7 +2669,7 @@ def main():
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||||
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
|
parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.')
|
||||||
parser.add_argument('mysql', help='Specify number of MySQL instances to be used.')
|
parser.add_argument('--mysql', help='Specify number of MySQL instances to be used.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logging.InstallLog.writeToFile("Starting CyberPanel installation..")
|
logging.InstallLog.writeToFile("Starting CyberPanel installation..")
|
||||||
@@ -2687,6 +2687,11 @@ def main():
|
|||||||
|
|
||||||
checks = preFlightsChecks("/usr/local/lsws/",args.publicip,"/usr/local",cwd,"/usr/local/CyberCP")
|
checks = preFlightsChecks("/usr/local/lsws/",args.publicip,"/usr/local",cwd,"/usr/local/CyberCP")
|
||||||
|
|
||||||
|
try:
|
||||||
|
mysql = args.mysql
|
||||||
|
except:
|
||||||
|
mysql = 'One'
|
||||||
|
|
||||||
|
|
||||||
checks.checkPythonVersion()
|
checks.checkPythonVersion()
|
||||||
checks.setup_account_cyberpanel()
|
checks.setup_account_cyberpanel()
|
||||||
@@ -2706,12 +2711,12 @@ def main():
|
|||||||
|
|
||||||
import installCyberPanel
|
import installCyberPanel
|
||||||
|
|
||||||
installCyberPanel.Main(cwd, args.mysql)
|
installCyberPanel.Main(cwd, mysql)
|
||||||
checks.fix_selinux_issue()
|
checks.fix_selinux_issue()
|
||||||
checks.install_psmisc()
|
checks.install_psmisc()
|
||||||
checks.install_postfix_davecot()
|
checks.install_postfix_davecot()
|
||||||
checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, args.mysql)
|
checks.setup_email_Passwords(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql)
|
||||||
checks.setup_postfix_davecot_config(args.mysql)
|
checks.setup_postfix_davecot_config(mysql)
|
||||||
|
|
||||||
|
|
||||||
checks.install_unzip()
|
checks.install_unzip()
|
||||||
@@ -2731,7 +2736,7 @@ def main():
|
|||||||
|
|
||||||
checks.installCertBot()
|
checks.installCertBot()
|
||||||
checks.test_Requests()
|
checks.test_Requests()
|
||||||
checks.download_install_CyberPanel(installCyberPanel.InstallCyberPanel.mysqlPassword, args.mysql)
|
checks.download_install_CyberPanel(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql)
|
||||||
checks.setup_cron()
|
checks.setup_cron()
|
||||||
checks.installTLDExtract()
|
checks.installTLDExtract()
|
||||||
#checks.installdnsPython()
|
#checks.installdnsPython()
|
||||||
|
|||||||
@@ -14,6 +14,17 @@ class CyberCPLogFileWriter:
|
|||||||
except IOError,msg:
|
except IOError,msg:
|
||||||
return "Can not write to error file."
|
return "Can not write to error file."
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def writeforCLI(message, level, method):
|
||||||
|
try:
|
||||||
|
file = open(CyberCPLogFileWriter.fileName, 'a')
|
||||||
|
file.writelines("[" + time.strftime(
|
||||||
|
"%I-%M-%S-%a-%b-%Y") + "] [" + level + ":" + method + "] " + message + "\n")
|
||||||
|
file.close()
|
||||||
|
file.close()
|
||||||
|
except IOError:
|
||||||
|
return "Can not write to error file!"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def readLastNFiles(numberOfLines,fileName):
|
def readLastNFiles(numberOfLines,fileName):
|
||||||
try:
|
try:
|
||||||
|
|||||||
0
plogical/childDomain.py
Normal file
0
plogical/childDomain.py
Normal file
@@ -1,7 +1,14 @@
|
|||||||
|
#!/usr/bin/env python2.7
|
||||||
|
import os,sys
|
||||||
|
sys.path.append('/usr/local/CyberCP')
|
||||||
|
import django
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
|
django.setup()
|
||||||
import CyberCPLogFileWriter as logging
|
import CyberCPLogFileWriter as logging
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shlex
|
||||||
|
from dns.models import Domains,Records
|
||||||
|
|
||||||
|
|
||||||
class DNS:
|
class DNS:
|
||||||
|
|
||||||
@@ -9,373 +16,298 @@ class DNS:
|
|||||||
zones_base_dir = "/usr/local/lsws/conf/zones/"
|
zones_base_dir = "/usr/local/lsws/conf/zones/"
|
||||||
create_zone_dir = "/usr/local/lsws/conf/zones"
|
create_zone_dir = "/usr/local/lsws/conf/zones"
|
||||||
|
|
||||||
|
## DNS Functions
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createNameServer(virtualHostName, firstNS, firstNSIP, secondNS, secondNSIP):
|
def dnsTemplate(domain, admin):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if not os.path.exists(DNS.zones_base_dir):
|
ipFile = "/etc/cyberpanel/machineIP"
|
||||||
os.mkdir(DNS.create_zone_dir)
|
f = open(ipFile)
|
||||||
|
ipData = f.read()
|
||||||
|
ipAddress = ipData.split('\n', 1)[0]
|
||||||
|
|
||||||
zonePath = DNS.zones_base_dir + virtualHostName
|
import tldextract
|
||||||
zoneFilePath = zonePath + "/zone.conf"
|
|
||||||
|
|
||||||
|
extractDomain = tldextract.extract(domain)
|
||||||
|
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
||||||
|
subDomain = extractDomain.subdomain
|
||||||
|
|
||||||
|
if len(subDomain) == 0:
|
||||||
|
|
||||||
data = open(DNS.nsd_base, "r").readlines()
|
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
||||||
|
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
|
||||||
|
zone.save()
|
||||||
|
|
||||||
if DNS.checkIfZoneExists(virtualHostName, data) == 1:
|
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
|
||||||
|
|
||||||
os.mkdir(zonePath)
|
soaRecord = Records(domainOwner=zone,
|
||||||
zoneFileToWrite = open(zoneFilePath, "w")
|
domain_id=zone.id,
|
||||||
|
name=topLevelDomain,
|
||||||
|
type="SOA",
|
||||||
|
content=content,
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
soaRecord.save()
|
||||||
|
|
||||||
if DNS.addEntryInMainZone(virtualHostName, data) == 1:
|
## Main A record.
|
||||||
if DNS.perVirtualHostZoneFile(virtualHostName, zoneFileToWrite) == 1:
|
|
||||||
if DNS.addNSRecord(firstNS, firstNSIP, secondNS, secondNSIP, zoneFileToWrite) == 1:
|
|
||||||
DNS.restartNSD()
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
record = Records(domainOwner=zone,
|
||||||
|
domain_id=zone.id,
|
||||||
|
name=topLevelDomain,
|
||||||
|
type="A",
|
||||||
|
content=ipAddress,
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
# CNAME Records.
|
||||||
|
|
||||||
|
cNameValue = "www." + topLevelDomain
|
||||||
|
|
||||||
|
record = Records(domainOwner=zone,
|
||||||
|
domain_id=zone.id,
|
||||||
|
name=cNameValue,
|
||||||
|
type="CNAME",
|
||||||
|
content=topLevelDomain,
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
cNameValue = "ftp." + topLevelDomain
|
||||||
|
|
||||||
|
record = Records(domainOwner=zone,
|
||||||
|
domain_id=zone.id,
|
||||||
|
name=cNameValue,
|
||||||
|
type="CNAME",
|
||||||
|
content=topLevelDomain,
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
## MX Record.
|
||||||
|
|
||||||
|
mxValue = "mail." + topLevelDomain
|
||||||
|
|
||||||
|
record = Records(domainOwner=zone,
|
||||||
|
domain_id=zone.id,
|
||||||
|
name=topLevelDomain,
|
||||||
|
type="MX",
|
||||||
|
content=mxValue,
|
||||||
|
ttl=3600,
|
||||||
|
prio="10",
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
record = Records(domainOwner=zone,
|
||||||
|
domain_id=zone.id,
|
||||||
|
name=mxValue,
|
||||||
|
type="A",
|
||||||
|
content=ipAddress,
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
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()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(zonePath):
|
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
||||||
os.mkdir(zonePath)
|
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
|
||||||
zoneFileToWrite = open(zoneFilePath, "w")
|
zone.save()
|
||||||
|
|
||||||
|
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
|
||||||
|
|
||||||
if DNS.perVirtualHostZoneFile(virtualHostName, zoneFileToWrite) == 1:
|
soaRecord = Records(domainOwner=zone,
|
||||||
if DNS.addNSRecord(firstNS, firstNSIP, secondNS, secondNSIP, zoneFileToWrite) == 1:
|
domain_id=zone.id,
|
||||||
DNS.restartNSD()
|
name=topLevelDomain,
|
||||||
zoneFileToWrite.close()
|
type="SOA",
|
||||||
return 1
|
content=content,
|
||||||
else:
|
ttl=3600,
|
||||||
zoneFileToWrite.close()
|
prio=0,
|
||||||
return 0
|
disabled=0,
|
||||||
else:
|
auth=1)
|
||||||
zoneFileToWrite.close()
|
soaRecord.save()
|
||||||
return 0
|
|
||||||
|
|
||||||
else:
|
## Main A record.
|
||||||
|
|
||||||
zoneFileToWrite = open(zoneFilePath, "a")
|
record = Records(domainOwner=zone,
|
||||||
if DNS.addNSRecord(firstNS, firstNSIP, secondNS, secondNSIP, zoneFileToWrite) == 1:
|
domain_id=zone.id,
|
||||||
DNS.restartNSD()
|
name=topLevelDomain,
|
||||||
zoneFileToWrite.close()
|
type="A",
|
||||||
return 1
|
content=ipAddress,
|
||||||
else:
|
ttl=3600,
|
||||||
zoneFileToWrite.close()
|
prio=0,
|
||||||
return 0
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
zoneFileToWrite.close()
|
# CNAME Records.
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
"Zone file for virtualhost already exists. " + "[createNameServer]")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
except IOError, msg:
|
cNameValue = "www." + topLevelDomain
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [addEntryInMainZone]")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@staticmethod
|
record = Records(domainOwner=zone,
|
||||||
def checkIfZoneExists(virtualHostName,data):
|
domain_id=zone.id,
|
||||||
for items in data:
|
name=cNameValue,
|
||||||
if items.find(virtualHostName) > -1:
|
type="CNAME",
|
||||||
return 0
|
content=topLevelDomain,
|
||||||
return 1
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
cNameValue = "ftp." + topLevelDomain
|
||||||
|
|
||||||
@staticmethod
|
record = Records(domainOwner=zone,
|
||||||
def addEntryInMainZone(virtualHostName,data):
|
domain_id=zone.id,
|
||||||
|
name=cNameValue,
|
||||||
|
type="CNAME",
|
||||||
|
content=topLevelDomain,
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
# Defining zone to be added
|
## MX Record.
|
||||||
zone = "zone:" + "\n"
|
|
||||||
zoneName = " name: " + virtualHostName + "\n"
|
|
||||||
zoneFile = " zonefile: "+virtualHostName+"/zone.conf" + "\n"
|
|
||||||
|
|
||||||
|
mxValue = "mail." + topLevelDomain
|
||||||
|
|
||||||
try:
|
record = Records(domainOwner=zone,
|
||||||
mainZoneFile = open(DNS.nsd_base,"w")
|
domain_id=zone.id,
|
||||||
zoneCheck = 1
|
name=topLevelDomain,
|
||||||
noZones = 1
|
type="MX",
|
||||||
|
content=mxValue,
|
||||||
|
ttl=3600,
|
||||||
|
prio="10",
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
for items in data:
|
record = Records(domainOwner=zone,
|
||||||
if items.find("zone:")>-1 and zoneCheck==1:
|
domain_id=zone.id,
|
||||||
mainZoneFile.writelines(zone)
|
name=mxValue,
|
||||||
mainZoneFile.writelines(zoneName)
|
type="A",
|
||||||
mainZoneFile.writelines(zoneFile)
|
content=ipAddress,
|
||||||
mainZoneFile.writelines("\n")
|
ttl=3600,
|
||||||
mainZoneFile.writelines(items)
|
prio=0,
|
||||||
noZones = 0
|
disabled=0,
|
||||||
zoneCheck = 0
|
auth=1)
|
||||||
else:
|
record.save()
|
||||||
mainZoneFile.writelines(items)
|
|
||||||
|
|
||||||
if noZones ==1:
|
## Creating sub-domain level record.
|
||||||
mainZoneFile.writelines(zone)
|
|
||||||
mainZoneFile.writelines(zoneName)
|
|
||||||
mainZoneFile.writelines(zoneFile)
|
|
||||||
mainZoneFile.writelines("\n")
|
|
||||||
|
|
||||||
mainZoneFile.close()
|
zone = Domains.objects.get(name=topLevelDomain)
|
||||||
return 1
|
|
||||||
except IOError,msg:
|
|
||||||
mainZoneFile.close()
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [addEntryInMainZone]")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@staticmethod
|
actualSubDomain = subDomain + "." + topLevelDomain
|
||||||
def perVirtualHostZoneFile(virtualHostName, zoneFileToWrite):
|
|
||||||
|
|
||||||
# Make zone directory
|
## Main A record.
|
||||||
|
|
||||||
origin = "$ORIGIN " + virtualHostName + "." + "\n"
|
DNS.createDNSRecord(zone, actualSubDomain, "A", ipAddress, 0, 3600)
|
||||||
ttl = "$TTL 86400" + "\n"
|
|
||||||
|
|
||||||
try:
|
# CNAME Records.
|
||||||
zoneFileToWrite.writelines(origin)
|
|
||||||
zoneFileToWrite.writelines(ttl)
|
|
||||||
zoneFileToWrite.writelines("\n")
|
|
||||||
|
|
||||||
# Create SOA Record
|
cNameValue = "www." + actualSubDomain
|
||||||
|
|
||||||
DNS.createSOARecord(virtualHostName, zoneFileToWrite)
|
|
||||||
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
DNS.createDNSRecord(zone, cNameValue, "CNAME", actualSubDomain, 0, 3600)
|
||||||
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [perVirtualHostZoneFile]")
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
return 0
|
"We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createSOARecord(virtualHostName,fileHandle):
|
def createDKIMRecords(domain):
|
||||||
|
|
||||||
# Define SOA Record
|
|
||||||
|
|
||||||
soa = "@ IN SOA ns1 admin@"+virtualHostName+" (" + "\n"
|
|
||||||
serialNumber = " 2012082703" + "\n"
|
|
||||||
refreshRate = " 28800" + "\n"
|
|
||||||
retryRate = " 1400" + "\n"
|
|
||||||
expiry = " 864000" + "\n"
|
|
||||||
minTTL = " 86400" + "\n"
|
|
||||||
endSOA = " )" + "\n"
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fileHandle.writelines("\n")
|
|
||||||
|
|
||||||
fileHandle.writelines(soa)
|
import tldextract
|
||||||
fileHandle.writelines(serialNumber)
|
|
||||||
fileHandle.writelines(refreshRate)
|
|
||||||
fileHandle.writelines(retryRate)
|
|
||||||
fileHandle.writelines(expiry)
|
|
||||||
fileHandle.writelines(minTTL)
|
|
||||||
fileHandle.writelines(endSOA)
|
|
||||||
|
|
||||||
|
extractDomain = tldextract.extract(domain)
|
||||||
|
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
||||||
|
|
||||||
fileHandle.writelines("\n")
|
zone = Domains.objects.get(name=topLevelDomain)
|
||||||
|
|
||||||
|
path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt"
|
||||||
|
command = "sudo cat " + path
|
||||||
|
output = subprocess.check_output(shlex.split(command))
|
||||||
|
|
||||||
return 1
|
record = Records(domainOwner=zone,
|
||||||
except IOError,msg:
|
domain_id=zone.id,
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createSOARecord]")
|
name="default._domainkey." + topLevelDomain,
|
||||||
return 0
|
type="TXT",
|
||||||
|
content="v=DKIM1; k=rsa; p=" + output[53:269],
|
||||||
|
ttl=3600,
|
||||||
|
prio=0,
|
||||||
|
disabled=0,
|
||||||
|
auth=1)
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
|
"We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addNSRecord(nsRecordOne,firstNSIP, nsRecordTwo, secondNSIP, fileHandle):
|
def createDNSRecord(zone, name, type, value, priority, ttl):
|
||||||
# Defining NS Record
|
if Records.objects.filter(name=name, type=type).count() == 0:
|
||||||
|
record = Records(domainOwner=zone,
|
||||||
NSARecordOne = nsRecordOne.split(".")[0]
|
domain_id=zone.id,
|
||||||
NSARecordTwo = nsRecordTwo.split(".")[0]
|
name=name,
|
||||||
|
type=type,
|
||||||
NS1 = "\t\t" + "NS" + "\t" + nsRecordOne + "." "\n"
|
content=value,
|
||||||
NS2 = "\t\t" + "NS" + "\t" + nsRecordTwo + "."
|
ttl=ttl,
|
||||||
|
prio=priority,
|
||||||
try:
|
disabled=0,
|
||||||
fileHandle.writelines("\n")
|
auth=1)
|
||||||
fileHandle.writelines("\n")
|
record.save()
|
||||||
|
|
||||||
fileHandle.writelines(NS1)
|
|
||||||
fileHandle.writelines(NS2)
|
|
||||||
|
|
||||||
DNS.addRecord(NSARecordOne, "A", firstNSIP, fileHandle)
|
|
||||||
DNS.addRecord(NSARecordTwo, "A", secondNSIP, fileHandle)
|
|
||||||
|
|
||||||
fileHandle.writelines("\n")
|
|
||||||
return 1
|
|
||||||
except IOError, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [addRecord]")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addRecord(recordValue, recordType, recordIP, fileHandle):
|
def deleteDNSZone(virtualHostName):
|
||||||
|
|
||||||
# Define Record
|
|
||||||
|
|
||||||
recordString = recordValue +"\t" + "IN" + "\t" + recordType + "\t" + recordIP
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fileHandle.writelines("\n")
|
delZone = Domains.objects.get(name=virtualHostName)
|
||||||
fileHandle.writelines(recordString)
|
delZone.delete()
|
||||||
fileHandle.writelines("\n")
|
|
||||||
return 1
|
|
||||||
except IOError, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [addRecord]")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def restartNSD():
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
############## Restart NSD ######################
|
|
||||||
|
|
||||||
cmd = []
|
|
||||||
|
|
||||||
cmd.append("systemctl")
|
|
||||||
cmd.append("restart")
|
|
||||||
cmd.append("nsd")
|
|
||||||
|
|
||||||
res = subprocess.call(cmd)
|
|
||||||
|
|
||||||
if res == 1:
|
|
||||||
print("###############################################")
|
|
||||||
print(" Could restart NSD ")
|
|
||||||
print("###############################################")
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile("[Failed to restart NSD]")
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
print("###############################################")
|
|
||||||
print(" NSD Restarted ")
|
|
||||||
print("###############################################")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
except OSError, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [restartNSD]")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def deleteZone(virtualHostname):
|
|
||||||
try:
|
|
||||||
if os.path.exists(DNS.zones_base_dir+virtualHostname):
|
|
||||||
shutil.rmtree(DNS.zones_base_dir+virtualHostname)
|
|
||||||
|
|
||||||
data = open(DNS.nsd_base, "r").readlines()
|
|
||||||
|
|
||||||
writeDataToFile = open(DNS.nsd_base,"w")
|
|
||||||
|
|
||||||
index = 0
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
if items.find(virtualHostname) >-1:
|
|
||||||
try:
|
|
||||||
del data[index-1]
|
|
||||||
del data[index-1]
|
|
||||||
del data[index-1]
|
|
||||||
except:
|
except:
|
||||||
break
|
## There does not exist a zone for this domain.
|
||||||
break
|
pass
|
||||||
index = index+1
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
writeDataToFile.writelines(items)
|
|
||||||
|
|
||||||
writeDataToFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except OSError,msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [deleteZone]")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def addARecord(virtualHostName,recordValue,recordIP):
|
|
||||||
try:
|
|
||||||
|
|
||||||
if not os.path.exists(DNS.zones_base_dir):
|
|
||||||
os.mkdir(DNS.create_zone_dir)
|
|
||||||
|
|
||||||
data = open(DNS.nsd_base, "r").readlines()
|
|
||||||
|
|
||||||
zonePath = DNS.zones_base_dir + virtualHostName
|
|
||||||
zoneFilePath = zonePath + "/zone.conf"
|
|
||||||
|
|
||||||
if DNS.checkIfZoneExists(virtualHostName,data) == 1:
|
|
||||||
|
|
||||||
DNS.addEntryInMainZone(virtualHostName,data)
|
|
||||||
|
|
||||||
os.mkdir(zonePath)
|
|
||||||
zoneFileToWrite = open(zoneFilePath, "w")
|
|
||||||
|
|
||||||
DNS.perVirtualHostZoneFile(virtualHostName, zoneFileToWrite)
|
|
||||||
DNS.addRecord(recordValue,"A",recordIP,zoneFileToWrite)
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
if not os.path.exists(zonePath):
|
|
||||||
os.mkdir(zonePath)
|
|
||||||
zoneFileToWrite = open(zoneFilePath, "w")
|
|
||||||
|
|
||||||
|
|
||||||
if DNS.perVirtualHostZoneFile(virtualHostName, zoneFileToWrite) == 1:
|
|
||||||
if DNS.addRecord(recordValue,"A",recordIP,zoneFileToWrite) == 1:
|
|
||||||
DNS.restartNSD()
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
zoneFileToWrite = open(zoneFilePath, "a")
|
|
||||||
if DNS.addRecord(recordValue,"A",recordIP,zoneFileToWrite) == 1:
|
|
||||||
DNS.restartNSD()
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
zoneFileToWrite.close()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except BaseException,msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [addARecord]')
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def deleteRecord(recordValue, recordType, recordIP, virtualHostName):
|
|
||||||
|
|
||||||
try:
|
|
||||||
zonePath = DNS.zones_base_dir + virtualHostName
|
|
||||||
zoneFilePath = zonePath + "/zone.conf"
|
|
||||||
|
|
||||||
data = open(zoneFilePath, "r").readlines()
|
|
||||||
|
|
||||||
writeDataToFile = open(zoneFilePath, "w")
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
if items.find(recordIP) > -1 and items.find(recordValue) > -1 and items.find(recordType)>-1:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
writeDataToFile.writelines(items)
|
|
||||||
|
|
||||||
writeDataToFile.close()
|
|
||||||
|
|
||||||
return 1
|
|
||||||
except IOError, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [addRecord]")
|
|
||||||
return 0
|
|
||||||
@@ -143,7 +143,7 @@ class installUtilities:
|
|||||||
|
|
||||||
cmd = shlex.split(command)
|
cmd = shlex.split(command)
|
||||||
|
|
||||||
res = subprocess.call(cmd)
|
res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
if res == 1:
|
if res == 1:
|
||||||
print("###############################################")
|
print("###############################################")
|
||||||
|
|||||||
1069
plogical/vhost.py
Normal file
1069
plogical/vhost.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,6 @@ from random import randint
|
|||||||
import hashlib
|
import hashlib
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
from plogical.mailUtilities import mailUtilities
|
from plogical.mailUtilities import mailUtilities
|
||||||
from dns.views import createDNSRecord
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
@@ -170,248 +169,6 @@ def deleteWebsite(request):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def dnsTemplate(request, domain, admin):
|
|
||||||
try:
|
|
||||||
|
|
||||||
ipFile = "/etc/cyberpanel/machineIP"
|
|
||||||
f = open(ipFile)
|
|
||||||
ipData = f.read()
|
|
||||||
ipAddress = ipData.split('\n', 1)[0]
|
|
||||||
|
|
||||||
import tldextract
|
|
||||||
|
|
||||||
extractDomain = tldextract.extract(domain)
|
|
||||||
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
|
||||||
subDomain = extractDomain.subdomain
|
|
||||||
|
|
||||||
if len(subDomain) == 0:
|
|
||||||
|
|
||||||
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
|
||||||
|
|
||||||
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
|
|
||||||
zone.save()
|
|
||||||
|
|
||||||
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
|
|
||||||
|
|
||||||
soaRecord = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=topLevelDomain,
|
|
||||||
type="SOA",
|
|
||||||
content=content,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
soaRecord.save()
|
|
||||||
|
|
||||||
## Main A record.
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=topLevelDomain,
|
|
||||||
type="A",
|
|
||||||
content=ipAddress,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
# CNAME Records.
|
|
||||||
|
|
||||||
cNameValue = "www." + topLevelDomain
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=cNameValue,
|
|
||||||
type="CNAME",
|
|
||||||
content=topLevelDomain,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
cNameValue = "ftp." + topLevelDomain
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=cNameValue,
|
|
||||||
type="CNAME",
|
|
||||||
content=topLevelDomain,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
## MX Record.
|
|
||||||
|
|
||||||
mxValue = "mail." + topLevelDomain
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=topLevelDomain,
|
|
||||||
type="MX",
|
|
||||||
content=mxValue,
|
|
||||||
ttl=3600,
|
|
||||||
prio="10",
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=mxValue,
|
|
||||||
type="A",
|
|
||||||
content=ipAddress,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
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()
|
|
||||||
|
|
||||||
else:
|
|
||||||
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
|
||||||
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
|
|
||||||
zone.save()
|
|
||||||
|
|
||||||
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
|
|
||||||
|
|
||||||
soaRecord = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=topLevelDomain,
|
|
||||||
type="SOA",
|
|
||||||
content=content,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
soaRecord.save()
|
|
||||||
|
|
||||||
## Main A record.
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=topLevelDomain,
|
|
||||||
type="A",
|
|
||||||
content=ipAddress,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
# CNAME Records.
|
|
||||||
|
|
||||||
cNameValue = "www." + topLevelDomain
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=cNameValue,
|
|
||||||
type="CNAME",
|
|
||||||
content=topLevelDomain,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
cNameValue = "ftp." + topLevelDomain
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=cNameValue,
|
|
||||||
type="CNAME",
|
|
||||||
content=topLevelDomain,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
## MX Record.
|
|
||||||
|
|
||||||
mxValue = "mail." + topLevelDomain
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=topLevelDomain,
|
|
||||||
type="MX",
|
|
||||||
content=mxValue,
|
|
||||||
ttl=3600,
|
|
||||||
prio="10",
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
record = Records(domainOwner=zone,
|
|
||||||
domain_id=zone.id,
|
|
||||||
name=mxValue,
|
|
||||||
type="A",
|
|
||||||
content=ipAddress,
|
|
||||||
ttl=3600,
|
|
||||||
prio=0,
|
|
||||||
disabled=0,
|
|
||||||
auth=1)
|
|
||||||
record.save()
|
|
||||||
|
|
||||||
## Creating sub-domain level record.
|
|
||||||
|
|
||||||
zone = Domains.objects.get(name=topLevelDomain)
|
|
||||||
|
|
||||||
actualSubDomain = subDomain + "." + topLevelDomain
|
|
||||||
|
|
||||||
|
|
||||||
## Main A record.
|
|
||||||
|
|
||||||
createDNSRecord(request, zone, actualSubDomain, "A", ipAddress, 0, 3600)
|
|
||||||
|
|
||||||
# CNAME Records.
|
|
||||||
|
|
||||||
cNameValue = "www." + actualSubDomain
|
|
||||||
|
|
||||||
createDNSRecord(request, zone, cNameValue, "CNAME", actualSubDomain, 0, 3600)
|
|
||||||
|
|
||||||
except BaseException, msg:
|
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
|
||||||
"We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
|
|
||||||
|
|
||||||
def createDKIMRecords(request, domain, admin):
|
def createDKIMRecords(request, domain, admin):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
@@ -495,19 +252,6 @@ def submitWebsiteCreation(request):
|
|||||||
externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7]
|
externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7]
|
||||||
|
|
||||||
|
|
||||||
if Websites.objects.filter(domain=domain).count() > 0:
|
|
||||||
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
|
|
||||||
'error_message': "This website already exists."}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
if ChildDomains.objects.filter(domain=domain).count() > 0:
|
|
||||||
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
|
|
||||||
'error_message': "This website already exists as child domain."}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
####### Limitations check
|
####### Limitations check
|
||||||
|
|
||||||
admin = Administrator.objects.get(userName=websiteOwner)
|
admin = Administrator.objects.get(userName=websiteOwner)
|
||||||
@@ -523,12 +267,6 @@ def submitWebsiteCreation(request):
|
|||||||
|
|
||||||
####### Limitations Check End
|
####### Limitations Check End
|
||||||
|
|
||||||
##### Zone creation
|
|
||||||
|
|
||||||
dnsTemplate(requests, domain, admin)
|
|
||||||
|
|
||||||
## zone creation
|
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
@@ -536,9 +274,12 @@ def submitWebsiteCreation(request):
|
|||||||
|
|
||||||
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 + \
|
||||||
data['ssl']) + " --sslPath " + sslpath + " --dkimCheck " + str(data['dkimCheck']) + " --openBasedir " + str(data['openBasedir'])
|
" --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))
|
||||||
|
|
||||||
@@ -549,18 +290,6 @@ def submitWebsiteCreation(request):
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
## Create Configurations ends here
|
|
||||||
|
|
||||||
## DKIM Check
|
|
||||||
|
|
||||||
if data['dkimCheck'] == 1:
|
|
||||||
createDKIMRecords(request, domain, admin)
|
|
||||||
|
|
||||||
selectedPackage = Package.objects.get(packageName=packageName)
|
|
||||||
|
|
||||||
website = Websites(admin=admin, package=selectedPackage, domain=domain, adminEmail=adminEmail,phpSelection=phpSelection, ssl=data['ssl'], externalApp=externalApp)
|
|
||||||
|
|
||||||
website.save()
|
|
||||||
|
|
||||||
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
|
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -579,71 +308,45 @@ def submitDomainCreation(request):
|
|||||||
masterDomain = data['masterDomain']
|
masterDomain = data['masterDomain']
|
||||||
domain = data['domainName']
|
domain = data['domainName']
|
||||||
phpSelection = data['phpSelection']
|
phpSelection = data['phpSelection']
|
||||||
|
|
||||||
|
|
||||||
## Check if this domain either exists as website or child domain
|
|
||||||
|
|
||||||
if Websites.objects.filter(domain=domain).count() > 0:
|
|
||||||
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
|
|
||||||
'error_message': "This Domain already exists as a website."}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
if ChildDomains.objects.filter(domain=domain).count() > 0:
|
|
||||||
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
|
|
||||||
'error_message': "This domain already exists as child domain."}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
####### Limitations check
|
|
||||||
|
|
||||||
master = Websites.objects.get(domain=masterDomain)
|
|
||||||
domainsInPackage = master.package.allowedDomains
|
|
||||||
|
|
||||||
if domainsInPackage == 0:
|
|
||||||
pass
|
|
||||||
elif domainsInPackage > master.childdomains_set.all().count():
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
data_ret = {"existsStatus": 0, 'createWebSiteStatus': 0,
|
|
||||||
'error_message': "Exceeded maximum number of domains for this package"}
|
|
||||||
json_data = json.dumps(data_ret)
|
|
||||||
return HttpResponse(json_data)
|
|
||||||
|
|
||||||
####### Limitations Check End
|
|
||||||
|
|
||||||
ssl = data['ssl']
|
|
||||||
path = data['path']
|
path = data['path']
|
||||||
|
|
||||||
restart = 1
|
|
||||||
|
|
||||||
## Create Configurations
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
restore = data['restore']
|
restore = data['restore']
|
||||||
restart = 0
|
restore = '1'
|
||||||
except:
|
|
||||||
if len(path) > 0:
|
if len(path) > 0:
|
||||||
path = path.lstrip("/")
|
path = path.lstrip("/")
|
||||||
path = "/home/" + masterDomain + "/public_html/" + path
|
path = "/home/" + masterDomain + "/public_html/" + path
|
||||||
else:
|
else:
|
||||||
path = "/home/" + masterDomain + "/public_html/" + domain
|
path = "/home/" + masterDomain + "/public_html/" + domain
|
||||||
|
|
||||||
### Zone creation.
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
||||||
|
|
||||||
|
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + \
|
||||||
|
" --phpVersion '" + phpSelection + "' --ssl " + str(data['ssl']) + " --dkimCheck " + \
|
||||||
|
str(data['dkimCheck']) + " --openBasedir " + str(data['openBasedir']) + ' --path ' + path \
|
||||||
|
+ ' --restore ' + restore
|
||||||
|
|
||||||
|
except:
|
||||||
|
restore = '0'
|
||||||
|
|
||||||
|
if len(path) > 0:
|
||||||
|
path = path.lstrip("/")
|
||||||
|
path = "/home/" + masterDomain + "/public_html/" + path
|
||||||
|
else:
|
||||||
|
path = "/home/" + masterDomain + "/public_html/" + domain
|
||||||
|
|
||||||
val = request.session['userID']
|
val = request.session['userID']
|
||||||
admin = Administrator.objects.get(pk=val)
|
admin = Administrator.objects.get(pk=val)
|
||||||
dnsTemplate(requests, domain, admin)
|
|
||||||
|
|
||||||
|
|
||||||
externalApp = master.externalApp
|
|
||||||
numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count())
|
|
||||||
|
|
||||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
||||||
|
|
||||||
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + " --administratorEmail " + master.adminEmail + " --phpVersion '" + phpSelection + "' --virtualHostUser " + externalApp + " --numberOfSites " + numberOfWebsites + " --ssl " + str(
|
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + \
|
||||||
data['ssl']) + " --path " + path + " --dkimCheck " + str(data['dkimCheck']) + " --openBasedir " + str(data['openBasedir'])
|
" --phpVersion '" + phpSelection + "' --ssl " + str(data['ssl']) + " --dkimCheck " + str(data['dkimCheck']) \
|
||||||
|
+ " --openBasedir " + str(data['openBasedir']) + ' --path ' + path \
|
||||||
|
+ ' --restore ' + restore + ' --websiteOwner ' + admin.userName
|
||||||
|
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(execPath))
|
output = subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
@@ -654,21 +357,6 @@ def submitDomainCreation(request):
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
## Create Configurations ends here
|
|
||||||
|
|
||||||
## DKIM Check
|
|
||||||
|
|
||||||
try:
|
|
||||||
restore = data['restore']
|
|
||||||
restart = 0
|
|
||||||
except BaseException, msg:
|
|
||||||
if data['dkimCheck'] == 1:
|
|
||||||
admin = Administrator.objects.get(pk=val)
|
|
||||||
createDKIMRecords(request, domain, admin)
|
|
||||||
|
|
||||||
website = ChildDomains(master=master, domain=domain, path=path, phpSelection=phpSelection, ssl=ssl)
|
|
||||||
|
|
||||||
website.save()
|
|
||||||
|
|
||||||
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
|
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -850,41 +538,6 @@ def submitWebsiteDeletion(request):
|
|||||||
|
|
||||||
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:
|
|
||||||
## There does not exist a zone for this domain.
|
|
||||||
pass
|
|
||||||
|
|
||||||
installUtilities.reStartLiteSpeed()
|
|
||||||
|
|
||||||
## Delete mail accounts
|
|
||||||
|
|
||||||
command = "sudo rm -rf /home/vmail/" + websiteName
|
|
||||||
subprocess.call(shlex.split(command))
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -909,25 +562,12 @@ def submitDomainDeletion(request):
|
|||||||
data = json.loads(request.body)
|
data = json.loads(request.body)
|
||||||
websiteName = data['websiteName']
|
websiteName = data['websiteName']
|
||||||
|
|
||||||
numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count())
|
|
||||||
|
|
||||||
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 + " deleteDomain --virtualHostName " + websiteName
|
||||||
|
|
||||||
subprocess.check_output(shlex.split(execPath))
|
subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
|
|
||||||
delWebsite = ChildDomains.objects.get(domain=websiteName)
|
|
||||||
|
|
||||||
delWebsite.delete()
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -2718,14 +2358,6 @@ def submitAliasCreation(request):
|
|||||||
|
|
||||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||||
|
|
||||||
##### Zone creation
|
|
||||||
|
|
||||||
dnsTemplate(requests, aliasDomain, admin)
|
|
||||||
|
|
||||||
### Zone creation
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sslpath = "/home/" + masterDomain + "/public_html"
|
sslpath = "/home/" + masterDomain + "/public_html"
|
||||||
|
|
||||||
## Create Configurations
|
## Create Configurations
|
||||||
@@ -2733,7 +2365,7 @@ def submitAliasCreation(request):
|
|||||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
||||||
|
|
||||||
execPath = execPath + " createAlias --masterDomain " + masterDomain + " --aliasDomain " + aliasDomain + " --ssl " + str(
|
execPath = execPath + " createAlias --masterDomain " + masterDomain + " --aliasDomain " + aliasDomain + " --ssl " + str(
|
||||||
ssl) + " --sslPath " + sslpath + " --administratorEmail " + admin.email
|
ssl) + " --sslPath " + sslpath + " --administratorEmail " + admin.email + ' --websiteOwner ' + admin.userName
|
||||||
|
|
||||||
output = subprocess.check_output(shlex.split(execPath))
|
output = subprocess.check_output(shlex.split(execPath))
|
||||||
|
|
||||||
@@ -2746,8 +2378,6 @@ def submitAliasCreation(request):
|
|||||||
|
|
||||||
## Create Configurations ends here
|
## Create Configurations ends here
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_ret = {'createAliasStatus': 1, 'error_message': "None", "existsStatus": 0}
|
data_ret = {'createAliasStatus': 1, 'error_message': "None", "existsStatus": 0}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user