Add IP/Tor toggle for Bitcoin and LND

This commit is contained in:
Taylor Helsper 2020-01-28 19:59:46 -06:00
parent 588e58aa71
commit 32fdd8b011
14 changed files with 173 additions and 18 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,2 @@
# IPv4 only
onlynet=ipv4

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
[Application Options]
nat=true
[Tor]
tor.active=false

View File

@ -0,0 +1,8 @@
[Application Options]
nat=false
[Tor]
tor.active=true
tor.v2=true
tor.streamisolation=true

View File

@ -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")

View File

@ -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

View File

@ -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()

View File

@ -546,3 +546,58 @@ 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%;
}

View File

@ -8,7 +8,7 @@
<div class="app_title">Bitcoin</div>
<div class="app_status">{{ bitcoind_status }}</div>
<div class="app_contents">
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/bitcoind">Status</a>
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/bitcoind">Manage</a>
</div>
</div>
<div class="app_tile">
@ -17,7 +17,7 @@
<div class="app_title">Lightning</div>
<div class="app_status">{{ lnd_status }}</div>
<div class="app_contents">
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/lnd">Lightning Wallet</a>
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/lnd">Manage</a>
</div>
</div>
</div>

View File

@ -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'
}
});
});
</script>
</head>
@ -714,6 +729,21 @@
<div class="settings_block">
<div class="settings_block_header">Tor</div>
<div class="settings_block_subheader">Bitcoin and Lightning Tor</div>
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.
<br/><br/>
Saving will trigger a reboot.
<br/><br/>
<label class="switch">
<input type="checkbox" id="btc_lnd_tor_checkbox" {% if is_btc_lnd_tor_enabled %}checked{% endif %}>
<span class="slider round"></span>
</label>
<br/><br/>
<button id="btc_lnd_tor" style="display: none;" class="ui-button ui-widget ui-corner-all settings_button_small">Save</button>
<div class="divider"></div>
<div class="settings_block_subheader">Reset Tor</div>
This will reset all of your Tor service settings and regenerate your Onion URLs.
<br/>