5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
12 abort-upgrade|abort-remove|abort-deconfigure)
17 echo "postinst called with unknown argument \`$1'" >&2
24 . /usr/share/debconf/confmodule
26 # Include CARNet functions
27 . /usr/share/carnet-tools/functions.sh
31 CONF="$A2DIR/apache2.conf"
32 CONFDIR="$A2DIR/conf-available"
33 MODSECDIR="$A2DIR/mod-security"
34 MODSECCONF="$MODSECDIR/mod-security-cn.conf"
35 MODSECRBL="$MODSECDIR/rbl_lookup.conf"
36 MODSECLNK="$CONFDIR/security2-cn.conf"
37 MODSECTPL="/usr/share/mod-security-cn"
42 if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
43 . /usr/share/apache2/apache2-maintscript-helper
45 modsecurity_enable() {
46 cp_echo "CN: Enabling $PKG configuration for Apache2."
50 cp_echo "CN: Could not load Apache 2.4 maintainer script helper."
52 modsecurity_enable() {
59 # Cleanup all temp files or directories.
64 if [ -n "$temp_files" ]; then
65 for item in $temp_files; do
66 if [ -e "$item" ]; then
75 # Check if configuration file has CARNet package info lines.
76 # return: $RET => 0 - tagged
77 # 1 - file does not exists
78 # 2 - file exists, but it is not tagged
85 if [ -f "$conf_file" ]; then
86 if egrep -q "^## Begin - Generated by CARNet package mod-security-cn$" "$conf_file"; then
95 # Set trap for deleting all temp files.
100 # Remove obsolete symbolic link.
102 if [ "`readlink -q -m /etc/apache2/conf.d/$PKG.conf`" = "$MODSECCONF" ]; then
103 rm -f /etc/apache2/conf.d/$PKG.conf
107 # Generate ModSecurity configuration files and activate RBL lookup
108 # for ModSecurity if needed.
110 chk_conf_tag "$MODSECCONF"
111 if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then
113 # Create /etc/apache2/conf-available/ directory if missing.
114 if [ ! -d "$CONFDIR" ]; then
115 cp_echo "CN: Creating configuration directory $CONFDIR/"
119 # Create /etc/apache2/mod-security/ directory if missing.
120 if [ ! -d "$MODSECDIR" ]; then
121 cp_echo "CN: Creating ModSecurity configuration directory $MODSECDIR/"
125 out=$(mktemp $MODSECCONF.XXXXXX)
126 temp_files="${temp_files} ${out}"
128 db_get mod-security-cn/rbl || true
129 if [ "$RET" = "true" ]; then
131 # Add RBL configuration.
132 chk_conf_tag "$MODSECRBL"
133 if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then
135 if [ $RET -eq 1 ]; then
136 cp_echo "CN: Creating configuration file $MODSECRBL"
137 cp "$MODSECTPL/$(basename $MODSECRBL)" "$MODSECRBL"
139 if ! cmp -s "$MODSECRBL" "$MODSECTPL/$(basename $MODSECRBL)"; then
140 cp_echo "CN: Updating configuration file $MODSECRBL"
141 cp "$MODSECTPL/$(basename $MODSECRBL)" "$MODSECRBL"
146 sed "s,#RBLLOOKUP#,Include $MODSECRBL,g" \
147 "$MODSECTPL/$(basename $MODSECCONF)" > "$out"
149 if [ -e "$MODSECCONF" ]; then
150 if ! cmp -s "$MODSECCONF" "$out"; then
151 cp_echo "CN: Updating configuration file $MODSECCONF"
152 mv -f "$out" "$MODSECCONF"
153 cp_echo "CN: Enabled ModSecurity RBL lookup."
156 cp_echo "CN: Creating configuration file $MODSECCONF"
157 mv "$out" "$MODSECCONF"
158 cp_echo "CN: Enabled ModSecurity RBL lookup."
162 # Remove RBL configuration.
163 sed "s,#RBLLOOKUP#,# DISABLED,g" \
164 "$MODSECTPL/$(basename $MODSECCONF)" > "$out"
166 if [ -e "$MODSECCONF" ]; then
167 if ! cmp -s "$MODSECCONF" "$out"; then
168 cp_echo "CN: Updating configuration file $MODSECCONF"
169 mv -f "$out" "$MODSECCONF"
170 cp_echo "CN: Disabled ModSecurity RBL lookup."
173 cp_echo "CN: Creating configuration file $MODSECCONF"
174 mv "$out" "$MODSECCONF"
175 cp_echo "CN: Disabled ModSecurity RBL lookup."
178 chk_conf_tag "$MODSECRBL"
179 if [ $RET -eq 0 ]; then
180 cp_echo "CN: Removing configuration file $MODSECRBL"
185 if [ -f "$out" ]; then rm -f $out; fi
187 # Enable ModSecurity configuration.
188 if [ ! -e "$MODSECLNK" ]; then
189 ln -fs "$MODSECCONF" "$MODSECLNK"
191 if modsecurity_enable; then
192 apache2_invoke enmod security2
193 apache2_invoke enconf security2-cn
199 if ! apache2ctl configtest >/dev/null 2>&1; then
200 cp_echo "CN: Your Apache2 configuration seems to be broken."
201 cp_echo "CN: Please, check the service after the installation finishes!"