mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 16:26:12 +01:00
ssl bug fix for backups
This commit is contained in:
1326
backup/backupManager.py
Normal file
1326
backup/backupManager.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.shortcuts import redirect
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
import json
|
import json
|
||||||
from loginSystem.views import loadLoginPage
|
|
||||||
from plogical.backupManager import BackupManager
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
|
from backup.backupManager import BackupManager
|
||||||
from backup.pluginManager import pluginManager
|
from backup.pluginManager import pluginManager
|
||||||
|
from loginSystem.views import loadLoginPage
|
||||||
|
|
||||||
|
|
||||||
def loadBackupHome(request):
|
def loadBackupHome(request):
|
||||||
|
|||||||
@@ -1,30 +1,33 @@
|
|||||||
from loginSystem.models import Administrator
|
|
||||||
from django.shortcuts import HttpResponse
|
|
||||||
import json
|
import json
|
||||||
from plogical.website import WebsiteManager
|
import os
|
||||||
from plogical.acl import ACLManager
|
import shlex
|
||||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
import subprocess
|
||||||
from websiteFunctions.models import Websites
|
from random import randint
|
||||||
import subprocess, shlex
|
|
||||||
|
from django.shortcuts import HttpResponse
|
||||||
|
|
||||||
|
import userManagment.views as um
|
||||||
|
from backup.backupManager import BackupManager
|
||||||
from databases.databaseManager import DatabaseManager
|
from databases.databaseManager import DatabaseManager
|
||||||
from dns.dnsManager import DNSManager
|
from dns.dnsManager import DNSManager
|
||||||
from mailServer.mailserverManager import MailServerManager
|
|
||||||
from ftp.ftpManager import FTPManager
|
|
||||||
from manageSSL.views import issueSSL, obtainHostNameSSL, obtainMailServerSSL
|
|
||||||
from plogical.backupManager import BackupManager
|
|
||||||
import userManagment.views as um
|
|
||||||
from packages.packagesManager import PackagesManager
|
|
||||||
from plogical.processUtilities import ProcessUtilities
|
|
||||||
from firewall.firewallManager import FirewallManager
|
from firewall.firewallManager import FirewallManager
|
||||||
from serverLogs.views import getLogsFromFile
|
from ftp.ftpManager import FTPManager
|
||||||
from random import randint
|
|
||||||
from highAvailability.haManager import HAManager
|
from highAvailability.haManager import HAManager
|
||||||
|
from loginSystem.models import Administrator
|
||||||
|
from mailServer.mailserverManager import MailServerManager
|
||||||
|
from manageSSL.views import issueSSL, obtainHostNameSSL, obtainMailServerSSL
|
||||||
|
from packages.packagesManager import PackagesManager
|
||||||
|
from plogical.acl import ACLManager
|
||||||
from plogical.httpProc import httpProc
|
from plogical.httpProc import httpProc
|
||||||
from s3Backups.s3Backups import S3Backups
|
|
||||||
import os
|
|
||||||
from serverStatus.views import topProcessesStatus, killProcess
|
|
||||||
from plogical.mysqlUtilities import mysqlUtilities
|
from plogical.mysqlUtilities import mysqlUtilities
|
||||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
from plogical.processUtilities import ProcessUtilities
|
||||||
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||||
|
from plogical.website import WebsiteManager
|
||||||
|
from s3Backups.s3Backups import S3Backups
|
||||||
|
from serverLogs.views import getLogsFromFile
|
||||||
|
from serverStatus.views import topProcessesStatus, killProcess
|
||||||
|
from websiteFunctions.models import Websites
|
||||||
|
|
||||||
|
|
||||||
class CloudManager:
|
class CloudManager:
|
||||||
def __init__(self, data=None, admin = None):
|
def __init__(self, data=None, admin = None):
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ class backupUtilities:
|
|||||||
## Saving original vhost conf file
|
## Saving original vhost conf file
|
||||||
|
|
||||||
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + domainName + '/vhost.conf'
|
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + domainName + '/vhost.conf'
|
||||||
|
|
||||||
if os.path.exists(backupUtilities.licenseKey):
|
if os.path.exists(backupUtilities.licenseKey):
|
||||||
copy(completPathToConf, tempStoragePath + '/vhost.conf')
|
copy(completPathToConf, tempStoragePath + '/vhost.conf')
|
||||||
|
|
||||||
@@ -243,7 +244,12 @@ class backupUtilities:
|
|||||||
sslStoragePath = '/etc/letsencrypt/live/' + domainName
|
sslStoragePath = '/etc/letsencrypt/live/' + domainName
|
||||||
|
|
||||||
if os.path.exists(sslStoragePath):
|
if os.path.exists(sslStoragePath):
|
||||||
make_archive(os.path.join(tempStoragePath, "sslData-" + domainName), 'gztar', sslStoragePath)
|
try:
|
||||||
|
copy(os.path.join(sslStoragePath, "cert.pem"), os.path.join(tempStoragePath, domainName + ".cert.pem"))
|
||||||
|
copy(os.path.join(sslStoragePath, "fullchain.pem"), os.path.join(tempStoragePath, domainName + ".fullchain.pem"))
|
||||||
|
copy(os.path.join(sslStoragePath, "privkey.pem"), os.path.join(tempStoragePath, domainName + ".privkey.pem"))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
## backup email accounts
|
## backup email accounts
|
||||||
|
|
||||||
@@ -281,10 +287,23 @@ class backupUtilities:
|
|||||||
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + actualChildDomain + '/vhost.conf'
|
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + actualChildDomain + '/vhost.conf'
|
||||||
copy(completPathToConf, tempStoragePath + '/' + actualChildDomain + '.vhost.conf')
|
copy(completPathToConf, tempStoragePath + '/' + actualChildDomain + '.vhost.conf')
|
||||||
|
|
||||||
|
### Storing SSL for child domainsa
|
||||||
|
|
||||||
sslStoragePath = '/etc/letsencrypt/live/' + actualChildDomain
|
sslStoragePath = '/etc/letsencrypt/live/' + actualChildDomain
|
||||||
|
|
||||||
if os.path.exists(sslStoragePath):
|
if os.path.exists(sslStoragePath):
|
||||||
make_archive(os.path.join(tempStoragePath, "sslData-" + actualChildDomain), 'gztar', sslStoragePath)
|
try:
|
||||||
|
copy(os.path.join(sslStoragePath, "cert.pem"),
|
||||||
|
os.path.join(tempStoragePath, actualChildDomain + ".cert.pem"))
|
||||||
|
copy(os.path.join(sslStoragePath, "fullchain.pem"),
|
||||||
|
os.path.join(tempStoragePath, actualChildDomain + ".fullchain.pem"))
|
||||||
|
copy(os.path.join(sslStoragePath, "privkey.pem"),
|
||||||
|
os.path.join(tempStoragePath, actualChildDomain + ".privkey.pem"))
|
||||||
|
make_archive(os.path.join(tempStoragePath, "sslData-" + domainName), 'gztar',
|
||||||
|
sslStoragePath)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
|
||||||
|
|
||||||
@@ -295,10 +314,8 @@ class backupUtilities:
|
|||||||
make_archive(os.path.join(backupPath,backupName), 'gztar', tempStoragePath)
|
make_archive(os.path.join(backupPath,backupName), 'gztar', tempStoragePath)
|
||||||
rmtree(tempStoragePath)
|
rmtree(tempStoragePath)
|
||||||
|
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Completed\n")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Completed\n")
|
||||||
|
|
||||||
|
|
||||||
except BaseException,msg:
|
except BaseException,msg:
|
||||||
try:
|
try:
|
||||||
os.remove(os.path.join(backupPath,backupName+".tar.gz"))
|
os.remove(os.path.join(backupPath,backupName+".tar.gz"))
|
||||||
@@ -464,14 +481,22 @@ class backupUtilities:
|
|||||||
if result[0] == 1:
|
if result[0] == 1:
|
||||||
## Let us try to restore SSL.
|
## Let us try to restore SSL.
|
||||||
|
|
||||||
sslStoragePath = completPath + "/sslData-" + masterDomain + '.tar.gz'
|
sslStoragePath = completPath + "/" + masterDomain + ".cert.pem"
|
||||||
|
|
||||||
if os.path.exists(sslStoragePath):
|
if os.path.exists(sslStoragePath):
|
||||||
sslHome = '/etc/letsencrypt/live/' + masterDomain
|
sslHome = '/etc/letsencrypt/live/' + masterDomain
|
||||||
tar = tarfile.open(sslStoragePath)
|
|
||||||
tar.extractall(sslHome)
|
try:
|
||||||
tar.close()
|
if not os.path.exists(sslHome):
|
||||||
sslUtilities.installSSLForDomain(masterDomain)
|
os.mkdir(sslHome)
|
||||||
|
|
||||||
|
copy(completPath + "/" + masterDomain + ".cert.pem", sslHome + "/cert.pem")
|
||||||
|
copy(completPath + "/" + masterDomain + ".privkey.pem", sslHome + "/privkey.pem")
|
||||||
|
copy(completPath + "/" + masterDomain + ".fullchain.pem", sslHome + "/fullchain.pem")
|
||||||
|
|
||||||
|
sslUtilities.installSSLForDomain(masterDomain)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[1] + ". Not able to create Account, Databases and DNS Records, aborting. [5009]")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[1] + ". Not able to create Account, Databases and DNS Records, aborting. [5009]")
|
||||||
@@ -512,14 +537,23 @@ class backupUtilities:
|
|||||||
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + domain + '/vhost.conf'
|
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + domain + '/vhost.conf'
|
||||||
copy(completPath + '/' + domain + '.vhost.conf', completPathToConf)
|
copy(completPath + '/' + domain + '.vhost.conf', completPathToConf)
|
||||||
|
|
||||||
sslStoragePath = completPath + "/sslData-" + domain + '.tar.gz'
|
sslStoragePath = completPath + "/" + domain + ".cert.pem"
|
||||||
|
|
||||||
if os.path.exists(sslStoragePath):
|
if os.path.exists(sslStoragePath):
|
||||||
sslHome = '/etc/letsencrypt/live/' + domain
|
sslHome = '/etc/letsencrypt/live/' + domain
|
||||||
tar = tarfile.open(sslStoragePath)
|
|
||||||
tar.extractall(sslHome)
|
try:
|
||||||
tar.close()
|
if not os.path.exists(sslHome):
|
||||||
sslUtilities.installSSLForDomain(domain)
|
os.mkdir(sslHome)
|
||||||
|
|
||||||
|
copy(completPath + "/" + domain + ".cert.pem", sslHome + "/cert.pem")
|
||||||
|
copy(completPath + "/" + domain + ".privkey.pem", sslHome + "/privkey.pem")
|
||||||
|
copy(completPath + "/" + domain + ".fullchain.pem",
|
||||||
|
sslHome + "/fullchain.pem")
|
||||||
|
|
||||||
|
sslUtilities.installSSLForDomain(domain)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
except:
|
except:
|
||||||
logging.CyberCPLogFileWriter.writeToFile('While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.')
|
logging.CyberCPLogFileWriter.writeToFile('While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user