#!/bin/sh

set -e

trap "echo ;\
      echo 'Received signal.  Aborting configuration of dpkg-www package.' ;\
      echo ;\
      exit 1" 1 2 3 15

case "$1" in
    configure)
	;;
    abort-upgrade|abort-remove|abort-deconfigure)
	exit 0
	;;
    *)
	echo "ERROR: dpkg-www postinst called with unknown argument \"$1\"."
	echo "Aborting configuration of dpkg-www package."
	exit 1
	;;
esac

. /usr/share/debconf/confmodule
db_version 2.0
db_get dpkg-www/update-apache-config

if [ "$RET" = true ]; then
    for server in apache apache-ssl; do
	config="/etc/${server}/access.conf"
	apachectl="/usr/sbin/${server}ctl"
	test ! -f $config && continue
	grep -q "<Location /cgi-bin/dpkg>" $config && continue
	echo "Updating $server configuration file: $config"
	cat <<-EOF >>$config

	# Disable execution of dpkg from remote hosts
	<Location /cgi-bin/dpkg>
	order deny,allow
	deny from all
	allow from localhost
	# allow from .your_domain.com
	</Location>

EOF
	echo "Restarting $server..."
	$apachectl restart || true
    done
fi

#DEBHELPER#
exit 0

# end of file
