Add watchtower toggle

This commit is contained in:
Taylor Helsper 2021-03-31 20:41:52 -05:00
parent b36efea002
commit a54a9f2b50
7 changed files with 72 additions and 26 deletions

View File

@ -9,6 +9,7 @@ After=bitcoind.service lnd.service
[Service]
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
ExecStartPre=/usr/bin/wait_on_lnd.sh
ExecStart=/usr/local/bin/litd --lit-dir=/mnt/hdd/mynode/lit
User=bitcoin

View File

@ -10,6 +10,7 @@ After=bitcoind.service
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/pre_lnd.sh
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
ExecStartPre=/usr/bin/mynode_gen_lnd_config.sh
ExecStart=/usr/local/bin/lnd
ExecStartPost=/bin/echo 'abc' > /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/poke_login

View File

@ -13,6 +13,11 @@ else
# Generate a default config
cp -f /usr/share/mynode/lnd.conf /mnt/hdd/mynode/lnd/lnd.conf
# Append Tor/IP section
if [ -f /mnt/hdd/mynode/settings/.watchtower_enabled ]; then
cat /usr/share/mynode/lnd_watchtower.conf >> /mnt/hdd/mynode/lnd/lnd.conf
fi
# Append Tor/IP section
if [ -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled ]; then
cat /usr/share/mynode/lnd_tor.conf >> /mnt/hdd/mynode/lnd/lnd.conf

View File

@ -0,0 +1,3 @@
[Wtclient]
wtclient.active=1

View File

@ -436,3 +436,16 @@ def get_lnd_alias_file_data():
except:
return "ERROR"
return "ERROR"
def is_watchtower_enabled():
if os.path.isfile("/mnt/hdd/mynode/settings/.watchtower_enabled"):
return True
return False
def enable_watchtower():
os.system("touch /mnt/hdd/mynode/settings/.watchtower_enabled")
os.system("sync")
def disable_watchtower():
os.system("rm /mnt/hdd/mynode/settings/.watchtower_enabled")
os.system("sync")

View File

@ -68,6 +68,7 @@ def page_lnd():
"title": "myNode Lightning Wallet",
"wallet_exists": wallet_exists,
"wallet_logged_in": wallet_logged_in,
"watchtower_enabled": is_watchtower_enabled(),
"version": get_lnd_version(),
"loop_version": get_loop_version(),
"pool_version": get_pool_version(),
@ -81,6 +82,7 @@ def page_lnd():
"title": "myNode Lightning Wallet",
"wallet_exists": wallet_exists,
"wallet_logged_in": wallet_logged_in,
"watchtower_enabled": is_watchtower_enabled(),
"alias": alias,
"status": get_lnd_status(),
"version": get_lnd_version(),
@ -155,6 +157,7 @@ def page_lnd():
"pubkey": pubkey,
"uri": uri,
"ip": ip,
"watchtower_enabled": is_watchtower_enabled(),
"lit_password": get_lnd_lit_password(),
"lnd_deposit_address": lnd_deposit_address,
"channel_balance": format_sat_amount(balance_info["channel_balance"]),
@ -358,13 +361,6 @@ def page_lnd_lndconnect():
def page_lnd_change_alias():
check_logged_in()
# Load page
p = pam.pam()
pw = request.form.get('password_change_alias')
if pw == None or p.authenticate("admin", pw) == False:
flash("Invalid Password", category="error")
return redirect(url_for(".page_lnd"))
# Change alias
alias = request.form.get('alias')
if alias == None or alias == "":
@ -378,18 +374,11 @@ def page_lnd_change_alias():
f.write(utf8_alias)
f.close()
# Reboot
t = Timer(1.0, reboot_device)
t.start()
# Restart LND
restart_lnd()
# 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)
flash("Alias updated!", category="message")
return redirect(url_for(".page_lnd"))
@mynode_lnd.route("/lnd/reset_config")
def lnd_reset_config_page():
@ -444,6 +433,19 @@ def lnd_config_page():
}
return render_template('lnd_config.html', **templateData)
@mynode_lnd.route("/lnd/set_watchtower_enabled")
def lnd_set_watchtower_enabled_page():
check_logged_in()
if request.args.get("enabled") and request.args.get("enabled") == "1":
enable_watchtower()
else:
disable_watchtower()
restart_lnd()
flash("Watchtower settings updated!", category="message")
return redirect(url_for(".page_lnd"))
##############################################
## LND API Calls

View File

@ -91,6 +91,21 @@
$("#lit_password").show();
});
$('#watchtower_enabled_checkbox').change(function () {
$("#watchtower_enabled_save").show();
});
$("#watchtower_enabled_save").on("click", function() {
enabled=$('#watchtower_enabled_checkbox').is(":checked")
if (enabled)
{
window.location.href='/lnd/set_watchtower_enabled?enabled=1'
}
else
{
window.location.href='/lnd/set_watchtower_enabled?enabled=0'
}
});
function show_deposit_address(addr) {
$("#lnd_deposit_address_text").html( addr );
$("#lnd_deposit_address_qrcode").attr("src", "/api/get_qr_code_image?url="+addr);
@ -225,6 +240,17 @@
</td>
</tr>
{% endif %}
<tr>
<th>Watchtower</th>
<td>
<label class="switch">
<input type="checkbox" id="watchtower_enabled_checkbox" {% if watchtower_enabled %}checked{% endif %}>
<span class="slider round"></span>
</label>
<br/>
<button id="watchtower_enabled_save" style="display: none; margin-top: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Save</button>
</td>
</tr>
<tr>
<th>Config</th>
<td>
@ -465,15 +491,10 @@
<div id="change-alias-dialog" title="Change LND Alias" style="display:none;">
<form id="change_alias_form" name="change_alias_form" action="/lnd/change_alias" method="POST">
<p>The LND alias is a public name for your lightning node and you can modify it with the form below. Changing the alias will restart your myNode to take effect.</p>
<p>Please enter a new alias and your current password.</p>
<p>The LND alias is a public name for your lightning node and you can modify it with the form below.</p>
<b>New Alias:</b>
<br/>
<input type="text" name="alias" id="alias" value="" class="text ui-widget-content ui-corner-all" size="34" maxlength="34">
<br/><br/>
<b>Password:</b>
<br/>
<input type="password" name="password_change_alias" id="password_change_alias" value="" class="text ui-widget-content ui-corner-all">
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">