wok annotate dropbear/stuff/sshx @ rev 20644

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