From f6523fcc2151b49fe88b9380a2b7fa6039ea0473 Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Sat, 29 Jun 2019 21:08:19 -0500 Subject: [PATCH] Add ability to change alias --- rootfs/standard/usr/bin/mynode_startup.sh | 2 +- rootfs/standard/var/www/mynode/lnd.py | 35 +++++++++++++- .../var/www/mynode/templates/lnd.html | 47 ++++++++++++++++++- 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/rootfs/standard/usr/bin/mynode_startup.sh b/rootfs/standard/usr/bin/mynode_startup.sh index 92712caf..3ff9487f 100755 --- a/rootfs/standard/usr/bin/mynode_startup.sh +++ b/rootfs/standard/usr/bin/mynode_startup.sh @@ -82,7 +82,7 @@ fi # Setup LND Node Name if [ ! -f /home/bitcoin/.mynode/.lndalias ]; then - echo "mynodebtc.com [myNode]"> /home/bitcoin/.mynode/.lndalias + echo "mynodebtc.com [myNode]" > /home/bitcoin/.mynode/.lndalias fi diff --git a/rootfs/standard/var/www/mynode/lnd.py b/rootfs/standard/var/www/mynode/lnd.py index 933392ec..69322304 100644 --- a/rootfs/standard/var/www/mynode/lnd.py +++ b/rootfs/standard/var/www/mynode/lnd.py @@ -3,6 +3,7 @@ from pprint import pprint, pformat from threading import Timer from bitcoin_info import * from lightning_info import * +from settings import reboot_device import base64 import subprocess import json @@ -10,7 +11,7 @@ import pam import time import re import requests -import os.path +import os mynode_lnd = Blueprint('mynode_lnd',__name__) @@ -234,3 +235,35 @@ def page_lnd_lndconnect(): "lndconnect_remote_rest_img": lndconnect_remote_rest_img } return render_template('lndconnect.html', **templateData) + + +@mynode_lnd.route("/lnd/change_alias", methods=["POST"]) +def page_lnd_change_alias(): + # Load page + p = pam.pam() + pw = request.form.get('password_change_alias') + if pw == None or p.authenticate("admin", pw) == False: + return redirect(url_for(".page_lnd", error_message="Invalid Password")) + + # Change alias + alias = request.form.get('alias') + if alias == None or alias == "": + return redirect(url_for(".page_lnd", error_message="Empty Alias")) + if len(alias) > 35: + return redirect(url_for(".page_lnd", error_message="Invalid Alias")) + with open("/home/bitcoin/.mynode/.lndalias", "w") as f: + utf8_alias = alias.decode('utf-8', 'ignore') + f.write(utf8_alias) + f.close() + + # Reboot + t = Timer(1.0, reboot_device) + t.start() + + # Wait until device is restarted + templateData = { + "title": "myNode Reboot", + "header_text": "Restarting", + "subheader_text": "This will take several minutes..." + } + return render_template('reboot.html', **templateData) diff --git a/rootfs/standard/var/www/mynode/templates/lnd.html b/rootfs/standard/var/www/mynode/templates/lnd.html index a42219ba..91c684f4 100644 --- a/rootfs/standard/var/www/mynode/templates/lnd.html +++ b/rootfs/standard/var/www/mynode/templates/lnd.html @@ -14,6 +14,8 @@