Add Caravan and a Proxy for handling CORS issues

This commit is contained in:
Taylor Helsper 2020-06-05 20:46:39 -05:00
parent 2a585af356
commit cbad16e56e
19 changed files with 348 additions and 4 deletions

View File

@ -10,6 +10,7 @@
/var/log/mynode_quicksync.log
/var/log/redis-server.log
/var/log/rtl.log
/var/log/caravan.log
/var/log/www.log
/var/log/bitcoind.log
/var/log/unlock_lnd.log

View File

@ -0,0 +1,2 @@
if $programname == 'caravan' then /var/log/caravan.log
& stop

View File

@ -0,0 +1,34 @@
# caravan service
# /etc/systemd/system/caravan.service
[Unit]
Description=Caravan
Wants=bitcoind.service
After=bitcoind.service
[Service]
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
Environment="PORT=3020 NODE_ENV=production"
WorkingDirectory=/opt/mynode/caravan
ExecStart=/usr/bin/npm start
StandardInput=tty-force
TTYVHangup=yes
TTYPath=/dev/tty20
TTYReset=yes
User=bitcoin
Group=bitcoin
Type=simple
KillMode=process
LimitNOFILE=128000
TimeoutSec=30
Restart=on-failure
RestartSec=120
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=caravan
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,28 @@
# corsproxy_btcrpc service
# /etc/systemd/system/corsproxy_btcrpc.service
[Unit]
Description=corsproxy_btcrpc
Wants=bitcoind.service
After=bitcoind.service
[Service]
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
WorkingDirectory=/opt/mynode/corsproxy
Environment="CORSPROXY_PORT=8334" "CORSPROXY_HOST=0.0.0.0" "CORSPROXY_TARGET=localhost:8332"
ExecStart=/usr/bin/npm start
User=root
Group=root
Type=simple
KillMode=process
TimeoutSec=30
Restart=on-failure
RestartSec=120
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=corsproxy_btcrpc
[Install]
WantedBy=multi-user.target

View File

@ -28,11 +28,13 @@ ufw allow from 172.17.0.0/16 to any port 28333 comment 'allow Dojo zmqrawtx'
ufw allow from 172.28.0.0/16 to any port 28333 comment 'allow Dojo zmqrawtx'
ufw allow from 172.17.0.0/16 to any port 28334 comment 'allow Dojo zmqhashblock'
ufw allow from 172.28.0.0/16 to any port 28334 comment 'allow Dojo zmqhashblock'
ufw allow 8334 comment 'allow corsproxy for btc rpc'
ufw allow 2222 comment 'allow WebSSH2'
ufw allow 3000 comment 'allow LndHub'
ufw allow 3002 comment 'allow BTC RPC Explorer'
#ufw allow 3004 comment 'allow LND Admin'
ufw allow 3010 comment 'allow RTL'
ufw allow 3020 comment 'allow Caravan'
ufw allow 4080 comment 'allow Mempool'
ufw allow 5353 comment 'allow Avahi'
ufw allow 8899 comment 'allow Whirlpool'

View File

@ -56,6 +56,7 @@ $TORIFY apt-get -y install libatlas-base-dev libffi-dev libssl-dev glances pytho
$TORIFY apt-get -y -qq install apt-transport-https ca-certificates
$TORIFY apt-get -y install libgmp-dev automake libtool libltdl-dev libltdl7
$TORIFY apt-get -y install xorg chromium openbox lightdm openjdk-11-jre libevent-dev ncurses-dev
$TORIFY apt-get -y install libudev-dev libusb-1.0-0-dev python3-venv
# Make sure some software is removed
apt-get -y purge ntp # (conflicts with systemd-timedatectl)
@ -248,6 +249,58 @@ if [ "$CURRENT" != "$LNDHUB_UPGRADE_URL" ]; then
fi
cd ~
# Install Caravan
CARAVAN_VERSION="v0.2.0"
CARAVAN_UPGRADE_URL=https://github.com/unchained-capital/caravan/archive/${CARAVAN_VERSION}.tar.gz
CARAVAN_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.caravan_url
CURRENT=""
if [ -f $CARAVAN_UPGRADE_URL_FILE ]; then
CURRENT=$(cat $CARAVAN_UPGRADE_URL_FILE)
fi
if [ "$CURRENT" != "$CARAVAN_UPGRADE_URL" ]; then
cd /opt/mynode
rm -rf caravan
rm -f caravan.tar.gz
wget $CARAVAN_UPGRADE_URL -O caravan.tar.gz
tar -xzf caravan.tar.gz
rm -f caravan.tar.gz
mv caravan-* caravan
chown -R bitcoin:bitcoin caravan
cd caravan
sudo -u bitcoin npm install --only=production
sed -i 's/HTTPS=true/HTTPS=false/g' ./package.json || true
echo $CARAVAN_UPGRADE_URL > $CARAVAN_UPGRADE_URL_FILE
fi
cd ~
# Install cors proxy (my fork)
CORSPROXY_UPGRADE_URL=https://github.com/tehelsper/CORS-Proxy/archive/v1.6.0.tar.gz
CORSPROXY_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.corsproxy_url
CURRENT=""
if [ -f $CORSPROXY_UPGRADE_URL ]; then
CURRENT=$(cat $CORSPROXY_UPGRADE_URL_FILE)
fi
if [ "$CURRENT" != "$CORSPROXY_UPGRADE_URL" ]; then
cd /opt/mynode
rm -rf corsproxy
rm -f corsproxy.tar.gz
wget $CORSPROXY_UPGRADE_URL -O corsproxy.tar.gz
tar -xzf corsproxy.tar.gz
rm -f corsproxy.tar.gz
mv CORS-* corsproxy
cd corsproxy
npm install
echo $CORSPROXY_UPGRADE_URL > $CORSPROXY_UPGRADE_URL_FILE
fi
cd ~
# Install recent version of secp256k1
echo "Installing secp256k1..."
if [ ! -f /usr/include/secp256k1_ecdh.h ]; then
@ -457,6 +510,7 @@ systemctl enable webssh2
systemctl enable tor
systemctl enable loopd
systemctl enable rotate_logs
systemctl enable corsproxy_btcrpc
# Disable any old services
systemctl disable hitch || true

View File

@ -24,6 +24,8 @@ elif [ "$APP" = "loopd" ]; then
rm -f /home/bitcoin/.mynode/.loop_url
elif [ "$APP" = "btcrpcexplorer" ]; then
rm -f /home/bitcoin/.mynode/.btcrpcexplorer_url
elif [ "$APP" = "caravan" ]; then
rm -f /home/bitcoin/.mynode/.caravan_url
elif [ "$APP" = "joinmarket" ]; then
rm -f /home/bitcoin/.mynode/.joinmarket_url
elif [ "$APP" = "lndconnect" ]; then

View File

@ -0,0 +1,22 @@
from flask import Blueprint, render_template, redirect
from settings import read_ui_settings
from user_management import check_logged_in
import subprocess
import re
import os
mynode_caravan = Blueprint('mynode_caravan',__name__)
### Page functions
@mynode_caravan.route("/caravan")
def caravan_page():
check_logged_in()
# Load page
templateData = {
"title": "myNode Caravan",
"ui_settings": read_ui_settings()
}
return render_template('caravan.html', **templateData)

View File

@ -8,6 +8,7 @@ import subprocess
# Globals
local_ip = "unknown"
cached_data = {}
#==================================
# Utilities
@ -220,20 +221,36 @@ def get_system_date():
return date
def get_device_serial():
global cached_data
if "serial" in cached_data:
return cached_data["serial"]
serial = subprocess.check_output("cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2", shell=True)
serial = serial.strip()
if serial == "":
# For VMs, use the UUID
serial = subprocess.check_output("sudo dmidecode | grep UUID | cut -d ' ' -f 2", shell=True)
serial = serial.strip()
cached_data["serial"] = serial
return serial
def get_device_type():
device = subprocess.check_output("mynode-get-device-type", shell=True)
global cached_data
if "device_type" in cached_data:
return cached_data["device_type"]
device = subprocess.check_output("mynode-get-device-type", shell=True).strip()
cached_data["device_type"] = device
return device
def get_device_ram():
ram = subprocess.check_output("free --giga | grep Mem | awk '{print $2}'", shell=True)
global cached_data
if "ram" in cached_data:
return cached_data["ram"]
ram = subprocess.check_output("free --giga | grep Mem | awk '{print $2}'", shell=True).strip()
cached_data["ram"] = ram
return ram
def get_local_ip():

View File

@ -101,6 +101,18 @@ def disable_btcpayserver():
os.system("systemctl disable btcpayserver --no-pager")
def is_caravan_enabled():
return is_service_enabled("caravan")
def enable_caravan():
os.system("systemctl enable caravan --no-pager")
os.system("systemctl start caravan --no-pager")
def disable_caravan():
os.system("systemctl stop caravan --no-pager")
os.system("systemctl disable caravan --no-pager")
def is_vpn_enabled():
if os.path.isfile(VPN_ENABLED_FILE):
return True

View File

@ -5,6 +5,7 @@ from user_management import *
from bitcoind import mynode_bitcoind
from whirlpool import mynode_whirlpool, get_whirlpool_status
from dojo import mynode_dojo, get_dojo_status
from caravan import mynode_caravan
from tor import mynode_tor
from vpn import mynode_vpn
from electrum_server import *
@ -43,6 +44,7 @@ app.register_blueprint(mynode_bitcoind)
app.register_blueprint(mynode_lnd)
app.register_blueprint(mynode_whirlpool)
app.register_blueprint(mynode_dojo)
app.register_blueprint(mynode_caravan)
app.register_blueprint(mynode_tor)
app.register_blueprint(mynode_electrum_server)
app.register_blueprint(mynode_vpn)
@ -278,6 +280,9 @@ def index():
btcrpcexplorer_status = ""
btcrpcexplorer_ready = False
btcrpcexplorer_status_color = "gray"
caravan_status = ""
caravan_ready = False
caravan_status_color = "gray"
mempoolspace_status_color = "gray"
vpn_status_color = "gray"
vpn_status = ""
@ -448,6 +453,15 @@ def index():
dojo_status_color = "yellow"
dojo_status = "Installing..."
# Find caravan status
caravan_status = ""
caravan_ready = False
caravan_status_color = "gray"
if is_caravan_enabled():
caravan_status_color = get_service_status_color("caravan")
caravan_ready = True
caravan_status = "Running"
# Check for new version of software
upgrade_available = False
current = get_current_version()
@ -484,6 +498,10 @@ def index():
"btcrpcexplorer_status_color": btcrpcexplorer_status_color,
"btcrpcexplorer_status": btcrpcexplorer_status,
"btcrpcexplorer_enabled": is_btcrpcexplorer_enabled(),
"caravan_ready": caravan_ready,
"caravan_status_color": caravan_status_color,
"caravan_status": caravan_status,
"caravan_enabled": is_caravan_enabled(),
"mempoolspace_status_color": mempoolspace_status_color,
"mempoolspace_status": mempoolspace_status,
"mempoolspace_enabled": is_mempoolspace_enabled(),
@ -619,6 +637,15 @@ def page_toggle_btcpayserver():
enable_btcpayserver()
return redirect("/")
@app.route("/toggle-caravan")
def page_toggle_caravan():
check_logged_in()
if is_caravan_enabled():
disable_caravan()
else:
enable_caravan()
return redirect("/")
@app.route("/toggle-vpn")
def page_toggle_vpn():
check_logged_in()

View File

@ -268,7 +268,7 @@ a:active {
}
.instructions {
width: 75%;
width: 60%;
color: #444444;
margin: auto;
text-align: left;

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -0,0 +1,65 @@
<!DOCTYPE html lang="en">
<head>
<title>{{ title }}</title>
{% include 'includes/head.html' %}
<script>
$(document).ready(function() {
$("#caravan").on("click", function() {
url = 'http://'+location.hostname+':3020'
window.open(url,'_blank');
})
});
</script>
</head>
<body>
{% include 'includes/logo_header.html' %}
<div class="mynode_back_div">
<a class="ui-button ui-widget ui-corner-all mynode_back" href="/"><span class="ui-icon ui-icon-home"></span>home&nbsp;</a>
</div>
<div class="main_header">Caravan</div>
</br>
<div class="app_tile_row">
<div class="info_tile">
<div class="info_tile_header">Caravan</div>
<div class="info_tile_contents">
<a class="ui-button ui-widget ui-corner-all mynode_button_small" style="width: 70%;" href="#" id="caravan">Open</a>
</div>
</div>
</div>
<div class="instructions">
<div class="instructions-header"><u><strong>NOTICE</u></strong></div>
</br>
<p>Caravan is provided as-is and from Unchained Capital. It is alpha software.</p>
</br>
<div class="instructions-header"><u><strong>Using Caravan</u></strong></div>
</br>
<p>Caravan is a stateless app to help manage multi-sig wallets. The default settings use an external server for
accessing the Bitcoin network, but you can use the local Bitcoin Instance on your myNode device.</p>
<p>To use your node, you need to edit the Bitcoin Client settings within Caravan.</p>
<ol class="instructions-steps">
<li>Change the Public/Private option to Private</li>
<li>Change the URL to your node's IP address hostname with port 8334. For example:</li>
<ul>
<li>http://192.168.1.101:8334</li>
<li>http://mynode.local:8334</li>
</ul>
<li>Change the Username to "mynode"</li>
<li>Change the Password to the RPC Password from the <a href="/bitcoind">Bitcoin page</a></li>
<li>Click "Test Connection"</li>
<li>You should see a success message!</li>
</ol>
</div>
{% include 'includes/footer.html' %}
</body>
</html>

View File

@ -89,5 +89,7 @@
<li>Once connected, press back and now go to the option "Import external wallet" and restore your wallet using your seed phrase.</li>
</ol>
</div>
{% include 'includes/footer.html' %}
</body>
</html>

View File

@ -141,3 +141,22 @@
</div>
</div>
</div>
<div class="app_tile_row">
<div class="app_tile">
<div class="app_status_icon {{ caravan_status_color }}"></div>
<div class="app_logo"><img class="app_logo_icon" src="{{ url_for('static', filename="images/caravan.png")}}"/></div>
<div class="app_title">Caravan</div>
<div class="app_status">{{ caravan_status }}</div>
<div class="app_contents">
{% if caravan_enabled %}
{% if caravan_ready %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/caravan">Info</a>
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="toggle-caravan">Disable</a>
{% endif %}
{% else %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="toggle-caravan">Enable</a>
{% endif %}
</div>
</div>
</div>

View File

@ -99,6 +99,10 @@
window.location.href="/toggle-btcpayserver"
});
$("#toggle-caravan").on("click", function() {
window.location.href="/toggle-caravan"
});
function lndconnect() {
$("#lndconnect_form").submit();
lndconnect_dialog.dialog( "close" );

View File

@ -813,6 +813,7 @@
<option value="bitcoin">Bitcoin</option>
<option value="lnd">LND</option>
<option value="btcrpcexplorer">BTC RPC Explorer</option>
<option value="caravan">Caravan</option>
<option value="dojo">Dojo</option>
<option value="joinmarket">JoinMarket</option>
<option value="loopd">Lightning Loop</option>

View File

@ -121,7 +121,7 @@ apt-get -y install libfreetype6-dev libpng-dev libatlas-base-dev libgmp-dev libl
apt-get -y install libffi-dev libssl-dev glances python3-bottle automake libtool libltdl7
apt -y -qq install apt-transport-https ca-certificates
apt-get -y install xorg chromium openbox lightdm openjdk-11-jre libevent-dev ncurses-dev
apt-get -y install zlib1g-dev
apt-get -y install zlib1g-dev libudev-dev libusb-1.0-0-dev python3-venv
# Make sure some software is removed
@ -368,6 +368,57 @@ if [ "$CURRENT" != "$LNDHUB_UPGRADE_URL" ]; then
fi
cd ~
# Install Caravan
CARAVAN_VERSION="v0.2.0"
CARAVAN_UPGRADE_URL=https://github.com/unchained-capital/caravan/archive/${CARAVAN_VERSION}.tar.gz
CARAVAN_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.caravan_url
CURRENT=""
if [ -f $CARAVAN_UPGRADE_URL_FILE ]; then
CURRENT=$(cat $CARAVAN_UPGRADE_URL_FILE)
fi
if [ "$CURRENT" != "$CARAVAN_UPGRADE_URL" ]; then
cd /opt/mynode
rm -rf caravan
rm -f caravan.tar.gz
wget $CARAVAN_UPGRADE_URL -O caravan.tar.gz
tar -xzf caravan.tar.gz
rm -f caravan.tar.gz
mv caravan-* caravan
chown -R bitcoin:bitcoin caravan
cd caravan
sudo -u bitcoin npm install --only=production
sed -i 's/HTTPS=true/HTTPS=false/g' ./package.json || true
echo $CARAVAN_UPGRADE_URL > $CARAVAN_UPGRADE_URL_FILE
fi
cd ~
# Install cors proxy (my fork)
CORSPROXY_UPGRADE_URL=https://github.com/tehelsper/CORS-Proxy/archive/v1.6.0.tar.gz
CORSPROXY_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.corsproxy_url
CURRENT=""
if [ -f $CORSPROXY_UPGRADE_URL ]; then
CURRENT=$(cat $CORSPROXY_UPGRADE_URL_FILE)
fi
if [ "$CURRENT" != "$CORSPROXY_UPGRADE_URL" ]; then
cd /opt/mynode
rm -rf corsproxy
rm -f corsproxy.tar.gz
wget $CORSPROXY_UPGRADE_URL -O corsproxy.tar.gz
tar -xzf corsproxy.tar.gz
rm -f corsproxy.tar.gz
mv CORS-* corsproxy
cd corsproxy
npm install
echo $CORSPROXY_UPGRADE_URL > $CORSPROXY_UPGRADE_URL_FILE
fi
cd ~
# Install Electrs (only build to save new version, now included in overlay)
#cd /home/admin/download
#wget https://github.com/romanz/electrs/archive/v0.7.0.tar.gz
@ -589,6 +640,7 @@ systemctl enable glances
#systemctl enable netdata # DISABLED BY DEFAULT
systemctl enable webssh2
systemctl enable rotate_logs
systemctl enable corsproxy_btcrpc
# Regenerate MAC Address for Armbian devices