From 3942617e8d13c10626d52dfd812187ed41a00a31 Mon Sep 17 00:00:00 2001 From: openoms Date: Sun, 16 Feb 2020 18:13:20 +0000 Subject: [PATCH] add ob-watcher script --- FAQ.md | 5 +- README.md | 2 +- scripts/install.hiddenservice.sh | 103 +++++++++++++++++++++++++++++++ scripts/menu.sh | 16 ++++- scripts/start.ob-watcher.sh | 33 ++++++++++ 5 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 scripts/install.hiddenservice.sh create mode 100644 scripts/start.ob-watcher.sh diff --git a/FAQ.md b/FAQ.md index 545643c..69f4eb7 100644 --- a/FAQ.md +++ b/FAQ.md @@ -68,4 +68,7 @@ https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-09-30/ socket.gaierror: [Errno -2] Name or service not known ``` * Remember to use `torify` with the python scripts when connecting remotely through Tor. Example: - `torify wallet-tool.py wallet.jmdat` \ No newline at end of file + `torify wallet-tool.py wallet.jmdat` + +### Nuke the joinin user and the /home/joinin folder +`sudo userdel -r joinin` \ No newline at end of file diff --git a/README.md b/README.md index 555ccd5..5f6ea36 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ There is a terminal based GUI in the works. - [ ] TUMBLER "Run the Tumbler" - [x] YG "Run the Yield Generator" - [x] HISTORY "Show report" -- [ ] OBWATCH "Show the offer book" +- [x] OBWATCH "Show the offer book" - [ ] EMPTY "Empty a mixdepth" - [x] CONF_YG "Configure the Yield Generator" - [x] STOP "Stop the Yield Generator" diff --git a/scripts/install.hiddenservice.sh b/scripts/install.hiddenservice.sh new file mode 100644 index 0000000..92f3cd0 --- /dev/null +++ b/scripts/install.hiddenservice.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# $1 is the service name, same as the HiddenServiceDir in torrc +# $2 is the port the Hidden Service forwards to (to be used in the Tor browser) +# $3 is the port to be forwarded with the Hidden Service + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "config script to configure a Tor Hidden Service" + echo "internet.hiddenservice.sh [service] [toPort] [fromPort] [optional-toPort2] [optional-fromPort2]" + exit 1 +fi + +service="$1" +if [ ${#service} -eq 0 ]; then + echo "ERROR: service name is missing" + exit 1 +fi + +toPort="$2" +if [ ${#toPort} -eq 0 ]; then + echo "ERROR: the port to forward to is missing" + exit 1 +fi + +fromPort="$3" +if [ ${#fromPort} -eq 0 ]; then + echo "ERROR: the port to forward from is missing" + exit 1 +fi + +# not mandatory +toPort2="$4" + +# needed if $4 is given +fromPort2="$5" +if [ ${#toPort2} -gt 0 ]; then + if [ ${#fromPort2} -eq 0 ]; then + echo "ERROR: the second port to forward from is missing" + exit 1 + fi +fi + +if [ "${runBehindTor}" = "on" ]; then + #check if the service is already present + isHiddenService=$(sudo cat /etc/tor/torrc 2>/dev/null | grep -c $service) + if [ ${isHiddenService} -eq 0 ]; then + #check if the port is already forwarded + alreadyThere=$(sudo cat /etc/tor/torrc 2>/dev/null | grep -c 127.0.0.1:$fromPort) + if [ ${alreadyThere} -gt 0 ]; then + echo "The port $fromPort is already forwarded. Check /etc/tor/torrc for the details." + exit 1 + fi + echo " +# Hidden Service for $service +HiddenServiceDir /mnt/hdd/tor/$service +HiddenServiceVersion 3 +HiddenServicePort $toPort 127.0.0.1:$fromPort" | sudo tee -a /etc/tor/torrc + + # check and insert second port pair + if [ ${#toPort2} -gt 0 ]; then + alreadyThere=$(sudo cat /etc/tor/torrc 2>/dev/null | grep -c 127.0.0.1:$fromPort2) + if [ ${alreadyThere} -gt 0 ]; then + echo "The port $fromPort2 is already forwarded. Check the /etc/tor/torrc for the details." + else + echo "HiddenServicePort $toPort2 127.0.0.1:$fromPort2" | sudo tee -a /etc/tor/torrc + fi + fi + # restart tor + echo "" + echo "Restarting Tor to activate the Hidden Service..." + sudo systemctl restart tor + sleep 10 + else + echo "The Hidden Service for $service is already installed." + fi + # show the Hidden Service address + TOR_ADDRESS=$(sudo cat /mnt/hdd/tor/$service/hostname) + if [ -z "$TOR_ADDRESS" ]; then + echo "Waiting for the Hidden Service" + sleep 10 + TOR_ADDRESS=$(sudo cat /mnt/hdd/tor/$service/hostname) + if [ -z "$TOR_ADDRESS" ]; then + echo " FAIL - The Hidden Service address could not be found - Tor error?" + exit 1 + fi + fi + echo "" + echo "The Tor Hidden Service address for $service is:" + echo "$TOR_ADDRESS" + echo "use with the port: $toPort" + echo "" + alreadyThere=$(sudo cat /etc/tor/torrc 2>/dev/null | grep -c 127.0.0.1:$fromPort2) + if [ ${#toPort2} -gt 0 ]; then + if [ ${alreadyThere} -eq 0 ]; then + echo "or the port: $toPort2" + else + echo "The port $fromPort2 is forwarded for another Hidden Service. Check the /etc/tor/torrc for the details." + fi + fi +else + echo "Tor is not active" + exit 1 +fi diff --git a/scripts/menu.sh b/scripts/menu.sh index fef1182..cc7cd3f 100755 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -30,7 +30,7 @@ OPTIONS+=(\ YG_LIST "List the past YG activity" "" "" #HISTORY "Show the past transactions" \ - #OBWATCH "Show the offer book" \ + OBWATCH "Watch the offer book locally" \ #EMPTY "Empty a mixdepth" \ "" "" YG_CONF "Configure the Yield Generator" \ @@ -63,7 +63,7 @@ case $CHOICE in echo "" echo "Fund the wallet on addresses labeled 'new' to avoid address reuse." . /home/joinin/joinmarket-clientserver/jmvenv/bin/activate - python $HOME/scriptstarter.py wallet-tool $wallet + python /home/joinin/scriptstarter.py wallet-tool $wallet ./menu.sh ;; PAY) @@ -100,6 +100,18 @@ case $CHOICE in HISTORY) ;; OBWATCH) + #TODO show hidden service only if already running + ./start.ob-watcher.sh + errorOnInstall=$? + if [ ${errorOnInstall} -eq 0 ]; then + TOR_ADDRESS=$(sudo cat /mnt/hdd/tor/ob-watcher/hostname) + dialog --title "Started the ob-watcher service" \ + --msgbox "\nVisit the address in the Tor Browser:\n$TOR_ADDRESS" 8 56 + else + DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \ + --msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56 + fi + ./menu.sh ;; EMPTY) ;; diff --git a/scripts/start.ob-watcher.sh b/scripts/start.ob-watcher.sh new file mode 100644 index 0000000..d8a1279 --- /dev/null +++ b/scripts/start.ob-watcher.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +#install dependency +pip install matplotlib + +SCRIPT="ob-watcher" + +sudo systemctl stop $SCRIPT +sudo systemctl disable $SCRIPT 2>/dev/null + +echo " +[Unit] +Description=$SCRIPT + +[Service] +WorkingDirectory=/home/joinin/joinmarket-clientserver/scripts/ +ExecStart=/bin/sh -c '. /home/joinin/joinmarket-clientserver/jmvenv/bin/activate &&\ +python /home/joinin/joinmarket-clientserver/scripts/obwatch/ob-watcher.py' +User=joinin +Group=joinin +Type=simple +KillMode=process +TimeoutSec=600 +Restart=no + +[Install] +WantedBy=multi-user.target +" | sudo tee /etc/systemd/system/$SCRIPT.service 1>/dev/null + sudo systemctl enable $SCRIPT 2>/dev/null + sudo systemctl start $SCRIPT + +#create Hidden Service +./install.hiddenservice.sh ob-watcher 80 62601 \ No newline at end of file