#!/bin/sh

set -e

case "$1" in
    configure)
	;;
    abort-upgrade|abort-remove|abort-deconfigure)
	exit 0
	;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
	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}/httpd.conf"
	apachectl="/usr/sbin/${server}ctl"
	test -f $config || continue
	grep -q "<Location /cgi-bin/dpkg>" $config && continue
	echo "Updating $server configuration file: $config" >&2
	cat <<-EOF >>$config

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

EOF
	test -x $apachectl || continue
	echo "Restarting $server..." >&2
	$apachectl restart >&2 || true
    done
fi

#DEBHELPER#
exit 0

# end of file
