mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-10 23:36:11 +01:00
Firewall: Add Rules by IP, Bug Fixes: SSL, Error Logs, Remote Transfer
This commit is contained in:
@@ -36,159 +36,8 @@ class remoteBackup:
|
||||
|
||||
except BaseException,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [getKey]")
|
||||
return [0, msg]
|
||||
return [0,"Not able to fetch key from remote server, Error Message:" + str(msg)]
|
||||
|
||||
@staticmethod
|
||||
def startRestoreTemp(backupName, backupDir, admin, backupLogPath):
|
||||
try:
|
||||
adminEmail = admin.email
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
|
||||
writeToFile.writelines("\n")
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Preparing restore for: " + backupName + "\n")
|
||||
writeToFile.writelines("\n")
|
||||
|
||||
backupFileName = backupName.strip(".tar.gz")
|
||||
|
||||
completPath = backupDir + "/" + backupFileName
|
||||
originalFile = backupDir + "/" + backupName
|
||||
|
||||
pathToCompressedHome = completPath + "/public_html.tar.gz"
|
||||
|
||||
if not os.path.exists(completPath):
|
||||
os.mkdir(completPath)
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Extracting Main Archive\n")
|
||||
|
||||
status = open(completPath + '/status', "w")
|
||||
status.write("Extracting Main Archive")
|
||||
status.close()
|
||||
|
||||
tar = tarfile.open(originalFile)
|
||||
tar.extractall(completPath)
|
||||
tar.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " UnTar File for backup: " + backupName + "\n")
|
||||
|
||||
status = open(completPath + '/status', "w")
|
||||
status.write("Creating Account and databases")
|
||||
status.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Creating account and databases\n")
|
||||
|
||||
phpSelection = "PHP 7.0"
|
||||
|
||||
data = open(completPath + "/meta", 'r').readlines()
|
||||
domain = data[0].strip('\n')
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Domain for " + backupName + " found: "+domain+"\n")
|
||||
|
||||
try:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
status = open(completPath + '/status', "w")
|
||||
status.write("Website already exists")
|
||||
status.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Domain "+domain+" already exists. Skipping backup file.\n")
|
||||
|
||||
return 0
|
||||
except:
|
||||
pass
|
||||
|
||||
check = 0
|
||||
for items in data:
|
||||
if check == 0:
|
||||
if virtualHostUtilities.createDirectoryForVirtualHost(domain, adminEmail, phpSelection) != 1:
|
||||
numberOfWebsites = Websites.objects.count()
|
||||
virtualHostUtilities.deleteVirtualHostConfigurations(domain, numberOfWebsites)
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Unable to create configuration, see CyberCP main login file. Skipping backup file.\n")
|
||||
return 0
|
||||
|
||||
if virtualHostUtilities.createConfigInMainVirtualHostFile(domain) != 1:
|
||||
numberOfWebsites = Websites.objects.count()
|
||||
virtualHostUtilities.deleteVirtualHostConfigurations(domain, numberOfWebsites)
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Can not create configurations, see CyberCP main log file. Skipping backup file.\n")
|
||||
return 0
|
||||
|
||||
|
||||
selectedPackage = Package.objects.get(packageName="Default")
|
||||
|
||||
website = Websites(admin=admin, package=selectedPackage, domain=domain, adminEmail=adminEmail,
|
||||
phpSelection=phpSelection, ssl=0)
|
||||
|
||||
website.save()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Saved Configuration for domain\n")
|
||||
|
||||
check = check + 1
|
||||
else:
|
||||
dbData = items.split('-')
|
||||
mysqlUtilities.createDatabase(dbData[0], dbData[1], "cyberpanel")
|
||||
newDB = Databases(website=website, dbName=dbData[0], dbUser=dbData[1])
|
||||
newDB.save()
|
||||
|
||||
status = open(path + '/status', "w")
|
||||
status.write("Accounts and DBs Created")
|
||||
status.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Accounts and DBs Created\n")
|
||||
|
||||
data = open(completPath + "/meta", 'r').readlines()
|
||||
domain = data[0].strip('\n')
|
||||
websiteHome = "/home/" + domain + "/public_html"
|
||||
|
||||
check = 0
|
||||
|
||||
status = open(completPath + '/status', "w")
|
||||
status.write("Restoring Databases")
|
||||
status.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Restoring Databases\n")
|
||||
|
||||
for items in data:
|
||||
if check == 0:
|
||||
check = check + 1
|
||||
continue
|
||||
else:
|
||||
dbData = items.split('-')
|
||||
mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbData[0], completPath, dbData[2].strip('\n'))
|
||||
|
||||
status = open(completPath + '/status', "w")
|
||||
status.write("Extracting web home data")
|
||||
status.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Extracting Web Home Data\n")
|
||||
|
||||
|
||||
tar = tarfile.open(pathToCompressedHome)
|
||||
tar.extractall(websiteHome)
|
||||
tar.close()
|
||||
|
||||
status = open(completPath + '/status', "w")
|
||||
status.write("Done")
|
||||
status.close()
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Completed Restore for domain: " + domain + "\n")
|
||||
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
||||
|
||||
@staticmethod
|
||||
def startRestore(backupDir,backupLogPath,dir):
|
||||
@@ -420,7 +269,7 @@ class remoteBackup:
|
||||
try:
|
||||
|
||||
if virtualHost == "vmail" or virtualHost == "backup":
|
||||
pass
|
||||
continue
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
@@ -498,23 +347,6 @@ class remoteBackup:
|
||||
@staticmethod
|
||||
def remoteTransfer(ipAddress, dir,accountsToTransfer):
|
||||
try:
|
||||
destination = "/home/backup/transfer-" + dir
|
||||
backupLogPath = destination + "/backup_log"
|
||||
|
||||
if not os.path.exists(destination):
|
||||
os.makedirs(destination)
|
||||
|
||||
|
||||
writeToFile = open(backupLogPath, "w+")
|
||||
|
||||
writeToFile.writelines("############################\n")
|
||||
writeToFile.writelines(" Starting remote Backup\n")
|
||||
writeToFile.writelines(" Start date: " + time.strftime("%I-%M-%S-%a-%b-%Y") + "\n")
|
||||
writeToFile.writelines("############################\n")
|
||||
writeToFile.writelines("\n")
|
||||
writeToFile.writelines("\n")
|
||||
|
||||
|
||||
## fix yes/no
|
||||
|
||||
verify = backupUtil.backupUtilities.verifyHostKey(ipAddress)
|
||||
@@ -526,6 +358,23 @@ class remoteBackup:
|
||||
else:
|
||||
return [0,verify[1]]
|
||||
|
||||
####
|
||||
|
||||
destination = "/home/backup/transfer-" + dir
|
||||
backupLogPath = destination + "/backup_log"
|
||||
|
||||
if not os.path.exists(destination):
|
||||
os.makedirs(destination)
|
||||
|
||||
writeToFile = open(backupLogPath, "w+")
|
||||
|
||||
writeToFile.writelines("############################\n")
|
||||
writeToFile.writelines(" Starting remote Backup\n")
|
||||
writeToFile.writelines(" Start date: " + time.strftime("%I-%M-%S-%a-%b-%Y") + "\n")
|
||||
writeToFile.writelines("############################\n")
|
||||
writeToFile.writelines("\n")
|
||||
writeToFile.writelines("\n")
|
||||
|
||||
|
||||
if backupUtil.backupUtilities.checkIfHostIsUp(ipAddress) == 1:
|
||||
checkConn = backupUtil.backupUtilities.checkConnection(ipAddress)
|
||||
@@ -538,7 +387,7 @@ class remoteBackup:
|
||||
else:
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Host:" + ipAddress + " is down, aborting." + "\n")
|
||||
return [0, "Host is down"]
|
||||
return [0, "Remote server is not able to communicate with this server."]
|
||||
|
||||
writeToFile.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user