Skip to content

Commit f94b408

Browse files
committed
Merge branch 'master' of github.com:gjedeer/tuntox
2 parents d2e2adc + 9f24519 commit f94b408

File tree

1 file changed

+69
-19
lines changed

1 file changed

+69
-19
lines changed

scripts/tokssh

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,87 @@
11
#!/bin/bash
2+
set -e
3+
function help {
4+
cat <<EOF
5+
A simple wrapper to use like SSH
26
3-
#
4-
# A simple wrapper to use like SSH
5-
# Usage:
6-
# tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
7-
# tokssh 5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
8-
# tokssh -p 2222 -o ForwardAgent=yes user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
9-
# tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 -s TuNToXSeCreT
10-
#
7+
Usage:
8+
tokssh [ssh options] [user@]address [-s secret]
9+
10+
where
11+
12+
ssh options: options to pass to ssh process
13+
user: login on remote host
14+
address: either a ToxID or a hostname. ~/.tuntox/hosts is read to map
15+
hostname to ToxID. hostname MUST resolve to 127.0.0.1
16+
17+
-s optional secret to use to connect to tuntox server
18+
19+
examples:
20+
tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
21+
tokssh 5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
22+
tokssh -p 2222 -o ForwardAgent=yes user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
23+
tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 -s TuNToXSeCreT
24+
25+
files:
26+
~/.tuntox/hosts maps hostname to ToxID and optional secret.
27+
format is
28+
hostname ToxID secret(optional)
29+
EOF
30+
}
31+
32+
strargs="'$*'"
33+
if [ -z "${strargs##*-h*}" ] || [ -z "${strargs##*--help*}" ] ;then
34+
help
35+
exit
36+
fi
1137

1238
array=( $@ )
1339
len=${#array[@]}
14-
userhost=${array[$len-1]}
15-
args=${array[@]:0:$len-1}
1640

17-
if [ "${array[$len-2]}" == "-s" ]
41+
if [ $len -lt 1 ]; then
42+
help
43+
exit
44+
fi
45+
46+
47+
# look for secret and remvove it from args
48+
if [ $len -gt 2 ] && [ "${array[$len-2]}" == "-s" ]
1849
then
19-
secret="${array[@]:$len-2:$len-1}"
20-
len=$[len-2]
50+
secret="${array[@]:$len-2:$len-1}"
51+
len=$[len-2]
2152
fi
2253

54+
userhost=${array[$len-1]}
55+
args=${array[@]:0:$len-1}
2356

57+
# check for user@id
2458
arruserhost=(${userhost//@/ })
2559
arruserhostlen=${#arruserhost[@]}
2660

2761
if [ $arruserhostlen -gt 1 ]
2862
then
29-
# last argument is user@toxid
30-
user=${arruserhost[0]}
31-
toxid=${arruserhost[1]}
32-
ssh -o ProxyCommand="tuntox -i $toxid -W 127.0.0.1:%p $secret" $args $user@localhost
63+
# last argument is user@toxid
64+
user="${arruserhost[0]}@"
65+
toxid=${arruserhost[1]}
66+
hostname=localhost
3367
else
34-
# last argument is just toxid
35-
ssh -o ProxyCommand="tuntox -i $userhost -W 127.0.0.1:%p $secret" $args localhost
68+
# last argument is just toxid
69+
user=""
70+
toxid=$userhost
71+
hostname=localhost
72+
fi
73+
74+
#search toxid in ~/.tuntox/hosts and map it to toxid
75+
if [ -f ~/.tuntox/hosts ]; then
76+
while read c_hostname c_toxid c_secret; do
77+
if [ "${c_hostname:0:1}" != "#" ] && [ "$c_hostname" == "$toxid" ]; then
78+
toxid="$c_toxid"
79+
if [ "$secret" == "" ]; then
80+
secret="-s $c_secret"
81+
fi
82+
break
83+
fi
84+
done < ~/.tuntox/hosts
3685
fi
3786

87+
ssh -o ProxyCommand="tuntox -i $toxid -W 127.0.0.1:%p $secret" $args ${user}${hostname}

0 commit comments

Comments
 (0)