# HG changeset patch # User Pascal Bellard # Date 1454515386 -3600 # Node ID c75265fb6c4bf5def4a3fb9067f32e64a4d9d4a4 # Parent 8d652865a08a3355a0f8117009816e7128bbbf78 shellinabox: add init script diff -r 8d652865a08a -r c75265fb6c4b shellinabox/receipt --- a/shellinabox/receipt Tue Feb 02 08:29:58 2016 +0100 +++ b/shellinabox/receipt Wed Feb 03 17:03:06 2016 +0100 @@ -13,13 +13,14 @@ DEPENDS="zlib" BUILD_DEPENDS="zlib-dev" +SUGGESTED="ssh knock" # Rules to configure and make the package. compile_rules() { ./configure --prefix=/usr \ - --mandir=/usr/share/man \ - $CONFIGURE_ARGS && + --mandir=/usr/share/man \ + $CONFIGURE_ARGS && make && make DESTDIR=$DESTDIR install } @@ -27,6 +28,26 @@ # Rules to gen a SliTaz package suitable for Tazpkg. genpkg_rules() { - mkdir -p $fs/usr/bin + mkdir -p $fs/usr/bin $fs/usr/share/shellinabox $fs/etc/init.d cp -a $install/usr/bin $fs/usr + cp $install/usr/share/doc/shellinabox/*black*.css $fs/usr/share/shellinabox + cp $stuff/*.css $fs/usr/share/shellinabox + cp $stuff/shellinabox $fs/etc/init.d/ } + +# Pre and post install commands for Tazpkg. +# We stop the server by default in case of upgarde. +pre_install() +{ + [ -z "$1" ] && [ -f /etc/init.d/$PACKAGE ] && /etc/init.d/$PACKAGE stop +} + +post_install() +{ + [ "$1" ] || /etc/init.d/$PACKAGE start +} + +pre_remove() +{ + [ "$1" ] || /etc/init.d/$PACKAGE stop +} diff -r 8d652865a08a -r c75265fb6c4b shellinabox/stuff/10px.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shellinabox/stuff/10px.css Wed Feb 03 17:03:06 2016 +0100 @@ -0,0 +1,6 @@ +#vt100 #reconnect input { font-size: small; } +#vt100 #scrollable { font-size: 10px; } +#vt100 #cursize { font-size: 10px; } +#vt100 #console { font-size: 10px; } +#vt100 #cursor { font-size: 10px; } +#vt100 #linheight { font-size: 10px; } diff -r 8d652865a08a -r c75265fb6c4b shellinabox/stuff/12px.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shellinabox/stuff/12px.css Wed Feb 03 17:03:06 2016 +0100 @@ -0,0 +1,6 @@ +#vt100 #reconnect input { font-size: small; } +#vt100 #scrollable { font-size: 12px; } +#vt100 #cursize { font-size: 12px; } +#vt100 #console { font-size: 12px; } +#vt100 #cursor { font-size: 12px; } +#vt100 #linheight { font-size: 12px; } diff -r 8d652865a08a -r c75265fb6c4b shellinabox/stuff/14px.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shellinabox/stuff/14px.css Wed Feb 03 17:03:06 2016 +0100 @@ -0,0 +1,6 @@ +#vt100 #reconnect input { font-size: small; } +#vt100 #scrollable { font-size: 14px; } +#vt100 #cursize { font-size: 14px; } +#vt100 #console { font-size: 14px; } +#vt100 #cursor { font-size: 14px; } +#vt100 #linheight { font-size: 14px; } diff -r 8d652865a08a -r c75265fb6c4b shellinabox/stuff/16px.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shellinabox/stuff/16px.css Wed Feb 03 17:03:06 2016 +0100 @@ -0,0 +1,6 @@ +#vt100 #reconnect input { font-size: small; } +#vt100 #scrollable { font-size: 16px; } +#vt100 #cursize { font-size: 16px; } +#vt100 #console { font-size: 16px; } +#vt100 #cursor { font-size: 16px; } +#vt100 #linheight { font-size: 16px; } diff -r 8d652865a08a -r c75265fb6c4b shellinabox/stuff/object.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shellinabox/stuff/object.css Wed Feb 03 17:03:06 2016 +0100 @@ -0,0 +1,3 @@ +#vt100 #scrollable { + overflow: hidden; +} diff -r 8d652865a08a -r c75265fb6c4b shellinabox/stuff/shellinabox --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shellinabox/stuff/shellinabox Wed Feb 03 17:03:06 2016 +0100 @@ -0,0 +1,103 @@ +#!/bin/sh + +services="/" + +mkexe() +{ +exe=$0 +while true; do + cd $(dirname $exe) + exe=$(basename $exe) + [ -L $exe ] || break + exe=$(readlink $exe) +done +echo $(pwd)/$exe +} +exe=$(mkexe) + +services_arg() +{ +for i in $services ; do + echo -n "-s '$i:root:root:/tmp:LINES=25 /bin/sh -c \"$exe service $i " + echo -n "\${peer} \${url} \${columns} \${lines}\"' " +done +} + +launch_ssh() +{ + server="" + sequence="" + for i in $(echo "$2" | sed 's/[?&,]/ /g'); do + case "$i" in + host=*) server=${i#host=};; + knock=*) sequence=${i#knock=};; + esac + done + if [ -z "$server" ]; then + # Get SSH server + echo "Expected format [!][telnet/][user@][host][:port], default local login." + echo -n "TELNET/SSH server: " + read -t 300 server + fi + [ -n "$server" ] || exec /bin/login + + # Allow non default SSH port with format server:port + port="" + sshport="" + case "$server" in + *:*) port="${server#*:}" + sshport="-p $port" + server=${server%:*};; + esac + + # heading ! in server name means open remote ssh port with a knock sequence + if which knock > /dev/null; then + case "$server" in + !*) server=${server#*!} + if [ -z "$sequence" ]; then + echo -n "Knock sequence (port[:proto]...): " + read -t 30 sequence && + knock ${server#*@} ${sequence//-/ } + else + knock ${server#*@} ${sequence//-/ } + fi + esac + fi + + # Get SSH user if missing + case "$server" in + */*|*@*) ;; + *) echo -n "$server login: " + read -t 30 user || exit 1 + [ -n "$user" ] || exit 1 + server="$user@$server";; + esac + + # Launch OpenSSH or Dropbear + sshargs="-oPreferredAuthentications=keyboard-interactive,password -oNoHostAuthenticationForLocalhost=yes -oLogLevel=FATAL -F/dev/null"; + [ -L /usr/bin/ssh ] && sshargs="" + case "$server" in + */*) exec ${server%/*} ${server#*/} $port ;; + *) exec ssh $sshport $sshargs $server ;; + esac +} + +pidfile=/var/run/shellinaboxd.pid +case "$1" in +service) + case "$2" in + /) shift 2; launch_ssh "$@" ;; + esac + ;; +start) + dir=$(dirname $exe) + eval shellinaboxd --background=$pidfile --user=0 \ + --css=/usr/share/shellinabox/object.css \ + --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 \ + --user-css Normal:+/usr/share/shellinabox/black-on-white.css,Reverse:-/usr/share/shellinabox/white-on-black.css \ + -s /login:LOGIN $(services_arg) + ;; +stop) + [ -s $pidfile ] && kill $(cat $pidfile) + ;; +esac