diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/tokssh | 88 |
1 files changed, 69 insertions, 19 deletions
diff --git a/scripts/tokssh b/scripts/tokssh index 6bdb74d..53c88c1 100755 --- a/scripts/tokssh +++ b/scripts/tokssh | |||
@@ -1,37 +1,87 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | set -e | ||
3 | function help { | ||
4 | cat <<EOF | ||
5 | A simple wrapper to use like SSH | ||
2 | 6 | ||
3 | # | 7 | Usage: |
4 | # A simple wrapper to use like SSH | 8 | tokssk [ssh options] [user@]address [-s secret] |
5 | # Usage: | 9 | |
6 | # tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 | 10 | where |
7 | # tokssh 5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 | 11 | |
8 | # tokssh -p 2222 -o ForwardAgent=yes user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 | 12 | ssh options: options to pass to ssh process |
9 | # tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 -s TuNToXSeCreT | 13 | user: login on remote host |
10 | # | 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 | ||
11 | 37 | ||
12 | array=( $@ ) | 38 | array=( $@ ) |
13 | len=${#array[@]} | 39 | len=${#array[@]} |
14 | userhost=${array[$len-1]} | ||
15 | args=${array[@]:0:$len-1} | ||
16 | 40 | ||
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" ] | ||
18 | then | 49 | then |
19 | secret="${array[@]:$len-2:$len-1}" | 50 | secret="${array[@]:$len-2:$len-1}" |
20 | len=$[len-2] | 51 | len=$[len-2] |
21 | fi | 52 | fi |
22 | 53 | ||
54 | userhost=${array[$len-1]} | ||
55 | args=${array[@]:0:$len-1} | ||
23 | 56 | ||
57 | # check for user@id | ||
24 | arruserhost=(${userhost//@/ }) | 58 | arruserhost=(${userhost//@/ }) |
25 | arruserhostlen=${#arruserhost[@]} | 59 | arruserhostlen=${#arruserhost[@]} |
26 | 60 | ||
27 | if [ $arruserhostlen -gt 1 ] | 61 | if [ $arruserhostlen -gt 1 ] |
28 | then | 62 | then |
29 | # last argument is user@toxid | 63 | # last argument is user@toxid |
30 | user=${arruserhost[0]} | 64 | user="${arruserhost[0]}@" |
31 | toxid=${arruserhost[1]} | 65 | toxid=${arruserhost[1]} |
32 | ssh -o ProxyCommand="tuntox -i $toxid -W 127.0.0.1:%p $secret" $args $user@localhost | 66 | hostname=localhost |
33 | else | 67 | else |
34 | # last argument is just toxid | 68 | # last argument is just toxid |
35 | ssh -o ProxyCommand="tuntox -i $userhost -W 127.0.0.1:%p $secret" $args localhost | 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 | ||
36 | fi | 85 | fi |
37 | 86 | ||
87 | ssh -o ProxyCommand="tuntox -i $toxid -W 127.0.0.1:%p $secret" $args ${user}${hostname} | ||