hiddenservice: improve messages

This commit is contained in:
openoms 2020-01-05 10:29:04 +00:00
parent e678364da6
commit ce4aa3cd7e

View file

@ -26,7 +26,7 @@ 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
@ -37,7 +37,7 @@ toPort2="$4"
fromPort2="$5"
if [ ${#toPort2} -gt 0 ]; then
if [ ${#fromPort2} -eq 0 ]; then
echo "ERROR:the second port to forward from is missing"
echo "ERROR: the second port to forward from is missing"
exit 1
fi
fi
@ -49,7 +49,7 @@ if [ "${runBehindTor}" = "on" ]; 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 $fromPort is already forwarded. Check /etc/tor/torrc for the details"
echo "The port $fromPort is already forwarded. Check /etc/tor/torrc for the details."
exit 1
fi
echo "
@ -58,21 +58,22 @@ 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 $fromPort2 is already forwarded. Check /etc/tor/torrc for the details"
else
echo "HiddenServicePort $toPort2 127.0.0.1:$fromPort2" | sudo tee -a /etc/tor/torrc
fi
fi
# 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)
@ -85,11 +86,18 @@ fi
exit 1
fi
fi
echo ""
echo "The Tor Hidden Service address for $service is:"
echo "$TOR_ADDRESS"
echo "use with the port: $toPort"
if [ ${#toPort2} -gt 0 ] && [ ${alreadyThere} -eq 0 ]; then
echo "or the port: $toPort2"
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"