Merge pull request #956 from openoms/v1.4patch10

improve hidden service genarator script
This commit is contained in:
Christian Rotzoll
2020-01-06 18:57:32 +01:00
committed by GitHub
3 changed files with 60 additions and 7 deletions

View File

@@ -109,8 +109,7 @@ case $CHOICE in
;;
ELECTRS)
clear
./config.scripts/internet.hiddenservice.sh electrs 50002 50002
./config.scripts/internet.hiddenservice.sh electrsTCP 50001 50001
./config.scripts/internet.hiddenservice.sh electrs 50002 50002 50001 50001
TOR_ADDRESS=$(sudo cat /mnt/hdd/tor/electrs/hostname)
echo ""
echo "The Tor Hidden Service address for electrs is:"

View File

@@ -283,8 +283,7 @@ WantedBy=multi-user.target
# Hidden Service for electrs if Tor active
if [ "${runBehindTor}" = "on" ]; then
/home/admin/config.scripts/internet.hiddenservice.sh electrs 50002 50002
/home/admin/config.scripts/internet.hiddenservice.sh electrsTCP 50001 50001
/home/admin/config.scripts/internet.hiddenservice.sh electrs 50002 50002 50001 50001
TOR_ADDRESS=$(sudo cat /mnt/hdd/tor/electrs/hostname)
if [ -z "$TOR_ADDRESS" ]; then

View File

@@ -6,7 +6,7 @@
# 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]"
echo "internet.hiddenservice.sh [service] [toPort] [fromPort] [optional-toPort2] [optional-fromPort2]"
exit 1
fi
@@ -26,25 +26,80 @@ fi
fromPort="$3"
if [ ${#fromPort} -eq 0 ]; then
echo "ERROR:the port to forward from is missing"
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 is already installed"
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