5 [ "$1" = "configure" ] || exit 0
6 [ $DEBIAN_SCRIPT_DEBUG ] && set -vx
10 . /usr/share/debconf/confmodule
12 # Include CARNet functions
13 . /usr/share/carnet-tools/functions.sh
15 PKG="squirrelmail-change-pass-cn"
17 SQCONFDIR="/etc/squirrelmail"
18 SQCONF="$SQCONFDIR/config.php"
19 SQCPCONF="$SQCONFDIR/config_change_pass.php"
20 CPCONF="/usr/share/squirrelmail/plugins/change_pass/config.php"
25 set_min_pass_length () {
27 local sed_re conf_file
30 temp_files="$temp_files $conf_file.dpkg-tmp"
32 sed "$conf_re" "$conf_file" > "$conf_file.dpkg-tmp"
34 if ! cmp -s "$conf_file" "$conf_file.dpkg-tmp" 2>&1 >/dev/null; then
35 cp_mv "$conf_file.dpkg-tmp" "$conf_file"
38 rm -f "$conf_file.dpkg-tmp"
44 if [ -n "$temp_files" ]; then
45 for temp_item in $temp_files; do
46 if [ -e "$temp_item" ]; then
56 # Configure poppassd to refuse connection from all hosts
57 # but localhost (127.0.0.1).
59 if [ ! -f /etc/hosts.deny ]; then
62 if ! egrep -q '^poppassd:' /etc/hosts.deny; then
63 echo "poppassd: ALL" | cp-update "$PKG" /etc/hosts.deny
65 if [ ! -f /etc/hosts.allow ]; then
66 touch /etc/hosts.allow
68 if ! egrep -q '^poppassd:' /etc/hosts.allow; then
69 echo "poppassd: 127.0.0.1" | cp-update "$PKG" /etc/hosts.allow
73 # First of all, do the backup.
76 for cpconf_file in $SQCPCONF $CPCONF; do
77 if [ -f "$cpconf_file" ] && [ ! -L "$cpconf_file" ]; then
78 cp_echo "CN: Doing backup for $cpconf_file"
79 cp_backup_conffile -d "/var/backups/$PKG" -p $cpconf_file
83 if [ $done_backup -eq 1 ]; then
84 cp_echo "CN: Backup is located in directory: /var/backups/$PKG/"
88 # Remove change_pass configuration files if earlier version is
91 if [ "$2" ] && dpkg --compare-versions $2 lt 3.0-1; then
93 cp_echo "CN: This version of change_pass plugin contains major changes."
94 for cpconf_file in $SQCPCONF $CPCONF; do
95 if [ -f "$cpconf_file" ] || [ -L "$cpconf_file" ]; then
97 cp_echo "CN: Removed old $cpconf_file"
103 # Check for change_pass configuration files and notify user about
104 # minimum password length configuration.
106 if egrep -q '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
107 /usr/sbin/squirrelmail-configure --remove-plugin change_pass
110 if [ ! -f "$SQCPCONF" ]; then
112 if [ -f "$CPCONF" ]; then
113 cp -f "$CPCONF" "$SQCPCONF"
114 cp_echo "CN: $CPCONF copied to $SQCPCONF"
117 # Configuration file does not exist.
118 cp_echo "CN: Generating new file $SQCPCONF"
119 cat > "$SQCPCONF" <<EOF
121 //// Begin - Generated by CARNet package $PKG
123 // REMOVE this whole block if you DON'T WANT $PKG
124 // to edit your configuration file.
126 //// End - Generated by CARNet package $PKG
127 \$min_pass_length = 8;
129 // The default server is the configured IMAP server
130 #\$poppass_server = 'localhost';
132 // The default port is 106
133 #\$poppass_port = 106;
135 \$max_pass_length = 9999999;
141 if [ $min_pass_changed -eq 0 ]; then
143 echo "CN: Checking for minimum password length configuration."
145 cn_tag_re="^\/\/\/\/ Begin - Generated by CARNet package $PKG$"
146 seddef="/^[[:space:]]*\\\$min_pass_length[[:space:]]*=[^;]*;[[:space:]]*$/d;
147 s/\\\$min_pass_length[[:space:]]*=[^;]*;//g;"
149 if egrep -q "$cn_tag_re" "$SQCPCONF"; then
151 # Configuration file is tagged by CARNet.
152 seddef="$seddef /^\/\/\/\/ End - Generated by CARNet package $PKG$/s/\(.*\)/\1\n"
153 seddef="$seddef \\\$min_pass_length = 8;/"
154 set_min_pass_length "$seddef" "$SQCPCONF"
157 if dpkg --compare-versions "$2" lt 3.0-2; then
159 # Add CARNet package info lines to config's header and set up $min_pass_length.
160 seddef="$seddef 0,/?>/s/^[[:space:]]*\(<?php\|<?\)\(.*\)/\1\n"
161 seddef="$seddef\/\/\/\/ Begin - Generated by CARNet package $PKG\n\/\/\n"
162 seddef="$seddef\/\/ REMOVE this whole block if you DON'T WANT $PKG\n"
163 seddef="$seddef\/\/ to edit your configuration file.\n\/\/\n"
164 seddef="$seddef\/\/\/\/ End - Generated by CARNet package $PKG\n"
165 seddef="$seddef \\\$min_pass_length = 8;\n\2/"
166 set_min_pass_length "$seddef" "$SQCPCONF"
172 ln -sf "$SQCPCONF" "$CPCONF"
174 if [ $min_pass_changed -eq 1 ]; then
175 db_fset squirrelmail-change-pass-cn/min_pass_length seen false
176 db_title squirrelmail-change-pass-cn - konfiguracija
177 db_input critical squirrelmail-change-pass-cn/min_pass_length || true
179 cp_echo "CN: Minimum password length has been set to 8 characters."
185 # Enable change_pass plugin in SquirrelMail config.php.
187 if ! egrep -q '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
189 if cp_check_and_backup "$SQCONF"; then
190 cp_echo "CN: Old $SQCONF saved as \"/var/backups/${SQCONF##*/}.bak\"."
193 /usr/sbin/squirrelmail-configure --install-plugin change_pass
197 # Convert poppassd service from inetd.conf to xinetd.conf type.
198 # Service configuration is saved in /etc/xinetd.d/ directory.
200 if [ -x /etc/init.d/xinetd -a -d /etc/xinetd.d -a -x /usr/sbin/itox ]; then
202 if egrep -q '^poppassd' /etc/inetd.conf && \
203 [ ! -f /etc/xinetd.d/poppassd ]; then
205 cp_echo "CN: Enabling poppassd in /etc/xinetd.d/poppassd"
207 touch /etc/xinetd.d/poppassd.$$
208 grep "^poppassd" /etc/inetd.conf | \
209 itox -daemon_dir /usr/sbin | cp-update "$PKG" /etc/xinetd.d/poppassd.$$
210 cp_mv /etc/xinetd.d/poppassd.$$ /etc/xinetd.d/poppassd
217 # Restart xinetd if needed.
219 if [ $need_restart -eq 1 ]; then
221 if [ -x "/etc/init.d/xinetd" ]; then
222 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
223 invoke-rc.d xinetd restart || exit $?
225 /etc/init.d/xinetd restart || exit $?