new startegy of renewing connection

This commit is contained in:
Ville Rantanen
2019-08-16 14:12:34 +03:00
parent 022a53904c
commit 2e469d19d6
2 changed files with 19 additions and 13 deletions

View File

@@ -350,9 +350,9 @@ if __name__ == "__main__":
" Connected\r" " Connected\r"
) )
while True: while True:
# Run 1 hour, then exit to reconnect #~ # Run 1 hour, then exit to reconnect
if time.time() - start_time > 3600: #~ if time.time() - start_time > 3600:
sys.exit(0) #~ sys.exit(0)
db.check_die() db.check_die()
db.update(opts.id) db.update(opts.id)
for i in range(10): for i in range(10):

View File

@@ -13,8 +13,8 @@ if [[ "$1" = update ]]; then
fi fi
_ssh() { _ssh() {
trap 'kill -INT -$sshpid; exit;' INT trap 'kill -INT -$SSHPID; exit;' INT
timeout -k 10 3700 ssh \ ssh \
-o UserKnownHostsFile=/dev/null \ -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \ -o StrictHostKeyChecking=no \
-o ConnectTimeout=10 \ -o ConnectTimeout=10 \
@@ -23,14 +23,14 @@ _ssh() {
-p ${BACKDOORPORT} \ -p ${BACKDOORPORT} \
${BACKDOORHOST} \ ${BACKDOORHOST} \
"$@" & "$@" &
sshpid=$! SSHPID=$!
wait $sshpid wait $SSHPID
#~ -o "ExitOnForwardFailure yes" \
} }
BACKDOORHOST={{BACKDOORHOST}} BACKDOORHOST={{BACKDOORHOST}}
BACKDOORPORT={{BACKDOORPORT}} BACKDOORPORT={{BACKDOORPORT}}
USER=$( id -u -n ) USER=$( id -u -n )
BGPID=0
echo "Must use ssh agent (ssh-add)" echo "Must use ssh agent (ssh-add)"
while true; do while true; do
port=$( _ssh bin/ssh-backdoor open $USER@$HOSTNAME ) port=$( _ssh bin/ssh-backdoor open $USER@$HOSTNAME )
@@ -38,12 +38,18 @@ while true; do
echo "$port port assigned" echo "$port port assigned"
#~ _ssh pkill -a -f $USER@$HOSTNAME #~ _ssh pkill -a -f $USER@$HOSTNAME
_ssh \ _ssh \
-L $port:localhost:$port \
-R $port:localhost:22 \ -R $port:localhost:22 \
bin/ssh-backdoor keep $USER@$HOSTNAME || { bin/ssh-backdoor keep $USER@$HOSTNAME &
true BGPID=$!
# failed while true; do
#_ssh bin/ssh-kill $USER@$HOSTNAME $port || true sleep 60
timeout 20 ssh-keyscan -p "$port" localhost 2>/dev/null | grep -q "$port" || {
kill $BGPID
break
} }
done
for i in {1..10}; do for i in {1..10}; do
sleep 1 sleep 1
printf " $i\r" printf " $i\r"