wok-6.x view dropbear/stuff/sshx @ rev 19830

dropbear/xfbvnc: gateway support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 10 12:21:33 2017 +0100 (2017-03-10)
parents 1ae2567134a8
children 8211a9c470d6
line source
1 #!/bin/sh
3 xdbclient()
4 {
5 read host data
6 svr=${DISPLAY#*:}
7 n=$((10+($RANDOM % 90))); dpy=localhost:$n
8 scr=${DISPLAY/${DISPLAY%.*}/$dpy}
9 r=""
10 while true; do
11 a="$1"
12 r="$r $1"; shift
13 case "$a" in
14 -[piIlLRWKBJ]) r="$r $1"; shift;;
15 -*) ;;
16 *) break ;;
17 esac
18 done
19 [ -n "$1" ] || set -- "${TERM:-xterm} -ls || ${TERM:-sakura} -l || xterm -ls"
20 exec dbclient -f -R $((6000+$n)):localhost:$((6000+${svr%.*})) $r \
21 "xauth add $dpy $data; export DISPLAY=$scr; $@ ; xauth remove $dpy" \
22 </dev/null >/dev/null
23 }
25 pppssh()
26 {
27 ssh="dbclient -y"
28 $ssh $1 true || {
29 [ -z "$DROPBEAR_PASSWORD" ] && echo -n "ssh password: " &&
30 read -s -t 30 DROPBEAR_PASSWORD && export DROPBEAR_PASSWORD
31 $ssh $1 true || exit 1
32 }
33 extra="$(route -n | awk -vd=$(nslookup ${1#*@} | sed '/::/d' | \
34 sed '$!d;s/.*: \([^ ]*\).*/\1/') \
35 '$1=="0.0.0.0"{ print d " gw " $2 " dev " $8 }')"
36 for i in ${4/default/128.0.0.0/1 0.0.0.0/1} ; do
37 echo "route add -net $i dev \$1"
38 done > /etc/ppp/ip-up.d/pppssh$$
39 [ "$4" ] && echo "route add $extra" >> /etc/ppp/ip-up.d/pppssh$$
40 chmod +x /etc/ppp/ip-up.d/pppssh$$
41 n=10.$(($$%256)).$(($$/256))
42 n="${2:-$n.1:$n.2} passive"
43 ppp="/usr/sbin/pppd local noauth nodetach"
44 arg="$n pty '$ssh $1 $ppp ${3:-proxyarp} notty'"
45 pppsvr="$ppp $n ${3:-proxyarp} notty >/dev/null"
46 sshcmd="nc -ulp $5 -e $pppsvr"
47 udpcmd="nc -u ${1#*@} $5"
48 [ "$6" == "test" ] && sshcmd="nc -ulp $5 -e nc localhost 22" &&
49 udpcmd="dbclient -J \"nc -u ${1#*@} $5\" ${1%@*}@localhost $pppsvr"
50 [ -n "$5" ] && arg="noipdefault pty '$udpcmd'" && $ssh -f $1 "$sshcmd"
51 eval $ppp $arg ipparam pppssh$$
52 [ "$4" ] && route del $extra
53 rm -f /etc/ppp/ip-up.d/pppssh$$ 2> /dev/null
54 }
56 xfbvnc()
57 {
58 p=5900
59 while netstat -tln | grep -q ":$p " ; do p=$(($p+1)); done
60 [ -r /dev/input/mice ] || echo "Warning: Cannot read mouse input." 1>&2
61 svr=${1#*/}; [ "$svr" == "$1" ] && svr=127.0.0.1
62 dbclient -f -N -L $p:$svr:${2:-5900} ${1%/*}
63 fbvnc 127.0.0.1 $p
64 kill $(netstat -tlnp 2> /dev/null | \
65 sed "/:$p /!d;s|.* \\([0-9]*\\)/[^ ]*|\\1|")
66 }
68 case "$(basename $0)" in
69 *vnc) [ -z "$1" ] && cat <<EOT || xfbvnc "$@" ;;
70 Usage: $0 '[sshargs] user@remote[/lanip]' [vncport]
71 $(fbvnc --help 2>&1 | sed '1,/Usage:/d')
72 EOT
73 ppp*) [ -z "$1" ] && cat <<EOT || pppssh "$@" ;;
74 Usage: $0 '[sshargs] user@remote' '[localip:remoteip] [localpppargs]' 'remotepppargs' 'routes' [udp-port]
75 Example: $0 tux@slitaz.org '' '' '192.168.1.0/24 10.1.2.0/24'
76 EOT
77 *) [ -z "$DISPLAY" ] && exec dbclient "$@"
78 xauth list $DISPLAY | xdbclient "$@"
79 esac