Пример #1
0
    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
Пример #2
0
    def get_page(self, request):

        try:
            prefs = preferences.get_preferences()
        except OperationalError as oe:
            report_operational_error(oe)

        try:
            if prefs.data_dir is None:
                prefs.data_dir = os.path.join(getdir(), '.bitcoin')

            if prefs.backup_dir is None and prefs.data_dir is not None:
                prefs.backup_dir = os.path.join(prefs.data_dir,
                                                constants.DEFAULT_BACKUPS_DIR)

            if prefs.bin_dir is None:
                prefs.bin_dir = bitcoin_utils.get_path_of_core_apps()

            form = PreferencesForm(instance=prefs)
        except:  # 'bare except' because it catches more than "except Exception"
            log(format_exc())
            form = PreferencesForm()

        return render(request, self.form_url, {
            'form': form,
            'context': bitcoin_utils.get_blockchain_context()
        })
Пример #3
0
    def get_page(self, request):

        global backup_task

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

        context = bitcoin_utils.get_blockchain_context()
        context['update_interval'] = '1000'

        return render(request,
                      'bitcoin/interrupt_backup.html',
                      context=context)
Пример #4
0
    def get_page(self, request):

        global restore_task

        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 = bitcoin_utils.get_blockchain_context()
        context['update_interval'] = '1000'

        return render(request,
                      'bitcoin/interrupt_restore.html',
                      context=context)
Пример #5
0
    def get_page(self, request):

        global update_task

        log('stopping update of blockchain')

        # don't check if we are updating() to avoid race
        # it should be ok to call stop() multiple times
        if update_task:
            update_task.interrupt()
            log('interrupted UpdateTask')

        context = bitcoin_utils.get_blockchain_context()
        context['update_interval'] = '1000'

        return render(request,
                      'bitcoin/interrupt_update.html',
                      context=context)
Пример #6
0
    def get_page(self, request):

        log('getting restore page')

        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 = bitcoin_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
                context['update_interval'] = '1000'

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

        return response
Пример #7
0
    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
Пример #8
0
    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
Пример #9
0
    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