wok annotate shellinabox/stuff/shellinabox @ rev 25125
updated apache-mod-wsgi (4.6.5 -> 4.9.0)
author | Hans-G?nter Theisgen |
---|---|
date | Tue Jun 28 16:29:10 2022 +0100 (2022-06-28) |
parents | |
children |
rev | line source |
---|---|
pascal@18869 | 1 #!/bin/sh |
pascal@18869 | 2 |
pascal@18869 | 3 services="/" |
pascal@18869 | 4 |
pascal@18869 | 5 mkexe() |
pascal@18869 | 6 { |
pascal@18869 | 7 exe=$0 |
pascal@18869 | 8 while true; do |
pascal@18869 | 9 cd $(dirname $exe) |
pascal@18869 | 10 exe=$(basename $exe) |
pascal@18869 | 11 [ -L $exe ] || break |
pascal@18869 | 12 exe=$(readlink $exe) |
pascal@18869 | 13 done |
pascal@18869 | 14 echo $(pwd)/$exe |
pascal@18869 | 15 } |
pascal@18869 | 16 exe=$(mkexe) |
pascal@18869 | 17 |
pascal@18869 | 18 services_arg() |
pascal@18869 | 19 { |
pascal@18869 | 20 for i in $services ; do |
pascal@18869 | 21 echo -n "-s '$i:root:root:/tmp:LINES=25 /bin/sh -c \"$exe service $i " |
pascal@18869 | 22 echo -n "\${peer} \${url} \${columns} \${lines}\"' " |
pascal@18869 | 23 done |
pascal@18869 | 24 } |
pascal@18869 | 25 |
pascal@18869 | 26 launch_ssh() |
pascal@18869 | 27 { |
pascal@18869 | 28 server="" |
pascal@18869 | 29 sequence="" |
pascal@18869 | 30 for i in $(echo "$2" | sed 's/[?&,]/ /g'); do |
pascal@18869 | 31 case "$i" in |
pascal@18869 | 32 host=*) server=${i#host=};; |
pascal@18869 | 33 knock=*) sequence=${i#knock=};; |
pascal@18869 | 34 esac |
pascal@18869 | 35 done |
pascal@18869 | 36 if [ -z "$server" ]; then |
pascal@18869 | 37 # Get SSH server |
pascal@18869 | 38 echo "Expected format [!][telnet/][user@][host][:port], default local login." |
pascal@18869 | 39 echo -n "TELNET/SSH server: " |
pascal@18869 | 40 read -t 300 server |
pascal@18869 | 41 fi |
pascal@18869 | 42 [ -n "$server" ] || exec /bin/login |
pascal@18869 | 43 |
pascal@18869 | 44 # Allow non default SSH port with format server:port |
pascal@18869 | 45 port="" |
pascal@18869 | 46 sshport="" |
pascal@18869 | 47 case "$server" in |
pascal@18869 | 48 *:*) port="${server#*:}" |
pascal@18869 | 49 sshport="-p $port" |
pascal@18869 | 50 server=${server%:*};; |
pascal@18869 | 51 esac |
pascal@18869 | 52 |
pascal@18869 | 53 # heading ! in server name means open remote ssh port with a knock sequence |
pascal@18869 | 54 if which knock > /dev/null; then |
pascal@18869 | 55 case "$server" in |
pascal@18869 | 56 !*) server=${server#*!} |
pascal@18869 | 57 if [ -z "$sequence" ]; then |
pascal@18869 | 58 echo -n "Knock sequence (port[:proto]...): " |
pascal@18869 | 59 read -t 30 sequence && |
pascal@18869 | 60 knock ${server#*@} ${sequence//-/ } |
pascal@18869 | 61 else |
pascal@18869 | 62 knock ${server#*@} ${sequence//-/ } |
pascal@18869 | 63 fi |
pascal@18869 | 64 esac |
pascal@18869 | 65 fi |
pascal@18869 | 66 |
pascal@18869 | 67 # Get SSH user if missing |
pascal@18869 | 68 case "$server" in |
pascal@18869 | 69 */*|*@*) ;; |
pascal@18869 | 70 *) echo -n "$server login: " |
pascal@18869 | 71 read -t 30 user || exit 1 |
pascal@18869 | 72 [ -n "$user" ] || exit 1 |
pascal@18869 | 73 server="$user@$server";; |
pascal@18869 | 74 esac |
pascal@18869 | 75 |
pascal@18869 | 76 # Launch OpenSSH or Dropbear |
pascal@18869 | 77 sshargs="-oPreferredAuthentications=keyboard-interactive,password -oNoHostAuthenticationForLocalhost=yes -oLogLevel=FATAL -F/dev/null"; |
pascal@18869 | 78 [ -L /usr/bin/ssh ] && sshargs="" |
pascal@18869 | 79 case "$server" in |
pascal@18869 | 80 */*) exec ${server%/*} ${server#*/} $port ;; |
pascal@18869 | 81 *) exec ssh $sshport $sshargs $server ;; |
pascal@18869 | 82 esac |
pascal@18869 | 83 } |
pascal@18869 | 84 |
pascal@18869 | 85 pidfile=/var/run/shellinaboxd.pid |
pascal@18869 | 86 case "$1" in |
pascal@18869 | 87 service) |
pascal@18869 | 88 case "$2" in |
pascal@18869 | 89 /) shift 2; launch_ssh "$@" ;; |
pascal@18869 | 90 esac |
pascal@18869 | 91 ;; |
pascal@18869 | 92 start) |
pascal@18869 | 93 dir=$(dirname $exe) |
pascal@18869 | 94 eval shellinaboxd --background=$pidfile --user=0 \ |
pascal@18869 | 95 --css=/usr/share/shellinabox/object.css \ |
pascal@18869 | 96 --user-css 10px:-/usr/share/shellinabox/10px.css,12px:+/usr/share/shellinabox/12px.css,14px:-/usr/share/shellinabox/14px.css,16px:-/usr/share/shellinabox/16px.css \ |
pascal@18869 | 97 --user-css Normal:+/usr/share/shellinabox/black-on-white.css,Reverse:-/usr/share/shellinabox/white-on-black.css \ |
pascal@18869 | 98 -s /login:LOGIN $(services_arg) |
pascal@18869 | 99 ;; |
pascal@18869 | 100 stop) |
pascal@18869 | 101 [ -s $pidfile ] && kill $(cat $pidfile) |
pascal@18869 | 102 ;; |
pascal@18869 | 103 esac |