From d19271d41c21311026714d69267be785d9554a0f Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Tue, 17 May 2022 22:08:25 +0200 Subject: [PATCH] Adding #2152 Homer Dashboard (#2541) --- CHANGES.md | 1 + README.md | 1 + home.admin/00mainMenu.sh | 7 + home.admin/00settingsMenuServices.sh | 21 ++ home.admin/99updateMenu.sh | 7 + home.admin/_provision_.sh | 9 + .../nginx/sites-available/homer_ssl.conf | 18 ++ .../nginx/sites-available/homer_tor.conf | 14 + .../nginx/sites-available/homer_tor_ssl.conf | 17 ++ home.admin/config.scripts/bonus.homer.sh | 256 ++++++++++++++++++ 10 files changed, 351 insertions(+) create mode 100644 home.admin/assets/nginx/sites-available/homer_ssl.conf create mode 100644 home.admin/assets/nginx/sites-available/homer_tor.conf create mode 100644 home.admin/assets/nginx/sites-available/homer_tor_ssl.conf create mode 100644 home.admin/config.scripts/bonus.homer.sh diff --git a/CHANGES.md b/CHANGES.md index b2ca421af..ff82b2b8b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - New: BackendAPI - New: ZRAM - compressed swap in memory [details](https://github.com/rootzoll/raspiblitz/issues/2905) - New: Core Lightning GRPC plugin [details](https://github.com/rootzoll/raspiblitz/pull/3109) +- New: Homer Dashboard [details](https://github.com/bastienwirtz/homer#readme) - Update: Bitcoin Core v23.0 [details](https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-23.0.md) - Update: Core Lightning (CLN - formerly C-lightning) v0.11.0.1 [details](https://github.com/ElementsProject/lightning/releases/tag/v0.11.0.1) - Update: LND v0.14.3 [details](https://github.com/lightningnetwork/lnd/releases/tag/v0.14.3-beta) diff --git a/README.md b/README.md index 2e6d1be96..2816fc45a 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ There are further Services that can be switched on: * **Chantools** (Fund Rescue) [details](https://github.com/guggero/chantools/blob/master/README.md) * **Suez** (Channel Visualization for LND & CL) [details](https://github.com/prusnak/suez#suez) * **Helipad** (Podcasting 2.0 Boostagram reader) [details](https://github.com/Podcastindex-org/helipad) +* **Homer** (Web Dashboard) [details](https://github.com/bastienwirtz/homer#readme) * **CL Spark Wallet** (WalletUI with BOLT12 offers) [details](https://github.com/shesek/spark-wallet#progressive-web-app) * **CL plugin: Sparko** (WalletUI & HTTP-RPC bridge) [details](https://github.com/fiatjaf/sparko#the-sparko-plugin) * **CL plugin: CLBOSS** (Automated Node Manager) [details](https://github.com/ZmnSCPxj/clboss#clboss-the-c-lightning-node-manager) diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index 17470c837..6378c70d6 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -147,6 +147,10 @@ fi if [ "${chantools}" == "on" ]; then OPTIONS+=(CHANTOOLS "ChannelTools (Fund Rescue)") fi +if [ "${homer}" == "on" ]; then + OPTIONS+=(HOMER "Homer Dashboard") + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi if [ "${circuitbreaker}" == "on" ]; then OPTIONS+=(CIRCUIT "Circuitbreaker (LND firewall)") fi @@ -315,6 +319,9 @@ case $CHOICE in SUBSCRIBE) /home/admin/config.scripts/blitz.subscriptions.py ;; + HOMER) + sudo /home/admin/config.scripts/bonus.homer.sh menu + ;; SERVICES) /home/admin/00settingsMenuServices.sh ;; diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index 99e80293d..00a376ee8 100755 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -24,6 +24,7 @@ if [ ${#sphinxrelay} -eq 0 ]; then sphinxrelay="off"; fi if [ ${#lit} -eq 0 ]; then lit="off"; fi if [ ${#whitepaper} -eq 0 ]; then whitepaper="off"; fi if [ ${#chantools} -eq 0 ]; then chantools="off"; fi +if [ ${#homer} -eq 0 ]; then homer="off"; fi if [ ${#sparko} -eq 0 ]; then sparko="off"; fi if [ ${#spark} -eq 0 ]; then spark="off"; fi if [ ${#tallycoinConnect} -eq 0 ]; then tallycoinConnect="off"; fi @@ -73,6 +74,8 @@ if [ "${lightning}" == "cl" ] || [ "${cl}" == "on" ]; then OPTIONS+=(n 'C-Lightning Spark Wallet' ${spark}) fi +OPTIONS+=(m 'Homer Dashboard' ${homer}) + CHOICES=$(dialog --title ' Additional Mainnet Services ' \ --checklist ' use spacebar to activate/de-activate ' \ 27 55 20 "${OPTIONS[@]}" 2>&1 >/dev/tty) @@ -519,6 +522,24 @@ else echo "Whitepaper setting unchanged." fi +# Homer process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "m") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${homer}" != "${choice}" ]; then + echo "Homer settings changed .." + anychange=1 + /home/admin/config.scripts/bonus.homer.sh ${choice} + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + whiptail --title " Installed Homer" --msgbox "\ +Homer was installed.\n +Use the new 'Homer' entry in Main Menu for more info.\n +" 10 35 + fi +else + echo "Homer Setting unchanged." +fi + # BitcoinMinds process choice choice="off"; check=$(echo "${CHOICES}" | grep -c "v") if [ ${check} -eq 1 ]; then choice="on"; fi diff --git a/home.admin/99updateMenu.sh b/home.admin/99updateMenu.sh index f7c395edf..4217e82d2 100755 --- a/home.admin/99updateMenu.sh +++ b/home.admin/99updateMenu.sh @@ -481,6 +481,10 @@ if [ "${sphinxrelay}" == "on" ]; then OPTIONS+=(SPHINX "Update Sphinx Server Relay") fi +if [ "${homer}" == "on" ]; then + OPTIONS+=(HOMER "Update Homer") +fi + if [ "${mempoolExplorer}" == "on" ]; then OPTIONS+=(MEMPOOL "Update Mempool Explorer") fi @@ -535,6 +539,9 @@ case $CHOICE in TOR) sudo /home/admin/config.scripts/tor.network.sh update ;; + HOMER) + /home/admin/config.scripts/bonus.homer.sh update + ;; MEMPOOL) /home/admin/config.scripts/bonus.mempool.sh update ;; diff --git a/home.admin/_provision_.sh b/home.admin/_provision_.sh index d07f5383b..189b7b0d2 100755 --- a/home.admin/_provision_.sh +++ b/home.admin/_provision_.sh @@ -700,6 +700,15 @@ else echo "Provisioning CircuitBreaker - keep default" >> ${logFile} fi +# homer +if [ "${homer}" = "on" ]; then + echo "Provisioning Homer - run config script" >> ${logFile} + sudo sed -i "s/^message=.*/message='Setup Homer'/g" ${infoFile} + sudo -u admin /home/admin/config.scripts/bonus.homer.sh on >> ${logFile} 2>&1 +else + echo "Provisioning Homer - keep default" >> ${logFile} +fi + # tallycoin_connect if [ "${tallycoinConnect}" = "on" ]; then echo "Provisioning Tallycoin Connect - run config script" >> ${logFile} diff --git a/home.admin/assets/nginx/sites-available/homer_ssl.conf b/home.admin/assets/nginx/sites-available/homer_ssl.conf new file mode 100644 index 000000000..6ee57914e --- /dev/null +++ b/home.admin/assets/nginx/sites-available/homer_ssl.conf @@ -0,0 +1,18 @@ +## homer_ssl.conf + +server { + listen 4091 ssl; + listen [::]:4091 ssl; + server_name _; + + include /etc/nginx/snippets/ssl-params.conf; + include /etc/nginx/snippets/ssl-certificate-app-data.conf; + + access_log /var/log/nginx/access_homer.log; + error_log /var/log/nginx/error_homer.log; + + root /var/www/homer; + index index.html; + + +} diff --git a/home.admin/assets/nginx/sites-available/homer_tor.conf b/home.admin/assets/nginx/sites-available/homer_tor.conf new file mode 100644 index 000000000..297574dc4 --- /dev/null +++ b/home.admin/assets/nginx/sites-available/homer_tor.conf @@ -0,0 +1,14 @@ +## homer_tor.conf + +server { + listen localhost:4092; + listen [::1]:4092; + server_name _; + + access_log /var/log/nginx/access_homer.log; + error_log /var/log/nginx/error_homer.log; + + root /var/www/homer; + index index.html; + +} \ No newline at end of file diff --git a/home.admin/assets/nginx/sites-available/homer_tor_ssl.conf b/home.admin/assets/nginx/sites-available/homer_tor_ssl.conf new file mode 100644 index 000000000..ea37696a3 --- /dev/null +++ b/home.admin/assets/nginx/sites-available/homer_tor_ssl.conf @@ -0,0 +1,17 @@ +## homer_tor_ssl.conf + +server { + listen localhost:4093; + listen [::1]:4093; + server_name _; + + include /etc/nginx/snippets/ssl-params.conf; + include /etc/nginx/snippets/ssl-certificate-app-data-tor.conf; + + access_log /var/log/nginx/access_homer.log; + error_log /var/log/nginx/error_homer.log; + + root /var/www/homer; + index index.html; + +} diff --git a/home.admin/config.scripts/bonus.homer.sh b/home.admin/config.scripts/bonus.homer.sh new file mode 100644 index 000000000..d6b9bab84 --- /dev/null +++ b/home.admin/config.scripts/bonus.homer.sh @@ -0,0 +1,256 @@ +#!/bin/bash + +# https://github.com/bastienwirtz/homer + +installVersion="v21.03.2" +remoteVersion=$(curl -s https://api.github.com/repos/bastienwirtz/homer/releases/latest|grep tag_name|head -1|cut -d '"' -f4) + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "# small config script to switch Homer on or off" + echo "# installs the $installVersion by default" + echo "# bonus.homer.sh [status|on|off|update]" + exit 1 +fi + +source /mnt/hdd/raspiblitz.conf + +# show info menu +if [ "$1" = "menu" ]; then + + # get status + echo "# collecting status info ... (please wait)" + source <(sudo /home/admin/config.scripts/bonus.homer.sh status) + + + # get network info + localip=$(ip addr | grep 'state UP' -A2 | egrep -v 'docker0' | grep 'eth0\|wlan0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + toraddress=$(sudo cat /mnt/hdd/tor/homer/hostname 2>/dev/null) + fingerprint=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout | cut -d"=" -f2) + + if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then + + # TOR + /home/admin/config.scripts/blitz.display.sh qr "${toraddress}" + whiptail --title " Homer " --msgbox "Open in your local web browser & accept self-signed cert: +https://${localip}:4091\n +SHA1 Thumb/Fingerprint: +${fingerprint}\n +Hidden Service address for TOR Browser (QR see LCD): +${toraddress} +" 16 67 + /home/admin/config.scripts/blitz.display.sh hide + else + + # IP + Domain + whiptail --title " Homer " --msgbox "Open in your local web browser & accept self-signed cert: +https://${localip}:4091\n +SHA1 Thumb/Fingerprint: +${fingerprint}\n +Activate TOR to access the web block explorer from outside your local network. +" 16 54 + fi + + echo "please wait ..." + exit 0 +fi + +# add default value to raspi config if needed +if ! grep -Eq "^homer=" /mnt/hdd/raspiblitz.conf; then + echo "homer=off" >> /mnt/hdd/raspiblitz.conf +fi + +# status +if [ "$1" = "status" ]; then + + if [ "${homer}" = "on" ]; then + echo "configured=1" + else + echo "configured=0" + fi + exit 0 +fi + +# Update (quick hack) +# Stores configuration and assets found in /var/www/homer +if [ "$1" = "update" ]; then + + cd /home/homer/homer + sudo -u homer git fetch + # Comment out until official release that fixes issue #206 + # sudo -u homer git reset --hard $remoteVersion + + # Save config file + sudo cp /var/www/homer/assets/config.yml /mnt/hdd/app-data/homer/config.yml + + # Save any icons + sudo rsync -av /var/www/homer/assets/icons/ /mnt/hdd/app-data/homer/icons + + # Install Homer + sudo -u homer NG_CLI_ANALYTICS=false npm install + if ! [ $? -eq 0 ]; then + echo "FAIL - npm install did not run correctly, aborting" + exit 1 + fi + sudo -u homer NG_CLI_ANALYTICS=false npm run build + if ! [ $? -eq 0 ]; then + echo "FAIL - npm run build did not run correctly, aborting" + exit 1 + fi + + # remove conf link + sudo rm /var/www/homer/assets/config.yml + + # copy new dist over to nginx + sudo rsync -av --delete dist/ /var/www/homer/ + + # link config again + sudo -u www-data ln -s /mnt/hdd/app-data/homer/config.yml /var/www/homer/assets/config.yml + + #restore saved icons + sudo rsync -av /mnt/hdd/app-data/homer/icons/ /var/www/homer/assets/icons/ + sudo chown -R www-data:www-data /var/www/homer/ + + echo "# OK - Homer should now be serving latest code from Version $remoteVersion" + exit 0 + +fi + +# switch on +if [ "$1" = "1" ] || [ "$1" = "on" ]; then + + echo "# *** INSTALL Homer ***" + + isInstalled=$(sudo ls /var/www/homer/assets/config.yml.dist 2>/dev/null | grep -c 'config.yml.dist') + if [ ${isInstalled} -eq 0 ]; then + + # add homer user + sudo adduser --disabled-password --gecos "" homer + + # install homer + cd /home/homer + sudo -u homer git clone https://github.com/bastienwirtz/homer.git + cd homer + # sudo -u homer git reset --hard $installVersion + + sudo -u homer NG_CLI_ANALYTICS=false npm install + if ! [ $? -eq 0 ]; then + echo "FAIL - npm install did not run correctly, aborting" + exit 1 + fi + sudo -u homer NG_CLI_ANALYTICS=false npm run build + if ! [ $? -eq 0 ]; then + echo "FAIL - npm run build did not run correctly, aborting" + exit 1 + fi + + sudo mkdir -p /var/www/homer + sudo rsync -av --delete dist/ /var/www/homer/ + sudo chown -R www-data:www-data /var/www/homer + + # if no persistent data exists - create data dir & use standard config + oldConfigExists=$(ls /mnt/hdd/app-data/homer/config.yml 2>/dev/null | grep -c 'config.yml') + if [ "${oldConfigExists}" == "0" ]; then + sudo -u homer cp /home/homer/homer/dist/assets/config.yml.dist /home/homer/homer/dist/assets/config.yml + sudo mkdir -p /mnt/hdd/app-data/homer + sudo cp /home/homer/homer/dist/assets/config.yml.dist /mnt/hdd/app-data/homer/config.yml + fi + + # link config into nginx directory + sudo chown www-data:www-data /mnt/hdd/app-data/homer/config.yml + sudo -u www-data ln -s /mnt/hdd/app-data/homer/config.yml /var/www/homer/assets/config.yml + + ################## + # NGINX + ################## + + if ! [ -f /etc/nginx/sites-available/homer_ssl.conf ]; then + sudo cp /home/admin/assets/nginx/sites-available/homer_ssl.conf /etc/nginx/sites-available/homer_ssl.conf + fi + if ! [ -f /etc/nginx/sites-available/homer_tor.conf ]; then + sudo cp /home/admin/assets/nginx/sites-available/homer_tor.conf /etc/nginx/sites-available/homer_tor.conf + fi + if ! [ -f /etc/nginx/sites-available/homer_tor_ssl.conf ]; then + sudo cp /home/admin/assets/nginx/sites-available/homer_tor_ssl.conf /etc/nginx/sites-available/homer_tor_ssl.conf + fi + sudo ln -sf /etc/nginx/sites-available/homer_ssl.conf /etc/nginx/sites-enabled/ + sudo ln -sf /etc/nginx/sites-available/homer_tor.conf /etc/nginx/sites-enabled/ + sudo ln -sf /etc/nginx/sites-available/homer_tor_ssl.conf /etc/nginx/sites-enabled/ + + sudo nginx -t + sudo systemctl restart nginx + + # open the firewall + echo "*** Updating Firewall ***" + sudo ufw allow from any to any port 4090 comment 'allow homer HTTP' + sudo ufw allow from any to any port 4091 comment 'allow homer HTTPS' + echo "" + + else + echo "# homer is already installed." + fi + + # start the service if ready + source /home/admin/raspiblitz.info + + # setting value in raspi blitz config + sudo sed -i "s/^homer=.*/homer=on/g" /mnt/hdd/raspiblitz.conf + + # Hidden Service for Mempool if Tor is active + source /mnt/hdd/raspiblitz.conf + if [ "${runBehindTor}" = "on" ]; then + # make sure to keep in sync with internet.tor.sh script + /home/admin/config.scripts/internet.hiddenservice.sh homer 80 4092 443 4093 + fi + exit 0 +fi + + +# switch off +# Stores configuration on persistent disk for quick restore +if [ "$1" = "0" ] || [ "$1" = "off" ]; then + + # setting value in raspi blitz config + sudo sed -i "s/^homer=.*/homer=off/g" /mnt/hdd/raspiblitz.conf + + isInstalled=$(sudo ls /var/www/homer/assets/config.yml.dist 2>/dev/null | grep -c 'config.yml.dist') + if [ ${isInstalled} -eq 1 ]; then + + echo "Saving assets to external drive. If you no longer require these files, it is safe delete from persistent disk at /mnt/hdd/app-data/homer." + sudo cp /var/www/homer/assets/config.yml /mnt/hdd/app-data/homer/config.yml + sudo rsync -av --delete /var/www/homer/assets/icons/ /mnt/hdd/app-data/homer/icons/ + + + echo "# *** REMOVING homer ***" + # delete user and home directory + sudo userdel -rf homer + sudo rm -rf /var/www/homer + + # remove nginx symlinks + sudo rm -f /etc/nginx/sites-enabled/homer_ssl.conf + sudo rm -f /etc/nginx/sites-enabled/homer_tor.conf + sudo rm -f /etc/nginx/sites-enabled/homer_tor_ssl.conf + sudo rm -f /etc/nginx/sites-available/homer_ssl.conf + sudo rm -f /etc/nginx/sites-available/homer_tor.conf + sudo rm -f /etc/nginx/sites-available/homer_tor_ssl.conf + sudo nginx -t + sudo systemctl reload nginx + + # Hidden Service if Tor is active + if [ "${runBehindTor}" = "on" ]; then + # make sure to keep in sync with internet.tor.sh script + /home/admin/config.scripts/internet.hiddenservice.sh off homer + fi + + echo "# OK Homer removed." + + else + echo "# Homer is not installed." + fi + + exit 0 +fi + +echo "error='unknown parameter'" +exit 1 +