diff --git a/torxi.sh b/torxi.sh index 5226458..2da674f 100755 --- a/torxi.sh +++ b/torxi.sh @@ -29,6 +29,9 @@ transparent="\e[0m" ############ FOR TORRC ################# #These settings are pushed to the torrc of the gateway container. +# TODO: Implement menu voices for custom node configuration +#ExitNodes $COUNTRY ---- with $COUNTRY as curly braces wrapped ISO country code +# enables geo restriction for exit nodes (eg. {hu} for Hungary, {en} for england and so on) _torSettings="VirtualAddrNetworkIPv4 10.192.0.0/10 Log notice file /root/.tor/notices.log DataDirectory /root/.tor @@ -42,10 +45,10 @@ HashedControlPassword 16:0430F4846DCB79EB605DAB188CF619860A18B86C20D075B84CB97E0 AutomapHostsOnResolve 1 TransPort $_gwIP:9040 DNSPort $_gwIP:53" + ######################################### ########## Functions #################### - function print_banner { printf "$red%b\n" '████████╗ ██████╗ ██████╗ ██╗ ██╗██╗' printf "$red%b\n" '╚══██╔══╝██╔═══██╗██╔══██╗╚██╗██╔╝██║' @@ -125,11 +128,18 @@ function start_tor { while [ "$test" != "100%" ] do - test=$(docker exec -it $_gwID /bin/sh -c "cat log" | tail -n1 | awk '{ print $6 }' | cut -d':' -f1) - printf "\033[K%s\r" "Connection Status: $test" sleep 1 - timeout+=1 - if [ $timeout -eq 20 ]; then + log="$(docker exec -it $_gwID /bin/sh -c "cat log" | tail -n2)" + new_test="$(echo $log | grep -Po "(?<=Bootstrapped )\d+%" | tail -n1)" + + if [ "${new_test}" == "${test}" ]; then + timeout+=1 + fi + + test="$new_test" + printf "\033[K%s\r" "Connection Status: ${test}" + + if [ $timeout -eq 10 ]; then if [ "$try" = "3" ]; then printf "$yellow%s$transparent\n" "[Tried three times. Giving up..]" sleep 2 @@ -139,15 +149,13 @@ function start_tor { printf "$yellow%s$transparent\n" "[Connection timeout. Retry..]" docker exec -it -d $_gwID /bin/sh -c "pkill tor" docker exec -it -d $_gwID /bin/sh -c "rm -rf /root/.tor" - sleep 2 + sleep 2 docker exec -it -d $_gwID sh -c "tor > log" sleep 2 timeout=0 - - fi done - printf "$green%s$transparent\n" "[Success!]" + printf "$green%s$transparent\n" "[Success!] " return 0 } @@ -156,7 +164,7 @@ function stop_tor { docker exec -it -d $_gwID /bin/sh -c "pkill tor" docker exec -it -d $_gwID /bin/sh -c "rm -rf /root/.tor" docker exec -it -d $_gwID /bin/sh -c "rm -rf log" - + if [ "$(docker exec -it -d $_gwID /bin/sh -c "pgrep tor")" = "" ]; then printf "$green%s$transparent\n" "[Success!]" else printf "$red%s$transparent\n" "[Stopping Tor was not successful!]" @@ -231,8 +239,7 @@ function ws_start { printf "$green%s$transparent\n" "[Success!]" else printf "$red%s$transparent\n" "[Error!]" fi - - + ########## Set the gateway container as the workstation's default gateway ########## printf "\n$white%s$transparent\n" "Setting default gateway of workstation..." @@ -255,25 +262,25 @@ function ws_start { function checkip { printf "\n$white%s$transparent\n" "Checking connection..." - while true; do #Check if tor is running in gw container if [ "$(docker exec -it $_gwID sh -c 'pgrep tor')" = "" ]; then printf "$yellow%s$transparent\n" "[Tor is not running in gateway]" - return 0 + return 1 fi # WS_CONTAINER CURL LEAVES '\r' CHAR, IN ORDER TO MATCH REGEX IT HAS TO BE STRIPPED + printf "$yellow%s$transparent" "[Getting TOR IP: " _torip=$(docker exec -it torxi_ws sh -c "curl --silent checkip.amazonaws.com" | tr -d '\r') + printf "$yellow%s$transparent\n" "${_torip}]" + printf "$yellow%s$transparent" "[Getting clearnet IP: " _clearip="$(curl --silent checkip.amazonaws.com)" - - #echo "Host IP: ${_clearip}" - #echo "TOR IP: ${_torip}" + printf "$yellow%s$transparent\n" "${_clearip}]" # Check clear net IP ## if [[ ! $_clearip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then printf "$red%s$transparent\n" "[Error. Do we have an Internet connection?]" - return 0 + return 1 fi ## Check public Container IP ## @@ -289,10 +296,11 @@ function checkip { printf "%b\n" "Retry? Tor may needs some time to establish circuits!" printf "%b" "Choice (y/n): " read retry - if [ $retry != "y" ]; then return 0; fi + if [ $retry != "y" ]; then return 1; fi fi done geoiplookup ${_torip} + clear } @@ -339,7 +347,6 @@ function start_vnc { function menu { ############### MENU ######################## - clear print_banner printf "%b\n" "$_geoipmsg" printf "%b\n\n" "$_novncBanner" @@ -363,12 +370,14 @@ function menu { if [ "$choice" = "t" ]; then printf "$white%s$transparent\n" "Connecting to Workstation Terminal.. (type 'exit' to return to menu)" docker exec -it -e USER=root $_wsID /bin/bash + clear return 1 fi ## Start and connect workstation VNC if [ "$choice" = "v" ]; then start_vnc + clear return 1 fi @@ -391,18 +400,21 @@ function menu { if [ "$choice" = "g" ]; then printf "$white%s$transparent\n" "Connecting to Gateway Terminal.. (type 'exit' to return to menu)" docker exec -it -e USER=root $_gwID /bin/sh - return 1 + clear + return 1 fi # (re) start tor if [ "$choice" = "s" ]; then start_tor + checkip return 1 fi # stop tor if [ "$choice" = "x" ]; then stop_tor + clear return 1 fi @@ -450,15 +462,14 @@ function clean_start { done checkip - } function resume_start { printf "\n$yellow%s$transparent\n" "Some containers were found. Try to restore session?" - printf "%b" "Choice (y/n): " + printf "%b" "Choice (y/N): " read restore - + if [ "$restore" = "y" ]; then ##Get the Gateway ID because the menu needs the variable _gwID if [ "$(docker ps -a | grep $_gwName | awk '{print $1}' | xargs)" != "" ]; then