mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-06 15:42:06 +01:00
Include Emails/DNS in Backup/Restore process!
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
# CyberPanel
|
||||
|
||||
[](https://gitter.im/cyberpanel/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
Webhosting control panel that uses OpenLiteSpeed as web server.
|
||||
|
||||
## Features
|
||||
|
||||
@@ -25,6 +25,9 @@ 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 mailServer.models import EUsers
|
||||
|
||||
|
||||
|
||||
def loadBackupHome(request):
|
||||
@@ -272,7 +275,7 @@ def submitBackupCreation(request):
|
||||
child = SubElement(dnsRecordXML, 'content')
|
||||
child.text = items.content
|
||||
child = SubElement(dnsRecordXML, 'priority')
|
||||
child.text = items.prio
|
||||
child.text = str(items.prio)
|
||||
|
||||
dnsRecordsXML.append(dnsRecordXML)
|
||||
|
||||
@@ -281,6 +284,30 @@ def submitBackupCreation(request):
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
|
||||
## email accounts
|
||||
|
||||
try:
|
||||
emailRecordsXML = Element('emails')
|
||||
eDomain = eDomains.objects.get(domain=backupDomain)
|
||||
emailAccounts = eDomain.eusers_set.all()
|
||||
|
||||
for items in emailAccounts:
|
||||
emailRecordXML = Element('emailAccount')
|
||||
|
||||
child = SubElement(emailRecordXML, 'email')
|
||||
child.text = items.email
|
||||
child = SubElement(emailRecordXML, 'password')
|
||||
child.text = items.password
|
||||
|
||||
emailRecordsXML.append(emailRecordXML)
|
||||
|
||||
metaFileXML.append(emailRecordsXML)
|
||||
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
|
||||
## Email meta generated!
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -356,7 +356,7 @@ def addDNSRecord(request):
|
||||
auth=1 )
|
||||
record.save()
|
||||
elif recordType == "MX":
|
||||
recordContentMX = recordType = data['recordContentMX']
|
||||
recordContentMX = data['recordContentMX']
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=zoneDomain,
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -51,70 +51,61 @@ def createEmailAccount(request):
|
||||
|
||||
def submitEmailCreation(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
if request.method == 'POST':
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
userName = data['username']
|
||||
password = data['password']
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
userName = data['username']
|
||||
password = data['password']
|
||||
|
||||
## create email entry
|
||||
## create email entry
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||
|
||||
execPath = execPath + " createEmailAccount --domain " + domain
|
||||
execPath = execPath + " createEmailAccount --domain " + domain
|
||||
|
||||
output = subprocess.check_output(shlex.split(execPath))
|
||||
|
||||
if output.find("1,None") > -1:
|
||||
pass
|
||||
else:
|
||||
data_ret = {'createEmailStatus': 0, 'error_message': output}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
## create email entry ends
|
||||
|
||||
finalEmailUsername = userName + "@" + domain
|
||||
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if EUsers.objects.filter(email=finalEmailUsername).exists():
|
||||
data_ret = {'createEmailStatus': 0, 'error_message': "This account already exists"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if not Domains.objects.filter(domain=domain).exists():
|
||||
newEmailDomain = Domains(domainOwner=website, domain=domain)
|
||||
newEmailDomain.save()
|
||||
|
||||
emailAcct = EUsers(emailOwner=newEmailDomain, email=finalEmailUsername, password=password)
|
||||
emailAcct.save()
|
||||
|
||||
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
else:
|
||||
emailDomain = Domains.objects.get(domain=domain)
|
||||
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
|
||||
emailAcct.save()
|
||||
|
||||
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
|
||||
output = subprocess.check_output(shlex.split(execPath))
|
||||
|
||||
if output.find("1,None") > -1:
|
||||
pass
|
||||
else:
|
||||
data_ret = {'createEmailStatus': 0, 'error_message': output}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
## create email entry ends
|
||||
|
||||
finalEmailUsername = userName+"@"+domain
|
||||
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if EUsers.objects.filter(email=finalEmailUsername).exists():
|
||||
data_ret = {'createEmailStatus': 0, 'error_message': "This account already exists"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
if not Domains.objects.filter(domain=domain).exists():
|
||||
newEmailDomain = Domains(domainOwner=website,domain=domain)
|
||||
newEmailDomain.save()
|
||||
|
||||
emailAcct = EUsers(emailOwner=newEmailDomain,email=finalEmailUsername,password=password)
|
||||
emailAcct.save()
|
||||
|
||||
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
else:
|
||||
emailDomain = Domains.objects.get(domain=domain)
|
||||
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
|
||||
emailAcct.save()
|
||||
|
||||
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
except BaseException,msg:
|
||||
data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError,msg:
|
||||
except BaseException, msg:
|
||||
data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@@ -52,10 +52,19 @@ class backupUtilities:
|
||||
## Making archive of home directory
|
||||
|
||||
domainName = backupMetaData.find('masterDomain').text
|
||||
|
||||
## /home/example.com/backup/backup-example-06-50-03-Thu-Feb-2018 -- tempStoragePath
|
||||
## shutil.make_archive
|
||||
make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html"))
|
||||
|
||||
## backup email accounts
|
||||
|
||||
status = open(os.path.join(backupPath, 'status'), "w")
|
||||
status.write("Backing up email accounts!\n")
|
||||
status.close()
|
||||
|
||||
make_archive(os.path.join(tempStoragePath,domainName),'gztar',os.path.join("/home","vmail",domainName))
|
||||
|
||||
## Backing up databases
|
||||
databases = backupMetaData.findall('Databases/database')
|
||||
|
||||
@@ -223,6 +232,47 @@ class backupUtilities:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
||||
return 0
|
||||
|
||||
## Restoring email accounts
|
||||
|
||||
|
||||
status = open(os.path.join(completPath, 'status'), "w")
|
||||
status.write("Restoring email accounts!")
|
||||
status.close()
|
||||
|
||||
emailAccounts = backupMetaData.findall('emails/emailAccount')
|
||||
|
||||
try:
|
||||
for emailAccount in emailAccounts:
|
||||
|
||||
email = emailAccount.find('email').text
|
||||
username = email.split("@")[0]
|
||||
password = emailAccount.find('password').text
|
||||
|
||||
|
||||
finalData = json.dumps({'domain': masterDomain, 'username': username, 'password': password})
|
||||
|
||||
r = requests.post("http://localhost:5003/email/submitEmailCreation", data=finalData,verify=False)
|
||||
|
||||
data = json.loads(r.text)
|
||||
|
||||
if data['createEmailStatus'] == 1:
|
||||
continue
|
||||
else:
|
||||
status = open(os.path.join(completPath,'status'), "w")
|
||||
status.write("Error Message: " + data[
|
||||
'error_message'] + ". Not able to create email accounts, aborting. [5009]")
|
||||
status.close()
|
||||
return 0
|
||||
|
||||
except BaseException, msg:
|
||||
status = open(os.path.join(completPath,'status'), "w")
|
||||
status.write("Error Message: " + str(msg) +". Not able to create email accounts, aborting. [5009]")
|
||||
status.close()
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
||||
return 0
|
||||
|
||||
## Emails restored
|
||||
|
||||
## restoring databases
|
||||
|
||||
status = open(os.path.join(completPath,'status'), "w")
|
||||
@@ -237,15 +287,38 @@ class backupUtilities:
|
||||
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password) == 0:
|
||||
raise BaseException
|
||||
|
||||
## Databases restored
|
||||
|
||||
|
||||
status = open(os.path.join(completPath, 'status'), "w")
|
||||
status.write("Extracting web home data")
|
||||
status.write("Extracting web home data!")
|
||||
status.close()
|
||||
|
||||
|
||||
tar = tarfile.open(pathToCompressedHome)
|
||||
tar.extractall(websiteHome)
|
||||
tar.close()
|
||||
|
||||
## extracting email accounts
|
||||
|
||||
status = open(os.path.join(completPath, 'status'), "w")
|
||||
status.write("Extracting email accounts!")
|
||||
status.close()
|
||||
|
||||
pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz")
|
||||
emailHome = os.path.join("/home","vmail",masterDomain)
|
||||
|
||||
tar = tarfile.open(pathToCompressedEmails)
|
||||
tar.extractall(emailHome)
|
||||
tar.close()
|
||||
|
||||
## emails extracted
|
||||
|
||||
## change permissions
|
||||
|
||||
command = "chmod -r vmail:vmail " + emailHome
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
status = open(os.path.join(completPath,'status'), "w")
|
||||
status.write("Done")
|
||||
status.close()
|
||||
|
||||
@@ -1,8 +1,86 @@
|
||||
<?xml version="1.0" ?>
|
||||
<metaFile>
|
||||
<masterDomain>cyberpanel.net</masterDomain>
|
||||
<masterDomain>cybertronproject.com</masterDomain>
|
||||
<phpSelection>PHP 7.1</phpSelection>
|
||||
<externalApp>cyberpa</externalApp>
|
||||
<ChildDomains/>
|
||||
<Databases/>
|
||||
<externalApp>cybertr</externalApp>
|
||||
<ChildDomains>
|
||||
<domain>
|
||||
<domain>usman.com</domain>
|
||||
<phpSelection>PHP 7.0</phpSelection>
|
||||
<path>/home/cybertronproject.com/public_html/usman.com</path>
|
||||
</domain>
|
||||
</ChildDomains>
|
||||
<Databases>
|
||||
<database>
|
||||
<dbName>LdH8eQ5j4T7lUw</dbName>
|
||||
<dbUser>LdH8eQ5j4T7lUw</dbUser>
|
||||
<password>*C8FF97B66E672C39EA314B6F1FF1991950AA4D94</password>
|
||||
</database>
|
||||
</Databases>
|
||||
<dnsrecords>
|
||||
<dnsrecord>
|
||||
<type>SOA</type>
|
||||
<name>cybertronproject.com</name>
|
||||
<content>ns1.cybertronproject.com hostmaster.cybertronproject.com 1 10800 3600 604800 3600</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>NS</type>
|
||||
<name>cybertronproject.com</name>
|
||||
<content>ns1.cybertronproject.com</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>A</type>
|
||||
<name>ns1.cybertronproject.com</name>
|
||||
<content>139.59.214.173</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>NS</type>
|
||||
<name>cybertronproject.com</name>
|
||||
<content>ns2.cybertronproject.com</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>A</type>
|
||||
<name>ns2.cybertronproject.com</name>
|
||||
<content>139.59.214.173</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>A</type>
|
||||
<name>cybertronproject.com</name>
|
||||
<content>139.59.214.173</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>A</type>
|
||||
<name>mail.cybertronproject.com</name>
|
||||
<content>139.59.214.173</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>MX</type>
|
||||
<name>cybertronproject.com</name>
|
||||
<content>mail.cybertronproject.com</content>
|
||||
<priority>10</priority>
|
||||
</dnsrecord>
|
||||
<dnsrecord>
|
||||
<type>SPF</type>
|
||||
<name>cybertronproject.com</name>
|
||||
<content>v=spf1 a mx ip4:139.59.214.173 ?all</content>
|
||||
<priority>0</priority>
|
||||
</dnsrecord>
|
||||
</dnsrecords>
|
||||
<emails>
|
||||
<emailAccount>
|
||||
<email>rehan@cybertronproject.com</email>
|
||||
<password>rehan</password>
|
||||
</emailAccount>
|
||||
<emailAccount>
|
||||
<email>usman@cybertronproject.com</email>
|
||||
<password>9xvps</password>
|
||||
</emailAccount>
|
||||
</emails>
|
||||
</metaFile>
|
||||
@@ -5,10 +5,6 @@ from random import randint
|
||||
try:
|
||||
mydoc = ElementTree.parse('domain.xml')
|
||||
|
||||
len = 1
|
||||
|
||||
if len==1:
|
||||
raise BaseException
|
||||
|
||||
print mydoc.find('masterDomain').text
|
||||
|
||||
@@ -26,6 +22,14 @@ try:
|
||||
print d.find('dbUser').text
|
||||
print d.find('password').text
|
||||
|
||||
dnsrecords = mydoc.findall('dnsrecords/dnsrecord')
|
||||
|
||||
for dnsrecord in dnsrecords:
|
||||
print dnsrecord.find('type').text
|
||||
print dnsrecord.find('name').text
|
||||
print dnsrecord.find('content').text
|
||||
print dnsrecord.find('priority').text
|
||||
|
||||
print os.path.join("/home", "cyberpanel", str(randint(1000, 9999)) + ".xml/", "test")
|
||||
except BaseException,msg:
|
||||
print "hello"
|
||||
|
||||
@@ -1764,6 +1764,117 @@ def CreateWebsiteFromBackup(request):
|
||||
newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
|
||||
newDB.save()
|
||||
|
||||
|
||||
## Create dns zone
|
||||
|
||||
dnsrecords = backupMetaData.findall('dnsrecords/dnsrecord')
|
||||
|
||||
zone = Domains(admin=admin, name=domain, type="NATIVE")
|
||||
zone.save()
|
||||
|
||||
for dnsrecord in dnsrecords:
|
||||
|
||||
recordType = dnsrecord.find('type').text
|
||||
value = dnsrecord.find('name').text
|
||||
content = dnsrecord.find('content').text
|
||||
prio = int(dnsrecord.find('priority').text)
|
||||
|
||||
if recordType == "SOA":
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="SOA",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
elif recordType == "NS":
|
||||
record = Records( domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="NS",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1 )
|
||||
record.save()
|
||||
|
||||
elif recordType == "A":
|
||||
record = Records( domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="A",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1 )
|
||||
record.save()
|
||||
elif recordType == "MX":
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="MX",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=prio,
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
elif recordType == "AAAA":
|
||||
record = Records( domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="AAAA",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1 )
|
||||
record.save()
|
||||
|
||||
elif recordType == "CNAME":
|
||||
record = Records( domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="CNAME",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1 )
|
||||
record.save()
|
||||
|
||||
|
||||
elif recordType == "SPF":
|
||||
record = Records( domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="SPF",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1 )
|
||||
record.save()
|
||||
|
||||
|
||||
elif recordType == "TXT":
|
||||
record = Records( domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=value,
|
||||
type="TXT",
|
||||
content=content,
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1 )
|
||||
record.save()
|
||||
|
||||
|
||||
data_ret = {'createWebSiteStatus': 1, 'error_message': "None", "existsStatus": 0}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
Reference in New Issue
Block a user