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