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