From 4e22a1e6f00f1900f8a2ee63db993f21503bcd4c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 8 Apr 2023 00:12:51 +0500 Subject: [PATCH] fixconfiguregdrive --- IncBackups/urls.py | 3 +- IncBackups/views.py | 20 +++++----- plogical/Backupsv2.py | 93 +++++++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/IncBackups/urls.py b/IncBackups/urls.py index 0e7984db2..831a7476c 100644 --- a/IncBackups/urls.py +++ b/IncBackups/urls.py @@ -23,10 +23,9 @@ urlpatterns = [ url(r'^removeSite$', views.remove_site, name='removeSite'), url(r'^addWebsite$', views.add_website, name='addWebsite'), ### V2 Backups URls - url(r'^CreateV2Backup$', views.CreateV2Backup, name='CreateV2Backup'), url(r'^ConfigureV2Backup$', views.ConfigureV2Backup, name='ConfigureV2Backup'), - url(r'^ConfigureV2BackupSetup$', views.createV2BackupSetup, name='ConfigureV2BackupSetup'), + url(r'^ConfigureV2BackupSetup$', views.ConfigureV2BackupSetup, name='ConfigureV2BackupSetup'), url(r'^RestoreV2backupSite$', views.RestoreV2backupSite, name='RestoreV2backupSite'), url(r'^selectwebsiteRetorev2$', views.selectwebsiteRetorev2, name='selectwebsiteRetorev2'), url(r'^selectreporestorev2$', views.selectreporestorev2, name='selectreporestorev2'), diff --git a/IncBackups/views.py b/IncBackups/views.py index 579ef51fe..fc4baf769 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -731,15 +731,7 @@ def ConfigureV2Backup(request): logging.writeToFile(str(msg)) return redirect(loadLoginPage) -def CreateV2Backup(request): - try: - userID = request.session['userID'] - bm = BackupManager() - return bm.CreateV2backupSite(request, userID) - except KeyError: - return redirect(loadLoginPage) - -def createV2BackupSetup(request): +def ConfigureV2BackupSetup(request): try: userID = request.session['userID'] @@ -771,6 +763,15 @@ def createV2BackupSetup(request): return ConfigureV2Backup(request) + except BaseException as msg: + logging.writeToFile("Error configure"+str(msg)) + return redirect(loadLoginPage) + +def CreateV2Backup(request): + try: + userID = request.session['userID'] + bm = BackupManager() + return bm.CreateV2backupSite(request, userID) except KeyError: return redirect(loadLoginPage) @@ -801,7 +802,6 @@ def CreateV2BackupButton(request): extra_args['BackupEmails'] = data['websiteEmails'] if 'websiteEmails' in data else False extra_args['BackupDatabase'] = data['websiteDatabases'] if 'websiteDatabases' in data else False - background = CPBackupsV2(extra_args) background.start() # background = CPBackupsV2({'domain': Selectedwebsite, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1, diff --git a/plogical/Backupsv2.py b/plogical/Backupsv2.py index b77465223..7a50d7155 100644 --- a/plogical/Backupsv2.py +++ b/plogical/Backupsv2.py @@ -40,8 +40,11 @@ class CPBackupsV2(multi.Thread): def __init__(self, data): multi.Thread.__init__(self) self.data = data + try: - self.function = data['function'] + self.function = data['function'] + except: + pass ### set self.website as it is needed in many functions from websiteFunctions.models import Websites @@ -90,50 +93,51 @@ class CPBackupsV2(multi.Thread): return 0, str(msg) def SetupRcloneBackend(self, type, config): - - self.LocalRclonePath = f'/home/{self.website.domain}/.config/rclone' - self.ConfigFilePath = f'{self.LocalRclonePath}/rclone.conf' - - command = f'mkdir -p {self.LocalRclonePath}' - ProcessUtilities.executioner(command, self.website.externalApp) - - command = f'cat {self.ConfigFilePath}' - CurrentContent = ProcessUtilities.outputExecutioner(command, self.website.externalApp) - try: + logging.CyberCPLogFileWriter.writeToFile(' [Configure.1]') + self.LocalRclonePath = f'/home/{self.website.domain}/.config/rclone' + self.ConfigFilePath = f'{self.LocalRclonePath}/rclone.conf' - if CurrentContent.find('No such file or directory'): - CurrentContent = '' - except: - CurrentContent = '' - - if type == CPBackupsV2.SFTP: - ## config = {"name":, "host":, "user":, "port":, "path":, "password":,} - command = f'rclone obscure {config["password"]}' - ObsecurePassword = ProcessUtilities.outputExecutioner(command).rstrip('\n') - - content = f'''{CurrentContent} -[{config["name"]}] -type = sftp -host = {config["host"]} -user = {config["user"]} -pass = {ObsecurePassword} -''' - - command = f"echo '{content}' >> {self.ConfigFilePath}" - ProcessUtilities.executioner(command, self.website.externalApp, True) - - command = f"chmod 600 {self.ConfigFilePath}" + command = f'mkdir -p {self.LocalRclonePath}' ProcessUtilities.executioner(command, self.website.externalApp) - final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": None}) - return HttpResponse(final_json) - elif type == CPBackupsV2.GDrive: + command = f'cat {self.ConfigFilePath}' + CurrentContent = ProcessUtilities.outputExecutioner(command, self.website.externalApp) + logging.CyberCPLogFileWriter.writeToFile(' [Configure.2]') + try: - token = """{"access_token":"%s","token_type":"Bearer","refresh_token":"%s"}""" % ( - config["token"], config["refresh_token"]) + if CurrentContent.find('No such file or directory'): + CurrentContent = '' + except: + CurrentContent = '' + logging.CyberCPLogFileWriter.writeToFile(' [Configure.3]') + if type == CPBackupsV2.SFTP: + ## config = {"name":, "host":, "user":, "port":, "path":, "password":,} + command = f'rclone obscure {config["password"]}' + ObsecurePassword = ProcessUtilities.outputExecutioner(command).rstrip('\n') - content = f'''{CurrentContent} + content = f'''{CurrentContent} + [{config["name"]}] + type = sftp + host = {config["host"]} + user = {config["user"]} + pass = {ObsecurePassword} + ''' + + command = f"echo '{content}' >> {self.ConfigFilePath}" + ProcessUtilities.executioner(command, self.website.externalApp, True) + + command = f"chmod 600 {self.ConfigFilePath}" + ProcessUtilities.executioner(command, self.website.externalApp) + + final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": None}) + return HttpResponse(final_json) + elif type == CPBackupsV2.GDrive: + logging.CyberCPLogFileWriter.writeToFile(' [Configure.4]') + token = """{"access_token":"%s","token_type":"Bearer","refresh_token":"%s"}""" % ( + config["token"], config["refresh_token"]) + + content = f'''{CurrentContent} [{config["name"]}] type = Gdrive [Gdrive_Mount] @@ -144,11 +148,14 @@ root_folder_id = "" service_account_file = "" token = {token} ''' - command = f"echo '{content}' >> {self.ConfigFilePath}" - ProcessUtilities.executioner(command, self.website.externalApp, True) + command = f"echo '{content}' >> {self.ConfigFilePath}" + ProcessUtilities.executioner(command, self.website.externalApp, True) - command = f"chmod 600 {self.ConfigFilePath}" - ProcessUtilities.executioner(command, self.website.externalApp) + command = f"chmod 600 {self.ConfigFilePath}" + ProcessUtilities.executioner(command, self.website.externalApp) + logging.CyberCPLogFileWriter.writeToFile(' [Configure.5]') + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [Configure.run]') @staticmethod def FetchCurrentTimeStamp():