#!/bin/sh
# JLdL 18Apr08.
#
# Copyright (C) 2008 by Jorge L. deLyra <delyra@fma.if.usp.br>.
# This program may be copied and/or distributed freely. See the
# _ terms and conditions in /usr/share/doc/<package>/copyright.
#
# This is an /etc/init.d/ script that can be used to  establish
# _ an SSL tunnel around the HTTP server; it uses the "stunnel"
# _ SSL tunnel in order to do this.

# The daemon to be started.
DAEMON=/usr/bin/stunnel
# Where the PID files go.
PIDDIR=/var/run/stunnel
# The prefix for hosts.allow.
PREFIX=httpssl
# The prefix for the PID file.
PREPID=$PIDDIR/stunnel.$PREFIX

# Added so that this script can be executed by cron.
PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH

test -f  || $DAEMON exit 0

case "$1" in
    start)
	echo -n "Starting the stunnel channel for HTTP: "
	#
	start-stop-daemon --start --quiet --pidfile $PREPID.pid \
	--oknodo --exec $DAEMON -- -N $PREFIX \
	-d https -r http
	#
	echo "done."
	;;
    stop)
	echo -n "Stopping the stunnel channel for HTTP: "
	#
	start-stop-daemon --stop --quiet --pidfile $PREPID.pid \
	--oknodo --exec $DAEMON
	#
	echo "done."
	;;
    restart|reload)
	$0 stop
	$0 start
	;;
    *)
	echo "Usage: /etc/init.d/`basename $0` {start|stop|restart|reload}"
	exit 1
esac

exit 0

