3 [ "$1" = "configure" ] || exit 0
6 . /usr/share/carnet-tools/functions.sh
8 . /usr/share/debconf/confmodule
10 db_get postfix-cn/rbl || true
13 # Tue, 19 Dec 2006 10:31:01 +0100
14 # relays.ordb.org se gasi 2006-12-31
15 if echo $rbl | grep -q relays.ordb.org; then
16 rbl="`echo $rbl | sed 's/relays.ordb.org, //g'`"
17 # za svaki slucaj, ako je na kraju
18 rbl="`echo $rbl | sed 's/relays.ordb.org//g'`"
19 db_set postfix-cn/rbl "$rbl" || true
22 # Thu, 21 Dec 2006 09:03:50 +0100
23 # opm.blitzed.org je ugasen 2006-05
24 if echo $rbl | grep -q opm.blitzed.org; then
25 rbl="`echo $rbl | sed 's/opm.blitzed.org, //g'`"
26 # za svaki slucaj, ako je na kraju
27 rbl="`echo $rbl | sed 's/opm.blitzed.org//g'`"
28 db_set postfix-cn/rbl "$rbl" || true
31 db_get postfix-cn/matchgecos || true
35 fqdn="`hostname --fqdn`"
36 domain="`dnsdomainname`"
37 mailname="`cat /etc/mailname 2> /dev/null || hostname --fqdn`"
38 cp_get_netaddr || true
41 # ako ne postoje konfiguracijske datoteke, napravi ih
42 [ -f /etc/postfix/master.cf ] || touch /etc/postfix/master.cf
43 [ -f /etc/postfix/main.cf ] || touch /etc/postfix/main.cf
45 # spremi pocetnu verziju
46 cp -pf /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$
47 cp -pf /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$
49 # srediti master.cf za TLS
50 if [ -f /etc/postfix/master.cf ]; then
51 cp_check_and_sed '^#tlsmgr' \
52 's/^#tlsmgr/tlsmgr/g' \
53 /etc/postfix/master.cf || true
55 cp_check_and_sed '^#smtps' \
57 /etc/postfix/master.cf || true
60 # ovo manje/vise uzima kao default, ali u slucaju da je multihomed stroj,
61 # i eventualno je sprckan, mozda nesto nece raditi kako spada pa cemo konfigurirati
62 postconf -e myhostname="$fqdn"
63 postconf -e mydomain="$domain"
64 postconf -e myorigin="$mailname"
66 # zbog problema sa squirrelmailom
67 postconf -e append_dot_mydomain="yes"
68 postconf -e append_at_myorigin="yes"
70 # dodaj 127.0.0.0/8 i netaddr
71 mynetworks="`postconf -h mynetworks`"
72 for i in "127.0.0.0/8" "$netaddr"; do
73 if ! echo $mynetworks | grep -q $i; then
74 mynetworks="$mynetworks, $i"
77 postconf -e mynetworks="$mynetworks"
79 # obrisati $mydomain, ako je upgrade sa starije verzije
80 # te srediti mydestination
81 if dpkg --compare-versions "$2" lt 2.1.5-8; then
82 mydestination="`postconf -h mydestination`"
83 if echo $mydestination | grep -q ", \$mydomain"; then
84 mydestination="`echo $mydestination | sed 's/, \$mydomain//g'`"
86 postconf -e mydestination="$mydestination"
89 # default je: $myhostname, localhost.$mydomain, localhost
90 # treba dodati jos ", $mydomain", ako je host mx
91 cp_get_mx_domain || true
93 if [ "$mx_domain" != "$fqdn" ]; then
94 mydestination="`postconf -h mydestination`"
95 if ! echo $mydestination | grep -q ", \$mydomain"; then
96 postconf -e mydestination="$mydestination, \$mydomain"
98 postconf -e relay_domains="\$mydestination"
99 if [ "$mx_domain" != "$domain" ]; then
100 if dpkg --compare-versions "$2" lt 2.1.5-8; then
101 cp_echo "CN: This host is MX for more than one domain! postfix-cn package will"
102 cp_echo "CN only set up $mx_domain, you HAVE TO add the other domains manually"
103 cp_echo "CN to mydestination variable in /etc/postfix/main.cf, if you haven't"
104 cp_echo "CN done that already or you may lose mail."
110 if [ "$matchgecos" = "true" ]; then
111 aliasmaps="hash:/etc/aliases hash:/var/lib/postfix-cn/aliases_gecos"
112 elif [ "$matchgecos" = "false" ]; then
113 aliasmaps="hash:/etc/aliases"
114 alias_maps="`postconf -h alias_maps | \
115 sed -e 's#hash:/var/lib/postfix-cn/aliases_gecos,*##g' -e 's/,*[[:space:]]*$//g'`"
116 postconf -e alias_maps="$alias_maps"
119 for i in $aliasmaps; do
120 alias_maps="`postconf -h alias_maps`"
121 if ! echo $alias_maps | grep -q "$i"; then
122 postconf -e alias_maps="$alias_maps, $i"
126 postconf -e alias_database="hash:/etc/aliases"
127 postconf -e local_recipient_maps="proxy:unix:passwd.byname \$alias_maps"
130 postconf -e recipient_delimiter="+"
131 postconf -e smtpd_helo_required="yes"
132 postconf -e smtpd_helo_restrictions="permit_mynetworks"
133 postconf -e in_flow_delay="2s"
134 postconf -e initial_destination_concurrency="10"
135 postconf -e default_destination_concurrency_limit="30"
136 postconf -e smtpd_recipient_limit="400"
137 postconf -e hash_queue_depth="3"
139 if dpkg --compare-versions "$2" lt 2.1.5-6; then
140 postconf -e bounce_queue_lifetime="5d"
141 postconf -e maximal_queue_lifetime="5d"
144 # ako netko zeli maknuti maskiranje, da mu ga nova verzija ne doda
145 if dpkg --compare-versions "$2" lt 2.1.5-2; then
146 postconf -e masquerade_domains="\$mydomain"
149 # sredi smtpd_recipient_restrictions
150 smtpd_recipient_restrictions="reject_invalid_hostname, \
151 reject_unknown_sender_domain, \
152 reject_unknown_recipient_domain, \
153 reject_unauth_pipelining, \
154 permit_sasl_authenticated, \
156 reject_unauth_destination"
158 # dodaj samo rbl-ove iz debconfa
160 for i in `echo $rbl | tr -d ,`; do
161 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, reject_rbl_client $i"
165 # dodaj check_policy_service i permit na kraj
166 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, check_policy_service inet:127.0.0.1:60000, permit"
167 postconf -e smtpd_recipient_restrictions="$smtpd_recipient_restrictions"
170 postconf -e smtpd_sasl_auth_enable="yes"
171 postconf -e smtpd_sasl_security_options="noanonymous"
172 postconf -e smtpd_sasl_local_domain="\$myhostname"
173 postconf -e broken_sasl_auth_clients="yes"
175 [ -d /etc/postfix/sasl/ ] || mkdir -p /etc/postfix/sasl/
176 if [ ! -f /etc/postfix/sasl/smtpd.conf ]; then
177 cat - > /etc/postfix/sasl/smtpd.conf <<EOF
178 pwcheck_method: saslauthd
179 mech_list: plain login
181 restart_postfix="yes"
184 if [ -f /etc/default/saslauthd ]; then
185 cp_check_and_sed "^START=no" \
186 "s/^START=no/START=yes/g" \
187 /etc/default/saslauthd && restart_saslauthd="yes"
189 cp_check_and_sed "^#[[:blank:]]*START=" \
190 "s/^#[[:blank:]]*START=.*$/START=yes/g" \
191 /etc/default/saslauthd && restart_saslauthd="yes"
193 if ! grep -q "^START.*yes" /etc/default/saslauthd; then
194 echo "START=yes" >> /etc/default/saslauthd
195 restart_saslauthd="yes"
197 if ! grep -q "^PARAMS.*/var/spool/postfix/var/run/saslauthd" /etc/default/saslauthd; then
198 echo "PARAMS=\"-m /var/spool/postfix/var/run/saslauthd\"" >> /etc/default/saslauthd
199 restart_saslauthd="yes"
201 if ! grep -q "^PIDFILE.*/var/spool/postfix/var/run/saslauthd/saslauthd.pid" /etc/default/saslauthd; then
202 echo "PIDFILE=\"/var/spool/postfix/var/run/saslauthd/saslauthd.pid\"" >> /etc/default/saslauthd
203 restart_saslauthd="yes"
205 if ! grep -q "^PWDIR.*/var/spool/postfix/var/run/saslauthd" /etc/default/saslauthd; then
206 echo "PWDIR=\"/var/spool/postfix/var/run/saslauthd\"" >> /etc/default/saslauthd
207 restart_saslauthd="yes"
209 if ! grep -q "&& ln -s" /etc/default/saslauthd; then
210 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
211 restart_saslauthd="yes"
213 if [ ! -L /var/run/saslauthd ]; then
214 mkdir -p /var/spool/postfix/var/run/
215 if [ -d /var/run/saslauthd -a ! -d /var/spool/postfix/var/run/saslauthd ]; then
216 mv /var/run/saslauthd /var/spool/postfix/var/run/
217 elif [ -d /var/run/saslauthd -a -d /var/spool/postfix/var/run/saslauthd ]; then
218 rm -rf /var/run/saslauthd/
221 # XXX jos kad bi ln -s u /var/run/ radio (bootclean.sh)
222 if [ -d /var/spool/postfix/var/run/saslauthd -a ! -d /var/run/saslauthd ]; then
223 ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd
226 restart_saslauthd="yes"
228 if [ ! -d /var/spool/postfix/var/run/saslauthd ]; then
229 mkdir -p /var/spool/postfix/var/run/saslauthd
230 restart_saslauthd="yes"
232 if ! dpkg-statoverride --list /var/spool/postfix/var/run/saslauthd > /dev/null; then
233 dpkg-statoverride --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd
238 if [ "$restart_saslauthd" = "yes" ]; then
239 if [ -x /usr/sbin/invoke-rc.d ]; then
240 [ -x /etc/init.d/saslauthd ] && invoke-rc.d saslauthd restart
242 [ -x /etc/init.d/saslauthd ] && /etc/init.d/saslauthd restart
246 # izgenerirati certifikate
247 cert="postfix" # basename of certificate
248 description="Postfix SMTP daemon" # descriptive text
250 PATH=$PATH:/usr/bin/ssl
251 if [ -f "$cert.pem" ]; then
252 echo "CN: You already have /etc/ssl/certs/$cert.pem"
254 echo "CN: Creating generic self-signed certificate: /etc/ssl/certs/$cert.pem"
255 echo "CN: (replace with hand-crafted or authorized one if needed)."
256 HOSTNAME=`hostname -s`
258 openssl req -new -x509 -days 365 -nodes -out "$cert.pem" -keyout "$cert.pem" > /dev/null 2>&1 <<+
267 ln -sf "$cert.pem" `openssl x509 -noout -hash < "$cert.pem"`.0
268 chown root.root "/etc/ssl/certs/$cert.pem"
269 chmod 0640 "/etc/ssl/certs/$cert.pem"
273 postconf -e smtp_use_tls="yes"
274 postconf -e smtp_tls_key_file="\$smtp_tls_cert_file"
275 postconf -e smtp_tls_session_cache_database="sdbm:/var/spool/postfix/smtp_scache"
276 postconf -e smtp_tls_session_cache_timeout="3600s"
277 postconf -e smtpd_use_tls="yes"
278 postconf -e smtpd_tls_key_file="\$smtpd_tls_cert_file"
279 postconf -e smtpd_tls_session_cache_database="sdbm:/var/spool/postfix/smtpd_scache"
280 postconf -e smtpd_tls_session_cache_timeout="3600s"
281 postconf -e tls_random_source="dev:/dev/urandom"
282 # ako je postavljen neki drugi certifikat, ne diraj
283 smtp_tls_cert_file="`postconf -h smtp_tls_cert_file`"
284 if [ -z "$smtp_tls_cert_file" ]; then
285 postconf -e smtp_tls_cert_file="/etc/ssl/certs/$cert.pem"
287 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
288 if [ -z "$smtpd_tls_cert_file" ]; then
289 postconf -e smtpd_tls_cert_file="/etc/ssl/certs/$cert.pem"
292 # prije bilo u /etc/postfix/, od verzije 2.1.5-2 je u /var/spool/postfix
293 [ -f /etc/postfix/smtp_scache.dir ] && rm -f /etc/postfix/smtp_scache.dir
294 [ -f /etc/postfix/smtp_scache.pag ] && rm -f /etc/postfix/smtp_scache.pag
295 [ -f /etc/postfix/smtpd_scache.dir ] && rm -f /etc/postfix/smtpd_scache.dir
296 [ -f /etc/postfix/smtpd_scache.pag ] && rm -f /etc/postfix/smtpd_scache.pag
302 # ako postoji amavis, sredi
303 if [ -x /usr/share/amavisd-cn/postfixize.sh ]; then
304 /usr/share/amavisd-cn/postfixize.sh
307 # provjeri da li postoji sendmail-base
308 if ! dpkg -l sendmail-base | grep -q '^.n'; then
310 cp_echo "CN: Package sendmail-base detected."
311 cp_echo "CN: Please, purge this package with command:"
312 cp_echo "CN: # dpkg --purge sendmail-base"
316 # sendmailov /etc/mail/access
317 if [ -f /etc/mail/access -a /etc/mail/access.db ]; then
319 cp_echo "CN: Sendmail's access file (/etc/mail/access) detected."
320 cp_echo "CN: Please, upgrade your's /etc/postfix/access."
321 cp_echo "CN: http://www.postfix.org/SMTPD_ACCESS_README.html"
325 if ! id postfix | grep -q sasl; then
326 adduser postfix sasl > /dev/null
327 restart_postfix="yes"
330 # ako ima razlika, backupiraj stari, ako ne, obrisi privremeni backup
331 if ! cmp -s /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$; then
332 cp_echo "CN: Backing up old version of /etc/postfix/master.cf in /var/backups/..."
333 cp_backup_conffile /etc/postfix/master.cf.dpkg-tmp.$$ master.cf
334 restart_postfix="yes"
336 rm -f /etc/postfix/master.cf.dpkg-tmp.$$
338 if ! cmp -s /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$; then
339 cp_echo "CN: Backing up old version of /etc/postfix/main.cf in /var/backups/..."
340 cp_backup_conffile /etc/postfix/main.cf.dpkg-tmp.$$ main.cf
341 restart_postfix="yes"
343 rm -f /etc/postfix/main.cf.dpkg-tmp.$$
345 # kreiraj aliases_gecos
346 if [ -x /usr/share/postfix-cn/make-aliases-gecos.sh ]; then
347 if [ "$matchgecos" = "true" ]; then
348 echo "CN: Creating GECOS alias map..."
349 /usr/share/postfix-cn/make-aliases-gecos.sh
353 if dpkg --compare-versions "$2" lt 2.1.5-6 && \
354 [ -f /etc/postgrey/whitelist_clients ]; then
355 # dodaj CARNet MX u /etc/postgrey/whitelist_clients
356 cp-update postfix-cn /etc/postgrey/whitelist_clients < /usr/share/postfix-cn/carnet_whitelist_clients
357 restart_postgrey="yes"
360 if [ -f /etc/default/postgrey ]; then
361 if ! grep -q "^POSTGREY_OPTS=.*--delay" /etc/default/postgrey; then
362 cp_check_and_sed 'POSTGREY_OPTS=' \
363 's/^POSTGREY_OPTS="/POSTGREY_OPTS="--delay=58 /g' \
364 /etc/default/postgrey || true
365 restart_postgrey="yes"
369 if [ "$restart_postgrey" = "yes" ]; then
370 if [ -x /usr/sbin/invoke-rc.d ]; then
371 [ -x /etc/init.d/postgrey ] && invoke-rc.d postgrey restart
373 [ -x /etc/init.d/postgrey ] && /etc/init.d/postgrey restart
378 if [ "$restart_postfix" = "yes" ]; then
379 if [ -x /usr/sbin/invoke-rc.d ]; then
380 [ -x /etc/init.d/postfix ] && invoke-rc.d postfix restart
382 [ -x /etc/init.d/postfix ] && /etc/init.d/postfix restart