cd /home/fex/etc/
openssl req -new -x509 -days 9999 -nodes -out stunnel.pem -keyout stunnel.pem
# see http://www.infodrom.org/Debian/tips/stunnel.html
dd if=/dev/urandom count=2 | openssl dhparam -rand - 512 >> stunnel.pem
openssl x509 -text -in stunnel.pem
chown fex *
chmod 600 stunnel.pem

cd /etc/xinetd.d
fexsrv=$(awk '/fexsrv/{print $NF}' fex)
stunnel=$(which stunnel)
if [ -z "$stunnel" ]; then
  echo "no stunnel found" >&2
  exit
fi

cat <<EOD>fexs
# default: on
# description: fex web server with SSL
# note: only possible on port 443!
service fexs
{
        socket_type     = stream
        wait            = no
        type            = unlisted
        protocol        = tcp
        port            = 443
        cps             = 5 10
        user            = fex
        groups          = yes
        server          = $stunnel
        server_args     = -p /home/fex/etc/stunnel.pem -l $fexsrv -- fexsrv stunnel
        nice            = 0
        disable         = no
}
EOD

/etc/init.d/xinetd restart

exit

## SuSE stunnel 4:

cat <<EOD>/etc/xinetd.d/fexs
# default: on
# description: fex web server with SSL
# note: only possible on port 443!
service fexs
{
        socket_type     = stream
        wait            = no
        type            = unlisted
        protocol        = tcp
        port            = 443
        cps             = 5 10
        user            = fex
        groups          = yes
        server          = /usr/sbin/stunnel
        server_args     = /etc/stunnel/fex.conf
        nice            = 0
        disable         = no
}
EOD

cat <<EOD>/etc/stunnel/fex.conf
exec = /home/fex/bin/fexsrv
execargs = fexsrv stunnel
key = /home/fex/etc/stunnel.pem
TIMEOUTclose = 2
EOD
