From df4cea0ebb0a10f2f36f373d9bd046a8a155fe7a Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 22 May 2020 16:03:49 +0500 Subject: [PATCH 1/8] prevent local backup from running multiple processes --- plogical/backupSchedule.py | 7 +++++++ plogical/backupScheduleLocal.py | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index a6a420e8e..6c8f85af0 100755 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -228,6 +228,13 @@ class backupSchedule: backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S") + jobSuccessSites = 0 + jobFailedSites = 0 + + backupSchedule.backupLog = BackupJob(logFile=backupLogPath, location=backupSchedule.REMOTE, + jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites) + backupSchedule.backupLog.save() + backupSchedule.remoteBackupLogging(backupLogPath,"#################################################") backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S")) backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n") diff --git a/plogical/backupScheduleLocal.py b/plogical/backupScheduleLocal.py index 1fcee1aea..d37b1bb43 100755 --- a/plogical/backupScheduleLocal.py +++ b/plogical/backupScheduleLocal.py @@ -21,11 +21,22 @@ from websiteFunctions.models import BackupJob, BackupJobLogs class backupScheduleLocal: localBackupPath = '/home/cyberpanel/localBackupPath' + runningPath = '/home/cyberpanel/localBackupPID' now = datetime.now() @staticmethod def prepare(): try: + + if os.path.exists(backupScheduleLocal.runningPath): + pid = open(backupScheduleLocal.runningPath, 'r').read() + print('Local backup is already running with PID: %s. If you want to run againly kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid)) + return 0 + + writeToFile = open(backupScheduleLocal.runningPath, 'w') + writeToFile.write(str(os.getpid())) + writeToFile.close() + backupRunTime = time.strftime("%m.%d.%Y_%H-%M-%S") backupLogPath = "/usr/local/lscp/logs/local_backup_log." + backupRunTime @@ -70,8 +81,6 @@ class backupScheduleLocal: backupSchedule.remoteBackupLogging(backupLogPath, '[ERROR] Backup failed for %s, error: %s moving on..' % (virtualHost, str(msg)), backupSchedule.ERROR) - - backupSchedule.remoteBackupLogging(backupLogPath, "") backupSchedule.remoteBackupLogging(backupLogPath, "") @@ -89,6 +98,9 @@ class backupScheduleLocal: job.jobSuccessSites = jobSuccessSites job.save() + if os.path.exists(backupScheduleLocal.runningPath): + os.remove(backupScheduleLocal.runningPath) + except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [214:startBackup]") From 79aa5d4c271496f81e35ca459bfd56ef53635b30 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 22 May 2020 16:11:32 +0500 Subject: [PATCH 2/8] add similar logs for remote schedule backups --- plogical/backupSchedule.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index 6c8f85af0..91a5c452e 100755 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -27,6 +27,7 @@ class backupSchedule: INFO = 0 ERROR = 1 backupLog = '' + runningPath = '/home/cyberpanel/remoteBackupPID' @staticmethod def remoteBackupLogging(fileName, message, status = 0): @@ -183,6 +184,8 @@ class backupSchedule: backupSchedule.remoteBackupLogging(backupLogPath, "") else: + backupSchedule.remoteBackupLogging(backupLogPath, 'Remote backup creation failed for %s.' % (virtualHost) ) + backupSchedule.remoteBackupLogging(backupLogPath, "") backupSchedule.remoteBackupLogging(backupLogPath, "") @@ -224,16 +227,21 @@ class backupSchedule: @staticmethod def prepare(): try: + + if os.path.exists(backupSchedule.runningPath): + pid = open(backupSchedule.runningPath, 'r').read() + print('Remote backup is already running with PID: %s. If you want to run againly kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid)) + return 0 + + writeToFile = open(backupSchedule.runningPath, 'w') + writeToFile.write(str(os.getpid())) + writeToFile.close() + + destinations = backupUtilities.destinationsPath backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S") - jobSuccessSites = 0 - jobFailedSites = 0 - - backupSchedule.backupLog = BackupJob(logFile=backupLogPath, location=backupSchedule.REMOTE, - jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites) - backupSchedule.backupLog.save() backupSchedule.remoteBackupLogging(backupLogPath,"#################################################") backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S")) @@ -255,6 +263,13 @@ class backupSchedule: ipAddress = data['ipAddress'] + jobSuccessSites = 0 + jobFailedSites = 0 + + backupSchedule.backupLog = BackupJob(logFile=backupLogPath, location=backupSchedule.REMOTE, + jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites, ipAddress=ipAddress, port=port) + backupSchedule.backupLog.save() + ## IPAddress of local server ipFile = "/etc/cyberpanel/machineIP" @@ -287,7 +302,8 @@ class backupSchedule: backupSchedule.remoteBackupLogging(backupLogPath, "Remote backup job completed.\n") - + if os.path.exists(backupSchedule.runningPath): + os.remove(backupSchedule.runningPath) except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [prepare]") From 8dae110a9ce1d02173b7afa5f4c85300a1ba556e Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 22 May 2020 16:57:44 +0500 Subject: [PATCH 3/8] bug fix: schedule backup logs --- plogical/backupSchedule.py | 31 ++++++++++++++++--------------- plogical/backupScheduleLocal.py | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index 91a5c452e..0227aed6d 100755 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -230,26 +230,13 @@ class backupSchedule: if os.path.exists(backupSchedule.runningPath): pid = open(backupSchedule.runningPath, 'r').read() - print('Remote backup is already running with PID: %s. If you want to run againly kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid)) + print('\n\nRemote backup is already running with PID: %s. If you want to run again kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid)) return 0 writeToFile = open(backupSchedule.runningPath, 'w') writeToFile.write(str(os.getpid())) writeToFile.close() - - destinations = backupUtilities.destinationsPath - - backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S") - - - backupSchedule.remoteBackupLogging(backupLogPath,"#################################################") - backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S")) - backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n") - - backupSchedule.remoteBackupLogging(backupLogPath, "") - backupSchedule.remoteBackupLogging(backupLogPath, "") - ## IP of Remote server. destinations = backupUtilities.destinationsPath @@ -266,10 +253,24 @@ class backupSchedule: jobSuccessSites = 0 jobFailedSites = 0 + backupLogPath = "/usr/local/lscp/logs/backup_log." + time.strftime("%m.%d.%Y_%H-%M-%S") + backupSchedule.backupLog = BackupJob(logFile=backupLogPath, location=backupSchedule.REMOTE, - jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites, ipAddress=ipAddress, port=port) + jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites, + ipAddress=ipAddress, port=port) backupSchedule.backupLog.save() + + destinations = backupUtilities.destinationsPath + + + backupSchedule.remoteBackupLogging(backupLogPath,"#################################################") + backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S")) + backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n") + + backupSchedule.remoteBackupLogging(backupLogPath, "") + backupSchedule.remoteBackupLogging(backupLogPath, "") + ## IPAddress of local server ipFile = "/etc/cyberpanel/machineIP" diff --git a/plogical/backupScheduleLocal.py b/plogical/backupScheduleLocal.py index d37b1bb43..3a69f20fa 100755 --- a/plogical/backupScheduleLocal.py +++ b/plogical/backupScheduleLocal.py @@ -30,7 +30,7 @@ class backupScheduleLocal: if os.path.exists(backupScheduleLocal.runningPath): pid = open(backupScheduleLocal.runningPath, 'r').read() - print('Local backup is already running with PID: %s. If you want to run againly kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid)) + print('\n\nLocal backup is already running with PID: %s. If you want to run again kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid)) return 0 writeToFile = open(backupScheduleLocal.runningPath, 'w') From d71b3045bb04211b42d2c01c63958506f8f8ebaa Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 22 May 2020 22:02:40 +0500 Subject: [PATCH 4/8] bug fix: fix text --- backup/templates/backup/backupLogs.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup/templates/backup/backupLogs.html b/backup/templates/backup/backupLogs.html index 0c7dadf49..2736eddef 100755 --- a/backup/templates/backup/backupLogs.html +++ b/backup/templates/backup/backupLogs.html @@ -18,7 +18,7 @@

- {% trans "Restore Website" %} + {% trans "Backup Logs" %}

From ca1d507ac242439afbe4e3930477860bd02abf49 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 23 May 2020 01:41:06 +0500 Subject: [PATCH 5/8] bug fix: https://github.com/usmannasir/cyberpanel/issues/346 --- manageServices/serviceManager.py | 16 ++++++----- .../manageServices/managePowerDNS.html | 18 ++++++------- manageServices/views.py | 27 ++++++++++++++++--- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index c37468a3b..877c30472 100755 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -30,8 +30,8 @@ class ServiceManager: ipsString = ipsString.rstrip(' ') ipStringNoSubnet = ipStringNoSubnet.rstrip(' ') - - + tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + writeToFile = open(tempPath, 'w') for items in data: if items.find('allow-axfr-ips') > -1: @@ -49,14 +49,14 @@ class ServiceManager: if items.find('slave') > -1: continue + if items.find('master') > -1: + continue + counter = counter + 1 - tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) - writeToFile = open(tempPath, 'w') - - for items in data: writeToFile.writelines(items + '\n') + writeToFile.writelines('allow-axfr-ips=' + ipsString + '\n') writeToFile.writelines('also-notify=' + ipStringNoSubnet + '\n') writeToFile.writelines('daemon=no\n') @@ -82,6 +82,9 @@ class ServiceManager: if items.find('slave') > -1: continue + if items.find('slave=yes') > 1: + return 0 + counter = counter + 1 tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) @@ -112,6 +115,5 @@ superslave=yes Supermasters(ip=self.extraArgs['masterServerIP'], nameserver=self.extraArgs['slaveServerNS'], account='').save() command = 'sudo mv ' + tempPath + ' ' + path - #subprocess.call(shlex.split(command)) ProcessUtilities.executioner(command) diff --git a/manageServices/templates/manageServices/managePowerDNS.html b/manageServices/templates/manageServices/managePowerDNS.html index 685f53474..013dd0533 100755 --- a/manageServices/templates/manageServices/managePowerDNS.html +++ b/manageServices/templates/manageServices/managePowerDNS.html @@ -51,57 +51,57 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
- +
+
diff --git a/manageServices/views.py b/manageServices/views.py index 1facec6a0..b95965ed6 100755 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- - from django.shortcuts import render from django.shortcuts import HttpResponse, redirect import plogical.CyberCPLogFileWriter as logging @@ -14,19 +13,41 @@ from .serviceManager import ServiceManager from plogical.processUtilities import ProcessUtilities # Create your views here. - def managePowerDNS(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) + if currentACL['admin'] == 1: pass else: return ACLManager.loadError() try: - return render(request, 'manageServices/managePowerDNS.html', {"status": 1}) + data = {} + data['status'] = 1 + + pdnsStatus = PDNSStatus.objects.get(pk=1) + + if pdnsStatus.type == 'MASTER': + counter = 1 + + for items in SlaveServers.objects.all(): + + if counter == 1: + data['slaveServer'] = items.slaveServer + data['slaveServerIP'] = items.slaveServerIP + else: + data['slaveServer%s' % (str(counter))] = items.slaveServer + data['slaveServerIP%s' % (str(counter))] = items.slaveServerIP + + counter = counter + 1 + else: + data['slaveServerNS'] = pdnsStatus.masterServer + data['masterServerIP'] = pdnsStatus.masterIP + + return render(request, 'manageServices/managePowerDNS.html', data) except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse("See CyberCP main log file.") From bb63e366030b2f8b5053cb7d0e4502888b25a2c7 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 23 May 2020 01:57:30 +0500 Subject: [PATCH 6/8] bug fix: https://github.com/usmannasir/cyberpanel/issues/346 --- manageServices/serviceManager.py | 73 +++++++++++++++++--------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index 877c30472..27917605a 100755 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -6,6 +6,8 @@ from manageServices.models import SlaveServers class ServiceManager: + slaveConfPath = '/home/cyberpanel/slaveConf' + def __init__(self, extraArgs): self.extraArgs = extraArgs @@ -64,50 +66,55 @@ class ServiceManager: writeToFile.writelines('master=yes\n') writeToFile.close() else: - counter = 0 + import os - for items in data: - if items.find('allow-axfr-ips') > -1: - continue + if not os.path.exists(ServiceManager.slaveConfPath): - if items.find('also-notify') > -1: - continue + writeToFile = open(ServiceManager.slaveConfPath, 'w') + writeToFile.write('configured') + writeToFile.close() - if items.find('daemon=') > -1: - continue + counter = 0 - if items.find('disable-axfr') > -1: - continue + for items in data: + if items.find('allow-axfr-ips') > -1: + continue - if items.find('slave') > -1: - continue + if items.find('also-notify') > -1: + continue - if items.find('slave=yes') > 1: - return 0 + if items.find('daemon=') > -1: + continue - counter = counter + 1 + if items.find('disable-axfr') > -1: + continue - tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) - writeToFile = open(tempPath, 'w') + if items.find('slave') > -1: + continue - for items in data: - writeToFile.writelines(items + '\n') + counter = counter + 1 - slaveData = """slave=yes -daemon=yes -disable-axfr=yes -guardian=yes -local-address=0.0.0.0 -local-port=53 -master=no -slave-cycle-interval=60 -setgid=pdns -setuid=pdns -superslave=yes -""" + tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + writeToFile = open(tempPath, 'w') - writeToFile.writelines(slaveData) - writeToFile.close() + for items in data: + writeToFile.writelines(items + '\n') + + slaveData = """slave=yes + daemon=yes + disable-axfr=yes + guardian=yes + local-address=0.0.0.0 + local-port=53 + master=no + slave-cycle-interval=60 + setgid=pdns + setuid=pdns + superslave=yes + """ + + writeToFile.writelines(slaveData) + writeToFile.close() for items in Supermasters.objects.all(): items.delete() From 6a6d3261836f7c59481571e55c7823415ebfd6d7 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 23 May 2020 02:04:02 +0500 Subject: [PATCH 7/8] bug fix: https://github.com/usmannasir/cyberpanel/issues/346 --- manageServices/serviceManager.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index 27917605a..4823be81d 100755 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -100,27 +100,28 @@ class ServiceManager: for items in data: writeToFile.writelines(items + '\n') - slaveData = """slave=yes - daemon=yes - disable-axfr=yes - guardian=yes - local-address=0.0.0.0 - local-port=53 - master=no - slave-cycle-interval=60 - setgid=pdns - setuid=pdns - superslave=yes - """ + slaveData = """ +slave=yes +daemon=yes +disable-axfr=yes +guardian=yes +local-address=0.0.0.0 +local-port=53 +master=no +slave-cycle-interval=60 +setgid=pdns +setuid=pdns +superslave=yes +""" writeToFile.writelines(slaveData) writeToFile.close() + command = 'sudo mv ' + tempPath + ' ' + path + ProcessUtilities.executioner(command) + for items in Supermasters.objects.all(): items.delete() Supermasters(ip=self.extraArgs['masterServerIP'], nameserver=self.extraArgs['slaveServerNS'], account='').save() - command = 'sudo mv ' + tempPath + ' ' + path - ProcessUtilities.executioner(command) - From 00bfaa1bb391815cf18e807d8742380bcd56370d Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 23 May 2020 18:17:55 +0500 Subject: [PATCH 8/8] bug fix: https://github.com/usmannasir/cyberpanel/issues/347 --- manageServices/serviceManager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index 4823be81d..05ef80e92 100755 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -26,11 +26,11 @@ class ServiceManager: ipStringNoSubnet = '' for items in SlaveServers.objects.all(): - ipsString = ipsString + '%s/32 ' % (items.slaveServerIP) - ipStringNoSubnet = ipStringNoSubnet + '%s ' % (items.slaveServerIP) + ipsString = ipsString + '%s/32, ' % (items.slaveServerIP) + ipStringNoSubnet = ipStringNoSubnet + '%s, ' % (items.slaveServerIP) - ipsString = ipsString.rstrip(' ') - ipStringNoSubnet = ipStringNoSubnet.rstrip(' ') + ipsString = ipsString.rstrip(', ') + ipStringNoSubnet = ipStringNoSubnet.rstrip(', ') tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) writeToFile = open(tempPath, 'w')