def restore(self): global restore_task, restore_dir clear_action_updates() if restoring(): log('already restoring blockchain') else: from blockchain_backup.bitcoin.restore import RestoreTask restore_task = RestoreTask(restore_dir) restore_task.start() log('restore blockchain started') # make sure the button doesn't appear any more bitcoin_utils.send_socketio_message('button', ' ') context = bitcoin_utils.get_blockchain_context() context['header'] = 'Restoring Bitcoin Blockchain' context[ 'notice'] = 'WARNING: Do not shut down your computer until the restore finishes.' context['progress'] = 'Starting to restore the blockchain' context['update_interval'] = '1000' response = render(self.request, 'bitcoin/restore.html', context=context) return response
def ask_user_to_confirm(self, request, backup_dates, preselected_date, context): ''' Set up to ask the user to confirm they want to restore. ''' log('ask user to confirm they want to restore the blockchain') clear_action_updates() form = RestoreForm() show_backup_dates = len(backup_dates) > 1 if show_backup_dates: warning = self.WARNING1 else: warning = self.WARNING2.format(preselected_date[1]) context[ 'header'] = '<h4>Are you sure you want to restore the Bitcoin blockchain?</h4>' context['notice'] = warning context['subnotice'] = '' context[ 'backup_dates_with_dirs'], __ = state.get_backup_dates_and_dirs() context['form'] = form context['update_interval'] = '1000' # make sure we replace any notice about an error with the warning bitcoin_utils.send_socketio_message('notice', warning.replace('\n', '<br/>')) response = render(request, 'bitcoin/ready_to_restore.html', context=context) return response
def update_location(self, location): ''' Send browser to a new location. >>> manager = BitcoinManager('blockchain_backup.bitcoin.manager.log') >>> manager.update_location(constants.BACKUP_URL) ''' set_action_update(constants.LOCATION_NAME, location) utils.send_socketio_message(constants.LOCATION_NAME, location)
def update_menu(self, menu_state): ''' Update whether the menu is active or not. >>> manager = BitcoinManager('blockchain_backup.bitcoin.manager.log') >>> manager.update_menu(constants.DISABLE_ITEM) ''' html = f'state={menu_state}' set_action_update('nav-link', html) utils.send_socketio_message('nav-link', html)
def update_alert_color(self, color): ''' Change the color of the alert box. >>> manager = BitcoinManager('blockchain_backup.bitcoin.manager.log') >>> manager.update_alert_color('green') ''' html = f'style=max-width: 40rem; background-color:{color}' set_action_update('alert', html) utils.send_socketio_message('alert', html)
def update_progress(self, text): ''' Send progress update to user. >>> manager = BitcoinManager('blockchain_backup.bitcoin.manager.log') >>> manager.update_progress('Details') ''' if self.last_progress_update != text: self.last_progress_update = text html = text.replace('\n', '<br/>') set_action_update('progress', html) utils.send_socketio_message('progress', html) self.log(f'progress: {text}')
def update_subnotice(self, text): ''' Send a sub-notice to the user. >>> manager = BitcoinManager('blockchain_backup.bitcoin.manager.log') >>> manager.update_subnotice('More info') ''' if self.last_subnotice_update != text: self.last_subnotice_update = text html = text.replace('\n', '<br/>') set_action_update('subnotice', html) utils.send_socketio_message('subnotice', html) self.log(f'subnotice: {text}')
def update_header(self, text): ''' Send an updated header to the user. >>> manager = BitcoinManager('blockchain_backup.bitcoin.manager.log') >>> manager.update_header('Test Header') ''' if self.last_header_update != text: self.last_header_update = text html = text.replace('\n', '<br/>') set_action_update('header', html) utils.send_socketio_message('header', html) self.log(f'header: {text}')
def get_page(self, request): global backup_task log('backing up blockchain') clear_action_updates() # check that no other bitcoin-core app is running if bitcoin_utils.is_bitcoin_core_running(): message = NO_BACKUP_IF_CORE_RUNNING response = warn_core_running(request, message=message) # tell user if another app is running elif bitcoin_utils.is_restore_running(): response = warn_bcb_app_running(request, app=constants.RESTORE_PROGRAM) # tell user if another task is running elif accessing_wallet() or updating() or restoring(): response = warn_bcb_task_running(request) # tell user if backups have been disabled elif not state.get_backups_enabled(): response = HttpResponseRedirect('/bitcoin/change_backup_status/') log('tried to backup when backups disabled') log(f'response: {response}') else: SUBNOTICE1 = 'If you need to stop the backup, then <a class="btn btn-secondary " href="/bitcoin/interrupt_backup/"' SUBNOTICE2 = 'role="button" id="stop-button" title="Click to stop backing up the blockchain">click here</a>.' SUBNOTICE = f'{SUBNOTICE1} {SUBNOTICE2}' context = bitcoin_utils.get_blockchain_context() data_dir_ok, error = preferences.data_dir_ok() if not preferences.bin_dir_ok(): context['notice'] = BAD_BIN_DIR context['subnotice'] = '' elif not data_dir_ok: context['notice'] = BAD_DATA_DIR context['subnotice'] = error else: context['header'] = "Backing up bitcoin's blockchain" context[ 'notice'] = 'WARNING: Stopping the backup could damage the ability to restore the blockchain.' context['subnotice'] = SUBNOTICE context['progress'] = 'Starting to back up the blockchain' context['update_interval'] = '1000' if backing_up(): log('already backing_up blockchain') else: from blockchain_backup.bitcoin.backup import BackupTask backup_task = BackupTask() backup_task.start() log('backup started') # make sure the button doesn't appear any more bitcoin_utils.send_socketio_message('button', ' ') response = render(request, 'bitcoin/backup.html', context=context) return response
def get_page(self, request): global update_task log('trying to update blockchain') clear_action_updates() # check that no other bitcoin-core app is running if (bitcoin_utils.is_bitcoin_qt_running() or bitcoin_utils.is_bitcoin_tx_running() or (bitcoin_utils.is_bitcoind_running() and not updating())): response = warn_core_running(request) # tell user if another blockchain_backup app is running elif bitcoin_utils.is_backup_running( ) or bitcoin_utils.is_restore_running(): response = warn_bcb_app_running(request) # tell user if another task is running elif accessing_wallet() or backing_up() or restoring(): response = warn_bcb_task_running(request) else: NOTICE1 = 'WARNING: Don\'t shut down your computer before you <a class="btn btn-secondary " role="button"' NOTICE2 = 'id="stop_button" href="/bitcoin/interrupt_update/" title="Click to stop updating the blockchain">Stop update</a>' NOTICE = f'{NOTICE1} {NOTICE2}' context = bitcoin_utils.get_blockchain_context() data_dir_ok, error = preferences.data_dir_ok() if not preferences.bin_dir_ok(): context['notice'] = BAD_BIN_DIR log(BAD_BIN_DIR) elif not data_dir_ok: context['notice'] = BAD_DATA_DIR log(error) else: context['header'] = "Updating Bitcoin's blockchain" context[ 'notice'] = 'WARNING: Don\'t shut down your computer before you <a class="btn btn-secondary " role="button" id="stop_button" href="/bitcoin/interrupt_update/" title="Click to stop updating the blockchain">Stop update</a>' context[ 'subnotice'] = 'Shutting down before this window says it is safe <em>could damage the blockchain</em>.' context['progress'] = 'Starting to update the blockchain' context['update_interval'] = '5000' if updating(): log('already updating blockchain') else: from blockchain_backup.bitcoin.update import UpdateTask update_task = UpdateTask() update_task.start() log('UpdateTask started') # make sure the button doesn't appear any more bitcoin_utils.send_socketio_message('button', ' ') log(f'context: {context}') response = render(request, 'bitcoin/update.html', context=context) return response
def get_page(self, request): global accessing_wallet_task log('accessing bitcoin interactively') clear_action_updates() # it's ok if bitcoin-qt is running in our task if (bitcoin_utils.is_bitcoind_running() or bitcoin_utils.is_bitcoin_tx_running() or (bitcoin_utils.is_bitcoin_qt_running() and not accessing_wallet())): response = warn_core_running(request) # tell user if another app is running elif bitcoin_utils.is_backup_running( ) or bitcoin_utils.is_restore_running(): response = warn_bcb_app_running(request) # tell user if another task is running elif updating() or backing_up() or restoring(): response = warn_bcb_task_running(request) else: SUBNOTICE1 = "Waiting until you exit Bitcoin-QT.<p>Bitcoin-QT will start in another window." SUBNOTICE2 = "You can send and receive transactions from that window." SUBNOTICE3 = "After you exit Bitcoin-QT, Blockchain Backup will continue updating the blockchain until it's time to back it up." SUBNOTICE4 = "Don't forget to back up your wallet routinely." SUBNOTICE = f'{SUBNOTICE1} {SUBNOTICE2} {SUBNOTICE3} {SUBNOTICE4}' context = bitcoin_utils.get_blockchain_context() data_dir_ok, error = preferences.data_dir_ok() if not preferences.bin_dir_ok(): context['notice'] = BAD_BIN_DIR elif not data_dir_ok: context['notice'] = BAD_DATA_DIR context['subnotice'] = error else: context[ 'header'] = "Accessing Bitcoin Core Wallet Interactively" context[ 'notice'] = 'WARNING: Do not shut down your computer until Bitcoin-QT stops completely.' context['subnotice'] = SUBNOTICE if accessing_wallet(): log('already accessing wallet') else: from blockchain_backup.bitcoin.access_wallet import AccessWalletTask accessing_wallet_task = AccessWalletTask() accessing_wallet_task.start() log('access wallet started') # make sure the button doesn't appear any more bitcoin_utils.send_socketio_message('button', ' ') response = render(request, 'bitcoin/access_wallet.html', context=context) return response