wok view dropbear/stuff/sshx @ rev 25276
updated reiser4progs and reiser4progs-dev (2.0.0 -> 2.0.5)
author | Hans-G?nter Theisgen |
---|---|
date | Mon Jul 18 14:19:27 2022 +0100 (2022-07-18) |
parents | be6d6007394f |
children |
line source
1 #!/bin/sh
3 xdbclient()
4 {
5 read host data
6 svr=${DISPLAY#*:}
7 n=$((10+($RANDOM % 90))); dpy=127.0.0.1:$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 +127.0.0.1 > /dev/null 2>&1
24 pxypass="${DBPROXY_PASSWORD:+export DROPBEAR_PASSWORD=$DBPROXY_PASSWORD; }"
25 [ -n "$1" ] || set -- "${TERMINAL:-sakura} -l || ${TERM:-xterm} -ls || lxterminal"
26 exec dbclient -f -R $((6000+$n)):127.0.0.1:$((6000+${svr%.*})) ${r/:/ -p } \
27 ${DBPROXY:+-J "sh -c '${pxypass}dbclient ${k}-B ${a#*@}:$p ${DBPROXY/:/ -p }'"} \
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/:/ -p } true || {
36 [ -z "$DROPBEAR_PASSWORD" ] && echo -n "ssh password: " &&
37 read -s -t 30 DROPBEAR_PASSWORD && export DROPBEAR_PASSWORD
38 $ssh ${1/:/ -p } true || exit 1
39 }
40 ipsvr=${1#*@}; ipsvr=${ipsvr%:*}
41 extra="$(route -n | awk -vd=$(nslookup $ipsvr | sed '/::/d' | \
42 sed '$!d;s/.*: \([^ ]*\).*/\1/') \
43 '$1=="0.0.0.0"{ print d " gw " $2 " dev " $8 }')"
44 for i in ${4/default/128.0.0.0/1 0.0.0.0/1} ; do
45 echo "route add -net $i dev \$1"
46 done > /etc/ppp/ip-up.d/pppssh$$
47 [ "$4" ] && echo "route add $extra" >> /etc/ppp/ip-up.d/pppssh$$
48 chmod +x /etc/ppp/ip-up.d/pppssh$$
49 n=10.$(($$%256)).$(($$/256))
50 n="${2:-$n.1:$n.2} passive"
51 ppp="/usr/sbin/pppd local noauth nodetach"
52 arg="$n pty '$ssh ${1/:/ -p } $ppp ${3:-proxyarp} notty'"
53 pppsvr="$ppp $n ${3:-proxyarp} notty >/dev/null"
54 sshcmd="nc -ulp $5 -e $pppsvr"
55 udpcmd="nc -u $ipsvr $5"
56 [ "$6" = "test" ] && sshcmd="nc -ulp $5 -e nc 127.0.0.1 22" &&
57 udpcmd="dbclient -y -J \"nc -u $ipsvr $5\" ${1%@*}@127.0.0.1 $pppsvr"
58 [ -n "$5" ] && arg="noipdefault pty '$udpcmd'" && $ssh -f ${1/:/ -p } "$sshcmd"
59 eval $ppp $arg ipparam pppssh$$
60 [ "$4" ] && route del $extra
61 rm -f /etc/ppp/ip-up.d/pppssh$$ 2> /dev/null
62 }
64 xfbvnc()
65 {
66 p=5900
67 while netstat -tln | grep -q ":$p " ; do p=$(($p+1)); done
68 [ -r /dev/input/mice ] || echo "Warning: Cannot read mouse input." 1>&2
69 r=${1%/*}; svr=${1#*/}; [ "$svr" = "$1" ] && svr=127.0.0.1
70 dbclient -y -f -N -L $p:$svr:${2:-5900} ${r/:/ -p }
71 fbvnc 127.0.0.1 $p
72 kill $(netstat -tlnp 2> /dev/null | \
73 sed "/:$p /!d;s|.* \\([0-9]*\\)/[^ ]*|\\1|")
74 }
76 case "$(basename $0)" in
77 *vnc) [ -z "$1" ] && cat <<EOT || xfbvnc "$@" ;;
78 Usage: $0 '[sshargs] user@remote[:port][/lanip]' [vncport]
79 $(fbvnc --help 2>&1 | sed '1,/Usage:/d')
80 EOT
81 ppp*) [ -z "$1" ] && cat <<EOT || pppssh "$@" ;;
82 Usage: $0 '[sshargs] user@remote[:port]' '[localip:remoteip] [localpppargs]' 'remotepppargs' 'routes' [udp-port]
83 Example: $0 tux@slitaz.org '' '' '192.168.1.0/24 10.1.2.0/24'
84 EOT
85 *) [ -z "$DISPLAY" ] && exec dbclient -y "$@"
86 xauth list $DISPLAY | xdbclient -y "$@"
87 esac