wok view shellinabox/stuff/shellinabox @ rev 23395

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