From 3808955f859da0fb2fec21905eb75de7f28cc13f Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Sun, 9 Apr 2017 11:02:26 +0200 Subject: [PATCH 1/3] Added optional parameters --- xiringuito | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/xiringuito b/xiringuito index 150d4c7..de5dc41 100755 --- a/xiringuito +++ b/xiringuito @@ -4,6 +4,16 @@ # set -e +function print_help() { + echo "Usage: ${0} [OPTIONS] [SSH_USER@]SSH_SERVER [NETWORK1, NETWORK2, ... NETWORKx]" + echo + echo "OPTIONS" + echo "-R do not reconnect after connection failure" + echo "-D do not fetch DNS config from server" + echo "-h show this extremely helpful message" + echo +} + declare -r KERNEL=$(uname -s | tr [A-Z] [a-z]) if [[ ${KERNEL} != linux && ${KERNEL} != darwin ]]; then echo "Unsupported system: ${KERNEL}" @@ -19,10 +29,30 @@ if [[ ${KERNEL} == darwin ]]; then fi if [[ ${#} -lt 1 ]]; then - echo "Usage: ${0} [SSH_USER@]SSH_SERVER [NETWORK1, NETWORK2, ... NETWORKx]" + print_help exit 1 fi +while getopts "RDh" o; do + case ${o} in + R) + NO_RECONNECT=true + ;; + D) + NO_DNS=true + ;; + h) + print_help + exit 0 + ;; + *) + print_help + exit 1 + esac +done + +shift $((OPTIND-1)) + cd $(dirname ${0}) ./scripts/client-preexec.sh From 047a457a2ff8e3a8cd227a7a2f012232e336b1b3 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Sun, 9 Apr 2017 11:24:27 +0200 Subject: [PATCH 2/3] Add reconnection functionality --- scripts/server-execute.sh | 2 +- xiringuito | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/server-execute.sh b/scripts/server-execute.sh index 56705bc..b6ddb7e 100755 --- a/scripts/server-execute.sh +++ b/scripts/server-execute.sh @@ -26,7 +26,7 @@ function teardown() { echo "CONNECTED" FAILED_PINGS=0 -while [[ ${FAILED_PINGS} -lt 20 ]]; do +while [[ ${FAILED_PINGS} -lt 10 ]]; do ping -c3 -nq ${CLIENT_IP_ADDR} >/dev/null if [[ ${?} -ne 0 ]]; then let FAILED_PINGS+=1 diff --git a/xiringuito b/xiringuito index de5dc41..ff1ee81 100755 --- a/xiringuito +++ b/xiringuito @@ -33,6 +33,10 @@ if [[ ${#} -lt 1 ]]; then exit 1 fi +# We need to save executable path and arguments for reconnection functionality +declare -r ORIGINAL_EXEC=${0} +declare -r ORIGINAL_ARGS=${@} + while getopts "RDh" o; do case ${o} in R) @@ -151,8 +155,8 @@ fi set +e FAILED_PINGS=0 -while [[ ${FAILED_PINGS} -lt 20 ]]; do - kill -0 ${SSH_PID} &>/dev/null || exit 17 +while [[ ${FAILED_PINGS} -lt 10 ]]; do + kill -0 ${SSH_PID} &>/dev/null || break ./scripts/client-ping-server.sh ${TUNNEL_ID} ${IP_BASE} if [[ ${?} -ne 0 ]]; then @@ -166,3 +170,7 @@ while [[ ${FAILED_PINGS} -lt 20 ]]; do done teardown + +if [[ -z "${NO_RECONNECT}" ]]; then + exec ${ORIGINAL_EXEC} ${ORIGINAL_ARGS} +fi From b5e2e8fe418f6bfbc12071242df9a1b883595c29 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Sun, 9 Apr 2017 11:43:36 +0200 Subject: [PATCH 3/3] Add "RECONNECTING" parameter --- xiringuito | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xiringuito b/xiringuito index ff1ee81..34593be 100755 --- a/xiringuito +++ b/xiringuito @@ -37,7 +37,7 @@ fi declare -r ORIGINAL_EXEC=${0} declare -r ORIGINAL_ARGS=${@} -while getopts "RDh" o; do +while getopts "RDrh" o; do case ${o} in R) NO_RECONNECT=true @@ -45,6 +45,9 @@ while getopts "RDh" o; do D) NO_DNS=true ;; + r) + RECONNECTING=true + ;; h) print_help exit 0 @@ -133,8 +136,8 @@ fi set +e for NETWORK in ${NETWORKS}; do - echo "> ROUTE: ${NETWORK}" - ./scripts/${KERNEL}/client-route.sh ${LOCAL_TUNNEL_ID} ${NETWORK} + echo "> ROUTE: ${NETWORK}" + [[ -z "${RECONNECTING}" ]] && ./scripts/${KERNEL}/client-route.sh ${LOCAL_TUNNEL_ID} ${NETWORK} done set -e @@ -172,5 +175,5 @@ done teardown if [[ -z "${NO_RECONNECT}" ]]; then - exec ${ORIGINAL_EXEC} ${ORIGINAL_ARGS} + exec ${ORIGINAL_EXEC} -r ${ORIGINAL_ARGS} fi