cloud backups

This commit is contained in:
Usman Nasir
2020-12-22 12:12:41 +05:00
parent d32104337e
commit 4cd72a7ad8
5 changed files with 106 additions and 30 deletions

View File

@@ -24,7 +24,7 @@ from containerization.views import *
class CloudManager: class CloudManager:
def __init__(self, data=None, admin = None): def __init__(self, data=None, admin=None):
self.data = data self.data = data
self.admin = admin self.admin = admin
@@ -964,14 +964,14 @@ class CloudManager:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/IncScheduler.py forceRunAWSBackup --planName %s" % (self.data['planName']) execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/IncScheduler.py forceRunAWSBackup --planName %s" % (
self.data['planName'])
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
return self.ajaxPre(1, None) return self.ajaxPre(1, None)
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str(msg)) return self.ajaxPre(0, str(msg))
def systemStatus(self, request): def systemStatus(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
@@ -979,7 +979,6 @@ class CloudManager:
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str(msg)) return self.ajaxPre(0, str(msg))
def killProcess(self, request): def killProcess(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
@@ -987,7 +986,6 @@ class CloudManager:
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str(msg)) return self.ajaxPre(0, str(msg))
def connectAccountDO(self, request): def connectAccountDO(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
@@ -1004,7 +1002,6 @@ class CloudManager:
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str(msg)) return self.ajaxPre(0, str(msg))
def createPlanDO(self, request): def createPlanDO(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
@@ -1073,7 +1070,7 @@ class CloudManager:
def showStatus(self, request): def showStatus(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1088,24 +1085,22 @@ class CloudManager:
def fetchRam(self, request): def fetchRam(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
#if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: # if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
# return self.ajaxPre(0, 'This feature is currently only available on CentOS.') # return self.ajaxPre(0, 'This feature is currently only available on CentOS.')
from psutil import virtual_memory from psutil import virtual_memory
import math import math
finalData = {} finalData = {}
mem = virtual_memory() mem = virtual_memory()
inGB = math.ceil(float(mem.total)/float(1024 * 1024 * 1024)) inGB = math.ceil(float(mem.total) / float(1024 * 1024 * 1024))
finalData['ramInGB'] = inGB finalData['ramInGB'] = inGB
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
finalData['conf'] = ProcessUtilities.outputExecutioner('sudo cat /etc/my.cnf') finalData['conf'] = ProcessUtilities.outputExecutioner('sudo cat /etc/my.cnf')
else: else:
@@ -1121,7 +1116,7 @@ class CloudManager:
def applyMySQLChanges(self, request): def applyMySQLChanges(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1139,7 +1134,7 @@ class CloudManager:
def restartMySQL(self, request): def restartMySQL(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1154,7 +1149,7 @@ class CloudManager:
def fetchDatabasesMYSQL(self, request): def fetchDatabasesMYSQL(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1169,7 +1164,7 @@ class CloudManager:
def fetchTables(self, request): def fetchTables(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1184,7 +1179,7 @@ class CloudManager:
def deleteTable(self, request): def deleteTable(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1199,7 +1194,7 @@ class CloudManager:
def fetchTableData(self, request): def fetchTableData(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1214,7 +1209,7 @@ class CloudManager:
def fetchStructure(self, request): def fetchStructure(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
currentACL = ACLManager.loadedACL( self.admin.pk) currentACL = ACLManager.loadedACL(self.admin.pk)
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return self.ajaxPre(0, 'Only administrators can see MySQL status.') return self.ajaxPre(0, 'Only administrators can see MySQL status.')
@@ -1266,7 +1261,6 @@ class CloudManager:
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str(msg)) return self.ajaxPre(0, str(msg))
def deletePlanMINIO(self, request): def deletePlanMINIO(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
@@ -1340,7 +1334,6 @@ class CloudManager:
except BaseException as msg: except BaseException as msg:
return self.ajaxPre(0, str(msg)) return self.ajaxPre(0, str(msg))
def switchServer(self, request): def switchServer(self, request):
try: try:
request.session['userID'] = self.admin.pk request.session['userID'] = self.admin.pk
@@ -1666,9 +1659,9 @@ class CloudManager:
except: except:
databases = '0' databases = '0'
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s" % (self.data['domain'], data, emails, databases, tempStatusPath) execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s" % (
self.data['domain'], data, emails, databases, tempStatusPath)
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath} final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
@@ -1695,7 +1688,7 @@ class CloudManager:
counter = 1 counter = 1
for items in backups: for items in backups:
size = str(int(int(os.path.getsize('%s/%s' % (backupsPath, items)))/int(1048576))) size = str(int(int(os.path.getsize('%s/%s' % (backupsPath, items))) / int(1048576)))
dic = {'id': counter, dic = {'id': counter,
'file': items, 'file': items,
@@ -1782,7 +1775,8 @@ class CloudManager:
writeToFile.close() writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --tempStoragePath %s" % (self.data['domain'], self.data['backupFile'], tempStatusPath) execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --tempStoragePath %s" % (
self.data['domain'], self.data['backupFile'], tempStatusPath)
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath} final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
@@ -1874,7 +1868,7 @@ class CloudManager:
's3', 's3',
aws_access_key_id=aws_access_key_id, aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key, aws_secret_access_key=aws_secret_access_key,
endpoint_url = region endpoint_url=region
) )
else: else:
s3 = boto3.resource( s3 = boto3.resource(
@@ -1902,7 +1896,34 @@ class CloudManager:
writeToFile.close() writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " SubmitS3BackupRestore --backupDomain %s --backupFile '%s' --tempStoragePath %s --planName %s" % (self.data['domain'], self.data['backupFile'], tempStatusPath, self.data['planName']) execPath = execPath + " SubmitS3BackupRestore --backupDomain %s --backupFile '%s' --tempStoragePath %s --planName %s" % (
self.data['domain'], self.data['backupFile'], tempStatusPath, self.data['planName'])
ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException as msg:
return self.ajaxPre(0, str(msg))
def DeployWordPress(self):
try:
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'w')
writeToFile.write('Starting..,0')
writeToFile.close()
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/applicationInstaller.py"
execPath = execPath + " DeployWordPress --tempStatusPath %s --appsSet '%s' --domain '%s' --email '%s' --password '%s' " \
"--pluginUpdates '%s' --themeUpdates '%s' --title '%s' --updates '%s' --userName '%s' " \
"--version '%s'" % (
tempStatusPath, self.data['appsSet'], self.data['domain'], self.data['email'], self.data['password'],
self.data['pluginUpdates'], self.data['themeUpdates'], self.data['title'], self.data['updates'],
self.data['userName'], self.data['version'])
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath} final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}

View File

@@ -63,6 +63,8 @@ def router(request):
return cm.deleteCloudBackup() return cm.deleteCloudBackup()
elif controller == 'SubmitCloudBackupRestore': elif controller == 'SubmitCloudBackupRestore':
return cm.SubmitCloudBackupRestore() return cm.SubmitCloudBackupRestore()
elif controller == 'DeployWordPress':
return cm.DeployWordPress()
elif controller == 'getCurrentS3Backups': elif controller == 'getCurrentS3Backups':
return cm.getCurrentS3Backups() return cm.getCurrentS3Backups()
elif controller == 'deleteS3Backup': elif controller == 'deleteS3Backup':

View File

@@ -1,4 +1,5 @@
#!/usr/local/CyberCP/bin/python #!/usr/local/CyberCP/bin/python
import argparse
import os, sys import os, sys
sys.path.append('/usr/local/CyberCP') sys.path.append('/usr/local/CyberCP')
@@ -1217,3 +1218,54 @@ $parameters = array(
# statusFile.writelines(str(msg) + " [404]") # statusFile.writelines(str(msg) + " [404]")
# statusFile.close() # statusFile.close()
# return 0 # return 0
def DeployWordPress(self):
try:
logging.statusWriter(self.extraArgs['tempStatusPath'], 'Checking if MailServer SSL issued..,10')
import time
time.sleep(5)
logging.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
except BaseException as msg:
logging.statusWriter(self.extraArgs['tempStatusPath'], '%s [404].' % (str(msg)))
def main():
parser = argparse.ArgumentParser(description='CyberPanel Application Installer')
parser.add_argument('function', help='Specify a function to call!')
parser.add_argument('--tempStatusPath', help='')
parser.add_argument('--appsSet', help='')
parser.add_argument('--domain', help='')
parser.add_argument('--email', help='')
parser.add_argument('--password', help='')
parser.add_argument('--pluginUpdates', help='')
parser.add_argument('--themeUpdates', help='')
parser.add_argument('--title', help='')
parser.add_argument('--updates', help='')
parser.add_argument('--userName', help='')
parser.add_argument('--version', help='')
args = parser.parse_args()
if args.function == "DeployWordPress":
extraArgs = {}
extraArgs['domain'] = args.domain
extraArgs['tempStatusPath'] = args.tempStatusPath
extraArgs['appsSet'] = args.appsSet
extraArgs['email'] = args.email
extraArgs['password'] = args.password
extraArgs['pluginUpdates'] = args.pluginUpdates
extraArgs['themeUpdates'] = args.themeUpdates
extraArgs['title'] = args.title
extraArgs['updates'] = args.updates
extraArgs['userName'] = args.userName
extraArgs['version'] = args.version
ai = ApplicationInstaller(None, extraArgs)
ai.DeployWordPress()
if __name__ == "__main__":
main()

View File

@@ -2085,6 +2085,5 @@ def main():
bu = backupUtilities(extraArgs) bu = backupUtilities(extraArgs)
bu.SubmitS3BackupRestore() bu.SubmitS3BackupRestore()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -148,6 +148,7 @@ class S3Backups(multi.Thread):
if currentACL['admin'] == 0: if currentACL['admin'] == 0:
return proc.ajax(0, 'Only administrators can use AWS S3 Backups.') return proc.ajax(0, 'Only administrators can use AWS S3 Backups.')
from botocore.client import Config
aws_access_key_id, aws_secret_access_key, region = self.fetchAWSKeys() aws_access_key_id, aws_secret_access_key, region = self.fetchAWSKeys()
@@ -156,7 +157,8 @@ class S3Backups(multi.Thread):
's3', 's3',
aws_access_key_id=aws_access_key_id, aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key, aws_secret_access_key=aws_secret_access_key,
endpoint_url=region endpoint_url=region,
config=Config(signature_version='v4')
) )
else: else:
s3 = boto3.resource( s3 = boto3.resource(