Automatsko podesavanje minimalne duzine zaporke (8 znakova)
[squirrelmail-change-pass-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$1" = "configure" ] || exit 0
6 [ $DEBIAN_SCRIPT_DEBUG ] && set -vx
7
8
9 # Load debconf
10 . /usr/share/debconf/confmodule
11
12 # Include CARNet functions
13 . /usr/share/carnet-tools/functions.sh
14
15 PKG="squirrelmail-change-pass-cn"
16 VERSION="3.0-2"
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"
21 need_restart=0
22 min_pass_changed=0
23 temp_files=
24
25 set_min_pass_length () {
26
27     local sed_re conf_file
28     conf_re="$1"
29     conf_file="$2"
30     temp_files="$temp_files $conf_file.dpkg-tmp"
31
32     sed "$conf_re" "$conf_file" > "$conf_file.dpkg-tmp"
33
34     if ! cmp -s "$conf_file" "$conf_file.dpkg-tmp" 2>&1 >/dev/null; then
35         cp_mv "$conf_file.dpkg-tmp" "$conf_file"
36         min_pass_changed=1
37     else
38         rm -f "$conf_file.dpkg-tmp"
39     fi
40 }
41
42 cleanup () {
43
44     if [ -n "$temp_files" ]; then
45         for temp_item in $temp_files; do
46             if [ -e "$temp_item" ]; then
47                 rm -f $temp_item
48             fi
49         done
50     fi
51 }
52
53 trap cleanup 0 1 2 15
54
55
56 # Configure poppassd to refuse connection from all hosts
57 # but localhost (127.0.0.1).
58 #
59 if [ ! -f /etc/hosts.deny ]; then
60     touch /etc/hosts.deny
61 fi
62 if ! egrep -q '^poppassd:' /etc/hosts.deny; then
63     echo "poppassd: ALL" | cp-update "$PKG" /etc/hosts.deny
64 fi
65 if [ ! -f /etc/hosts.allow ]; then
66     touch /etc/hosts.allow
67 fi
68 if ! egrep -q '^poppassd:' /etc/hosts.allow; then
69     echo "poppassd: 127.0.0.1" | cp-update "$PKG" /etc/hosts.allow
70 fi
71
72
73 # Configure SquirrelMail change_pass plugin - using defaults,
74 # no configuration files if earlier version is older than 3.0-1.
75 #
76 if [ "$2" ] && dpkg --compare-versions $2 lt 3.0-1; then
77
78     cp_echo "CN: This version of change_pass plugin contains major changes."
79     cp_echo "CN: For detailed description, see documentation in /usr/share/doc/$PKG/."
80
81     if [ -f "$SQCPCONF" ]; then
82         mv -f "$SQCPCONF" "$SQCPCONF.cn-old"
83         cp_echo "CN: Old $SQCPCONF disabled and renamed to $SQCPCONF.cn-old."
84     fi
85     if [ -f "$CPCONF" ]; then
86         mv -f "$CPCONF" "$CPCONF.cn-old"
87         cp_echo "CN: Old $CPCONF disabled and renamed to $CPCONF.cn-old."
88     fi
89 fi
90
91
92 # Check for change_pass configuration file and notify user about
93 # minimum password length configuration.
94 #
95 if [ ! -f "$SQCPCONF" ] && [ ! -f "$CPCONF" ]; then
96
97     # Configuration file does not exist.
98     cp_echo "CN: Generating new file $CPCONF"
99     cat > "$CPCONF" <<EOF
100 <?php
101 //// Begin - Generated by CARNet package $PKG
102 //
103 //  REMOVE this whole block if you DON'T WANT $PKG
104 //  to edit your configuration file.
105 //
106 //// End - Generated by CARNet package $PKG
107     \$min_pass_length = 8;
108
109     // The default server is the configured IMAP server
110     #\$poppass_server = 'localhost';
111
112     // The default port is 106
113     #\$poppass_port = 106;
114
115     \$max_pass_length = 9999999;
116 EOF
117     min_pass_changed=1
118 else
119
120     # Checking for configuration file/s and minimum password length.
121     echo "CN: Checking for minimum password length configuration."
122     cn_tag_re="^\/\/\/\/ Begin - Generated by CARNet package $PKG$"
123
124     for cpconf_file in $SQCPCONF $CPCONF; do
125
126         min_pass_changed=0
127         if [ -f "$cpconf_file" ]; then
128
129             seddef="/^[[:space:]]*\\\$min_pass_length[[:space:]]*=[^;]*;[[:space:]]*$/d;
130                     s/\\\$min_pass_length[[:space:]]*=[^;]*;//g;"
131
132             if egrep -q "$cn_tag_re" "$cpconf_file"; then
133
134                 # Configuration file is tagged by CARNet.
135                 seddef="$seddef /^\/\/\/\/ End - Generated by CARNet package $PKG$/s/\(.*\)/\1\n"
136                 seddef="$seddef    \\\$min_pass_length = 8;/"
137
138                 set_min_pass_length "$seddef" "$cpconf_file"
139             else
140
141                 if [ "$2" ] && dpkg --compare-versions $2 lt 3.0-2; then
142
143                     # Add CARNet package info lines to config's header and set up $min_pass_length.
144                     seddef="$seddef 0,/?>/s/^[[:space:]]*\(<?php\|<?\)\(.*\)/\1\n"
145                     seddef="$seddef\/\/\/\/ Begin - Generated by CARNet $PKG\n\/\/\n"
146                     seddef="$seddef\/\/  REMOVE this whole block if you DON'T WANT $PKG\n"
147                     seddef="$seddef\/\/  to edit your configuration file.\n\/\/\n"
148                     seddef="$seddef\/\/\/\/ End - Generated by CARNet package $PKG\n"
149                     seddef="$seddef    \\\$min_pass_length = 8;\n\2/"
150
151                     set_min_pass_length "$seddef" "$cpconf_file"
152                 fi
153             fi
154         fi
155     done
156 fi
157
158 if [ $min_pass_changed -eq 1 ]; then
159     db_fset squirrelmail-change-pass-cn/min_pass_length seen false
160     db_title squirrelmail-change-pass-cn - konfiguracija
161     db_input critical squirrelmail-change-pass-cn/min_pass_length || true
162     db_go || true
163     cp_echo "CN: Minimum password length has been set to 8 characters."
164 fi
165
166 db_stop || true
167
168
169 # Enable change_pass plugin in SquirrelMail config.php.
170 #
171 if ! egrep -q '^\$plugins\[[0-9]+\][\ ]*=[\ ]*'\''change_pass'\' "$SQCONF"; then
172
173     if cp_check_and_backup "$SQCONF"; then
174         cp_echo "CN: Old $SQCONF saved as \"/var/backups/${SQCONF##*/}.bak\"."
175     fi
176
177     cp_echo "CN: Enabling SquirrelMail change_pass plugin in $SQCONF"
178     /usr/sbin/squirrelmail-configure --install-plugin change_pass
179 fi
180
181
182 # Convert poppassd service from inetd.conf to xinetd.conf type.
183 # Service configuration is saved in /etc/xinetd.d/ directory.
184 #
185 if [ -x /etc/init.d/xinetd -a -d /etc/xinetd.d -a -x /usr/sbin/itox ]; then
186
187   if egrep -q '^poppassd' /etc/inetd.conf && \
188      [ ! -f /etc/xinetd.d/poppassd ]; then
189
190         cp_echo "CN: Enabling poppassd in /etc/xinetd.d/poppassd"
191
192         touch /etc/xinetd.d/poppassd.$$
193         grep "^poppassd" /etc/inetd.conf  | \
194                 itox -daemon_dir /usr/sbin | cp-update "$PKG" /etc/xinetd.d/poppassd.$$
195         cp_mv /etc/xinetd.d/poppassd.$$ /etc/xinetd.d/poppassd
196
197         need_restart=1
198   fi
199 fi
200
201
202 # Restart xinetd if needed.
203 #
204 if [ $need_restart -eq 1 ]; then
205
206         if [ -x "/etc/init.d/xinetd" ]; then
207                 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
208                         invoke-rc.d xinetd restart || exit $?
209                 else
210                         /etc/init.d/xinetd restart || exit $?
211                 fi
212         fi
213 fi
214
215
216 # Mail root
217 #
218 cp_mail "$PKG"
219
220 exit 0