DNS Records improvements while creating Websites/Child domains.

This commit is contained in:
usmannasir
2018-04-20 23:49:49 +05:00
parent 2533721602
commit 0ddac1e80c
5 changed files with 561 additions and 50 deletions

View File

@@ -18,7 +18,7 @@
<!-- Angular JS -->
<script src="https://cdn.jsdelivr.net/npm/angular@1.6.6/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
<script src="{% static 'filemanager/js/fileManager.js' %}"></script>
<!-- Fix for old browsers -->

View File

@@ -14,8 +14,8 @@
<file leaf-file-name="fileManager.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/php/fileManager.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="455">
<caret line="26" column="41" lean-forward="true" selection-start-line="0" selection-start-column="0" selection-end-line="652" selection-end-column="26" />
<state relative-caret-position="329">
<caret line="19" column="0" lean-forward="true" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<folding>
<element signature="n#listForTable#0;n#fileManager#0;n#!!top" expanded="false" />
<element signature="n#readFileContents#0;n#fileManager#0;n#!!top" expanded="false" />
@@ -163,18 +163,17 @@
<workItem from="1512371928726" duration="717000" />
<workItem from="1512401006678" duration="9000" />
<workItem from="1512401100852" duration="2365000" />
<workItem from="1523948661253" duration="6266000" />
<workItem from="1523948661253" duration="7874000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="34759000" />
<option name="totallyTimeSpent" value="36367000" />
</component>
<component name="ToolWindowManager">
<frame x="1431" y="-4" width="1301" height="772" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.10069177" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.23443505" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
@@ -265,10 +264,18 @@
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.cache/.fr-Tsiwv1/CyberCP/install/FileManager/php/fileManager.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/php/fileManager.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="455">
<caret line="26" column="41" lean-forward="true" selection-start-line="0" selection-start-column="0" selection-end-line="652" selection-end-column="26" />
<state relative-caret-position="329">
<caret line="19" column="0" lean-forward="true" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<folding>
<element signature="n#listForTable#0;n#fileManager#0;n#!!top" expanded="false" />
<element signature="n#readFileContents#0;n#fileManager#0;n#!!top" expanded="false" />

View File

@@ -703,7 +703,7 @@ class preFlightsChecks:
count = 0
while (1):
command = "wget http://cyberpanel.net/CyberPanel.1.6.2.tar.gz"
command = "wget http://cyberpanel.net/CyberPanel.1.6.3.tar.gz"
#command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz"
res = subprocess.call(shlex.split(command))
@@ -723,7 +723,7 @@ class preFlightsChecks:
count = 0
while(1):
command = "tar zxf CyberPanel.1.6.2.tar.gz"
command = "tar zxf CyberPanel.1.6.3.tar.gz"
#command = "tar zxf CyberPanelTemp.tar.gz"
res = subprocess.call(shlex.split(command))
@@ -2490,6 +2490,31 @@ class preFlightsChecks:
logging.InstallLog.writeToFile(str(msg) + " [modSecPreReqs]")
return 0
def installTLDExtract(self):
try:
count = 0
while (1):
command = "pip install tldextract"
res = subprocess.call(shlex.split(command))
if res == 1:
count = count + 1
preFlightsChecks.stdOut(
"Trying to install tldextract, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Failed to install tldextract! [installTLDExtract]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
else:
logging.InstallLog.writeToFile("tldextract successfully installed! [pip]")
preFlightsChecks.stdOut("tldextract successfully installed! [pip]")
break
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installTLDExtract]")
return 0
def main():
@@ -2562,6 +2587,7 @@ def main():
checks.test_Requests()
checks.download_install_CyberPanel(installCyberPanel.InstallCyberPanel.mysqlPassword)
checks.setup_cron()
checks.installTLDExtract()
checks.modSecPreReqs()
checks.installation_successfull()

View File

@@ -0,0 +1,7 @@
import tldextract
ext = tldextract.extract('http://forums.bbc.co.uk')
print ext.subdomain
print ext.domain
print ext.suffix

View File

@@ -304,17 +304,32 @@ def submitWebsiteCreation(request):
## Create Configurations ends here
## zone creation
##### Zone creation
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
try:
newZone = Domains(admin=admin, name=domain, type="NATIVE")
newZone.save()
import tldextract
content = "ns1." + domain + " hostmaster." + domain + " 1 10800 3600 604800 3600"
extractDomain = tldextract.extract(domain)
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
subDomain = extractDomain.subdomain
soaRecord = Records(domainOwner=newZone,
domain_id=newZone.id,
name=domain,
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,
@@ -323,47 +338,196 @@ def submitWebsiteCreation(request):
auth=1)
soaRecord.save()
try:
## Main A record.
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
recordContentA = ipData.split('\n', 1)[0]
zone = Domains.objects.get(name=domain)
record = Records(domainOwner=zone,
domain_id=zone.id,
name=domain,
name=topLevelDomain,
type="A",
content=recordContentA,
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile("Unable to add A record while creating website, error: " + str(msg))
except:
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
recordContentA = ipData.split('\n', 1)[0]
# CNAME Records.
cNameValue = "www." + topLevelDomain
zone = Domains.objects.get(name=domain)
record = Records(domainOwner=zone,
domain_id=zone.id,
name=domain,
type="A",
content=recordContentA,
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()
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.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=actualSubDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + actualSubDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=actualSubDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile("Unable to add A record while creating website, error: " + str(msg))
logging.CyberCPLogFileWriter.writeToFile("We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
## zone creation
@@ -451,8 +615,6 @@ def submitDomainCreation(request):
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + " --administratorEmail " + master.adminEmail + " --phpVersion '" + phpSelection + "' --virtualHostUser " + externalApp + " --numberOfSites " + numberOfWebsites + " --ssl " + str(
data['ssl']) + " --path " + path
output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1:
@@ -462,6 +624,315 @@ def submitDomainCreation(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
### Zone creation.
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
try:
restore = data['restore']
restart = 0
except BaseException,msg:
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
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()
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.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=actualSubDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + actualSubDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=actualSubDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException,msg:
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
recordContentA = ipData.split('\n', 1)[0]
try:
zone = Domains.objects.get(name=domain)
record = Records(domainOwner=zone,
domain_id=zone.id,
name=domain,
type="A",
content=recordContentA,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except:
newZone = Domains(admin=admin, name=domain, type="NATIVE")
newZone.save()
content = "ns1." + domain + " hostmaster." + domain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=newZone,
domain_id=newZone.id,
name=domain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
recordContentA = ipData.split('\n', 1)[0]
zone = Domains.objects.get(name=domain)
record = Records(domainOwner=zone,
domain_id=zone.id,
name=domain,
type="A",
content=recordContentA,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# For www part
cNameValue = "www." + domain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=domain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(
"Unable to add A record while creating website, error: " + str(msg))
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile("Unable to add A record while creating website, error: " + str(msg))
## Zone creation.
## Create Configurations ends here
website = ChildDomains(master=master, domain=domain, path=path, phpSelection=phpSelection, ssl=ssl)