5 [ "$1" = "configure" ] || exit 0
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
9 . /usr/share/carnet-tools/functions.sh
11 . /usr/share/debconf/confmodule
13 db_get postfix-cn/rbl || true
16 # Tue, 19 Dec 2006 10:31:01 +0100
17 # relays.ordb.org se gasi 2006-12-31
18 if echo $rbl | grep -q relays.ordb.org; then
19 rbl="`echo $rbl | sed 's/relays.ordb.org, //g'`"
20 # za svaki slucaj, ako je na kraju
21 rbl="`echo $rbl | sed 's/relays.ordb.org//g'`"
22 db_set postfix-cn/rbl "$rbl" || true
25 # Thu, 21 Dec 2006 09:03:50 +0100
26 # opm.blitzed.org je ugasen 2006-05
27 if echo $rbl | grep -q opm.blitzed.org; then
28 rbl="`echo $rbl | sed 's/opm.blitzed.org, //g'`"
29 # za svaki slucaj, ako je na kraju
30 rbl="`echo $rbl | sed 's/opm.blitzed.org//g'`"
31 db_set postfix-cn/rbl "$rbl" || true
34 # Wed, 12 Jun 2013 15:15:28 +0200
35 # dnsbl.njabl.org je ugasen 2013-03
36 if echo $rbl | grep -q dnsbl.njabl.org; then
37 rbl="`echo $rbl | sed 's/dnsbl.njabl.org, //g'`"
38 # za svaki slucaj, ako je na kraju
39 rbl="`echo $rbl | sed 's/dnsbl.njabl.org//g'`"
40 db_set postfix-cn/rbl "$rbl" || true
43 db_get postfix-cn/matchgecos || true
47 fqdn="`hostname --fqdn`"
48 domain="`dnsdomainname`"
49 mailname="`cat /etc/mailname 2> /dev/null || hostname --fqdn`"
50 cp_get_netaddr || true
53 # ako ne postoje konfiguracijske datoteke, napravi ih
54 [ -f /etc/postfix/master.cf ] || touch /etc/postfix/master.cf
55 [ -f /etc/postfix/main.cf ] || touch /etc/postfix/main.cf
57 # spremi pocetnu verziju
58 cp -pf /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$
59 cp -pf /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$
61 # srediti master.cf za TLS & submission & retry
62 if [ -f /etc/postfix/master.cf ]; then
63 cp_check_and_sed '^#tlsmgr' \
64 's/^#tlsmgr/tlsmgr/g' \
65 /etc/postfix/master.cf || true
67 cp_check_and_sed '^#submission' \
68 's/^#submission/submission/g' \
69 /etc/postfix/master.cf || true
71 cp_check_and_sed '^#retry' \
73 /etc/postfix/master.cf || true
75 cp_check_and_sed '^#smtps' \
77 /etc/postfix/master.cf || true
79 cp_check_and_sed '^# -o' \
81 /etc/postfix/master.cf || true
83 for option in "-o milter_macro_daemon_name=ORIGINATING" \
84 "-o smtpd_recipient_restrictions=" \
85 "-o smtpd_reject_unlisted_recipient=no" \
86 "-o smtpd_relay_restrictions=permit_sasl_authenticated,reject" \
87 "-o smtpd_sasl_auth_enable=yes" \
88 "-o smtpd_tls_security_level=encrypt" \
89 "-o smtpd_tls_wrappermode=yes" \
90 "-o syslog_name=postfix/smtps" \
91 "-o syslog_name=postfix/submission"; do
92 cp_check_and_sed "^# $option" \
93 "s/# $option/$option/g" \
94 /etc/postfix/master.cf || true
98 # ovo manje/vise uzima kao default, ali u slucaju da je multihomed stroj,
99 # i eventualno je sprckan, mozda nesto nece raditi kako spada pa cemo konfigurirati
100 postconf -e myhostname="$fqdn"
101 postconf -e mydomain="$domain"
102 postconf -e myorigin="$mailname"
104 # zbog problema sa squirrelmailom
105 postconf -e append_dot_mydomain="yes"
106 postconf -e append_at_myorigin="yes"
108 # dodaj 127.0.0.0/8, netaddr i ipv6-localhost
109 mynetworks="`postconf -h mynetworks`"
110 for i in "127.0.0.0/8" "$netaddr" "[::1]/128"; do
111 if ! echo $mynetworks | grep -q $i; then
112 mynetworks="$mynetworks $i"
115 postconf -e mynetworks="$mynetworks"
117 # obrisati $mydomain, ako je upgrade sa starije verzije
118 # te srediti mydestination
119 if dpkg --compare-versions "$2" lt 2.3.8-2; then
120 mydestination="`postconf -h mydestination`"
121 if echo $mydestination | grep -q ", \$mydomain"; then
122 mydestination="`echo $mydestination | sed 's/, \$mydomain//g'`"
124 if ! echo $mydestination | grep -q "localhost.\$mydomain"; then
125 mydestination="$mydestination, localhost.\$mydomain"
127 if ! echo $mydestination | grep -q "\$myhostname"; then
128 mydestination="\$myhostname, $mydestination"
130 postconf -e mydestination="$mydestination"
133 # default je: $myhostname, localhost.$mydomain, localhost
134 # treba dodati jos ", $mydomain", ako je host mx
135 cp_get_mx_domain || true
137 if [ "$mx_domain" != "$fqdn" ]; then
138 mydestination="`postconf -h mydestination`"
139 if ! echo $mydestination | grep -q ", \$mydomain"; then
140 postconf -e mydestination="$mydestination, \$mydomain"
142 postconf -e relay_domains="\$mydestination"
143 if [ "$mx_domain" != "$domain" ]; then
144 if dpkg --compare-versions "$2" lt 2.1.5-8; then
145 cp_echo "CN: This host is MX for more than one domain! postfix-cn package will"
146 cp_echo "CN: only set up $mx_domain, you HAVE TO add the other domains manually"
147 cp_echo "CN: to mydestination variable in /etc/postfix/main.cf, if you haven't"
148 cp_echo "CN: done that already or you may lose mail."
154 if [ "$matchgecos" = "true" ]; then
155 aliasmaps="hash:/etc/aliases hash:/var/lib/postfix-cn/aliases_gecos"
156 elif [ "$matchgecos" = "false" ]; then
157 aliasmaps="hash:/etc/aliases"
158 alias_maps="`postconf -h alias_maps | \
159 sed -e 's#hash:/var/lib/postfix-cn/aliases_gecos,*##g' -e 's/,*[[:space:]]*$//g'`"
160 postconf -e alias_maps="$alias_maps"
163 for i in $aliasmaps; do
164 alias_maps="`postconf -h alias_maps`"
165 if ! echo $alias_maps | grep -q "$i"; then
166 postconf -e alias_maps="$alias_maps, $i"
170 postconf -e alias_database="hash:/etc/aliases"
171 postconf -e local_recipient_maps="proxy:unix:passwd.byname \$alias_maps"
174 postconf -e recipient_delimiter="+"
175 postconf -e smtpd_helo_required="yes"
176 postconf -e smtpd_helo_restrictions="permit_mynetworks"
177 postconf -e in_flow_delay="2s"
178 postconf -e initial_destination_concurrency="10"
179 postconf -e default_destination_concurrency_limit="30"
180 postconf -e smtpd_recipient_limit="400"
181 postconf -e hash_queue_depth="3"
183 if dpkg --compare-versions "$2" lt 2.1.5-6; then
184 postconf -e bounce_queue_lifetime="5d"
185 postconf -e maximal_queue_lifetime="5d"
188 # ako netko zeli maknuti maskiranje, da mu ga nova verzija ne doda
189 if dpkg --compare-versions "$2" lt 2.1.5-2; then
190 postconf -e masquerade_domains="\$mydomain"
193 # sredi smtpd_recipient_restrictions
194 smtpd_recipient_restrictions="reject_invalid_hostname, \
195 reject_unknown_sender_domain, \
196 reject_unknown_recipient_domain, \
197 reject_unauth_pipelining, \
198 permit_sasl_authenticated, \
200 reject_unauth_destination"
202 # dodaj samo rbl-ove iz debconfa
204 for i in `echo $rbl | tr -d ,`; do
205 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, reject_rbl_client $i"
209 # dodaj permit na kraj
210 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, permit"
211 postconf -e smtpd_recipient_restrictions="$smtpd_recipient_restrictions"
214 postconf -e smtpd_sasl_auth_enable="yes"
215 postconf -e smtpd_sasl_security_options="noanonymous"
216 postconf -e smtpd_sasl_local_domain="\$myhostname"
217 postconf -e broken_sasl_auth_clients="yes"
219 [ -d /etc/postfix/sasl/ ] || mkdir -p /etc/postfix/sasl/
220 if [ ! -f /etc/postfix/sasl/smtpd.conf ]; then
221 cat - > /etc/postfix/sasl/smtpd.conf <<EOF
222 pwcheck_method: saslauthd
223 mech_list: plain login
225 restart_postfix="yes"
228 if [ -f /etc/default/saslauthd ]; then
229 cp_check_and_sed "^START=no" \
230 "s/^START=no/START=yes/g" \
231 /etc/default/saslauthd && restart_saslauthd="yes"
233 cp_check_and_sed "^#[[:blank:]]*START=" \
234 "s/^#[[:blank:]]*START=.*$/START=yes/g" \
235 /etc/default/saslauthd && restart_saslauthd="yes"
237 if ! grep -q "^START.*yes" /etc/default/saslauthd; then
238 echo "START=yes" >> /etc/default/saslauthd
239 restart_saslauthd="yes"
242 if ! grep -q "^OPTIONS.*/var/spool/postfix/var/run/saslauthd" /etc/default/saslauthd; then
243 echo "OPTIONS=\"-c -m /var/spool/postfix/var/run/saslauthd\"" >> /etc/default/saslauthd
244 restart_saslauthd="yes"
247 if ! grep -q "&& ln -s" /etc/default/saslauthd; then
248 echo "[ ! -L /var/run/saslauthd -a -d /var/spool/postfix/var/run/saslauthd -a ! -d /var/run/saslauthd ] && ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd || true" >> /etc/default/saslauthd
249 restart_saslauthd="yes"
252 if [ ! -L /var/run/saslauthd ]; then
253 mkdir -p /var/spool/postfix/var/run/
254 if [ -d /var/run/saslauthd -a ! -d /var/spool/postfix/var/run/saslauthd ]; then
255 mv /var/run/saslauthd /var/spool/postfix/var/run/
256 elif [ -d /var/run/saslauthd -a -d /var/spool/postfix/var/run/saslauthd ]; then
257 rm -rf /var/run/saslauthd/
259 # XXX jos kad bi ln -s u /var/run/ radio (bootclean.sh)
260 if [ -d /var/spool/postfix/var/run/saslauthd -a ! -d /var/run/saslauthd ]; then
261 ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd
263 restart_saslauthd="yes"
266 if [ ! -d /var/spool/postfix/var/run/saslauthd ]; then
267 mkdir -p /var/spool/postfix/var/run/saslauthd
268 restart_saslauthd="yes"
271 if ! dpkg-statoverride --list /var/spool/postfix/var/run/saslauthd > /dev/null; then
272 dpkg-statoverride --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd
277 if [ "$restart_saslauthd" = "yes" ]; then
278 service saslauthd restart
282 postconf -e smtp_tls_security_level="may"
283 postconf -e smtp_tls_session_cache_database="sdbm:/var/lib/postfix/smtp_scache"
284 postconf -e smtp_tls_session_cache_timeout="3600s"
285 postconf -e smtpd_tls_security_level="may"
286 postconf -e smtpd_tls_session_cache_database="sdbm:/var/lib/postfix/smtpd_scache"
287 postconf -e smtpd_tls_session_cache_timeout="3600s"
288 postconf -e tls_random_source="dev:/dev/urandom"
289 postconf -e smtpd_tls_exclude_ciphers="aNULL"
290 postconf -e smtpd_tls_mandatory_exclude_ciphers="aNULL"
292 # nije potrebno generiranje certifikata jer postfix koristi paket ssl-cert
293 # ako je postavljen snakeoil certifikat za smtpd_tls_* postavi isti za smtp_tls_*
294 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
295 if [ "$smtpd_tls_cert_file" = "/etc/ssl/certs/ssl-cert-snakeoil.pem" ]; then
296 postconf -e smtp_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
297 postconf -e smtp_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
300 # ako je prazan, postavi na defaultni iz paketa ssl-cert
301 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
302 if [ -z "$smtpd_tls_cert_file" ]; then
303 postconf -e smtpd_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
304 postconf -e smtpd_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
306 smtp_tls_cert_file="`postconf -h smtp_tls_cert_file`"
307 if [ -z "$smtp_tls_cert_file" ]; then
308 postconf -e smtp_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
309 postconf -e smtp_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
312 # prije bilo u /etc/postfix/, od verzije 2.1.5-2 je u /var/spool/postfix
313 [ -f /etc/postfix/smtp_scache.dir ] && rm -f /etc/postfix/smtp_scache.dir
314 [ -f /etc/postfix/smtp_scache.pag ] && rm -f /etc/postfix/smtp_scache.pag
315 [ -f /etc/postfix/smtpd_scache.dir ] && rm -f /etc/postfix/smtpd_scache.dir
316 [ -f /etc/postfix/smtpd_scache.pag ] && rm -f /etc/postfix/smtpd_scache.pag
317 # prije bilo u /var/spool/postfix/, od verzije 2.5.5 je u /var/lib/postfix
318 [ -f /var/spool/postfix/smtp_scache.dir ] && rm -f /var/spool/postfix/smtp_scache.dir
319 [ -f /var/spool/postfix/smtp_scache.pag ] && rm -f /var/spool/postfix/smtp_scache.pag
320 [ -f /var/spool/postfix/smtpd_scache.dir ] && rm -f /var/spool/postfix/smtpd_scache.dir
321 [ -f /var/spool/postfix/smtpd_scache.pag ] && rm -f /var/spool/postfix/smtpd_scache.pag
327 # ako postoji amavis, sredi
328 if [ -x /usr/share/amavisd-cn/postfixize.sh ]; then
329 /usr/share/amavisd-cn/postfixize.sh
332 # provjeri da li postoji sendmail-base
333 if ! dpkg -l sendmail-base | grep -q '^.n'; then
335 cp_echo "CN: Package sendmail-base detected."
336 cp_echo "CN: Please, purge this package with command:"
337 cp_echo "CN: # dpkg --purge sendmail-base"
341 # sendmailov /etc/mail/access
342 if [ -f /etc/mail/access -a /etc/mail/access.db ]; then
344 cp_echo "CN: Sendmail's access file (/etc/mail/access) detected."
345 cp_echo "CN: Please, upgrade your's /etc/postfix/access."
346 cp_echo "CN: http://www.postfix.org/SMTPD_ACCESS_README.html"
350 if ! id postfix | grep -q sasl; then
351 adduser postfix sasl > /dev/null
352 restart_postfix="yes"
355 # ako ima razlika, backupiraj stari, ako ne, obrisi privremeni backup
356 if ! cmp -s /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$; then
357 cp_echo "CN: Backing up old version of /etc/postfix/master.cf in /var/backups/..."
358 cp_backup_conffile /etc/postfix/master.cf.dpkg-tmp.$$ master.cf
359 restart_postfix="yes"
361 rm -f /etc/postfix/master.cf.dpkg-tmp.$$
363 if ! cmp -s /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$; then
364 cp_echo "CN: Backing up old version of /etc/postfix/main.cf in /var/backups/..."
365 cp_backup_conffile /etc/postfix/main.cf.dpkg-tmp.$$ main.cf
366 restart_postfix="yes"
368 rm -f /etc/postfix/main.cf.dpkg-tmp.$$
370 #if ! grep -q "retry unix - - y - - error" /etc/postfix/master.cf; then
371 # echo "CN: Please, add this line in /etc/postfix/master.cf and restart Postfix."
372 # echo "retry unix - - y - - error"
376 # kreiraj aliases_gecos
377 if [ -x /usr/share/postfix-cn/make-aliases-gecos.sh ]; then
378 if [ "$matchgecos" = "true" ]; then
379 echo "CN: Creating GECOS alias map..."
380 /usr/share/postfix-cn/make-aliases-gecos.sh
385 if [ "$restart_postfix" = "yes" ]; then
386 service postfix restart