From 32fdd8b011c3d48de2da10d294a705b79d65e02f Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Tue, 28 Jan 2020 19:59:46 -0600 Subject: [PATCH] Add IP/Tor toggle for Bitcoin and LND --- .../usr/bin/mynode_gen_bitcoin_config.sh | 16 ++++++ .../standard/usr/bin/mynode_gen_lnd_config.sh | 9 +++ rootfs/standard/usr/share/mynode/bitcoin.conf | 9 --- .../usr/share/mynode/bitcoin_ipv4.conf | 2 + .../usr/share/mynode/bitcoin_tor.conf | 9 +++ rootfs/standard/usr/share/mynode/lnd.conf | 7 +-- .../standard/usr/share/mynode/lnd_ipv4.conf | 5 ++ rootfs/standard/usr/share/mynode/lnd_tor.conf | 8 +++ rootfs/standard/var/www/mynode/device_info.py | 11 ++++ rootfs/standard/var/www/mynode/mynode.py | 2 +- rootfs/standard/var/www/mynode/settings.py | 24 ++++++++ .../var/www/mynode/static/css/mynode.css | 55 +++++++++++++++++++ .../mynode/templates/includes/services.html | 4 +- .../var/www/mynode/templates/settings.html | 30 ++++++++++ 14 files changed, 173 insertions(+), 18 deletions(-) create mode 100644 rootfs/standard/usr/share/mynode/bitcoin_ipv4.conf create mode 100644 rootfs/standard/usr/share/mynode/bitcoin_tor.conf create mode 100644 rootfs/standard/usr/share/mynode/lnd_ipv4.conf create mode 100644 rootfs/standard/usr/share/mynode/lnd_tor.conf diff --git a/rootfs/standard/usr/bin/mynode_gen_bitcoin_config.sh b/rootfs/standard/usr/bin/mynode_gen_bitcoin_config.sh index 6ab01b12..3aa2d32c 100755 --- a/rootfs/standard/usr/bin/mynode_gen_bitcoin_config.sh +++ b/rootfs/standard/usr/bin/mynode_gen_bitcoin_config.sh @@ -1,10 +1,26 @@ #!/bin/bash +# Setup default settings +if [ ! -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled_defaulted ]; then + touch /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled_defaulted + touch /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled + sync +fi + # Generate BTC Config if [ -f /mnt/hdd/mynode/settings/bitcoin_custom.conf ]; then + # Use Custom Config cp -f /mnt/hdd/mynode/settings/bitcoin_custom.conf /mnt/hdd/mynode/bitcoin/bitcoin.conf else + # Generate a default config cp -f /usr/share/mynode/bitcoin.conf /mnt/hdd/mynode/bitcoin/bitcoin.conf + + # Append other sections + if [ -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled ]; then + cat /usr/share/mynode/bitcoin_tor.conf >> /mnt/hdd/mynode/bitcoin/bitcoin.conf + else + cat /usr/share/mynode/bitcoin_ipv4.conf >> /mnt/hdd/mynode/bitcoin/bitcoin.conf + fi fi PW=$(cat /mnt/hdd/mynode/settings/.btcrpcpw) diff --git a/rootfs/standard/usr/bin/mynode_gen_lnd_config.sh b/rootfs/standard/usr/bin/mynode_gen_lnd_config.sh index e33bc319..0d89cfe4 100755 --- a/rootfs/standard/usr/bin/mynode_gen_lnd_config.sh +++ b/rootfs/standard/usr/bin/mynode_gen_lnd_config.sh @@ -2,9 +2,18 @@ # Generate LND Config if [ -f /mnt/hdd/mynode/settings/lnd_custom.conf ]; then + # Use Custom Config cp -f /mnt/hdd/mynode/settings/lnd_custom.conf /mnt/hdd/mynode/lnd/lnd.conf else + # Generate a default config cp -f /usr/share/mynode/lnd.conf /mnt/hdd/mynode/lnd/lnd.conf + + # Append other sections + if [ -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled ]; then + cat /usr/share/mynode/lnd_tor.conf >> /mnt/hdd/mynode/lnd/lnd.conf + else + cat /usr/share/mynode/lnd_ipv4.conf >> /mnt/hdd/mynode/lnd/lnd.conf + fi fi ALIAS=$(cat /mnt/hdd/mynode/settings/.lndalias) diff --git a/rootfs/standard/usr/share/mynode/bitcoin.conf b/rootfs/standard/usr/share/mynode/bitcoin.conf index 06889cb1..2311c0cd 100644 --- a/rootfs/standard/usr/share/mynode/bitcoin.conf +++ b/rootfs/standard/usr/share/mynode/bitcoin.conf @@ -36,12 +36,3 @@ maxmempool=200 maxconnections=40 maxuploadtarget=1000 -# Tor config -proxy=127.0.0.1:9050 -listen=1 -bind=127.0.0.1 - -# Tor only (default) -onlynet=onion -dnsseed=0 -dns=0 diff --git a/rootfs/standard/usr/share/mynode/bitcoin_ipv4.conf b/rootfs/standard/usr/share/mynode/bitcoin_ipv4.conf new file mode 100644 index 00000000..8518b9d9 --- /dev/null +++ b/rootfs/standard/usr/share/mynode/bitcoin_ipv4.conf @@ -0,0 +1,2 @@ +# IPv4 only +onlynet=ipv4 diff --git a/rootfs/standard/usr/share/mynode/bitcoin_tor.conf b/rootfs/standard/usr/share/mynode/bitcoin_tor.conf new file mode 100644 index 00000000..5f7d2716 --- /dev/null +++ b/rootfs/standard/usr/share/mynode/bitcoin_tor.conf @@ -0,0 +1,9 @@ +# Tor config +proxy=127.0.0.1:9050 +listen=1 +bind=127.0.0.1 + +# Tor only (default) +onlynet=onion +dnsseed=0 +dns=0 diff --git a/rootfs/standard/usr/share/mynode/lnd.conf b/rootfs/standard/usr/share/mynode/lnd.conf index ef9c7303..ad39646f 100644 --- a/rootfs/standard/usr/share/mynode/lnd.conf +++ b/rootfs/standard/usr/share/mynode/lnd.conf @@ -10,7 +10,7 @@ color=#68F442 #nat=true # Tor-only by default -nat=false +nat=true listen=localhost rpclisten=0.0.0.0:10009 @@ -22,11 +22,6 @@ tlsextradomain=mynode.local debuglevel=info #debuglevel=debug -[Tor] -tor.active=true -tor.v2=true -tor.streamisolation=true - [Bitcoin] bitcoin.active=1 diff --git a/rootfs/standard/usr/share/mynode/lnd_ipv4.conf b/rootfs/standard/usr/share/mynode/lnd_ipv4.conf new file mode 100644 index 00000000..7f44245d --- /dev/null +++ b/rootfs/standard/usr/share/mynode/lnd_ipv4.conf @@ -0,0 +1,5 @@ +[Application Options] +nat=true + +[Tor] +tor.active=false diff --git a/rootfs/standard/usr/share/mynode/lnd_tor.conf b/rootfs/standard/usr/share/mynode/lnd_tor.conf new file mode 100644 index 00000000..dcb1e2f9 --- /dev/null +++ b/rootfs/standard/usr/share/mynode/lnd_tor.conf @@ -0,0 +1,8 @@ +[Application Options] +nat=false + +[Tor] +tor.active=true +tor.v2=true +tor.streamisolation=true + diff --git a/rootfs/standard/var/www/mynode/device_info.py b/rootfs/standard/var/www/mynode/device_info.py index 91dba404..600fbeb5 100644 --- a/rootfs/standard/var/www/mynode/device_info.py +++ b/rootfs/standard/var/www/mynode/device_info.py @@ -400,3 +400,14 @@ def reset_tor(): os.system("rm -rf /var/lib/tor/*") os.system("rm -rf /mnt/hdd/mynode/bitcoin/onion_private_key") os.system("rm -rf /mnt/hdd/mynode/lnd/v2_onion_private_key") + +def is_btc_lnd_tor_enabled(): + return os.path.isfile("/mnt/hdd/mynode/settings/.btc_lnd_tor_enabled") + +def enable_btc_lnd_tor(): + os.system("touch mnt/hdd/mynode/settings/.btc_lnd_tor_enabled") + os.system("sync") + +def disable_btc_lnd_tor(): + os.system("rm -f mnt/hdd/mynode/settings/.btc_lnd_tor_enabled") + os.system("sync") \ No newline at end of file diff --git a/rootfs/standard/var/www/mynode/mynode.py b/rootfs/standard/var/www/mynode/mynode.py index 16cf14ab..53cea034 100644 --- a/rootfs/standard/var/www/mynode/mynode.py +++ b/rootfs/standard/var/www/mynode/mynode.py @@ -582,7 +582,7 @@ def not_found_error(error): templateData = { "title": "myNode 404", "header_text": "Page not found", - "subheader_text": "Click on the mynode logo reach the home page", + "subheader_text": "Click on the myNode logo to reach the home page", "ui_settings": read_ui_settings() } return render_template('state.html', **templateData), 404 diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index 042a9e0c..54e56732 100644 --- a/rootfs/standard/var/www/mynode/settings.py +++ b/rootfs/standard/var/www/mynode/settings.py @@ -170,6 +170,7 @@ def page_settings(): "is_uploader_device": is_uploader(), "download_rate": download_rate, "upload_rate": upload_rate, + "is_btc_lnd_tor_enabled": is_btc_lnd_tor_enabled(), "uptime": uptime, "public_ip": public_ip, "local_ip": local_ip, @@ -410,6 +411,29 @@ def page_reset_tor(): } return render_template('reboot.html', **templateData) +@mynode_settings.route("/settings/enable_btc_lnd_tor") +def page_enable_btc_lnd_tor(): + check_logged_in() + + enable = request.args.get('enable') + if enable == "1": + enable_btc_lnd_tor() + else: + disable_btc_lnd_tor() + + # Trigger 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...", + "ui_settings": read_ui_settings() + } + return render_template('reboot.html', **templateData) + @mynode_settings.route("/settings/mynode_logs.tar.gz") def download_logs_page(): check_logged_in() diff --git a/rootfs/standard/var/www/mynode/static/css/mynode.css b/rootfs/standard/var/www/mynode/static/css/mynode.css index 52ad32f8..0ae6c611 100644 --- a/rootfs/standard/var/www/mynode/static/css/mynode.css +++ b/rootfs/standard/var/www/mynode/static/css/mynode.css @@ -545,4 +545,59 @@ a:active { .loading_image { width: 128px; +} + +/* The switch - the box around the slider */ +.switch { + position: relative; + display: inline-block; + width: 36px; + height: 22px; +} +/* Hide default HTML checkbox */ +.switch input { + opacity: 0; + width: 0; + height: 0; +} +/* The slider */ +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; +} +.slider:before { + position: absolute; + content: ""; + height: 14px; + width: 14px; + left: 4px; + bottom: 4px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; +} +input:checked + .slider { + background-color: #2196F3; +} +input:focus + .slider { + box-shadow: 0 0 1px #2196F3; +} +input:checked + .slider:before { + -webkit-transform: translateX(14px); + -ms-transform: translateX(14px); + transform: translateX(14px); +} +/* Rounded sliders */ +.slider.round { + border-radius: 20px; +} +.slider.round:before { + border-radius: 50%; } \ No newline at end of file diff --git a/rootfs/standard/var/www/mynode/templates/includes/services.html b/rootfs/standard/var/www/mynode/templates/includes/services.html index 8ed8d24b..53abcf3b 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/services.html +++ b/rootfs/standard/var/www/mynode/templates/includes/services.html @@ -8,7 +8,7 @@
Bitcoin
{{ bitcoind_status }}
- Status + Manage
@@ -17,7 +17,7 @@
Lightning
{{ lnd_status }}
diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index 79850a84..a436c836 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -340,6 +340,21 @@ $("#reinstall_button").on("click", function() { window.location.href='/settings/reinstall-app?app='+reinstall_app_choice }); + + $('#btc_lnd_tor_checkbox').change(function () { + $("#btc_lnd_tor").show(); + }); + $("#btc_lnd_tor").on("click", function() { + enabled=$('#btc_lnd_tor_checkbox').is(":checked") + if (enabled) + { + window.location.href='/settings/enable_btc_lnd_tor?enable=1' + } + else + { + window.location.href='/settings/enable_btc_lnd_tor?enable=0' + } + }); }); @@ -713,6 +728,21 @@
Tor
+ +
Bitcoin and Lightning Tor
+ You can use Tor for Bitcoin and Lightning to increase privacy. However, it can slow down block download, + especially during IBD. If you have customized your Bitcoin or LND config, this setting has no effect. +

+ Saving will trigger a reboot. +

+ +

+ + +
Reset Tor
This will reset all of your Tor service settings and regenerate your Onion URLs.