wok-current view dropbear/stuff/sshx @ rev 19380
Up palemoon (26.4.0)
author | Xander Ziiryanoff <psychomaniak@xakep.ru> |
---|---|
date | Thu Aug 18 16:16:50 2016 +0200 (2016-08-18) |
parents | 90cba0814151 |
children | 035492d51952 |
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 [ -n "$5" ] && arg="noipdefault pty 'nc -u ${1#*@} $5'" && $ssh -f $1 \
46 "$ppp $n ${3:-proxyarp} pty 'nc -ulp $5' >/dev/null"
47 eval $ppp $arg ipparam pppssh$$
48 [ "$4" ] && route del $extra
49 rm -f /etc/ppp/ip-up.d/pppssh$$ 2> /dev/null
50 }
52 xfbvnc()
53 {
54 p=5900
55 while netstat -tln | grep -q ":$p " ; do p=$(($p+1)); done
56 [ -r /dev/input/mice ] || echo "Warning: Cannot read mouse input." 1>&2
57 dbclient -f -N -L $p:127.0.0.1:${2:-5900} $1
58 fbvnc 127.0.0.1 $p
59 kill $(netstat -tlnp 2> /dev/null | \
60 sed "/:$p /!d;s|.* \\([0-9]*\\)/[^ ]*|\\1|")
61 }
63 case "$(basename $0)" in
64 *vnc) [ -z "$1" ] && cat <<EOT || xfbvnc "$@" ;;
65 Usage: $0 '[sshargs] user@remote' [vncport]
66 $(fbvnc --help 2>&1 | sed '1,/Usage:/d')
67 EOT
68 ppp*) [ -z "$1" ] && cat <<EOT || pppssh "$@" ;;
69 Usage: $0 '[sshargs] user@remote' '[localip:remoteip] [localpppargs]' 'remotepppargs' 'routes' [udp-port]
70 Example: $0 tux@slitaz.org '' '' '192.168.1.0/24 10.1.2.0/24'
71 EOT
72 *) [ -z "$DISPLAY" ] && exec dbclient "$@"
73 xauth list $DISPLAY | xdbclient "$@"
74 esac