From 75a2a38f60c7e5182ffe4ab6b1e99b6331434117 Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Sun, 21 Apr 2024 23:58:26 -0500 Subject: [PATCH] Add lnbits setting options (thanks to tlindi) --- .../etc/systemd/system/lnbits.service | 6 ++-- .../standard/usr/bin/mynode_docker_images.sh | 2 +- rootfs/standard/var/pynode/device_info.py | 13 ++++++++ rootfs/standard/var/www/mynode/api.py | 18 +++++++++++ rootfs/standard/var/www/mynode/settings.py | 10 +++++++ .../var/www/mynode/templates/settings.html | 30 +++++++++++++++++++ 6 files changed, 75 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 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..38c29bc5 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) + +@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) \ No newline at end of file diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index e22adf04..5c495de5 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(1.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..876f0fde 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -710,6 +710,17 @@ $('#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 +1226,25 @@ +
+ +
LNbits
+ +
Reset LNbits Settings
+ This will delete your LNbits settings from the database. This should not impact users, wallets and installed extension data. After deletion, LNbits will re-read its default settings from the environment file and save it in the new settings database. This will also reset super user username and password. +
+ Delete Settings + +
+ +
Show LNbits superuser ID
+ Show the superuser ID for LNbits. It is needed to access the admin UI. +
+ +

+        
+ +
Specter