mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 13:25:51 +01:00
further refactor backupManager
This commit is contained in:
@@ -47,40 +47,22 @@ class BackupManager:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def backupSite(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'createBackup') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
proc = httpProc(request, 'backup/backup.html', {'websiteList': websitesName})
|
||||
return proc.render()
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
proc = httpProc(request, 'backup/backup.html', {'websiteList': websitesName}, 'createBackup')
|
||||
return proc.render()
|
||||
|
||||
def gDrive(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'createBackup') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
gDriveAcctsList = []
|
||||
|
||||
gDriveAccts = admin.gdrive_set.all()
|
||||
|
||||
for items in gDriveAccts:
|
||||
gDriveAcctsList.append(items.name)
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
|
||||
proc = httpProc(request, 'backup/googleDrive.html', {'accounts': gDriveAcctsList, 'websites': websitesName})
|
||||
return proc.render()
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
gDriveAcctsList = []
|
||||
gDriveAccts = admin.gdrive_set.all()
|
||||
for items in gDriveAccts:
|
||||
gDriveAcctsList.append(items.name)
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
proc = httpProc(request, 'backup/googleDrive.html', {'accounts': gDriveAcctsList, 'websites': websitesName},
|
||||
'createBackup')
|
||||
return proc.render()
|
||||
|
||||
def gDriveSetup(self, userID=None, request=None):
|
||||
try:
|
||||
@@ -361,34 +343,23 @@ class BackupManager:
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def restoreSite(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
path = os.path.join("/home", "backup")
|
||||
if not os.path.exists(path):
|
||||
proc = httpProc(request, 'backup/restore.html', 'restoreBackup')
|
||||
return proc.render()
|
||||
else:
|
||||
all_files = []
|
||||
ext = ".tar.gz"
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'restoreBackup') == 0:
|
||||
return ACLManager.loadError()
|
||||
command = 'sudo chown -R cyberpanel:cyberpanel ' + path
|
||||
ACLManager.executeCall(command)
|
||||
|
||||
path = os.path.join("/home", "backup")
|
||||
|
||||
if not os.path.exists(path):
|
||||
proc = httpProc(request, 'backup/restore.html')
|
||||
return proc.render()
|
||||
else:
|
||||
all_files = []
|
||||
ext = ".tar.gz"
|
||||
|
||||
command = 'sudo chown -R cyberpanel:cyberpanel ' + path
|
||||
ACLManager.executeCall(command)
|
||||
|
||||
files = os.listdir(path)
|
||||
for filename in files:
|
||||
if filename.endswith(ext):
|
||||
all_files.append(filename)
|
||||
|
||||
proc = httpProc(request, 'backup/restore.html', {'backups': all_files})
|
||||
return proc.render()
|
||||
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
files = os.listdir(path)
|
||||
for filename in files:
|
||||
if filename.endswith(ext):
|
||||
all_files.append(filename)
|
||||
proc = httpProc(request, 'backup/restore.html', {'backups': all_files}, 'restoreBackup')
|
||||
return proc.render()
|
||||
|
||||
def getCurrentBackups(self, userID=None, data=None):
|
||||
try:
|
||||
@@ -702,17 +673,8 @@ class BackupManager:
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def backupDestinations(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'addDeleteDestinations') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
proc = httpProc(request, 'backup/backupDestinations.html', {})
|
||||
return proc.render()
|
||||
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
proc = httpProc(request, 'backup/backupDestinations.html', {}, 'addDeleteDestinations')
|
||||
return proc.render()
|
||||
|
||||
def submitDestinationCreation(self, userID=None, data=None):
|
||||
try:
|
||||
@@ -876,26 +838,15 @@ class BackupManager:
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def scheduleBackup(self, request, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'scheDuleBackups') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
destinations = NormalBackupDests.objects.all()
|
||||
|
||||
dests = []
|
||||
|
||||
for dest in destinations:
|
||||
dests.append(dest.name)
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
|
||||
proc = httpProc(request, 'backup/backupSchedule.html', {'destinations': dests, 'websites': websitesName})
|
||||
return proc.render()
|
||||
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
destinations = NormalBackupDests.objects.all()
|
||||
dests = []
|
||||
for dest in destinations:
|
||||
dests.append(dest.name)
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
proc = httpProc(request, 'backup/backupSchedule.html', {'destinations': dests, 'websites': websitesName},
|
||||
'scheDuleBackups')
|
||||
return proc.render()
|
||||
|
||||
def getCurrentBackupSchedules(self, userID=None, data=None):
|
||||
try:
|
||||
@@ -1018,17 +969,8 @@ class BackupManager:
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def remoteBackups(self, request, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'remoteBackups') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
proc = httpProc(request, 'backup/remoteBackups.html')
|
||||
return proc.render()
|
||||
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
proc = httpProc(request, 'backup/remoteBackups.html', 'remoteBackups')
|
||||
return proc.render()
|
||||
|
||||
def submitRemoteBackups(self, userID=None, data=None):
|
||||
try:
|
||||
@@ -1381,26 +1323,12 @@ class BackupManager:
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def backupLogs(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
all_files = []
|
||||
|
||||
logFiles = BackupJob.objects.all().order_by('-id')
|
||||
|
||||
for logFile in logFiles:
|
||||
all_files.append(logFile.logFile)
|
||||
|
||||
proc = httpProc(request, 'backup/backupLogs.html', {'backups': all_files})
|
||||
return proc.render()
|
||||
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
all_files = []
|
||||
logFiles = BackupJob.objects.all().order_by('-id')
|
||||
for logFile in logFiles:
|
||||
all_files.append(logFile.logFile)
|
||||
proc = httpProc(request, 'backup/backupLogs.html', {'backups': all_files}, 'admin')
|
||||
return proc.render()
|
||||
|
||||
def fetchLogs(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user