diff --git a/rootfs/standard/etc/logrotate.d/rsyslog b/rootfs/standard/etc/logrotate.d/rsyslog index b7b1cb71..83b38bd5 100644 --- a/rootfs/standard/etc/logrotate.d/rsyslog +++ b/rootfs/standard/etc/logrotate.d/rsyslog @@ -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 diff --git a/rootfs/standard/etc/rsyslog.d/caravan.conf b/rootfs/standard/etc/rsyslog.d/caravan.conf new file mode 100644 index 00000000..7eb5469a --- /dev/null +++ b/rootfs/standard/etc/rsyslog.d/caravan.conf @@ -0,0 +1,2 @@ +if $programname == 'caravan' then /var/log/caravan.log +& stop \ No newline at end of file diff --git a/rootfs/standard/etc/systemd/system/caravan.service b/rootfs/standard/etc/systemd/system/caravan.service new file mode 100644 index 00000000..0069e8cf --- /dev/null +++ b/rootfs/standard/etc/systemd/system/caravan.service @@ -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 diff --git a/rootfs/standard/etc/systemd/system/corsproxy_btcrpc.service b/rootfs/standard/etc/systemd/system/corsproxy_btcrpc.service new file mode 100644 index 00000000..a8b36f54 --- /dev/null +++ b/rootfs/standard/etc/systemd/system/corsproxy_btcrpc.service @@ -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 diff --git a/rootfs/standard/usr/bin/mynode_firewall.sh b/rootfs/standard/usr/bin/mynode_firewall.sh index 2cc4c8fb..c1fa808b 100755 --- a/rootfs/standard/usr/bin/mynode_firewall.sh +++ b/rootfs/standard/usr/bin/mynode_firewall.sh @@ -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' diff --git a/rootfs/standard/usr/bin/mynode_post_upgrade.sh b/rootfs/standard/usr/bin/mynode_post_upgrade.sh index f72be6a3..79811597 100755 --- a/rootfs/standard/usr/bin/mynode_post_upgrade.sh +++ b/rootfs/standard/usr/bin/mynode_post_upgrade.sh @@ -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 diff --git a/rootfs/standard/usr/bin/mynode_reinstall_app.sh b/rootfs/standard/usr/bin/mynode_reinstall_app.sh index 373ac8c2..e069031d 100755 --- a/rootfs/standard/usr/bin/mynode_reinstall_app.sh +++ b/rootfs/standard/usr/bin/mynode_reinstall_app.sh @@ -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 diff --git a/rootfs/standard/var/www/mynode/caravan.py b/rootfs/standard/var/www/mynode/caravan.py new file mode 100644 index 00000000..b3ce7431 --- /dev/null +++ b/rootfs/standard/var/www/mynode/caravan.py @@ -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) diff --git a/rootfs/standard/var/www/mynode/device_info.py b/rootfs/standard/var/www/mynode/device_info.py index 98286c2a..d1e654ff 100644 --- a/rootfs/standard/var/www/mynode/device_info.py +++ b/rootfs/standard/var/www/mynode/device_info.py @@ -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(): diff --git a/rootfs/standard/var/www/mynode/enable_disable_functions.py b/rootfs/standard/var/www/mynode/enable_disable_functions.py index 1f398faa..9a13414a 100644 --- a/rootfs/standard/var/www/mynode/enable_disable_functions.py +++ b/rootfs/standard/var/www/mynode/enable_disable_functions.py @@ -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 diff --git a/rootfs/standard/var/www/mynode/mynode.py b/rootfs/standard/var/www/mynode/mynode.py index 17daf375..435706b0 100644 --- a/rootfs/standard/var/www/mynode/mynode.py +++ b/rootfs/standard/var/www/mynode/mynode.py @@ -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() diff --git a/rootfs/standard/var/www/mynode/static/css/mynode.css b/rootfs/standard/var/www/mynode/static/css/mynode.css index da051271..9cb13a05 100644 --- a/rootfs/standard/var/www/mynode/static/css/mynode.css +++ b/rootfs/standard/var/www/mynode/static/css/mynode.css @@ -268,7 +268,7 @@ a:active { } .instructions { - width: 75%; + width: 60%; color: #444444; margin: auto; text-align: left; diff --git a/rootfs/standard/var/www/mynode/static/images/caravan.png b/rootfs/standard/var/www/mynode/static/images/caravan.png new file mode 100644 index 00000000..2eccd4a6 Binary files /dev/null and b/rootfs/standard/var/www/mynode/static/images/caravan.png differ diff --git a/rootfs/standard/var/www/mynode/templates/caravan.html b/rootfs/standard/var/www/mynode/templates/caravan.html new file mode 100644 index 00000000..a9304e75 --- /dev/null +++ b/rootfs/standard/var/www/mynode/templates/caravan.html @@ -0,0 +1,65 @@ + + + {{ title }} + {% include 'includes/head.html' %} + + + + + {% include 'includes/logo_header.html' %} +
+ home  +
+ +
Caravan
+
+
+
+
Caravan
+
+ Open +
+
+
+ +
+
NOTICE
+
+

Caravan is provided as-is and from Unchained Capital. It is alpha software.

+
+ +
Using Caravan
+
+ +

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.

+ +

To use your node, you need to edit the Bitcoin Client settings within Caravan.

+ +
    +
  1. Change the Public/Private option to Private
  2. +
  3. Change the URL to your node's IP address hostname with port 8334. For example:
  4. + +
  5. Change the Username to "mynode"
  6. +
  7. Change the Password to the RPC Password from the Bitcoin page
  8. +
  9. Click "Test Connection"
  10. +
  11. You should see a success message!
  12. +
+ +
+ + {% include 'includes/footer.html' %} + + diff --git a/rootfs/standard/var/www/mynode/templates/dojo.html b/rootfs/standard/var/www/mynode/templates/dojo.html index ae1e3182..b1e0a2c2 100644 --- a/rootfs/standard/var/www/mynode/templates/dojo.html +++ b/rootfs/standard/var/www/mynode/templates/dojo.html @@ -89,5 +89,7 @@
  • Once connected, press back and now go to the option "Import external wallet" and restore your wallet using your seed phrase.
  • + + {% include 'includes/footer.html' %} diff --git a/rootfs/standard/var/www/mynode/templates/includes/apps.html b/rootfs/standard/var/www/mynode/templates/includes/apps.html index 0503244c..0d5f54de 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/apps.html +++ b/rootfs/standard/var/www/mynode/templates/includes/apps.html @@ -141,3 +141,22 @@ + +
    +
    +
    + +
    Caravan
    +
    {{ caravan_status }}
    +
    + {% if caravan_enabled %} + {% if caravan_ready %} + Info + Disable + {% endif %} + {% else %} + Enable + {% endif %} +
    +
    +
    \ No newline at end of file diff --git a/rootfs/standard/var/www/mynode/templates/main.html b/rootfs/standard/var/www/mynode/templates/main.html index 5e315cec..233b6b99 100644 --- a/rootfs/standard/var/www/mynode/templates/main.html +++ b/rootfs/standard/var/www/mynode/templates/main.html @@ -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" ); diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index ebb80f76..69a17520 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -813,6 +813,7 @@ + diff --git a/setup/setup_device.sh b/setup/setup_device.sh index a369be6b..fbaf9c03 100755 --- a/setup/setup_device.sh +++ b/setup/setup_device.sh @@ -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