mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-20 22:42:09 +01:00
Merge branch 'v2.0.1' of https://github.com/usmannasir/cyberpanel into v2.0.1
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<div ng-controller="backupLogsScheduled" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Restore Website" %} <img ng-hide="cyberpanelLoading" src="{% static 'images/loading.gif' %}">
|
||||
{% trans "Backup Logs" %} <img ng-hide="cyberpanelLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ from manageServices.models import SlaveServers
|
||||
|
||||
class ServiceManager:
|
||||
|
||||
slaveConfPath = '/home/cyberpanel/slaveConf'
|
||||
|
||||
def __init__(self, extraArgs):
|
||||
self.extraArgs = extraArgs
|
||||
|
||||
@@ -24,14 +26,14 @@ class ServiceManager:
|
||||
ipStringNoSubnet = ''
|
||||
|
||||
for items in SlaveServers.objects.all():
|
||||
ipsString = ipsString + '%s/32 ' % (items.slaveServerIP)
|
||||
ipStringNoSubnet = ipStringNoSubnet + '%s ' % (items.slaveServerIP)
|
||||
|
||||
ipsString = ipsString.rstrip(' ')
|
||||
ipStringNoSubnet = ipStringNoSubnet.rstrip(' ')
|
||||
|
||||
ipsString = ipsString + '%s/32, ' % (items.slaveServerIP)
|
||||
ipStringNoSubnet = ipStringNoSubnet + '%s, ' % (items.slaveServerIP)
|
||||
|
||||
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 +51,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')
|
||||
@@ -64,33 +66,42 @@ 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
|
||||
|
||||
counter = counter + 1
|
||||
if items.find('daemon=') > -1:
|
||||
continue
|
||||
|
||||
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
writeToFile = open(tempPath, 'w')
|
||||
if items.find('disable-axfr') > -1:
|
||||
continue
|
||||
|
||||
for items in data:
|
||||
writeToFile.writelines(items + '\n')
|
||||
if items.find('slave') > -1:
|
||||
continue
|
||||
|
||||
slaveData = """slave=yes
|
||||
counter = counter + 1
|
||||
|
||||
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
writeToFile = open(tempPath, 'w')
|
||||
|
||||
for items in data:
|
||||
writeToFile.writelines(items + '\n')
|
||||
|
||||
slaveData = """
|
||||
slave=yes
|
||||
daemon=yes
|
||||
disable-axfr=yes
|
||||
guardian=yes
|
||||
@@ -103,15 +114,14 @@ setuid=pdns
|
||||
superslave=yes
|
||||
"""
|
||||
|
||||
writeToFile.writelines(slaveData)
|
||||
writeToFile.close()
|
||||
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
|
||||
#subprocess.call(shlex.split(command))
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
|
||||
@@ -51,57 +51,57 @@
|
||||
|
||||
<div ng-hide="masterServerHD" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="slaveServerNS='{{ slaveServerNS }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServerNS" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="masterServerHD" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Master Server IP" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="masterServerIP='{{ masterServerIP }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="masterServerIP" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="slaveIPs" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server 1" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="slaveServer='{{ slaveServer }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServer" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="slaveIPs" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server IP" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="slaveServerIP='{{ slaveServerIP }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServerIP" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="slaveIPs" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server 2 (Optional)" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="slaveServer2='{{ slaveServer2 }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServer2" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="slaveIPs" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server IP 2 (Optional)" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="slaveServerIP2='{{ slaveServerIP2 }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServerIP2" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="slaveIPs" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server 3 (Optional)" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div ng-init="slaveServer3='{{ slaveServer3 }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServer3" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="slaveIPs" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Slave Server IP 3 (Optional)" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveIPData" required>
|
||||
<div ng-init="slaveServerIP3='{{ slaveServerIP3 }}'" class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="slaveServerIP3" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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,15 @@ class backupSchedule:
|
||||
@staticmethod
|
||||
def prepare():
|
||||
try:
|
||||
destinations = backupUtilities.destinationsPath
|
||||
|
||||
backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S")
|
||||
if os.path.exists(backupSchedule.runningPath):
|
||||
pid = open(backupSchedule.runningPath, 'r').read()
|
||||
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
|
||||
|
||||
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, "")
|
||||
writeToFile = open(backupSchedule.runningPath, 'w')
|
||||
writeToFile.write(str(os.getpid()))
|
||||
writeToFile.close()
|
||||
|
||||
## IP of Remote server.
|
||||
|
||||
@@ -248,6 +250,27 @@ class backupSchedule:
|
||||
|
||||
ipAddress = data['ipAddress']
|
||||
|
||||
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)
|
||||
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"
|
||||
@@ -280,7 +303,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]")
|
||||
|
||||
@@ -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('\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')
|
||||
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]")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user