5 [ "$1" = "configure" ] || exit 0
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
9 . /usr/share/carnet-tools/functions.sh
12 . /usr/share/debconf/confmodule
16 utf=$(perl -lne 'print if /[^[:ascii:]]/' /etc/passwd)
18 if [ ! -z "$utf" ]; then
19 poruka="Detektirani su znakovi šđčćž u datoteci /etc/passwd. To bi moglo omesti generiranje mail aliasa u obliku Ime.Prezime@ustanova.hr.
21 Molimo uklonite naše znakove s naredbom
23 usermod -c \"Ime Prezime\" korisnik
25 Korisnici koji imaju znakove u imenu ili prezimenu su:
29 LC_MESSAGES=hr_HR dialog --backtitle "Postfix: problem s datotekom /etc/passwd" --msgbox "$poruka$utf" 18 75
33 db_get postfix-cn/rbl || true
36 # Tue, 19 Dec 2006 10:31:01 +0100
37 # relays.ordb.org se gasi 2006-12-31
38 if echo $rbl | grep -q relays.ordb.org; then
39 rbl="`echo $rbl | sed 's/relays.ordb.org, //g'`"
40 # za svaki slucaj, ako je na kraju
41 rbl="`echo $rbl | sed 's/relays.ordb.org//g'`"
42 db_set postfix-cn/rbl "$rbl" || true
45 # Thu, 21 Dec 2006 09:03:50 +0100
46 # opm.blitzed.org je ugasen 2006-05
47 if echo $rbl | grep -q opm.blitzed.org; then
48 rbl="`echo $rbl | sed 's/opm.blitzed.org, //g'`"
49 # za svaki slucaj, ako je na kraju
50 rbl="`echo $rbl | sed 's/opm.blitzed.org//g'`"
51 db_set postfix-cn/rbl "$rbl" || true
54 # Wed, 12 Jun 2013 15:15:28 +0200
55 # dnsbl.njabl.org je ugasen 2013-03
56 if echo $rbl | grep -q dnsbl.njabl.org; then
57 rbl="`echo $rbl | sed 's/dnsbl.njabl.org, //g'`"
58 # za svaki slucaj, ako je na kraju
59 rbl="`echo $rbl | sed 's/dnsbl.njabl.org//g'`"
60 db_set postfix-cn/rbl "$rbl" || true
64 # ako je spamhaus.org ovdje, postavi eta.cert.hr, a sam
65 # spamhaus je nepotreban, jer imamo zen.dnsbl-sh.carnet.hr
66 if echo $rbl | grep -q zen.spamhaus.org; then
67 rbl="`echo $rbl | sed 's/zen.spamhaus.org, /eta.cert.hr, /g'`"
68 # za svaki slucaj, ako je na kraju
69 rbl="`echo $rbl | sed 's/zen.spamhaus.org/eta.cert.hr/g'`"
70 db_set postfix-cn/rbl "$rbl" || true
73 db_get postfix-cn/matchgecos || true
77 fqdn="`hostname --fqdn`"
78 domain="`dnsdomainname`"
79 mailname="`cat /etc/mailname 2> /dev/null || hostname --fqdn`"
80 cp_get_netaddr || true
83 # ako ne postoje konfiguracijske datoteke, napravi ih
84 [ -f /etc/postfix/master.cf ] || touch /etc/postfix/master.cf
85 [ -f /etc/postfix/main.cf ] || touch /etc/postfix/main.cf
87 # spremi pocetnu verziju
88 cp -pf /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$
89 cp -pf /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$
91 # srediti master.cf za TLS & submission & retry
92 if [ -f /etc/postfix/master.cf ]; then
93 cp_check_and_sed '^#tlsmgr' \
94 's/^#tlsmgr/tlsmgr/g' \
95 /etc/postfix/master.cf || true
97 cp_check_and_sed '^#submission' \
98 's/^#submission/submission/g' \
99 /etc/postfix/master.cf || true
101 cp_check_and_sed '^#retry' \
102 's/^#retry/retry/g' \
103 /etc/postfix/master.cf || true
105 cp_check_and_sed '^#smtps' \
106 's/^#smtps/smtps/g' \
107 /etc/postfix/master.cf || true
109 cp_check_and_sed '^# -o' \
111 /etc/postfix/master.cf || true
113 for option in "-o milter_macro_daemon_name=ORIGINATING" \
114 "-o smtpd_recipient_restrictions=" \
115 "-o smtpd_reject_unlisted_recipient=no" \
116 "-o smtpd_relay_restrictions=permit_sasl_authenticated,reject" \
117 "-o smtpd_sasl_auth_enable=yes" \
118 "-o smtpd_tls_security_level=encrypt" \
119 "-o smtpd_tls_wrappermode=yes" \
120 "-o syslog_name=postfix/smtps" \
121 "-o syslog_name=postfix/submission"; do
122 cp_check_and_sed "^# $option" \
123 "s/# $option/$option/g" \
124 /etc/postfix/master.cf || true
127 for option in "o smtpd_client_restrictions=" \
128 "o smtpd_helo_restrictions=" \
129 "o smtpd_sender_restrictions="; do
130 cp_check_and_sed "$option" \
131 "s/.*$option/# -$option/g" \
132 /etc/postfix/master.cf || true
136 # ovo manje/vise uzima kao default, ali u slucaju da je multihomed stroj,
137 # i eventualno je sprckan, mozda nesto nece raditi kako spada pa cemo konfigurirati
138 postconf -e myhostname="$fqdn"
139 postconf -e mydomain="$domain"
140 postconf -e myorigin="$mailname"
142 # zbog problema sa squirrelmailom
143 postconf -e append_dot_mydomain="yes"
144 postconf -e append_at_myorigin="yes"
146 # dodaj 127.0.0.0/8, netaddr i ipv6-localhost
147 # dodaje izlazne servere za webmail --zelja
148 mynetworks="`postconf -h mynetworks`"
149 for i in "127.0.0.0/8" "\[::1\]/128" "$netaddr" "193.198.233.95" "193.198.233.96"; do
150 if ! echo $mynetworks | grep -q $i; then
151 mynetworks="$mynetworks, $i"
154 postconf -e mynetworks="$mynetworks"
156 # obrisati $mydomain, ako je upgrade sa starije verzije
157 # te srediti mydestination
158 if dpkg --compare-versions "$2" lt 2.3.8-2; then
159 mydestination="`postconf -h mydestination`"
160 if echo $mydestination | grep -q ", \$mydomain"; then
161 mydestination="`echo $mydestination | sed 's/, \$mydomain//g'`"
163 if ! echo $mydestination | grep -q "localhost.\$mydomain"; then
164 mydestination="$mydestination, localhost.\$mydomain"
166 if ! echo $mydestination | grep -q "\$myhostname"; then
167 mydestination="\$myhostname, $mydestination"
169 postconf -e mydestination="$mydestination"
172 # default je: $myhostname, localhost.$mydomain, localhost
173 # treba dodati jos ", $mydomain", ako je host mx
174 cp_get_mx_domain || true
176 if [ "$mx_domain" != "$fqdn" ]; then
177 mydestination="`postconf -h mydestination`"
178 if ! echo $mydestination | grep -q ", \$mydomain"; then
179 postconf -e mydestination="$mydestination, \$mydomain"
181 postconf -e relay_domains="\$mydestination"
182 if [ "$mx_domain" != "$domain" ]; then
183 if dpkg --compare-versions "$2" lt 2.1.5-8; then
184 cp_echo "CN: Ovaj poslužitelj je podešen kao MX za više od jedne domene! Paket postfix-cn će"
185 cp_echo "CN: podesiti samo domenu $mx_domain, ostale domene MORATE DODATI RUČNO"
186 cp_echo "CN: u varijablu 'mydestination' u /etc/postfix/main.cf. Ukoliko to ne"
187 cp_echo "CN: učinite, mogli biste (iz)gubiti mail za te domene."
193 if [ "$matchgecos" = "true" ]; then
194 aliasmaps="hash:/etc/aliases hash:/var/lib/postfix-cn/aliases_gecos"
195 elif [ "$matchgecos" = "false" ]; then
196 aliasmaps="hash:/etc/aliases"
197 alias_maps="`postconf -h alias_maps | \
198 sed -e 's#hash:/var/lib/postfix-cn/aliases_gecos,*##g' -e 's/,*[[:space:]]*$//g'`"
199 postconf -e alias_maps="$alias_maps"
202 for i in $aliasmaps; do
203 alias_maps="`postconf -h alias_maps`"
204 if ! echo $alias_maps | grep -q "$i"; then
205 postconf -e alias_maps="$alias_maps, $i"
209 postconf -e alias_database="hash:/etc/aliases"
210 postconf -e local_recipient_maps="proxy:unix:passwd.byname \$alias_maps"
213 postconf -e recipient_delimiter="+"
214 postconf -e smtpd_helo_required="yes"
215 postconf -e smtpd_helo_restrictions="permit_mynetworks"
216 postconf -e in_flow_delay="2s"
217 postconf -e initial_destination_concurrency="10"
218 postconf -e default_destination_concurrency_limit="30"
219 postconf -e smtpd_recipient_limit="400"
220 postconf -e hash_queue_depth="3"
222 if dpkg --compare-versions "$2" lt 2.1.5-6; then
223 postconf -e bounce_queue_lifetime="5d"
224 postconf -e maximal_queue_lifetime="5d"
227 # ako netko zeli maknuti maskiranje, da mu ga nova verzija ne doda
228 if dpkg --compare-versions "$2" lt 2.1.5-2; then
229 postconf -e masquerade_domains="\$mydomain"
232 # sredi smtpd_recipient_restrictions
233 smtpd_recipient_restrictions="reject_invalid_hostname, \
234 reject_unknown_sender_domain, \
235 reject_unknown_recipient_domain, \
236 reject_unauth_pipelining, \
237 permit_sasl_authenticated, \
239 reject_unauth_destination, \
240 check_client_access hash:/etc/postfix/cn-client-access, \
241 check_helo_access hash:/etc/postfix/cn-helo-access, \
242 check_sender_access hash:/etc/postfix/cn-sender-access, \
243 check_recipient_access hash:/etc/postfix/cn-recipient-access"
245 # dodaj samo rbl-ove iz debconfa
247 for i in `echo $rbl | tr -d ,`; do
248 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, reject_rbl_client $i"
252 # dodaj permit na kraj
253 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, permit"
254 postconf -e smtpd_recipient_restrictions="$smtpd_recipient_restrictions"
256 # Header & body checks
258 postconf -e header_checks="pcre:/etc/postfix/cn-header-checks"
259 postconf -e mime_header_checks="pcre:/etc/postfix/cn-mime-header-checks"
260 postconf -e nested_header_checks="pcre:/etc/postfix/cn-nested-header-checks"
261 postconf -e body_checks="pcre:/etc/postfix/cn-body-checks"
265 postconf -e smtpd_sasl_auth_enable="yes"
266 postconf -e smtpd_sasl_security_options="noanonymous"
267 postconf -e smtpd_sasl_local_domain="\$myhostname"
268 postconf -e broken_sasl_auth_clients="yes"
270 [ -d /etc/postfix/sasl/ ] || mkdir -p /etc/postfix/sasl/
271 if [ ! -f /etc/postfix/sasl/smtpd.conf ]; then
272 cat - > /etc/postfix/sasl/smtpd.conf <<EOF
273 pwcheck_method: saslauthd
274 mech_list: plain login
276 restart_postfix="yes"
279 if [ -f /etc/default/saslauthd ]; then
280 cp_check_and_sed "^START=no" \
281 "s/^START=no/START=yes/g" \
282 /etc/default/saslauthd && restart_saslauthd="yes"
284 cp_check_and_sed "^#[[:blank:]]*START=" \
285 "s/^#[[:blank:]]*START=.*$/START=yes/g" \
286 /etc/default/saslauthd && restart_saslauthd="yes"
288 if ! grep -q "^START.*yes" /etc/default/saslauthd; then
289 echo "START=yes" >> /etc/default/saslauthd
290 restart_saslauthd="yes"
293 if ! grep -q "^OPTIONS.*/var/spool/postfix/var/run/saslauthd" /etc/default/saslauthd; then
294 echo "OPTIONS=\"-c -m /var/spool/postfix/var/run/saslauthd\"" >> /etc/default/saslauthd
295 restart_saslauthd="yes"
298 if ! grep -q "&& ln -s" /etc/default/saslauthd; then
299 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
300 restart_saslauthd="yes"
303 if [ ! -L /var/run/saslauthd ]; then
304 mkdir -p /var/spool/postfix/var/run/
305 if [ -d /var/run/saslauthd -a ! -d /var/spool/postfix/var/run/saslauthd ]; then
306 mv /var/run/saslauthd /var/spool/postfix/var/run/
307 elif [ -d /var/run/saslauthd -a -d /var/spool/postfix/var/run/saslauthd ]; then
308 rm -rf /var/run/saslauthd/
310 # XXX jos kad bi ln -s u /var/run/ radio (bootclean.sh)
311 if [ -d /var/spool/postfix/var/run/saslauthd -a ! -d /var/run/saslauthd ]; then
312 ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd
314 restart_saslauthd="yes"
317 if [ ! -d /var/spool/postfix/var/run/saslauthd ]; then
318 mkdir -p /var/spool/postfix/var/run/saslauthd
319 restart_saslauthd="yes"
322 if ! dpkg-statoverride --list /var/spool/postfix/var/run/saslauthd > /dev/null; then
323 dpkg-statoverride --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd
328 if [ "$restart_saslauthd" = "yes" ]; then
329 service saslauthd restart
333 postconf -e smtp_tls_security_level="may"
334 postconf -e smtp_tls_session_cache_database="btree:/var/lib/postfix/smtp_scache"
335 postconf -e smtp_tls_session_cache_timeout="3600s"
336 postconf -e smtpd_tls_security_level="may"
337 postconf -e smtpd_tls_session_cache_database="btree:/var/lib/postfix/smtpd_scache"
338 postconf -e smtpd_tls_session_cache_timeout="3600s"
339 postconf -e tls_random_source="dev:/dev/urandom"
340 postconf -e smtpd_tls_exclude_ciphers="aNULL"
341 postconf -e smtpd_tls_mandatory_exclude_ciphers="aNULL"
343 # nije potrebno generiranje certifikata jer postfix koristi paket ssl-cert
344 # ako je postavljen snakeoil certifikat za smtpd_tls_* postavi isti za smtp_tls_*
345 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
346 if [ "$smtpd_tls_cert_file" = "/etc/ssl/certs/ssl-cert-snakeoil.pem" ]; then
347 postconf -e smtp_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
348 postconf -e smtp_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
351 # ako je prazan, postavi na defaultni iz paketa ssl-cert
352 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
353 if [ -z "$smtpd_tls_cert_file" ]; then
354 postconf -e smtpd_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
355 postconf -e smtpd_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
357 smtp_tls_cert_file="`postconf -h smtp_tls_cert_file`"
358 if [ -z "$smtp_tls_cert_file" ]; then
359 postconf -e smtp_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
360 postconf -e smtp_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
363 # prije bilo u /etc/postfix/, od verzije 2.1.5-2 je u /var/spool/postfix
364 [ -f /etc/postfix/smtp_scache.dir ] && rm -f /etc/postfix/smtp_scache.dir
365 [ -f /etc/postfix/smtp_scache.pag ] && rm -f /etc/postfix/smtp_scache.pag
366 [ -f /etc/postfix/smtpd_scache.dir ] && rm -f /etc/postfix/smtpd_scache.dir
367 [ -f /etc/postfix/smtpd_scache.pag ] && rm -f /etc/postfix/smtpd_scache.pag
368 # prije bilo u /var/spool/postfix/, od verzije 2.5.5 je u /var/lib/postfix
369 [ -f /var/spool/postfix/smtp_scache.dir ] && rm -f /var/spool/postfix/smtp_scache.dir
370 [ -f /var/spool/postfix/smtp_scache.pag ] && rm -f /var/spool/postfix/smtp_scache.pag
371 [ -f /var/spool/postfix/smtpd_scache.dir ] && rm -f /var/spool/postfix/smtpd_scache.dir
372 [ -f /var/spool/postfix/smtpd_scache.pag ] && rm -f /var/spool/postfix/smtpd_scache.pag
378 # ako postoji amavis, sredi
379 if [ -x /usr/share/amavisd-cn/postfixize.sh ]; then
380 /usr/share/amavisd-cn/postfixize.sh
383 # provjeri da li postoji sendmail-base
384 if ! dpkg -l sendmail-base | grep -q '^.n'; then
386 cp_echo "CN: Pronađen je paket sendmail-base."
387 cp_echo "CN: Molimo, obrišite paket s naredbom:"
388 cp_echo "CN: # dpkg --purge sendmail-base"
392 # sendmailov /etc/mail/access
393 if [ -f /etc/mail/access -a /etc/mail/access.db ]; then
395 cp_echo "CN: Pronađena je sendmailova datoteka /etc/mail/access."
396 cp_echo "CN: Ukoliko je potrebno, nadogradite /etc/mail/access po uputama sa:"
397 cp_echo "CN: http://www.postfix.org/SMTPD_ACCESS_README.html"
401 if ! id postfix | grep -q sasl; then
402 adduser postfix sasl > /dev/null
403 restart_postfix="yes"
406 # ako ima razlika, backupiraj stari, ako ne, obrisi privremeni backup
407 if ! cmp -s /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$; then
408 cp_echo "CN: Backupiram staru inačicu /etc/postfix/master.cf u /var/backups/..."
409 cp_backup_conffile /etc/postfix/master.cf.dpkg-tmp.$$ master.cf
410 restart_postfix="yes"
412 rm -f /etc/postfix/master.cf.dpkg-tmp.$$
414 if ! cmp -s /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$; then
415 cp_echo "CN: Backupiram staru inačicu /etc/postfix/main.cf u /var/backups/..."
416 cp_backup_conffile /etc/postfix/main.cf.dpkg-tmp.$$ main.cf
417 restart_postfix="yes"
419 rm -f /etc/postfix/main.cf.dpkg-tmp.$$
421 #if ! grep -q "retry unix - - y - - error" /etc/postfix/master.cf; then
422 # echo "CN: Please, add this line in /etc/postfix/master.cf and restart Postfix."
423 # echo "retry unix - - y - - error"
427 # Provjera postoje li naša slova šđčćž u /etc/passwd
430 # kreiraj aliases_gecos
431 if [ -x /usr/sbin/newaliases-gecos ]; then
432 if [ "$matchgecos" = "true" ]; then
433 echo "CN: Pravim GECOS alias mapu..."
434 /usr/sbin/newaliases-gecos
438 # rješava grešku "using backwards-compatible default setting chroot=y"
440 for service in smtps/inet smtp/inet smtp/unix submission/inet pickup/fifo cleanup/unix qmgr/fifo rewrite/unix bounce/unix defer/unix trace/unix verify/unix flush/unix relay/unix showq/unix error/unix scache/unix discard/unix retry/unix
442 postconf -F $service/chroot=y
444 restart_postfix="yes"
447 # obavijest za webmail
449 cp-update -t postfix-cn /etc/postfix/main.cf <<EOF
451 # Posluzitelji "193.198.233.95" "193.198.233.96" su odlazni posluzitelji za webmail.carnet.hr
452 # Ukoliko koristite uslugu CARNET-ovog Webmaila, nemojte ih brisati iz "mynetworks"!
456 test -f /etc/postfix/cn-client-access && /usr/sbin/postmap /etc/postfix/cn-client-access
457 test -f /etc/postfix/cn-recipient-access && /usr/sbin/postmap /etc/postfix/cn-recipient-access
458 test -f /etc/postfix/cn-sender-access && /usr/sbin/postmap /etc/postfix/cn-sender-access
459 test -f /etc/postfix/cn-helo-access && /usr/sbin/postmap /etc/postfix/cn-helo-access
463 if [ "$restart_postfix" = "yes" ]; then
464 service postfix restart