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