- Better start_tor timeout handling
- Minor edits
This commit is contained in:
45
torxi.sh
45
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
|
||||
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
|
||||
if [ $timeout -eq 20 ]; then
|
||||
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
|
||||
@@ -143,8 +153,6 @@ function start_tor {
|
||||
docker exec -it -d $_gwID sh -c "tor > log"
|
||||
sleep 2
|
||||
timeout=0
|
||||
|
||||
|
||||
fi
|
||||
done
|
||||
printf "$green%s$transparent\n" "[Success!] "
|
||||
@@ -233,7 +241,6 @@ function ws_start {
|
||||
fi
|
||||
|
||||
|
||||
|
||||
########## Set the gateway container as the workstation's default gateway ##########
|
||||
printf "\n$white%s$transparent\n" "Setting default gateway of workstation..."
|
||||
docker exec -it -d $_wsID sh -c "ip route del default"
|
||||
@@ -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
|
||||
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,13 +462,12 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user