| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -260,6 +260,30 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    nextcloud_folder_key = fields.Char(string='Next Cloud Folder Id', | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                       help="Field used to store the unique " | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                            "identifier for a Nextcloud folder.") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    gdrive_backup_error_test = fields.Boolean(string="Google Drive Error Test") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    onedrive_backup_error_test = fields.Boolean(string="OneDrive Error Test") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @api.onchange('backup_destination') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def _onchange_backup_destination(self): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.write({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            "gdrive_backup_error_test": False, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            "onedrive_backup_error_test": False | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @api.onchange('gdrive_client_key', 'gdrive_client_secret', | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  'google_drive_folder', 'onedrive_client_key', | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  'onedrive_client_secret', 'onedrive_folder_key') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def _onchange_gdrive_backup_error_test(self): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if self.backup_destination == 'google_drive': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if self.gdrive_backup_error_test: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                self.write({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    "gdrive_backup_error_test": False | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if self.backup_destination == 'onedrive': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if self.onedrive_backup_error_test: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                self.write({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    "onedrive_backup_error_test": False | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def action_nextcloud(self): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        """If it has next_cloud_password, domain, and next_cloud_user_name | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -453,11 +477,13 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    'gdrive_token_validity': fields.Datetime.now() + timedelta( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        seconds=expires_in) if expires_in else False, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        except requests.HTTPError: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            error_msg = _( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "Something went wrong during your token generation. Maybe " | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "your Authorization Code is invalid") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            raise UserError(error_msg) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if self.gdrive_backup_error_test: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    self.write({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        'gdrive_backup_error_test': False | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if not self.gdrive_backup_error_test: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                self.write({"gdrive_backup_error_test": True}) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @api.depends('onedrive_access_token', 'onedrive_refresh_token') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def _compute_is_onedrive_token_generated(self): | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -566,10 +592,13 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    'onedrive_token_validity': fields.Datetime.now() + timedelta | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    (seconds=expires_in) if expires_in else False, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        except requests.HTTPError as error: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            _logger.exception("Bad microsoft onedrive request : %s !", | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                              error.response.content) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            raise error | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if self.onedrive_backup_error_test: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    self.write({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        'onedrive_backup_error_test': False | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if not self.onedrive_backup_error_test: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                self.write({"onedrive_backup_error_test": True}) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def get_dropbox_auth_url(self): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        """Return dropbox authorization url""" | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -580,11 +609,15 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def set_dropbox_refresh_token(self, auth_code): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        """Generate and set the dropbox refresh token from authorization code""" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        try: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            dbx_auth = dropbox.oauth.DropboxOAuth2FlowNoRedirect( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                self.dropbox_client_key, self.dropbox_client_secret, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                token_access_type='offline') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            outh_result = dbx_auth.finish(auth_code) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            self.dropbox_refresh_token = outh_result.refresh_token | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            raise ValidationError( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                'Please Enter Valid Authentication Code') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @api.constrains('db_name') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    def _check_db_credentials(self): | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -764,6 +797,7 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    client.close() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # Google Drive backup | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            elif rec.backup_destination == 'google_drive': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                try: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if (rec.gdrive_token_validity is not False and | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            rec.gdrive_token_validity <= fields.Datetime.now()): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        rec.generate_gdrive_refresh_token() | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -815,8 +849,16 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        _logger.info('Google Drive Exception: %s', e) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            'Please check the credentials before activation') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError('Please check connection') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # Dropbox backup | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            elif rec.backup_destination == 'dropbox': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                try: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    temp = tempfile.NamedTemporaryFile( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        suffix='.%s' % rec.backup_format) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    with open(temp.name, "wb+") as tmp: | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -847,8 +889,16 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        _logger.info('Dropbox Exception: %s', error) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            'Please check the credentials before activation') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError('Please check connection') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # Onedrive Backup | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            elif rec.backup_destination == 'onedrive': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                try: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if (rec.onedrive_token_validity is not False and | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            rec.onedrive_token_validity <= fields.Datetime.now()): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        rec.generate_onedrive_refresh_token() | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -887,6 +937,13 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        _logger.info('Onedrive Exception: %s', error) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            'Please check the credentials before activation') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError('Please check connection') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # amazon S3 backup | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            elif rec.backup_destination == 'amazon_s3': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if rec.aws_access_key and rec.aws_secret_access_key: | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -965,6 +1022,7 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                                           force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # nextcloud backup | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            elif rec.backup_destination == 'next_cloud': | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                try: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if rec.domain and rec.next_cloud_password and \ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            rec.next_cloud_user_name: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        try: | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -1039,3 +1097,10 @@ class DbBackupConfigure(models.Model): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            remote_file_path = f"/{folder_name}/{rec.db_name}_" \ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                               f"{backup_time}.{rec.backup_format}" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            nc.put_file(remote_file_path, backup_file_path) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                except Exception: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if rec.notify_user: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        mail_template_failed.send_mail(rec.id, force_send=True) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            'Please check the credentials before activation') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    else: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        raise ValidationError('Please check connection') | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |