From 3758364341273d44fde24346be05531a1f76643d Mon Sep 17 00:00:00 2001 From: tlindi Date: Mon, 26 Feb 2024 20:55:27 +0200 Subject: [PATCH 1/3] Rename lnbits-legend docker to lnbits - change docker image name lnbits-legend to lnbits to match vendor naming --- rootfs/standard/etc/systemd/system/lnbits.service | 6 +++--- rootfs/standard/usr/bin/mynode_docker_images.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rootfs/standard/etc/systemd/system/lnbits.service b/rootfs/standard/etc/systemd/system/lnbits.service index 42d87a07..f6bc127d 100644 --- a/rootfs/standard/etc/systemd/system/lnbits.service +++ b/rootfs/standard/etc/systemd/system/lnbits.service @@ -15,15 +15,15 @@ ExecStartPre=/usr/bin/service_scripts/pre_lnbits.sh WorkingDirectory=/opt/mynode/lnbits ExecStart=/usr/bin/docker run --rm \ - --name lnbits-legend \ + --name lnbits \ -p 5000:5000 \ --volume /mnt/hdd/mynode/lnbits/.env:/app/.env \ --volume /mnt/hdd/mynode/lnbits/:/app/data \ --volume /mnt/hdd/mynode/lnd/tls.cert:/app/tls.cert \ --volume /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon:/app/admin.macaroon \ --add-host=host.docker.internal:host-gateway \ - lnbits-legend -ExecStop=/usr/bin/docker stop -t 2 lnbits-legend + lnbits +ExecStop=/usr/bin/docker stop -t 2 lnbits User=bitcoin Group=bitcoin diff --git a/rootfs/standard/usr/bin/mynode_docker_images.sh b/rootfs/standard/usr/bin/mynode_docker_images.sh index 7f7fd4fb..c15b8ecb 100755 --- a/rootfs/standard/usr/bin/mynode_docker_images.sh +++ b/rootfs/standard/usr/bin/mynode_docker_images.sh @@ -217,7 +217,7 @@ while true; do # Handled in pre_lnbits.sh # Build lnbits docker container - docker build --no-cache -t lnbits-legend . + docker build --no-cache -t lnbits . echo $LNBITS_VERSION > $LNBITS_VERSION_FILE fi From 736541ae883145979137c68cb2136d0ae8fbde09 Mon Sep 17 00:00:00 2001 From: tlindi Date: Mon, 26 Feb 2024 20:58:57 +0200 Subject: [PATCH 2/3] Fix LNbits .env creation use .env.example from LNbits package as .env template --- .../usr/bin/service_scripts/pre_lnbits.sh | 43 +++++++---- rootfs/standard/usr/share/mynode/lnbits.env | 77 ------------------- 2 files changed, 29 insertions(+), 91 deletions(-) delete mode 100644 rootfs/standard/usr/share/mynode/lnbits.env diff --git a/rootfs/standard/usr/bin/service_scripts/pre_lnbits.sh b/rootfs/standard/usr/bin/service_scripts/pre_lnbits.sh index c4f3deb9..3080bf20 100755 --- a/rootfs/standard/usr/bin/service_scripts/pre_lnbits.sh +++ b/rootfs/standard/usr/bin/service_scripts/pre_lnbits.sh @@ -1,23 +1,38 @@ #!/bin/bash set -x +source /usr/share/mynode/mynode_app_versions.sh -# Copy config file -if [ ! -f /mnt/hdd/mynode/lnbits/.env ]; then - cp /usr/share/mynode/lnbits.env /mnt/hdd/mynode/lnbits/.env +# Delete old myNode .env file created before 0.12.x +if [ -f /usr/share/mynode/lnbits.env ]; then + rm -f /usr/share/mynode/lnbits.env +fi + +# if current LNbits version config is missign create .env from .env.example +if [ ! -f /mnt/hdd/mynode/lnbits/update_config_$LNBITS_VERSION ]; then + rm -f /mnt/hdd/mynode/lnbits/update_config_* + touch /mnt/hdd/mynode/lnbits/update_config_$LNBITS_VERSION + + cp -f /opt/mynode/lnbits/.env.example /mnt/hdd/mynode/lnbits/.env chown bitcoin:bitcoin /mnt/hdd/mynode/lnbits/.env + +# debug Disable + sed -i "s|^DEBUG=.*|DEBUG=false|g" /mnt/hdd/mynode/lnbits/.env +# debug Enable +# sed -i "s|^DEBUG=.*|DEBUG=true|g" /mnt/hdd/mynode/lnbits/.env + +# ADMIN_UI Disable + sed -i "s|^LNBITS_ADMIN_UI=.*|LNBITS_ADMIN_UI=false|g" /mnt/hdd/mynode/lnbits/.env +# ADMIN_UI Enable +# sed -i "s|^LNBITS_ADMIN_UI=.*|LNBITS_ADMIN_UI=true|g" /mnt/hdd/mynode/lnbits/.env + +# Update env with mynode lnd REST ip and port + sed -i "s|^LND_REST_ENDPOINT=.*|LND_REST_ENDPOINT=https\:\/\/172.17.0.1:10080\/|g" /mnt/hdd/mynode/lnbits/.env + +# Update env with files mapped in lnbits.service + sed -i "s|^LND_REST_CERT=.*|LND_REST_CERT=\"/app/tls.cert\"|g" /mnt/hdd/mynode/lnbits/.env + sed -i "s|^LND_REST_MACAROON=.*|LND_REST_MACAROON=\"/app/admin.macaroon\"|g" /mnt/hdd/mynode/lnbits/.env fi -# Force update of LNBits config file (increment to force new update) -# LNBITS_CONFIG_UPDATE_NUM=1 -# if [ ! -f /mnt/hdd/mynode/lnbits/update_config_$LNBITS_CONFIG_UPDATE_NUM ]; then -# cp -f /usr/share/mynode/lnbits.env /mnt/hdd/mynode/lnbits/.env -# chown bitcoin:bitcoin /mnt/hdd/mynode/lnbits/.env -# touch /mnt/hdd/mynode/lnbits/update_config_$LNBITS_CONFIG_UPDATE_NUM -# fi -# Generate hex macaroons -#macaroonAdminHex=$(xxd -ps -u -c 1000 /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon) -# Update env file -sed -i "s|^LND_REST_MACAROON=.*|LND_REST_MACAROON=\"/app/admin.macaroon\"|g" /mnt/hdd/mynode/lnbits/.env diff --git a/rootfs/standard/usr/share/mynode/lnbits.env b/rootfs/standard/usr/share/mynode/lnbits.env deleted file mode 100644 index f76ab95c..00000000 --- a/rootfs/standard/usr/share/mynode/lnbits.env +++ /dev/null @@ -1,77 +0,0 @@ -HOST=127.0.0.1 -PORT=5000 - -# uvicorn variable, uncomment to allow https behind a proxy -# FORWARDED_ALLOW_IPS="*" - -DEBUG=false - -# Server security, rate limiting ips, blocked ips, allowed ips -LNBITS_RATE_LIMIT_NO="200" -LNBITS_RATE_LIMIT_UNIT="minute" -LNBITS_ALLOWED_IPS="" -LNBITS_BLOCKED_IPS="" - -# Allow users and admins by user IDs (comma separated list) -LNBITS_ALLOWED_USERS="" -LNBITS_ADMIN_USERS="" -# Extensions only admin can access -LNBITS_ADMIN_EXTENSIONS="ngrok, admin" - -# Enable Admin GUI, available for the first user in LNBITS_ADMIN_USERS if available -# Warning: Enabling this will make LNbits ignore this configuration file. Your settings will -# be stored in your database and you will be able to change them only through the Admin UI. -# Disable this to make LNbits use this config file again. -# MYNODE TODO: CHANGE THIS TO TRUE -LNBITS_ADMIN_UI=false - -LNBITS_DEFAULT_WALLET_NAME="LNbits wallet" - -# Ad space description -# LNBITS_AD_SPACE_TITLE="Supported by" -# csv ad space, format ";;, ;;", extensions can choose to honor -LNBITS_AD_SPACE="" - -# Hides wallet api, extensions can choose to honor -LNBITS_HIDE_API=false - -# Disable extensions for all users, use "all" to disable all extensions -LNBITS_DISABLED_EXTENSIONS="amilk" - -# Database: to use SQLite, specify LNBITS_DATA_FOLDER -# to use PostgreSQL, specify LNBITS_DATABASE_URL=postgres://... -# to use CockroachDB, specify LNBITS_DATABASE_URL=cockroachdb://... -# for both PostgreSQL and CockroachDB, you'll need to install -# psycopg2 as an additional dependency -LNBITS_DATA_FOLDER="./data" -# LNBITS_DATABASE_URL="postgres://user:password@host:port/databasename" - -LNBITS_FORCE_HTTPS=false -LNBITS_SERVICE_FEE="0.0" -# value in millisats -LNBITS_RESERVE_FEE_MIN=2000 -# value in percent -LNBITS_RESERVE_FEE_PERCENT=1.0 - -# Limit fiat currencies allowed to see in UI -# LNBITS_ALLOWED_CURRENCIES="EUR, USD" - -# Change theme -LNBITS_SITE_TITLE="LNbits" -LNBITS_SITE_TAGLINE="free and open-source lightning wallet" -LNBITS_SITE_DESCRIPTION="Some description about your service, will display if title is not 'LNbits'" -# Choose from bitcoin, mint, flamingo, freedom, salvador, autumn, monochrome, classic, cyber -LNBITS_THEME_OPTIONS="classic, bitcoin, flamingo, freedom, mint, autumn, monochrome, salvador, cyber" -# LNBITS_CUSTOM_LOGO="https://lnbits.com/assets/images/logo/logo.svg" - -# Choose from LNPayWallet, OpenNodeWallet, LntxbotWallet, ClicheWallet -# LndRestWallet, CoreLightningWallet, LNbitsWallet, SparkWallet, FakeWallet, EclairWallet -LNBITS_BACKEND_WALLET_CLASS=LndRestWallet - -# LndRestWallet -LND_REST_ENDPOINT=https://172.17.0.1:10080/ -#LND_REST_ENDPOINT=https://host.docker.internal:10080/ -LND_REST_CERT="/app/tls.cert" -LND_REST_MACAROON=FILL_IN -# To use an AES-encrypted macaroon, set -# LND_REST_MACAROON_ENCRYPTED="eNcRyPtEdMaCaRoOn" From d9cc901e0e3c335ef02683d98dbac8af9dc10dd1 Mon Sep 17 00:00:00 2001 From: tlindi Date: Tue, 13 Feb 2024 21:01:03 +0200 Subject: [PATCH 3/3] Add LNbits lnbits-cli delete-settings and superuser add LNbits to settings page, fetch superuser usr and reset database --- rootfs/standard/var/pynode/device_info.py | 13 ++++++++ rootfs/standard/var/www/mynode/api.py | 20 ++++++++++++- rootfs/standard/var/www/mynode/settings.py | 10 +++++++ .../var/www/mynode/templates/settings.html | 30 +++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/rootfs/standard/var/pynode/device_info.py b/rootfs/standard/var/pynode/device_info.py index e1b9c06c..24d22752 100644 --- a/rootfs/standard/var/pynode/device_info.py +++ b/rootfs/standard/var/pynode/device_info.py @@ -1228,6 +1228,19 @@ def clear_mempool_cache(): os.system("sync") os.system("systemctl restart mempool") +#================================== +# LNbits Functions +#================================== +def delete_lnbits_settings(): + os.system("rm -rf /mnt/hdd/mynode/lnbits/.super_user") + os.system("/usr/bin/docker run --rm \ + --name lnbits-delete-settings \ + --volume /mnt/hdd/mynode/lnbits/.env:/app/.env \ + --volume /mnt/hdd/mynode/lnbits/:/app/data \ + lnbits poetry run lnbits-cli delete-settings") + if is_service_enabled("lnbits"): + restart_service("lnbits") + #================================== # Specter Functions #================================== diff --git a/rootfs/standard/var/www/mynode/api.py b/rootfs/standard/var/www/mynode/api.py index 8a66fb6d..49937232 100644 --- a/rootfs/standard/var/www/mynode/api.py +++ b/rootfs/standard/var/www/mynode/api.py @@ -313,4 +313,22 @@ def api_get_usb_info(): data["status"] = "success" except Exception as e: data["data"] = str(e) - return generate_api_json_response(data) \ No newline at end of file + return generate_api_json_response(data) + +@mynode_api.route("/api/get_lnbits_superuser") +def api_get_lnbits_superuser(): + check_logged_in() + + data = {} + data["status"] = "error" + data["data"] = "UNKNOWN" + try: + info = "" + + info += to_string(subprocess.check_output("cat /mnt/hdd/mynode/lnbits/.super_user", shell=True)) + info += "\n" + data["data"] = info + data["status"] = "success" + except Exception as e: + data["data"] = str(e) + return generate_api_json_response(data) diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index e22adf04..ab600d33 100644 --- a/rootfs/standard/var/www/mynode/settings.py +++ b/rootfs/standard/var/www/mynode/settings.py @@ -591,6 +591,16 @@ def reset_thunderhub_config_page(): flash("Thunderhub Configuration Reset", category="message") return redirect("/settings") +@mynode_settings.route("/settings/delete-lnbits-settings") +def delete_lnbits_settings_page(): + check_logged_in() + + t = Timer(10.0, delete_lnbits_settings) + t.start() + + flash("LNbits Settings Deleted", category="message") + return redirect("/settings") + @mynode_settings.route("/settings/reset-specter-config") def reset_specter_config_page(): check_logged_in() diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index f0a1e000..d29be4eb 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -710,6 +710,18 @@ $('#loading_spinner_overlay').fadeIn(); window.location.href='/settings/toggle_setting?name=torify_apt_get&enable='+val }); + + $("#run-lnbits-cli-superuser").on("click", function() { + $("#run-lnbits-cli-superuser").prop("disabled",true); + $("#run-lnbits-cli-superuser-result").html("Loading..."); + $.get("/api/get_lnbits_superuser") + .done(function( data ) { + $("#run-lnbits-cli-superuser").prop("disabled",false); + $("#run-lnbits-cli-superuser-result").html( data["data"] ); + } + ); + }); + }); function hideAllUpgradeLogs() { @@ -1215,6 +1227,24 @@ +
+ +
LNbits
+ +
Reset LNbits Settings
+ This will delete your LNbits settings from database. This should not impact users, wallets and installed extension data stored in LNbits. When applied LNbits will read its default settings from .env file to database. Use this also if you need reset super user username and password. +
+ Delete Settings + +
+ +
Show LNbits superuser ID
+ Run lnbits-cli superuser command and show usr ID. It is needed to access LNbits admin UI. +
+ +

+        
+
Specter