events for backups and dns modules

This commit is contained in:
usmannasir
2018-10-05 23:05:02 +05:00
parent d2b8a71c57
commit e4fa05fc41
12 changed files with 1016 additions and 666 deletions

80
backup/pluginManager.py Normal file
View File

@@ -0,0 +1,80 @@
from signals import *
from plogical.pluginManagerGlobal import pluginManagerGlobal
class pluginManager:
@staticmethod
def preSubmitBackupCreation(request):
return pluginManagerGlobal.globalPlug(request, preSubmitBackupCreation)
@staticmethod
def preDeleteBackup(request):
return pluginManagerGlobal.globalPlug(request, preDeleteBackup)
@staticmethod
def postDeleteBackup(request, response):
return pluginManagerGlobal.globalPlug(request, postDeleteBackup, response)
@staticmethod
def preSubmitRestore(request):
return pluginManagerGlobal.globalPlug(request, preSubmitRestore)
@staticmethod
def preSubmitDestinationCreation(request):
return pluginManagerGlobal.globalPlug(request, preSubmitDestinationCreation)
@staticmethod
def postSubmitDestinationCreation(request, response):
return pluginManagerGlobal.globalPlug(request, postSubmitDestinationCreation, response)
@staticmethod
def preDeleteDestination(request):
return pluginManagerGlobal.globalPlug(request, preDeleteDestination)
@staticmethod
def postDeleteDestination(request, response):
return pluginManagerGlobal.globalPlug(request, postDeleteDestination, response)
@staticmethod
def preSubmitBackupSchedule(request):
return pluginManagerGlobal.globalPlug(request, preSubmitBackupSchedule)
@staticmethod
def postSubmitBackupSchedule(request, response):
return pluginManagerGlobal.globalPlug(request, postSubmitBackupSchedule, response)
@staticmethod
def preScheduleDelete(request):
return pluginManagerGlobal.globalPlug(request, preScheduleDelete)
@staticmethod
def postScheduleDelete(request, response):
return pluginManagerGlobal.globalPlug(request, postScheduleDelete, response)
@staticmethod
def preSubmitRemoteBackups(request):
return pluginManagerGlobal.globalPlug(request, preSubmitRemoteBackups)
@staticmethod
def postSubmitRemoteBackups(request, response):
return pluginManagerGlobal.globalPlug(request, postSubmitRemoteBackups, response)
@staticmethod
def preStarRemoteTransfer(request):
return pluginManagerGlobal.globalPlug(request, preStarRemoteTransfer)
@staticmethod
def postStarRemoteTransfer(request, response):
return pluginManagerGlobal.globalPlug(request, postStarRemoteTransfer, response)
@staticmethod
def preRemoteBackupRestore(request):
return pluginManagerGlobal.globalPlug(request, preRemoteBackupRestore)
@staticmethod
def postRemoteBackupRestore(request, response):
return pluginManagerGlobal.globalPlug(request, postRemoteBackupRestore, response)
@staticmethod
def postDeleteBackup(request, response):
return pluginManagerGlobal.globalPlug(request, postRemoteBackupRestore, response)

57
backup/signals.py Normal file
View File

@@ -0,0 +1,57 @@
# The world is a prison for the believer.
from django.dispatch import Signal
## This event is fired before CyberPanel core start creating backup of a website
preSubmitBackupCreation = Signal(providing_args=["request"])
## This event is fired before CyberPanel core start deletion of a backup
preDeleteBackup = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished the backup deletion
postDeleteBackup = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core start restoring a backup.
preSubmitRestore = Signal(providing_args=["request"])
## This event is fired before CyberPanel core starts to add a remote backup destination
preSubmitDestinationCreation = Signal(providing_args=["request"])
## This event is fired after CyberPanel core is finished adding remote backup destination
postSubmitDestinationCreation = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core starts to delete a backup destination
preDeleteDestination = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished deleting a backup destination
postDeleteDestination = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core start adding a backup schedule
preSubmitBackupSchedule = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished adding a backup schedule
postSubmitBackupSchedule = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core start the deletion of backup schedule
preScheduleDelete = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished the deletion of backup schedule
postScheduleDelete = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core star the remote backup process
preSubmitRemoteBackups = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished remote backup process
postSubmitRemoteBackups = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core star the remote backup process
preStarRemoteTransfer = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished remote backup process
postStarRemoteTransfer = Signal(providing_args=["request", "response"])
## This event is fired before CyberPanel core start restore of remote backups
preRemoteBackupRestore = Signal(providing_args=["request"])
## This event is fired after CyberPanel core finished restoring remote backups in local server
postRemoteBackupRestore = Signal(providing_args=["request", "response"])

View File

@@ -6,6 +6,7 @@ from django.shortcuts import redirect
import json
from loginSystem.views import loadLoginPage
from plogical.backupManager import BackupManager
from backup.pluginManager import pluginManager
def loadBackupHome(request):
@@ -43,8 +44,16 @@ def getCurrentBackups(request):
def submitBackupCreation(request):
try:
userID = 1
result = pluginManager.preSubmitBackupCreation(request)
if result != 200:
return result
wm = BackupManager()
return wm.submitBackupCreation(userID, json.loads(request.body))
coreResult = wm.submitBackupCreation(userID, json.loads(request.body))
return coreResult
except KeyError:
return redirect(loadLoginPage)
@@ -67,15 +76,33 @@ def cancelBackupCreation(request):
def deleteBackup(request):
try:
userID = request.session['userID']
result = pluginManager.preDeleteBackup(request)
if result != 200:
return result
wm = BackupManager()
return wm.deleteBackup(userID, json.loads(request.body))
coreResult = wm.deleteBackup(userID, json.loads(request.body))
result = pluginManager.postDeleteBackup(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
def submitRestore(request):
try:
result = pluginManager.preSubmitRestore(request)
if result != 200:
return result
wm = BackupManager()
return wm.submitRestore(json.loads(request.body))
coreResult = wm.submitRestore(json.loads(request.body))
return coreResult
except KeyError:
return redirect(loadLoginPage)
@@ -97,8 +124,19 @@ def backupDestinations(request):
def submitDestinationCreation(request):
try:
userID = request.session['userID']
bm = BackupManager()
return bm.submitDestinationCreation(userID, json.loads(request.body))
result = pluginManager.preSubmitDestinationCreation(request)
if result != 200:
return result
wm = BackupManager()
coreResult = wm.submitDestinationCreation(userID, json.loads(request.body))
result = pluginManager.postSubmitDestinationCreation(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
@@ -121,8 +159,18 @@ def getConnectionStatus(request):
def deleteDestination(request):
try:
userID = request.session['userID']
bm = BackupManager()
return bm.deleteDestination(userID, json.loads(request.body))
result = pluginManager.preDeleteDestination(request)
if result != 200:
return result
wm = BackupManager()
coreResult = wm.deleteDestination(userID, json.loads(request.body))
result = pluginManager.postDeleteDestination(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
@@ -145,16 +193,36 @@ def getCurrentBackupSchedules(request):
def submitBackupSchedule(request):
try:
userID = request.session['userID']
result = pluginManager.preSubmitBackupSchedule(request)
if result != 200:
return result
wm = BackupManager()
return wm.submitBackupSchedule(userID, json.loads(request.body))
coreResult = wm.submitBackupSchedule(userID, json.loads(request.body))
result = pluginManager.postSubmitBackupSchedule(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
def scheduleDelete(request):
try:
userID = request.session['userID']
result = pluginManager.preScheduleDelete(request)
if result != 200:
return result
wm = BackupManager()
return wm.scheduleDelete(userID, json.loads(request.body))
coreResult = wm.scheduleDelete(userID, json.loads(request.body))
result = pluginManager.postScheduleDelete(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
@@ -169,16 +237,36 @@ def remoteBackups(request):
def submitRemoteBackups(request):
try:
userID = request.session['userID']
result = pluginManager.preSubmitRemoteBackups(request)
if result != 200:
return result
wm = BackupManager()
return wm.submitRemoteBackups(userID, json.loads(request.body))
coreResult = wm.submitRemoteBackups(userID, json.loads(request.body))
result = pluginManager.postSubmitRemoteBackups(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
def starRemoteTransfer(request):
try:
userID = request.session['userID']
result = pluginManager.preStarRemoteTransfer(request)
if result != 200:
return result
wm = BackupManager()
return wm.starRemoteTransfer(userID, json.loads(request.body))
coreResult = wm.starRemoteTransfer(userID, json.loads(request.body))
result = pluginManager.postStarRemoteTransfer(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
@@ -193,8 +281,18 @@ def getRemoteTransferStatus(request):
def remoteBackupRestore(request):
try:
userID = request.session['userID']
result = pluginManager.preRemoteBackupRestore(request)
if result != 200:
return result
wm = BackupManager()
return wm.remoteBackupRestore(userID, json.loads(request.body))
coreResult = wm.remoteBackupRestore(userID, json.loads(request.body))
result = pluginManager.postRemoteBackupRestore(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)