Esempio n. 1
0
def index():
    check_logged_in()
    status = get_status()

    bitcoin_block_height = get_bitcoin_block_height()
    mynode_block_height = get_mynode_block_height()
    uptime_in_seconds = get_system_uptime_in_seconds()
    pk_skipped = skipped_product_key()
    pk_error = not is_valid_product_key()

    # Show uploader page if we are marked as an uploader
    if is_uploader():
        status=""
        try:
            status = subprocess.check_output(["mynode-get-quicksync-status"])
        except:
            status = "Waiting on quicksync to start..."

        status = status.decode("utf8")
        status = Markup("<div style='text-align: left; font-size: 12px; width: 800px;'><pre>"+status+"</pre></div>")
        templateData = {
            "title": "myNode Uploader",
            "header_text": "Uploader Device",
            "quicksync_status": status,
            "ui_settings": read_ui_settings()
        }
        return render_template('uploader.html', **templateData)

    if status == STATE_UNKNOWN:
        templateData = {
            "title": "myNode Error",
            "header_text": "Status Unknown",
            "subheader_text": "An error has occurred. You may want to reboot the device.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_ROOTFS_READ_ONLY:
        templateData = {
            "title": "myNode Error",
            "header_text": "SD Card Error",
            "subheader_text": "The root filesystem is read only. Your SD card may be corrupt.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_MISSING:
        # Drive may be getting repaired
        if is_drive_being_repaired():
            templateData = {
                "title": "myNode Repairing Drive",
                "header_text": "Repairing Drive",
                "subheader_text": Markup("Drive is being checked and repaired...<br/><br/>This will take several hours."),
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)

        templateData = {
            "title": "myNode Looking for Drive",
            "header_text": "Looking for Drive",
            "subheader_text": "Please attach a drive to your myNode",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_CONFIRM_FORMAT:
        if request.args.get('format'):
            os.system("touch /tmp/format_ok")
            time.sleep(1)
            return redirect("/")

        templateData = {
            "title": "myNode Confirm Drive Format",
            "ui_settings": read_ui_settings()
        }
        return render_template('confirm_drive_format.html', **templateData)
    elif status == STATE_DRIVE_FORMATTING:
        templateData = {
            "title": "myNode Drive Formatting",
            "header_text": "Drive Formatting",
            "subheader_text": "myNode is preparing the drive for use...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_MOUNTED:
        templateData = {
            "title": "myNode Drive Mounted",
            "header_text": "Drive Mounted",
            "subheader_text": "myNode starting soon...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif not has_product_key() and not skipped_product_key():
        # Show product key page if key not set
        return redirect("/product-key")
    elif status == STATE_QUICKSYNC_COPY:
        try:
            current = subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/bitcoin/"]).split()[0]
            total = subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/quicksync/"]).split()[0]
        except:
            current = 0.0
            total = 100.0

        total = float(total) * 1.3
        percent = (float(current) / float(total)) * 100.0
        if percent >= 99.99:
            percent = 99.99

        message = "<div class='small_message'>{}</<div>".format( get_message() )

        subheader_msg = Markup("Copying files... This will take several hours.<br/>{:.2f}%{}".format(percent, message))

        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": subheader_msg,
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_RESET:
        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": "Restarting QuickSync...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_DOWNLOAD:
        subheader = Markup("")
        try:
            tc = transmissionrpc.Client('localhost', port=9091)
            t = tc.get_torrent(1)

            dl_rate = float(t.rateDownload) / 1000 / 1000
            complete = t.percentDone * 100

            include_funny = False
            if dl_rate > 3.0:
                include_funny = True
            message = "<div class='small_message'>{}</<div>".format( get_message(include_funny) )

            subheader = Markup("Downloading...<br/>{:.2f}%</br>{:.2f} MB/s{}".format(complete, dl_rate, message))
        except Exception as e:
            subheader = Markup("Starting<br/>Waiting on download client to start...")

        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": subheader,
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_STABLE:
        bitcoind_status_code = get_service_status_code("bitcoind")
        lnd_status_code = get_service_status_code("lnd")
        tor_status_color = "gray"
        bitcoind_status_color = "red"
        lnd_status_color = "red"
        lnd_ready = is_lnd_ready()
        rtl_status_color = "gray"
        rtl_status = "Lightning Wallet"
        electrs_status_color = "gray"
        electrs_active = is_electrs_active()
        lndhub_status_color = "gray"
        bitcoind_status = "Inactive"
        lnd_status = "Inactive"
        electrs_status = ""
        explorer_status = ""
        explorer_ready = False
        explorer_status_color = "red"
        lndconnect_status_color = "gray"
        btcpayserver_status_color = "gray"
        btcrpcexplorer_status = ""
        btcrpcexplorer_ready = False
        btcrpcexplorer_status_color = "gray"
        mempoolspace_status_color = "gray"
        vpn_status_color = "gray"
        vpn_status = ""
        current_block = 1234

        if not get_has_updated_btc_info() or uptime_in_seconds < 150:
            error_message = ""
            if bitcoind_status_code != 0 and uptime_in_seconds > 300:
                error_message = "Bitcoin has experienced an error. Please check the logs."
            message = "<div class='small_message'>{}</<div>".format( get_message(include_funny=True) )
            templateData = {
                "title": "myNode Status",
                "header_text": "Starting...",
                "subheader_text": Markup("Launching myNode services...{}".format(message)),
                "error_message": error_message,
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)

        # if is_installing_docker_images():
        #     message = "<div class='small_message'>{}</<div>".format( get_message(include_funny=True) )
        #     templateData = {
        #         "title": "myNode Status",
        #         "header_text": "Starting...",
        #         "subheader_text": Markup("Building Docker Images...{}".format(message)),
        #         "ui_settings": read_ui_settings()
        #     }
        #     return render_template('state.html', **templateData)

        # Display sync info if not synced
        if not is_bitcoind_synced():
            subheader = Markup("Syncing...")
            if bitcoin_block_height != None:
                message = "<div class='small_message'>{}</<div>".format( get_message(include_funny=True) )

                remaining = bitcoin_block_height - mynode_block_height
                subheader = Markup("Syncing...<br/>Block {} of {}{}".format(mynode_block_height, bitcoin_block_height, message))
            templateData = {
                "title": "myNode Sync",
                "header_text": "Bitcoin Blockchain",
                "subheader_text": subheader,
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)

        # Find tor status
        tor_status_color = get_service_status_color("tor@default")

        # Find bitcoind status
        if bitcoind_status_code != 0:
            bitcoind_status_color = "red"
        else:
            bitcoind_status = "Validating blocks..."
            bitcoind_status_color = "green"
            if bitcoin_block_height != None:
                remaining = bitcoin_block_height - mynode_block_height
                if remaining == 0:
                    bitcoind_status = "Running"
                else:
                    bitcoind_status = "Syncing<br/>{} blocks remaining...".format(remaining)
            else:
                bitcoind_status = "Waiting for info..."
            current_block = get_mynode_block_height()

        # Find lnd status
        if is_bitcoind_synced():
            lnd_status_color = "green"
            lnd_status = get_lnd_status()
            
            # Get LND status
            if not lnd_wallet_exists():
                # This hides the restart /login attempt LND does from the GUI
                lnd_status_color = "green"
            elif lnd_status_code != 0:
                lnd_status_color = "red"
                if lnd_status == "Logging in...":
                    lnd_status_color = "yellow"
        else:
            lnd_status_color = "yellow"
            lnd_status = "Waiting..."

        # Find lndhub status
        if is_lndhub_enabled():
            if lnd_ready:
                lndhub_status_color = get_service_status_color("lndhub")

        # Find RTL status
        if lnd_ready:
            status_code = get_service_status_code("rtl")
            if status_code != 0:
                rtl_status_color = "red"
            else:
                rtl_status_color = "green"

        # Find electrs status
        if is_electrs_enabled():
            status_code = get_service_status_code("electrs")
            electrs_status_color = get_service_status_color("electrs")
            if status_code == 0:
                electrs_status = get_electrs_status()

        # Find btc-rpc-explorer status
        btcrpcexplorer_status = "BTC RPC Explorer"
        if is_btcrpcexplorer_enabled():
            if is_bitcoind_synced():
                if electrs_active:
                    btcrpcexplorer_status_color = get_service_status_color("btc_rpc_explorer")
                    status_code = get_service_status_code("btc_rpc_explorer")
                    if status_code == 0:
                        btcrpcexplorer_ready = True
                else:
                    btcrpcexplorer_status_color = "green"
                    btcrpcexplorer_status = "Waiting on electrs..."
            else:
                btcrpcexplorer_status_color = "gray"
                btcrpcexplorer_status = "Waiting on bitcoin..."

        # Find mempool space status
        mempoolspace_status = "Mempool Viewer"
        if is_mempoolspace_enabled():
            if is_installing_docker_images():
                mempoolspace_status_color = "yellow"
                mempoolspace_status = "Installing..."
            else:
                mempoolspace_status_color = get_service_status_color("mempoolspace")

        # Find lndconnect status
        if lnd_ready:
            lndconnect_status_color = "green"

        # Find btcpayserver status
        btcpayserver_status = "Merchant Tool"
        if lnd_ready:
            btcpayserver_status_color = get_service_status_color("btcpayserver")
        else:
            btcpayserver_status = "Waiting on LND..."

        # Find explorer status
        explorer_status_color = electrs_status_color
        if is_electrs_enabled():
            if electrs_active:
                explorer_ready = True
                explorer_status = "myNode BTC Explorer"
            else:
                explorer_status = Markup("Bitcoin Explorer<br/><br/>Waiting on Electrum Server...")
        else:
            explorer_status = Markup("Bitcoin Explorer<br/><br/>Requires Electrum Server")

        # Find VPN status
        if is_vpn_enabled():
            vpn_status_color = get_service_status_color("vpn")
            status_code = get_service_status_code("vpn")
            if status_code != 0:
                vpn_status = "Unknown"
            else:
                if os.path.isfile("/home/pivpn/ovpns/mynode_vpn.ovpn"):
                     vpn_status = "Running"
                else:
                    vpn_status = "Setting up..."

        # Find whirlpool status
        whirlpool_status, whirlpool_status_color, whirlpool_initialized = get_whirlpool_status()

        # Find dojo status
        dojo_status, dojo_status_color, dojo_initialized = get_dojo_status()
        if is_installing_docker_images():
            dojo_status_color = "yellow"
            dojo_status = "Installing..."

        # Check for new version of software
        upgrade_available = False
        current = get_current_version()
        latest = get_latest_version()
        if current != "0.0" and latest != "0.0" and current != latest:
            upgrade_available = True


        templateData = {
            "title": "myNode Home",
            "config": CONFIG,
            "bitcoind_status_color": bitcoind_status_color,
            "bitcoind_status": Markup(bitcoind_status),
            "current_block": current_block,
            "lnd_status_color": lnd_status_color,
            "lnd_status": Markup(lnd_status),
            "lnd_ready": lnd_ready,
            "tor_status_color": tor_status_color,
            "is_installing_docker_images": is_installing_docker_images(),
            "is_device_from_reseller": is_device_from_reseller(),
            "electrs_status_color": electrs_status_color,
            "electrs_status": Markup(electrs_status),
            "electrs_enabled": is_electrs_enabled(),
            "electrs_active": electrs_active,
            "rtl_status_color": rtl_status_color,
            "rtl_status": rtl_status,
            "lndhub_status_color": lndhub_status_color,
            "lndhub_enabled": is_lndhub_enabled(),
            "explorer_ready": explorer_ready,
            "explorer_status_color": explorer_status_color,
            "explorer_status": explorer_status,
            "btcrpcexplorer_ready": btcrpcexplorer_ready,
            "btcrpcexplorer_status_color": btcrpcexplorer_status_color,
            "btcrpcexplorer_status": btcrpcexplorer_status,
            "btcrpcexplorer_enabled": is_btcrpcexplorer_enabled(),
            "mempoolspace_status_color": mempoolspace_status_color,
            "mempoolspace_status": mempoolspace_status,
            "mempoolspace_enabled": is_mempoolspace_enabled(),
            "btcpayserver_enabled": is_btcpayserver_enabled(),
            "btcpayserver_status_color": btcpayserver_status_color,
            "btcpayserver_status": btcpayserver_status,
            "lndconnect_status_color": lndconnect_status_color,
            "vpn_status_color": vpn_status_color,
            "vpn_status": vpn_status,
            "vpn_enabled": is_vpn_enabled(),
            "whirlpool_status": whirlpool_status,
            "whirlpool_status_color": whirlpool_status_color,
            "whirlpool_enabled": is_whirlpool_enabled(),
            "whirlpool_initialized": whirlpool_initialized,
            "is_dojo_installed": is_dojo_installed(),
            "dojo_status": dojo_status,
            "dojo_status_color": dojo_status_color,
            "dojo_enabled": is_dojo_enabled(),
            "dojo_initialized": dojo_initialized,
            "product_key_skipped": pk_skipped,
            "product_key_error": pk_error,
            "fsck_error": has_fsck_error(),
            "fsck_results": get_fsck_results(),
            "sd_rw_error": has_sd_rw_error(),
            "drive_usage": get_drive_usage(),
            "cpu_usage": get_cpu_usage(),
            "ram_usage": get_ram_usage(),
            "swap_usage": get_swap_usage(),
            "device_temp": get_device_temp(),
            "upgrade_available": upgrade_available,
            "has_changed_password": has_changed_password(),
            "ui_settings": read_ui_settings()
        }
        return render_template('main.html', **templateData)
    else:
        templateData = {
            "title": "myNode Error",
            "header_text": "Error",
            "subheader_text": "Unknown State ("+status+"). Please restart your myNode.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
Esempio n. 2
0
def index():
    check_logged_in()
    status = get_mynode_status()

    bitcoin_block_height = get_bitcoin_block_height()
    mynode_block_height = get_mynode_block_height()
    uptime_in_seconds = get_system_uptime_in_seconds()
    pk_skipped = skipped_product_key()
    pk_error = not is_valid_product_key()

    # Show uploader page if we are marked as an uploader
    if is_uploader():
        status=""
        try:
            status = subprocess.check_output(["mynode-get-quicksync-status"])
        except:
            status = "Waiting on quicksync to start..."

        status = status.decode("utf8")
        status = Markup("<div style='text-align: left; font-size: 12px; width: 800px;'><pre>"+status+"</pre></div>")
        templateData = {
            "title": "myNode Uploader",
            "header_text": "Uploader Device",
            "quicksync_status": status,
            "ui_settings": read_ui_settings()
        }
        return render_template('uploader.html', **templateData)

    if status == STATE_UNKNOWN:
        templateData = {
            "title": "myNode Error",
            "header_text": "Status Unknown",
            "subheader_text": "An error has occurred. You may want to reboot the device.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_ROOTFS_READ_ONLY:
        templateData = {
            "title": "myNode Error",
            "header_text": "SD Card Error",
            "subheader_text": "The root filesystem is read only. Your SD card may be corrupt.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_HDD_READ_ONLY:
        templateData = {
            "title": "myNode Error",
            "header_text": "Drive Error",
            "subheader_text": "The external drive filesystem is read only. Try rebooting the device.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif is_warning_present():
        warning = get_current_warning()
        templateData = {
            "title": "myNode Warning",
            "header_text": "Warning",
            "subheader_text": get_warning_header(warning),
            "description_text": get_warning_description(warning),
            "warning_name": warning,
            "ui_settings": read_ui_settings()
        }
        return render_template('warning.html', **templateData)
    elif status == STATE_DRIVE_MISSING:
        # Drive may be getting repaired
        if is_drive_being_repaired():
            templateData = {
                "title": "myNode Repairing Drive",
                "header_text": "Repairing Drive",
                "subheader_text": Markup("Drive is being checked and repaired...<br/><br/>This may take several hours."),
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)

        templateData = {
            "title": "myNode Looking for Drive",
            "header_text": "Looking for Drive",
            "subheader_text": "Please attach a drive to your myNode",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_CONFIRM_FORMAT:
        if request.args.get('format'):
            os.system("touch /tmp/format_ok")
            time.sleep(1)
            return redirect("/")

        templateData = {
            "title": "myNode Confirm Drive Format",
            "ui_settings": read_ui_settings()
        }
        return render_template('confirm_drive_format.html', **templateData)
    elif status == STATE_DRIVE_FORMATTING:
        templateData = {
            "title": "myNode Drive Formatting",
            "header_text": "Drive Formatting",
            "subheader_text": "myNode is preparing the drive for use...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_MOUNTED:
        templateData = {
            "title": "myNode Drive Mounted",
            "header_text": "Drive Mounted",
            "subheader_text": "myNode starting soon...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_FULL:
        message  = "Your drive is full!<br/><br/>"
        message += "<p style='font-size: 16px; width: 800px; margin: auto;'>"
        message += "To prevent corrupting any data, your device has stopped running most apps until more free space is available. "
        message += "Please free up some space or attach a larger drive.<br/><br/>"
        message += "If enabled, disabling <a href='/settings#quicksync'>QuickSync</a> can save a large amount of space.<br/><br/>"
        message += "To move to larger drive, try the <a href='/settings#clone_tool'>Clone Tool</a>."
        message += "</p>"
        templateData = {
            "title": "myNode Drive Full",
            "header_text": "Drive Full",
            "subheader_text": Markup(message),
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_CLONE:
        clone_state = get_clone_state()
        if clone_state == CLONE_STATE_DETECTING:
            templateData = {
                "title": "myNode Clone Tool",
                "header_text": "Cloning Tool",
                "subheader_text": Markup("Detecting Drives..."),
                "ui_settings": read_ui_settings(),
                "refresh_rate": 10
            }
            return render_template('state.html', **templateData)
        elif clone_state == CLONE_STATE_ERROR:
            error = get_clone_error()
            templateData = {
                "title": "myNode Clone Tool",
                "header_text": "Cloning Tool",
                "subheader_text": Markup("Clone Error<br/></br>" + error + "<br/><br/><br/><small>Retrying in one minute."),
                "ui_settings": read_ui_settings(),
                "refresh_rate": 10
            }
            return render_template('state.html', **templateData)
        elif clone_state == CLONE_STATE_NEED_CONFIRM:
            # Clone was confirmed
            if request.args.get('clone_confirm'):
                os.system("touch /tmp/.clone_confirm")
                time.sleep(3)
                return redirect("/")

            source_drive = get_clone_source_drive()
            target_drive = get_clone_target_drive()
            target_drive_has_mynode = get_clone_target_drive_has_mynode()
            source_drive_info = get_drive_info(source_drive)
            target_drive_info = get_drive_info(target_drive)
            templateData = {
                "title": "myNode Clone Tool",
                "header_text": "Cloning Tool",
                "target_drive_has_mynode": target_drive_has_mynode,
                "source_drive_info": source_drive_info,
                "target_drive_info": target_drive_info,
                "ui_settings": read_ui_settings(),
            }
            return render_template('clone_confirm.html', **templateData)
        elif clone_state == CLONE_STATE_IN_PROGRESS:
            progress = get_clone_progress()
            templateData = {
                "title": "myNode Clone Tool",
                "header_text": "Cloning Tool",
                "subheader_text": Markup("Cloning...<br/><br/>" + progress),
                "ui_settings": read_ui_settings(),
                "refresh_rate": 5
            }
            return render_template('state.html', **templateData)
        elif clone_state == CLONE_STATE_COMPLETE:
            templateData = {
                "title": "myNode Clone Tool",
                "header_text": "Cloning Tool",
                "subheader_text": Markup("Clone Complete!"),
                "ui_settings": read_ui_settings(),
            }
            return render_template('clone_complete.html', **templateData)
        else:
            templateData = {
                "title": "myNode Clone Tool",
                "header_text": "Cloning Tool",
                "subheader_text": "Unknown Clone State: " + clone_state,
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)
    elif status == STATE_GEN_DHPARAM:
        templateData = {
            "title": "myNode Generating Data",
            "header_text": "Generating Data",
            "subheader_text": "This may take 15-20 minutes...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif not has_product_key() and not skipped_product_key():
        # Show product key page if key not set
        return redirect("/product-key")
    elif status == STATE_QUICKSYNC_COPY:
        try:
            current = subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/bitcoin/"]).split()[0]
            total = subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/quicksync/"]).split()[0]
        except:
            current = 0.0
            total = 100.0

        total = float(total) * 1.3
        percent = (float(current) / float(total)) * 100.0
        if percent >= 99.99:
            percent = 99.99

        message = "<div class='small_message'>{}</<div>".format( get_message() )

        subheader_msg = Markup("Copying files... This will take several hours.<br/>{:.2f}%{}".format(percent, message))

        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": subheader_msg,
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_RESET:
        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": "Restarting QuickSync...",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_DOWNLOAD:
        subheader = Markup("")
        try:
            tc = transmissionrpc.Client('localhost', port=9091)
            t = tc.get_torrent(1)

            dl_rate = float(t.rateDownload) / 1000 / 1000
            complete = t.percentDone * 100

            include_funny = False
            if dl_rate > 3.0:
                include_funny = True
            message = "<div class='small_message'>{}</<div>".format( get_message(include_funny) )

            subheader = Markup("Downloading...<br/>{:.2f}%</br>{:.2f} MB/s{}".format(complete, dl_rate, message))
        except Exception as e:
            subheader = Markup("Starting<br/>Waiting on download client to start...")

        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": subheader,
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_UPGRADING:
        templateData = {
            "title": "myNode Upgrading",
            "header_text": "Upgrading...",
            "subheader_text": "This may take a while...",
            "refresh_rate": 120,
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_SHUTTING_DOWN or is_shutting_down():
        templateData = {
            "title": "myNode Reboot",
            "header_text": "Restarting",
            "subheader_text": "This will take several minutes...",
            "refresh_rate": 120,
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
    elif status == STATE_STABLE:
        bitcoind_status_code = get_service_status_code("bitcoind")
        lnd_status_code = get_service_status_code("lnd")
        tor_status_color = "gray"
        bitcoind_status_color = "red"
        lnd_status_color = "red"
        lnd_ready = is_lnd_ready()
        electrs_active = is_electrs_active()
        bitcoind_status = "Inactive"
        lnd_status = "Inactive"
        electrs_status = ""
        lndconnect_status_color = "gray"
        btcpayserver_status_color = "gray"
        mempoolspace_status_color = "gray"
        vpn_status_color = "gray"
        vpn_status = ""
        current_block = 1234

        if not get_has_updated_btc_info() or uptime_in_seconds < 180:
            error_message = ""
            if bitcoind_status_code != 0 and uptime_in_seconds > 600:
                error_message = "Bitcoin has experienced an error. Please check the logs."
            message = "<div class='small_message'>{}</<div>".format( get_message(include_funny=True) )
            templateData = {
                "title": "myNode Status",
                "header_text": "Starting...",
                "subheader_text": Markup("Launching myNode Services{}".format(message)),
                "error_message": error_message,
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)

        # if is_installing_docker_images():
        #     message = "<div class='small_message'>{}</<div>".format( get_message(include_funny=True) )
        #     templateData = {
        #         "title": "myNode Status",
        #         "header_text": "Starting...",
        #         "subheader_text": Markup("Building Docker Images...{}".format(message)),
        #         "ui_settings": read_ui_settings()
        #     }
        #     return render_template('state.html', **templateData)

        # Display sync info if not synced
        if not is_bitcoind_synced():
            subheader = Markup("Syncing...")
            if bitcoin_block_height != None:
                message = "<div class='small_message'>{}</<div>".format( get_message(include_funny=True) )

                remaining = bitcoin_block_height - mynode_block_height
                subheader = Markup("Syncing...<br/>Block {} of {}{}".format(mynode_block_height, bitcoin_block_height, message))
            templateData = {
                "title": "myNode Sync",
                "header_text": "Bitcoin Blockchain",
                "subheader_text": subheader,
                "refresh_rate": 10,
                "ui_settings": read_ui_settings()
            }
            return render_template('state.html', **templateData)

        # Find tor status
        tor_status_color = get_service_status_color("tor@default")
        tor_status = "Private Connections"

        # Find bitcoind status
        bitcoin_info = get_bitcoin_blockchain_info()
        bitcoin_peers = get_bitcoin_peers()
        if bitcoind_status_code != 0:
            bitcoind_status_color = "red"
        else:
            bitcoind_status_color = "green"
            bitcoind_status = get_bitcoin_status()
            current_block = get_mynode_block_height()

        # Find lnd status
        lnd_status = get_lnd_status()
        lnd_status_color = get_lnd_status_color()

        # Find drive usage
        drive_usage = get_drive_usage()
        low_drive_space_error = False
        if int(re.sub("[^0-9]", "", drive_usage)) > 95:
            low_drive_space_error = True


        # Find lndhub status
        lndhub_status, lndhub_status_color = get_lndhub_status_and_color()

        # Find RTL status
        rtl_status, rtl_status_color = get_rtl_status_and_color()

        # Find LNbits status
        lnbits_status, lnbits_status_color = get_lnbits_status_and_color()

        # Find Thunderhub status
        thunderhub_status, thunderhub_status_color = get_thunderhub_status_and_color()

        # Find electrs status
        electrs_status, electrs_status_color = get_electrs_status_and_color()

        # Find btc-rpc-explorer status
        btcrpcexplorer_status, btcrpcexplorer_status_color, btcrpcexplorer_ready = get_btcrpcexplorer_status_and_color_and_ready()

        # Find mempool space status
        mempoolspace_status, mempoolspace_status_color = get_mempool_status_and_color()

        # Find btcpayserver status
        btcpayserver_status, btcpayserver_status_color = get_btcpayserver_status_and_color()

        # Find VPN status
        vpn_status, vpn_status_color = get_vpn_status_and_color()

        # Find whirlpool status
        whirlpool_status, whirlpool_status_color, whirlpool_initialized = get_whirlpool_status()

        # Find dojo status
        dojo_status, dojo_status_color, dojo_initialized = get_dojo_status()

        # Find caravan status
        caravan_status, caravan_status_color = get_caravan_status_and_color()

        # Find specter status
        specter_status, specter_status_color = get_specter_status_and_color()

        # Check for new version of software
        upgrade_available = False
        current = get_current_version()
        latest = get_latest_version()
        if current != "0.0" and latest != "0.0" and current != latest:
            upgrade_available = True

        # Refresh rate
        refresh_rate = 3600 * 24
        if bitcoind_status_color == "red" or lnd_status_color == "red":
            refresh_rate = 60
        elif bitcoind_status_color == "yellow" or lnd_status_color == "yellow":
            refresh_rate = 120

        templateData = {
            "title": "myNode Home",
            "refresh_rate": refresh_rate,
            "config": CONFIG,
            "bitcoind_status_color": bitcoind_status_color,
            "bitcoind_status": Markup(bitcoind_status),
            "current_block": current_block,
            "bitcoin_peer_count": get_bitcoin_peer_count(),
            "bitcoin_difficulty": get_bitcoin_difficulty(),
            "bitcoin_mempool_size": get_bitcoin_mempool_size(),
            "bitcoin_version": get_bitcoin_version(),
            "lnd_status_color": lnd_status_color,
            "lnd_status": Markup(lnd_status),
            "lnd_ready": lnd_ready,
            "lnd_peer_count": get_lightning_peer_count(),
            "lnd_channel_count": get_lightning_channel_count(),
            "lnd_balance_info": get_lightning_balance_info(),
            "lnd_version": get_lnd_version(),
            "tor_status_color": tor_status_color,
            "tor_status": tor_status,
            "is_installing_docker_images": is_installing_docker_images(),
            "is_device_from_reseller": is_device_from_reseller(),
            "electrs_status_color": electrs_status_color,
            "electrs_status": Markup(electrs_status),
            "electrs_enabled": is_electrs_enabled(),
            "electrs_active": electrs_active,
            "rtl_status_color": rtl_status_color,
            "rtl_status": rtl_status,
            "rtl_enabled": is_rtl_enabled(),
            "lnbits_status_color": lnbits_status_color,
            "lnbits_status": lnbits_status,
            "lnbits_enabled": is_lnbits_enabled(),
            "thunderhub_status_color": thunderhub_status_color,
            "thunderhub_status": thunderhub_status,
            "thunderhub_enabled": is_thunderhub_enabled(),
            "lndhub_status_color": lndhub_status_color,
            "lndhub_status": lndhub_status,
            "lndhub_enabled": is_lndhub_enabled(),
            "btcrpcexplorer_ready": btcrpcexplorer_ready,
            "btcrpcexplorer_status_color": btcrpcexplorer_status_color,
            "btcrpcexplorer_status": btcrpcexplorer_status,
            "btcrpcexplorer_enabled": is_btcrpcexplorer_enabled(),
            "btcrpcexplorer_sso_token": get_btcrpcexplorer_sso_token(),
            "caravan_status_color": caravan_status_color,
            "caravan_status": caravan_status,
            "caravan_enabled": is_caravan_enabled(),
            "specter_status_color": specter_status_color,
            "specter_status": specter_status,
            "specter_enabled": is_specter_enabled(),
            "mempoolspace_status_color": mempoolspace_status_color,
            "mempoolspace_status": mempoolspace_status,
            "mempoolspace_enabled": is_mempoolspace_enabled(),
            "btcpayserver_enabled": is_btcpayserver_enabled(),
            "btcpayserver_status_color": btcpayserver_status_color,
            "btcpayserver_status": btcpayserver_status,
            "vpn_status_color": vpn_status_color,
            "vpn_status": vpn_status,
            "vpn_enabled": is_vpn_enabled(),
            "whirlpool_status": whirlpool_status,
            "whirlpool_status_color": whirlpool_status_color,
            "whirlpool_enabled": is_whirlpool_enabled(),
            "whirlpool_initialized": whirlpool_initialized,
            "is_dojo_installed": is_dojo_installed(),
            "dojo_status": dojo_status,
            "dojo_status_color": dojo_status_color,
            "dojo_enabled": is_dojo_enabled(),
            "dojo_initialized": dojo_initialized,
            "product_key_skipped": pk_skipped,
            "product_key_error": pk_error,
            "fsck_error": has_fsck_error(),
            "fsck_results": get_fsck_results(),
            "sd_rw_error": has_sd_rw_error(),
            "drive_usage": drive_usage,
            "low_drive_space_error": low_drive_space_error,
            "cpu_usage": get_cpu_usage(),
            "ram_usage": get_ram_usage(),
            "swap_usage": get_swap_usage(),
            "device_temp": get_device_temp(),
            "upgrade_available": upgrade_available,
            "has_changed_password": has_changed_password(),
            "ui_settings": read_ui_settings()
        }
        return render_template('main.html', **templateData)
    else:
        templateData = {
            "title": "myNode Error",
            "header_text": "Error",
            "subheader_text": "Unknown State ("+status+"). Please restart your myNode.",
            "ui_settings": read_ui_settings()
        }
        return render_template('state.html', **templateData)
Esempio n. 3
0
def index():
    status = get_status()

    bitcoin_block_height = get_bitcoin_block_height()
    mynode_block_height = get_mynode_block_height()
    lnd_info = get_lightning_info()
    pk_skipped = skipped_product_key()
    pk_error = not is_valid_product_key()

    # Show product key page if key not set
    if not has_product_key() and not skipped_product_key():
        return redirect("/product-key")

    if status == STATE_DRIVE_MISSING:
        templateData = {
            "title": "myNode Looking for Drive",
            "header_text": "Looking for Drive",
            "subheader_text": "Please attach a drive to your myNode"
        }
        return render_template('state.html', **templateData)
    elif status == STATE_DRIVE_MOUNTED:
        templateData = {
            "title": "myNode QuickSync",
            "header_text": "Drive Mounted",
            "subheader_text": "myNode starting soon..."
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_COPY:
        try:
            current = subprocess.check_output(
                ["du", "-m", "--max-depth=0",
                 "/mnt/hdd/mynode/bitcoin/"]).split()[0]
            total = subprocess.check_output(
                ["du", "-m", "--max-depth=0",
                 "/mnt/hdd/mynode/quicksync/"]).split()[0]
        except:
            current = 0.0
            total = 100.0

        total = float(total) * 1.3
        percent = (float(current) / float(total)) * 100.0
        if percent >= 99.99:
            percent = 99.99

        message = "<div class='small_message'>{}</<div>".format(get_message())

        subheader_msg = Markup(
            "Copying files... This will take several hours.<br/>{:.2f}%{}".
            format(percent, message))

        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": subheader_msg
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_RESET:
        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": "Restarting QuickSync..."
        }
        return render_template('state.html', **templateData)
    elif status == STATE_QUICKSYNC_DOWNLOAD:
        subheader = Markup("")
        try:
            tc = transmissionrpc.Client('localhost', port=9091)
            t = tc.get_torrent(1)

            dl_rate = float(t.rateDownload) / 1000 / 1000
            complete = t.percentDone * 100

            include_funny = False
            if dl_rate > 3.0:
                include_funny = True
            message = "<div class='small_message'>{}</<div>".format(
                get_message(include_funny))

            subheader = Markup(
                "Downloading...<br/>{:.2f}%</br>{:.2f} MB/s{}".format(
                    complete, dl_rate, message))
        except Exception as e:
            subheader = Markup(
                "Starting<br/>Waiting on download client to start...")

        templateData = {
            "title": "myNode QuickSync",
            "header_text": "QuickSync",
            "subheader_text": subheader
        }
        return render_template('state.html', **templateData)
    elif status == STATE_STABLE:
        bitcoind_status_code = os.system(
            "systemctl status bitcoind --no-pager")
        lnd_status_code = os.system("systemctl status lnd --no-pager")
        bitcoind_status_color = "red"
        lnd_status_color = "red"
        lnd_ready = is_lnd_ready()
        rtl_status_color = "gray"
        rtl_status = "Lightning Wallet"
        lnd_admin_status_color = "gray"
        lnd_admin_status = "Lightning Wallet"
        electrs_status_color = "gray"
        lndhub_status_color = "gray"
        bitcoind_status = "Inactive"
        lnd_status = "Inactive"
        electrs_status = ""
        explorer_status = ""
        explorer_ready = False
        explorer_status_color = "red"
        btcrpcexplorer_status = ""
        btcrpcexplorer_ready = False
        btcrpcexplorer_status_color = "gray"

        if not get_has_updated_btc_info():
            message = "<div class='small_message'>{}</<div>".format(
                get_message(include_funny=True))
            templateData = {
                "title":
                "myNode Status",
                "header_text":
                "Starting...",
                "subheader_text":
                Markup("Launching myNode services...{}".format(message))
            }
            return render_template('state.html', **templateData)

        # Display sync info if not synced
        if not is_bitcoind_synced():
            subheader = Markup("Syncing...")
            if bitcoin_block_height != None:
                message = "<div class='small_message'>{}</<div>".format(
                    get_message(include_funny=True))

                remaining = bitcoin_block_height - mynode_block_height
                subheader = Markup("Syncing...<br/>Block {} of {}{}".format(
                    mynode_block_height, bitcoin_block_height, message))
            templateData = {
                "title": "myNode Sync",
                "header_text": "Bitcoin Blockchain",
                "subheader_text": subheader
            }
            return render_template('state.html', **templateData)

        # Find bitcoind status
        if bitcoind_status_code != 0:
            bitcoind_status_color = "red"
        else:
            bitcoind_status = "Validating blocks..."
            bitcoind_status_color = "green"
            if bitcoin_block_height != None:
                remaining = bitcoin_block_height - mynode_block_height
                if remaining == 0:
                    bitcoind_status = "Running"
                else:
                    bitcoind_status = "Syncing<br/>{} blocks remaining...".format(
                        remaining)
            else:
                bitcoind_status = "Waiting for info..."

        # Find lnd status
        if is_bitcoind_synced():
            lnd_status_color = "green"
            lnd_status = get_lnd_status()

            # Get LND status
            if not lnd_wallet_exists():
                # This hides the restart /login attempt LND does from the GUI
                lnd_status_color = "green"
            elif lnd_status_code != 0:
                lnd_status_color = "red"
                if lnd_status == "Logging in...":
                    lnd_status_color = "yellow"
        else:
            lnd_status_color = "yellow"
            lnd_status = "Waiting..."

        # Find lndhub status
        if is_lndhub_enabled():
            if lnd_ready:
                status = os.system("systemctl status lndhub --no-pager")
                if status != 0:
                    lndhub_status_color = "red"
                else:
                    lndhub_status_color = "green"
            else:
                lndhub_status_color = "green"

        # Find RTL status
        if lnd_ready:
            status = os.system("systemctl status rtl --no-pager")
            if status != 0:
                rtl_status_color = "red"
            else:
                rtl_status_color = "green"

        # Find LND Admin Status
        if lnd_ready:
            status = os.system("systemctl status lnd_admin --no-pager")
            if status != 0:
                lnd_admin_status_color = "red"
            else:
                lnd_admin_status_color = "green"

        # Find electrs status
        if CONFIG["electrs_enabled"]:
            if is_electrs_enabled():
                status = os.system("systemctl status electrs --no-pager")
                if status != 0:
                    electrs_status_color = "red"
                else:
                    electrs_status_color = "green"
                    electrs_status = get_electrs_status()

        # Find btc-rpc-explorer status
        if CONFIG["btcrpcexplorer_enabled"]:
            btcrpcexplorer_status = "BTC RPC Explorer"
            if is_btcrpcexplorer_enabled():
                status = os.system(
                    "systemctl status btc_rpc_explorer --no-pager")
                if status != 0:
                    btcrpcexplorer_status_color = "red"
                else:
                    btcrpcexplorer_status_color = "green"

        # Find explorer status
        if CONFIG["explorer_enabled"]:
            explorer_status_color = electrs_status_color
            if is_electrs_enabled():
                if is_electrs_active():
                    explorer_ready = True
                    explorer_status = "myNode BTC Explorer"
                else:
                    explorer_status = Markup(
                        "Bitcoin Explorer<br/><br/>Waiting on Electrum Server..."
                    )
            else:
                explorer_status = Markup(
                    "Bitcoin Explorer<br/><br/>Requires Electrum Server")

        # Check for new version of software
        upgrade_available = False
        current = get_current_version()
        latest = get_latest_version()
        if current != "0.0" and latest != "0.0" and current != latest:
            upgrade_available = True

        templateData = {
            "title": "myNode Home",
            "config": CONFIG,
            "bitcoind_status_color": bitcoind_status_color,
            "bitcoind_status": Markup(bitcoind_status),
            "lnd_status_color": lnd_status_color,
            "lnd_status": Markup(lnd_status),
            "lnd_ready": lnd_ready,
            "electrs_status_color": electrs_status_color,
            "electrs_status": Markup(electrs_status),
            "electrs_enabled": is_electrs_enabled(),
            "rtl_status_color": rtl_status_color,
            "rtl_status": rtl_status,
            "lnd_admin_status_color": lnd_admin_status_color,
            "lnd_admin_status": lnd_admin_status,
            "lndhub_status_color": lndhub_status_color,
            "lndhub_enabled": is_lndhub_enabled(),
            "explorer_ready": explorer_ready,
            "explorer_status_color": explorer_status_color,
            "explorer_status": explorer_status,
            "btcrpcexplorer_ready": btcrpcexplorer_ready,
            "btcrpcexplorer_status_color": btcrpcexplorer_status_color,
            "btcrpcexplorer_status": btcrpcexplorer_status,
            "btcrpcexplorer_enabled": is_btcrpcexplorer_enabled(),
            "product_key_skipped": pk_skipped,
            "product_key_error": pk_error,
            "drive_usage": get_drive_usage(),
            "cpu_usage": get_cpu_usage(),
            "ram_usage": get_ram_usage(),
            "swap_usage": get_swap_usage(),
            "upgrade_available": upgrade_available
        }
        return render_template('main.html', **templateData)
    else:
        templateData = {
            "title":
            "myNode Error",
            "header_text":
            "Error",
            "subheader_text":
            "Unknown State (" + status + "). Please restart your myNode."
        }
        return render_template('state.html', **templateData)