summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGDR! <gdr@gdr.name>2018-05-04 20:22:45 +0200
committerGDR! <gdr@gdr.name>2018-05-04 20:22:45 +0200
commitf94b4083396676ed14681cff8d4e06f4194d31e5 (patch)
tree458578a1ba49ee23899358bcd8a767841b8ff76c /scripts
parentd2e2adc947ec929b831d6369421cd585b9e3d66b (diff)
parent9f245199da5a9e82e76177832153053bc32852e9 (diff)
Merge branch 'master' of github.com:gjedeer/tuntox
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/tokssh88
1 files changed, 69 insertions, 19 deletions
diff --git a/scripts/tokssh b/scripts/tokssh
index 6bdb74d..eeddb21 100755
--- a/scripts/tokssh
+++ b/scripts/tokssh
@@ -1,37 +1,87 @@
1#!/bin/bash 1#!/bin/bash
2set -e
3function help {
4 cat <<EOF
5A simple wrapper to use like SSH
2 6
3# 7Usage:
4# A simple wrapper to use like SSH 8 tokssh [ssh options] [user@]address [-s secret]
5# Usage: 9
6# tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 10where
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
19examples:
20 tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
21 tokssh 5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
22 tokssh -p 2222 -o ForwardAgent=yes user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054
23 tokssh user@5A40C3443ABD6E1DDEE682E83F84A4D556C24C22D2230DCC141A4723C123473C171A4D9C4054 -s TuNToXSeCreT
24
25files:
26 ~/.tuntox/hosts maps hostname to ToxID and optional secret.
27 format is
28 hostname ToxID secret(optional)
29EOF
30}
31
32strargs="'$*'"
33if [ -z "${strargs##*-h*}" ] || [ -z "${strargs##*--help*}" ] ;then
34 help
35 exit
36fi
11 37
12array=( $@ ) 38array=( $@ )
13len=${#array[@]} 39len=${#array[@]}
14userhost=${array[$len-1]}
15args=${array[@]:0:$len-1}
16 40
17if [ "${array[$len-2]}" == "-s" ] 41if [ $len -lt 1 ]; then
42 help
43 exit
44fi
45
46
47# look for secret and remvove it from args
48if [ $len -gt 2 ] && [ "${array[$len-2]}" == "-s" ]
18then 49then
19 secret="${array[@]:$len-2:$len-1}" 50 secret="${array[@]:$len-2:$len-1}"
20 len=$[len-2] 51 len=$[len-2]
21fi 52fi
22 53
54userhost=${array[$len-1]}
55args=${array[@]:0:$len-1}
23 56
57# check for user@id
24arruserhost=(${userhost//@/ }) 58arruserhost=(${userhost//@/ })
25arruserhostlen=${#arruserhost[@]} 59arruserhostlen=${#arruserhost[@]}
26 60
27if [ $arruserhostlen -gt 1 ] 61if [ $arruserhostlen -gt 1 ]
28then 62then
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
33else 67else
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
72fi
73
74#search toxid in ~/.tuntox/hosts and map it to toxid
75if [ -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
36fi 85fi
37 86
87ssh -o ProxyCommand="tuntox -i $toxid -W 127.0.0.1:%p $secret" $args ${user}${hostname}