wok-current view dropbear/stuff/sshx @ rev 18330
dropbear: add sshfbvnc
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Sep 09 08:55:46 2015 +0200 (2015-09-09) |
parents | e726e3214807 |
children | c68cd3e0f194 |
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#*@} | \
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 ppp="/usr/sbin/pppd local noauth nodetach"
43 $ppp ${2:-$n.1:$n.2} passive pty "$ssh $1 $ppp ${3:-proxyarp} notty" \
44 ipparam pppssh$$
45 [ "$4" ] && route del $extra
46 rm -f /etc/ppp/ip-up.d/pppssh$$
47 }
49 xfbvnc()
50 {
51 p=5900
52 while netstat -tln | grep -q ":$p " ; do p=$(($p+1)); done
53 dbclient -f -N -L $p:127.0.0.1:${2:-5900} $1
54 fbvnc 127.0.0.1 $p
55 kill $(netstat -tlnp 2> /dev/null | \
56 sed "/:$p /!d;s|.* \\([0-9]*\\)/[^ ]*|\\1|")
57 }
59 case "$(basename $0)" in
60 *vnc) [ -z "$1" ] && cat <<EOT || xfbvnc "$@" ;;
61 Usage: $0 '[sshargs] user@remote' [vncport]
62 EOT
63 ppp*) [ -z "$1" ] && cat <<EOT || pppssh "$@" ;;
64 Usage: $0 '[sshargs] user@remote' '[localip:remoteip] [localpppargs]' 'remotepppargs' 'routes'
65 Example: $0 tux@slitaz.org '' '' '192.168.1.0/24 10.1.2.0/24'
66 EOT
67 *) [ -z "$DISPLAY" ] && exec dbclient "$@"
68 xauth list $DISPLAY | xdbclient "$@"
69 esac