- 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 #################
|
############ FOR TORRC #################
|
||||||
|
|
||||||
#These settings are pushed to the torrc of the gateway container.
|
#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
|
_torSettings="VirtualAddrNetworkIPv4 10.192.0.0/10
|
||||||
Log notice file /root/.tor/notices.log
|
Log notice file /root/.tor/notices.log
|
||||||
DataDirectory /root/.tor
|
DataDirectory /root/.tor
|
||||||
@@ -42,10 +45,10 @@ HashedControlPassword 16:0430F4846DCB79EB605DAB188CF619860A18B86C20D075B84CB97E0
|
|||||||
AutomapHostsOnResolve 1
|
AutomapHostsOnResolve 1
|
||||||
TransPort $_gwIP:9040
|
TransPort $_gwIP:9040
|
||||||
DNSPort $_gwIP:53"
|
DNSPort $_gwIP:53"
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
########## Functions ####################
|
########## Functions ####################
|
||||||
|
|
||||||
|
|
||||||
function print_banner {
|
function print_banner {
|
||||||
printf "$red%b\n" '████████╗ ██████╗ ██████╗ ██╗ ██╗██╗'
|
printf "$red%b\n" '████████╗ ██████╗ ██████╗ ██╗ ██╗██╗'
|
||||||
printf "$red%b\n" '╚══██╔══╝██╔═══██╗██╔══██╗╚██╗██╔╝██║'
|
printf "$red%b\n" '╚══██╔══╝██╔═══██╗██╔══██╗╚██╗██╔╝██║'
|
||||||
@@ -125,11 +128,18 @@ function start_tor {
|
|||||||
|
|
||||||
while [ "$test" != "100%" ]
|
while [ "$test" != "100%" ]
|
||||||
do
|
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
|
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
|
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
|
if [ "$try" = "3" ]; then
|
||||||
printf "$yellow%s$transparent\n" "[Tried three times. Giving up..]"
|
printf "$yellow%s$transparent\n" "[Tried three times. Giving up..]"
|
||||||
sleep 2
|
sleep 2
|
||||||
@@ -143,8 +153,6 @@ function start_tor {
|
|||||||
docker exec -it -d $_gwID sh -c "tor > log"
|
docker exec -it -d $_gwID sh -c "tor > log"
|
||||||
sleep 2
|
sleep 2
|
||||||
timeout=0
|
timeout=0
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf "$green%s$transparent\n" "[Success!] "
|
printf "$green%s$transparent\n" "[Success!] "
|
||||||
@@ -233,7 +241,6 @@ function ws_start {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
########## Set the gateway container as the workstation's default gateway ##########
|
########## Set the gateway container as the workstation's default gateway ##########
|
||||||
printf "\n$white%s$transparent\n" "Setting default gateway of workstation..."
|
printf "\n$white%s$transparent\n" "Setting default gateway of workstation..."
|
||||||
docker exec -it -d $_wsID sh -c "ip route del default"
|
docker exec -it -d $_wsID sh -c "ip route del default"
|
||||||
@@ -255,25 +262,25 @@ function ws_start {
|
|||||||
function checkip {
|
function checkip {
|
||||||
|
|
||||||
printf "\n$white%s$transparent\n" "Checking connection..."
|
printf "\n$white%s$transparent\n" "Checking connection..."
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
#Check if tor is running in gw container
|
#Check if tor is running in gw container
|
||||||
if [ "$(docker exec -it $_gwID sh -c 'pgrep tor')" = "" ]; then
|
if [ "$(docker exec -it $_gwID sh -c 'pgrep tor')" = "" ]; then
|
||||||
printf "$yellow%s$transparent\n" "[Tor is not running in gateway]"
|
printf "$yellow%s$transparent\n" "[Tor is not running in gateway]"
|
||||||
return 0
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# WS_CONTAINER CURL LEAVES '\r' CHAR, IN ORDER TO MATCH REGEX IT HAS TO BE STRIPPED
|
# 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')
|
_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)"
|
_clearip="$(curl --silent checkip.amazonaws.com)"
|
||||||
|
printf "$yellow%s$transparent\n" "${_clearip}]"
|
||||||
#echo "Host IP: ${_clearip}"
|
|
||||||
#echo "TOR IP: ${_torip}"
|
|
||||||
|
|
||||||
# Check clear net IP ##
|
# Check clear net IP ##
|
||||||
if [[ ! $_clearip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
if [[ ! $_clearip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
printf "$red%s$transparent\n" "[Error. Do we have an Internet connection?]"
|
printf "$red%s$transparent\n" "[Error. Do we have an Internet connection?]"
|
||||||
return 0
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Check public Container IP ##
|
## Check public Container IP ##
|
||||||
@@ -289,10 +296,11 @@ function checkip {
|
|||||||
printf "%b\n" "Retry? Tor may needs some time to establish circuits!"
|
printf "%b\n" "Retry? Tor may needs some time to establish circuits!"
|
||||||
printf "%b" "Choice (y/n): "
|
printf "%b" "Choice (y/n): "
|
||||||
read retry
|
read retry
|
||||||
if [ $retry != "y" ]; then return 0; fi
|
if [ $retry != "y" ]; then return 1; fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
geoiplookup ${_torip}
|
geoiplookup ${_torip}
|
||||||
|
clear
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +347,6 @@ function start_vnc {
|
|||||||
|
|
||||||
function menu {
|
function menu {
|
||||||
############### MENU ########################
|
############### MENU ########################
|
||||||
clear
|
|
||||||
print_banner
|
print_banner
|
||||||
printf "%b\n" "$_geoipmsg"
|
printf "%b\n" "$_geoipmsg"
|
||||||
printf "%b\n\n" "$_novncBanner"
|
printf "%b\n\n" "$_novncBanner"
|
||||||
@@ -363,12 +370,14 @@ function menu {
|
|||||||
if [ "$choice" = "t" ]; then
|
if [ "$choice" = "t" ]; then
|
||||||
printf "$white%s$transparent\n" "Connecting to Workstation Terminal.. (type 'exit' to return to menu)"
|
printf "$white%s$transparent\n" "Connecting to Workstation Terminal.. (type 'exit' to return to menu)"
|
||||||
docker exec -it -e USER=root $_wsID /bin/bash
|
docker exec -it -e USER=root $_wsID /bin/bash
|
||||||
|
clear
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Start and connect workstation VNC
|
## Start and connect workstation VNC
|
||||||
if [ "$choice" = "v" ]; then
|
if [ "$choice" = "v" ]; then
|
||||||
start_vnc
|
start_vnc
|
||||||
|
clear
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -391,18 +400,21 @@ function menu {
|
|||||||
if [ "$choice" = "g" ]; then
|
if [ "$choice" = "g" ]; then
|
||||||
printf "$white%s$transparent\n" "Connecting to Gateway Terminal.. (type 'exit' to return to menu)"
|
printf "$white%s$transparent\n" "Connecting to Gateway Terminal.. (type 'exit' to return to menu)"
|
||||||
docker exec -it -e USER=root $_gwID /bin/sh
|
docker exec -it -e USER=root $_gwID /bin/sh
|
||||||
|
clear
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# (re) start tor
|
# (re) start tor
|
||||||
if [ "$choice" = "s" ]; then
|
if [ "$choice" = "s" ]; then
|
||||||
start_tor
|
start_tor
|
||||||
|
checkip
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stop tor
|
# stop tor
|
||||||
if [ "$choice" = "x" ]; then
|
if [ "$choice" = "x" ]; then
|
||||||
stop_tor
|
stop_tor
|
||||||
|
clear
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -450,13 +462,12 @@ function clean_start {
|
|||||||
done
|
done
|
||||||
|
|
||||||
checkip
|
checkip
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resume_start {
|
function resume_start {
|
||||||
|
|
||||||
printf "\n$yellow%s$transparent\n" "Some containers were found. Try to restore session?"
|
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
|
read restore
|
||||||
|
|
||||||
if [ "$restore" = "y" ]; then
|
if [ "$restore" = "y" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user