summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio <f.comuni@creative-group.it>2018-04-10 10:58:43 +0200
committerGDR! <gdr@gdr.name>2018-04-10 11:46:13 +0200
commitb4444039e733acc3e20e5b85749d95dd9eae298b (patch)
treeb0a1ae13b61324bc67b9f3ef71883e9a912266f4
parent64277a0a2f4cb8902c77f4d9867d18d980e51bc8 (diff)
Add config file to tokssh to map a memorable name to toxid
Tokssh search the hostname from commandline in ~/.tuntox/hosts to map it to a toxid and optionally to a secret.
-rwxr-xr-xscripts/tokssh88
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
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 tokssk [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}