예제 #1
0
    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')

        gen_utils.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'] = backup_dates
        context['backup_dates_with_dirs'] = backup_dates
        context['update_interval'] = '1000'
        context['form'] = form

        response = render(request,
                          'bitcoin/ready_to_restore.html',
                          context=context)

        return response
예제 #2
0
    def restore(self):

        global restore_task, restore_dir

        gen_utils.clear_action_updates()

        if restoring():
            log('already restoring blockchain')
        else:
            # late import to limit the code that is loaded on start up
            from blockchain_backup.bitcoin.restore import RestoreTask

            restore_task = RestoreTask(restore_dir)
            restore_task.start()
            log('restore blockchain started')

        context = gen_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'

        response = render(self.request,
                          'bitcoin/restore.html',
                          context=context)

        return response
예제 #3
0
    def get_page(self, request):

        global restore_task

        gen_utils.clear_action_updates()

        # don't check if we are restoring() to avoid race
        # it should be ok to call interrupt() multiple times
        if restore_task:
            restore_task.interrupt()
        log('interrupted restore')

        context = gen_utils.get_blockchain_context()

        return render(request,
                      'bitcoin/interrupt_restore.html',
                      context=context)
예제 #4
0
    def get_page(self, request):
        # let's see what we know about the environment

        gen_utils.clear_action_updates()

        # last block in django database; may be different from last in blockchain
        last_block_updated = state.get_last_block_updated()
        # ready if blockchain-backup has processed some blockchain data
        bcb_run_already = last_block_updated > 0
        bin_dir_ok = preferences.bin_dir_ok()
        data_dir = preferences.get_data_dir()
        backup_dir_ok, backup_dir_error = preferences.backup_dir_ok()
        backup_dir = preferences.get_backup_dir()
        last_bcb_version = state.get_latest_bcb_version()

        if bcb_run_already:
            data_dir_ok, __ = preferences.data_dir_ok()
        else:
            if data_dir and os.path.exists(data_dir):
                data_dir_ok, __ = preferences.data_dir_ok()
            else:
                data_dir_ok = False

        gen_utils.check_for_updates()

        params = {
            'data_dir': data_dir,
            'data_dir_ok': data_dir_ok,
            'backup_dir': backup_dir,
            'backup_dir_ok': backup_dir_ok,
            'backup_dir_error': backup_dir_error,
            'last_bcb_version': last_bcb_version,
            'bcb_up_to_date': last_bcb_version >= CURRENT_VERSION,
            'need_backup': get_next_backup_time() < now(),
            'last_backed_up_time': state.get_last_backed_up_time(),
        }
        #log('params: {}'.format(params))

        response = gen_utils.get_home_page_response(request, bcb_run_already,
                                                    bin_dir_ok, params)

        return response
예제 #5
0
    def get_page(self, request):

        log('getting restore page')

        gen_utils.clear_action_updates()

        response = self.check_for_conflicts(request)

        if response is None:
            log('nothing conflicting with restore')
            error_message = more_error_msg = None
            context = gen_utils.get_blockchain_context()

            backup_dates, preselected_date = state.get_backup_dates_and_dirs()
            error_message, more_error_msg = self.check_dirs_ok(backup_dates)
            if error_message is None:

                log('asking for confirmation')
                response = self.ask_user_to_confirm(request, backup_dates,
                                                    preselected_date, context)

            else:
                log(error_message)
                # show the user the errors
                log(error_message)
                context['header'] = self.BAD_HEADER
                context['notice'] = error_message
                if more_error_msg is None:
                    context['subnotice'] = ''
                else:
                    context['subnotice'] = more_error_msg

                response = render(request,
                                  'bitcoin/restore_not_ready.html',
                                  context=context)

        return response
예제 #6
0
    def get_page(self, request):

        log('change whether backups enabled or not')

        gen_utils.clear_action_updates()
        form = Form()
        context = {}
        backups_enabled = state.get_backups_enabled()
        if backups_enabled:
            context[
                'header'] = 'Blockchain Backup currently backups the blockchain on your schedule.'
            context[
                'notice'] = 'WARNING: If you disable backups, then Blockchain Backup cannot keep your copy of the blockchain safe.'
            context['status'] = 'Enabled'
        else:
            context[
                'header'] = 'Blockchain Backup temporarily disabled backups the blockchain.'
            context[
                'notice'] = 'WARNING: Do <i>not</i> enable backups until Bitcoin Core runs successfully.'
            context['status'] = 'Disabled'
        context['header'] = f"Backups {context['status']}"
        context['form'] = form

        return render(request, self.form_url, context=context)
예제 #7
0
    def get_page(self, request):

        global backup_task

        log('backing up blockchain')

        gen_utils.clear_action_updates()

        # check that no other bitcoin-core app is running
        if core_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 gen_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 = gen_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'

                if backing_up():
                    log('already backing_up blockchain')

                else:
                    # late import to limit the code that is loaded on start up
                    from blockchain_backup.bitcoin.backup import BackupTask

                    backup_task = BackupTask()
                    backup_task.start()
                    log('backup started')

            response = render(request, 'bitcoin/backup.html', context=context)

        return response
예제 #8
0
    def get_page(self, request):

        global update_task

        log('trying to update blockchain')

        gen_utils.clear_action_updates()

        # check that no other bitcoin-core app is running
        if (core_utils.is_bitcoin_qt_running()
                or core_utils.is_bitcoin_tx_running()
                or (core_utils.is_bitcoind_running() and not updating())):
            response = warn_core_running(request)

        # tell user if another blockchain_backup app is running
        elif is_backup_running() or gen_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 = gen_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:
                HEADER = "Updating Bitcoin's blockchain"
                SUBNOTICE = 'Shutting down before this window says it is safe <em>could damage the blockchain</em>.'
                PROGRESS = 'Starting to update the blockchain'

                context['header'] = HEADER
                context['notice'] = NOTICE
                context['subnotice'] = SUBNOTICE
                context['progress'] = PROGRESS

                if updating():
                    log('already updating blockchain')

                else:
                    # late import to limit the code that is loaded on start up
                    from blockchain_backup.bitcoin.update import UpdateTask

                    update_task = UpdateTask()
                    update_task.start()
                    log('UpdateTask started')

            log(f'context: {context}')
            response = render(request, 'bitcoin/update.html', context=context)

        return response
예제 #9
0
    def get_page(self, request):

        global accessing_wallet_task

        log('accessing bitcoin interactively')

        gen_utils.clear_action_updates()

        core_running = (core_utils.is_bitcoind_running()
                        or core_utils.is_bitcoin_tx_running()
                        or (core_utils.is_bitcoin_qt_running()
                            and not accessing_wallet()))

        # it's ok if bitcoin-qt is running in our task
        if core_running:
            response = warn_core_running(request)

        # tell user if another app is running
        elif is_backup_running() or gen_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 = gen_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:
                HEADER = 'Accessing Bitcoin Core Wallet Interactively'
                NOTICE = 'WARNING: Do not shut down your computer until Bitcoin-QT stops completely.'

                context['header'] = HEADER
                context['notice'] = NOTICE
                context['subnotice'] = SUBNOTICE

                if accessing_wallet():
                    log('already accessing wallet')

                else:
                    # late import to limit the code that is loaded on start up
                    from blockchain_backup.bitcoin.access_wallet import AccessWalletTask

                    accessing_wallet_task = AccessWalletTask()
                    accessing_wallet_task.start()
                    log('access wallet started')

            response = render(request,
                              'bitcoin/access_wallet.html',
                              context=context)

        return response