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"
)
while True:
# Run 1 hour, then exit to reconnect
if time.time() - start_time > 3600:
sys.exit(0)
#~ # Run 1 hour, then exit to reconnect
#~ if time.time() - start_time > 3600:
#~ sys.exit(0)
db.check_die()
db.update(opts.id)
for i in range(10):

View File

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