minor fixes and improvements
[distro-setup] / mail-setup
1 #!/bin/bash
2 # * intro
3 # Copyright (C) 2019 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
5
6 # todo: hosts should only allow external mail that is authed and
7 # destined for backup route. it is a minor issue since traffic is
8 # limited to the wghole network.
9
10 # todo: emailing info@amnimal.ninja produces a bounce, user doesn't exist
11 # instead of a simple rejection like it should.
12
13 # todo: auto restart of je on checkrestart
14
15 # todo: run mailping test after running, or otherwise
16 # clear out terminal alert
17
18 # todo: reinstall bk with bigger filesystem
19
20 # todo: on bk, dont send email if mailvpn is not up
21
22 # todo: mailtest-check should check on bk too
23
24 # todo: disable postgrey
25
26 # todo: in testforward-check, we should also look
27
28 # todo: test that bounces dont help create valid mailtest-check
29
30 # todo: move mail stuff in distro-end into this file
31
32 # todo: consider rotating dkim & publishing key so every past email I sent
33 # isnt necessarily signed
34
35 # todo: consider how to get clamav out of Debian-exim group
36 # so it cant read/write the whole mail spool, for better
37 # security.
38
39 # todo: create a cronjob to update or warn on expiring dnssec keys
40
41 # todo: we should test failed mail daily or so
42 # failed cronjob, failed sysd-log-once,
43 # a local bounce from a cronjob, a local bounce
44 # to a bad remote address, perhaps a local failure
45 # when the sending daemon is down.
46 # And send an alert email if no alerts have been sent
47 # in 2 or 3 days or something. todo, test cron mail on li.
48
49 # todo: look at mailinabox extra dns records, note these changelogs:
50 # - An MTA-STS policy for incoming mail is now published (in DNS and over HTTPS) when the primary hostname and email address domain both have a signed TLS certificate installed, allowing senders to know that an encrypted connection should be enforced.
51 # - The per-IP connection limit to the IMAP server has been doubled to allow more devices to connect at once, especially with multiple users behind a NAT.
52 #
53
54 # todo: mailtest-check failure on remote hosts is not going to alert me.
55 # sort that out.
56 # todo: test mail failure as well as success.
57 #
58 # todo: validate that mailtest-check is doing dnsbl checks.
59
60 # background: I want to run exim in a network namespace so it can send
61 # and receive through a vpn. This is needed so it can do ipv6, because
62 # outside the namespace if we dont have ipv6, to send ipv6 through the
63 # vpn, we have to send all our ipv6 through the vpn. I did this for a
64 # long time, it was fine, but it causes various pains, like increased
65 # latency, increased recaptcha because my ip is from a data center, just
66 # various issues I dont want on all the time. The problem with the
67 # namespace is that all kinds of programs want to invoke exim, but they
68 # wont be in the namespace. I could replace exim with a wrapper that
69 # jumps into the namespace, i tried that, it works fine. One remaining
70 # problem was that I would have needed to hook into exim upgrades to
71 # move exim and replace it with my wrapper script. Also, my script to
72 # join the namespace is not super reliable because it uses a pgrep.
73 # Instead, I should have created a systemd service for a process that
74 # will never die and just writes its pid somewhere convenient.
75 # That implementation
76 # is below here:
77 #
78 # sudoers:
79 # user ALL=(ALL) /usr/sbin/exim4
80 #
81 # move exim4 to eximian, use this script for exim4:
82 #
83 # #!/bin/bash
84 # if ip a show veth1-mail &>/dev/null; then
85 # /usr/sbin/eximian "$@"
86 # exit
87 # fi
88 # dosudo=false
89 # if [[ $USER && $USER != root ]]; then
90 # dosudo=true
91 # fi
92 # pid=$(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*mail.conf")
93 # if $dosudo; then
94 # sudo nsenter -t $pid -n -m sudo -u $USER /usr/sbin/eximian "$@"
95 # else
96 # nsenter -t $pid -n -m /usr/sbin/eximian "$@"
97 # fi
98 # ## end script
99 #
100 # an alternate solution: there is a small setguid program for
101 # network namespaces in my bookmarks.
102 #
103 # However, the solution I went with is: have 2 exim
104 # configs. A nonstandard location for the daemon that runs
105 # in the namespace. For all other invocations, it uses
106 # the default config location, which is altered to be
107 # in a smarthost config which sends mail to the deaemon.
108 #
109 # I have a bash function, enn to invoke exim like the daemon is running.
110 # and mailbash to just enter its network namespace.
111
112 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
113
114 shopt -s nullglob
115
116 if [[ -s /usr/local/lib/err ]]; then
117 source /usr/local/lib/err
118 elif [[ -s /a/bin/errhandle/err ]]; then
119 source /a/bin/errhandle/err
120 else
121 err "no err tracing script found"
122 fi
123 source /a/bin/distro-functions/src/identify-distros
124 source /a/bin/distro-functions/src/package-manager-abstractions
125
126 # has nextcloud_admin_pass in it
127 f=/p/c/machine_specific/$HOSTNAME/mail
128 if [[ -e $f ]]; then
129 # shellcheck source=/p/c/machine_specific/bk/mail
130 source $f
131 fi
132
133
134 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
135
136
137 u=$(id -nu 1000)
138
139
140 usage() {
141 cat <<EOF
142 Usage: ${0##*/} anything_here_to_debug
143 Setup exim4 & dovecot & related things
144
145 -h|--help Print help and exit.
146 EOF
147 exit $1
148 }
149
150 # debug output if we pass any arg
151 if (( $# )); then
152 set -x
153 fi
154
155
156 ####### instructions for icedove #####
157 # Incoming mail server: mail.iankelling.org, port 143, username iank, connection security starttls, authentication method normal password,
158 # then click advanced so it accepts it.
159 # we could also just use 127.0.0.1 with no ssl
160 #
161 # hamburger -> preferences -> preferences -> advanced tab -> config editor button -> security.ssl.enable_ocsp_must_staple = false
162 # background: dovecot does not yet have ocsp stapling support
163 # reference: https://community.letsencrypt.org/t/simple-guide-using-lets-encrypt-ssl-certs-with-dovecot/2921
164 #
165 # for phone, k9mail, same thing but username alerts, pass in ivy-pass.
166 # also, bk.b8.nz for secondary alerts, username is iank. same alerts pass.
167 # fetching mail settings: folder poll frequency 10 minutes
168 #######
169
170
171 # * perstent password instructions
172 # Note: for cert cron, we need to manually run first to accept known_hosts
173
174 # # exim passwords:
175 # # for hosts which have all private files I just use the same user
176 # # for other hosts, each one get\'s their own password.
177 # # for generating secure pass, and storing for server too:
178 # f=$(mktemp)
179 # host=tp
180 # apg -m 50 -x 70 -n 1 -a 1 -M CLN >$f
181 # s sed -i "/^$host:/d" /p/c/filesystem/etc/exim4/passwd
182 # echo "$host:$(mkpasswd -m sha-512 -s <$f)" >>/p/c/filesystem/etc/exim4/passwd
183 # #reference: exim4_passwd_client(5)
184 # dir=/p/c/machine_specific/$host/filesystem/etc/exim4
185 # mkdir -p $dir
186 # echo "mail.iankelling.org:$host:$(<$f)" > $dir/passwd.client
187 # # then run this script
188
189 # # dovecot password, i just need 1 as I\'m the only user
190 # mkdir /p/c/filesystem/etc/dovecot
191 # echo "iank:$(doveadm pw -s SHA512-CRYPT)::::::" >>/p/c/filesystem/etc/dovecot/users
192
193 ####### end perstent password instructions ######
194
195
196 # * dkim dns
197 # # Remove 1 level of comments in this section, set the domain var
198 # # for the domain you are setting up, then run this and copy dns settings
199 # # into dns.
200 # domain=iankelling.org
201 # c /p/c/filesystem/etc/exim4
202 # # this has several bugs addressed in comments, but it was helpful
203 # # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
204
205 # openssl genrsa -out $domain-private.pem 2048
206 # # Then, to get the public key strings to put in bind:
207
208 # # selector is needed for having multiple keys for one domain.
209 # # I dun do that, so just use a static one: li
210 # # Debadmin page does not have v=, fastmail does, and this
211 # # says it\'s recommended in 3.6.1, default is DKIM1 anyways.
212 # # https://www.ietf.org/rfc/rfc6376.txt
213 # # Join and print all but first and last line.
214 # # last line: swap hold & pattern, remove newlines, print.
215 # # lines 2+: append to hold space
216 # echo "bind txt record: remember to truncate $domain so its relative to the bind zone"
217 # cat <<EOF
218 # a._domainkey.$domain TXT (
219 # "v=DKIM1\059 k=rsa\059 p=$(openssl rsa -in $domain-private.pem -pubout |&sed -rn '${x;s/\n//g;s/^(.*)(.{240}$)/\1"\n"\2/p};3,$H')" )
220 # EOF
221 # # sed explanation: skip the first few lines, then put them into the hold space, then
222 # # on the last line, back to the patern space, remove the newlines, then add a newline
223 # # at the last char - 240, because bind txt records need strings <=255 chars,
224 # # other dkim stuff at the begining is is 25 chars, and the pubkey is 393, so this
225 # # leaves us a bit of extra room at the end and a bunch at the beginning.
226
227 # # selector was also put into /etc/exim4/conf.d/main/000_local,
228
229 # * dmarc dns
230
231 # # 2017-02 dmarc policies:
232 # # host -t txt _dmarc.gmail.com
233 # # yahoo: p=reject, hotmail: p=none, gmail: p=none, fastmail none for legacy reasons
234 # # there were articles claiming gmail would be changing
235 # # to p=reject, in early 2017, which didn\'t happen. I see no sources on them. It\'s
236 # # expected to cause problems
237 # # with a few old mailing lists, copying theirs for now.
238 #
239 # echo "dmarc dns, name: _dmarc value: v=DMARC1; p=none; rua=mailto:mailauth-reports@$domain"
240
241 # * other dns
242
243 # # 2017-02 spf policies:
244 # # host -t txt lists.fedoraproject.org
245 # # google ~all, hotmail ~all, yahoo: ?all, fastmail ?all, outlook ~all
246 # # i include fastmail\'s settings, per their instructions,
247 # # and follow their policy. In mail in a box, or similar instructions,
248 # # I\'ve seen recommended to not use a restrictive policy.
249
250 # # to check if dns has updated, you do
251 # host -a mesmtp._domainkey.$domain
252
253 # # mx records,
254 # # setting it to iankelling.org would work the same, but this
255 # # is more flexible, I could change where mail.iankelling.org pointed.
256 # cat <<'EOF'
257 # mx records, 2 records each, for * and empty domain
258 # pri 10 mail.iankelling.org
259 # EOF
260
261 # # dnssec
262 # from brc2, run dnsecgen then dsign, update named.local.conf, publish keys to registrar
263
264 # * functions & constants
265
266 pre="${0##*/}:"
267 m() { printf "$pre %s\n" "$*"; "$@"; }
268 e() { printf "$pre %s\n" "$*"; }
269 err() { printf "$pre %s\n" "$*" >&2; exit 1; }
270
271 reload=false
272 # This file is so if we fail in the middle and rerun, we dont lose state
273 if [[ -e /var/local/mail-setup-reload ]]; then
274 reload=true
275 fi
276 i() { # install file
277 local tmp tmpdir dest="$1"
278 local base="${dest##*/}"
279 mkdir -p ${dest%/*}
280 ir=false # i result
281 tmpdir=$(mktemp -d)
282 cat >$tmpdir/"$base"
283 tmp=$(rsync -ic $tmpdir/"$base" "$dest")
284 if [[ $tmp ]]; then
285 printf "%s\n" "$tmp"
286 ir=true
287 if [[ $dest == /etc/systemd/system/* ]]; then
288 touch /var/local/mail-setup-reload
289 reload=true
290 fi
291 fi
292 rm -rf $tmpdir
293 }
294 setini() {
295 key="$1" value="$2" section="$3"
296 file="/etc/radicale/config"
297 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
298 }
299 soff () {
300 for service; do
301 # ignore services that dont exist
302 if systemctl cat $service &>/dev/null; then
303 m systemctl disable --now $service
304 fi
305 done
306 }
307 sre() {
308 for service; do
309 m systemctl restart $service
310 m systemctl enable $service;
311 done
312 }
313 sstart() {
314 for service; do
315 m systemctl enable --now $service;
316 done
317 }
318 mailhost() {
319 [[ $HOSTNAME == "$MAIL_HOST" ]]
320 }
321 e() { printf "%s\n" "$*"; }
322 reifactive() {
323 for service; do
324 if systemctl is-active $service >/dev/null; then
325 m systemctl restart $service
326 fi
327 done
328 }
329 stopifactive() {
330 for service; do
331 if systemctl is-active $service >/dev/null; then
332 m systemctl stop $service
333 fi
334 done
335 }
336
337 mxhost=mx.iankelling.org
338 mxport=587
339 forward=$u@$mxhost
340
341 # old setup. left as comment for example
342 # mxhost=mail.messagingengine.com
343 # mxport=587
344 # forward=ian@iankelling.org
345
346 smarthost="$mxhost::$mxport"
347 uhome=$(eval echo ~$u)
348
349 # Somehow on one machine, a file got written with 664 perms.
350 # just being defensive here.
351 umask 0022
352
353 source /a/bin/bash_unpublished/source-state
354 if [[ ! $MAIL_HOST ]]; then
355 err "\$MAIL_HOST not set"
356 fi
357
358 bhost_t=false
359 case $HOSTNAME in
360 $MAIL_HOST) : ;;
361 kd|frodo|x2|x3|kw|sy)
362 bhost_t=true
363 ;;
364 esac
365
366
367 # * Install universal packages
368
369
370 # installs epanicclean
371 /a/bin/ds/install-my-scripts
372
373 if [[ $(debian-codename-compat) == bionic ]]; then
374 cat >/etc/apt/preferences.d/spamassassin <<'EOF'
375 Package: spamassassin sa-compile spamc
376 Pin: release n=focal,o=Ubuntu
377 Pin-Priority: 500
378 EOF
379 fi
380
381 # light version of exim does not have sasl auth support.
382 pi-nostart exim4 exim4-daemon-heavy spamassassin openvpn unbound clamav-daemon wireguard
383
384 # note: pyzor debian readme says you need to run some initialization command
385 # but its outdated.
386 pi spf-tools-perl p0f postgrey pyzor razor jq moreutils certbot
387 # bad packages that sometimes get automatically installed
388 pu openresolv resolvconf
389
390 soff openvpn
391
392
393 if [[ $(debian-codename) == etiona ]]; then
394 # ip6tables stopped loading on boot. openvpn has reduced capability set,
395 # so running iptables as part of openvpn startup wont work. This should do it.
396 pi iptables-persistent
397 cat >/etc/iptables/rules.v6 <<'EOF'
398 *mangle
399 COMMIT
400 *nat
401 COMMIT
402 EOF
403 # load it now.
404 m ip6tables -S >/dev/null
405 fi
406
407 # our nostart pi fails to avoid enabling
408
409
410 # * user forward file
411 case $HOSTNAME in
412 $MAIL_HOST)
413 # afaik, these will get ignored on MAIL_HOST because they are routing to my own
414 # machine, but rm them is safer
415 rm -fv $uhome/.forward /root/.forward
416 ;;
417 *)
418 # this can\'t be a symlink and has permission restrictions
419 # it might work in /etc/aliases, but this seems more proper.
420 e setting $uhome/.forward to $forward
421 install -m 644 {-o,-g}$u <(e $forward) $uhome/.forward
422 ;;
423 esac
424
425 # * Mail clean cronjob
426
427 i /etc/systemd/system/mailclean.timer <<'EOF'
428 [Unit]
429 Description=Run mailclean daily
430
431 [Timer]
432 OnCalendar=monthly
433
434 [Install]
435 WantedBy=timers.target
436 EOF
437
438 i /etc/systemd/system/mailclean.service <<EOF
439 [Unit]
440 Description=Delete and archive old mail files
441 After=multi-user.target
442
443 [Service]
444 User=$u
445 Type=oneshot
446 ExecStart=/usr/local/bin/sysd-mail-once mailclean /a/bin/distro-setup/mailclean
447 EOF
448
449 # * postgrey
450
451
452 i /etc/default/postgrey <<'EOF'
453 POSTGREY_OPTS="--exim --unix=/var/run/postgrey/postgrey.sock --retry-window=4 --max-age=60"
454 EOF
455
456 # * clamav
457
458 m usermod -a -G Debian-exim clamav
459
460 i /etc/systemd/system/clamav-daemon.service.d/fix.conf <<EOF
461 [Service]
462 ExecStartPre=-/bin/mkdir /var/run/clamav
463 ExecStartPre=/bin/chown clamav /var/run/clamav
464 EOF
465
466 # * mail vpn config
467
468 # old.
469 #vpnser=mailvpn.service
470 # todo: this hangs if it cant resolv the endpoint. we
471 # want it to just retry in the background.
472 vpnser=wg-quick@wgmail.service
473
474 case $HOSTNAME in
475 $MAIL_HOST)
476 rsync -aiSAX --chown=root:root --chmod=g-s /p/c/filesystem/etc/wireguard/ /etc/wireguard
477 bindpaths="/etc/127.0.0.1-resolv:/run/systemd/resolve /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind"
478 ;;&
479 bk)
480 bindpaths="/etc/10.173.8.1-resolv:/etc/127.0.0.1-resolv"
481 ;;&
482 *)
483 d=/p/c/machine_specific/$HOSTNAME/filesystem/etc/wireguard/
484 if [[ -d $d ]]; then
485 rsync -aiSAX --chown=root:root --chmod=g-s $d /etc/wireguard
486 fi
487 ;;
488 esac
489
490 i /etc/systemd/system/wg-quick@wgmail.service.d/override.conf <<EOF
491 [Unit]
492 Requires=mailnn.service
493 After=network.target mailnn.service
494 JoinsNamespaceOf=mailnn.service
495 BindsTo=mailnn.service
496
497 [Service]
498 PrivateNetwork=true
499 # i dont think we need any of these, but it doesnt hurt to stay consistent
500 BindPaths=$bindpaths
501 EOF
502
503 # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html
504 i /etc/systemd/system/mailvpn.service <<EOF
505 [Unit]
506 Description=OpenVPN tunnel for mail
507 After=syslog.target network-online.target mailnn.service
508 Wants=network-online.target
509 Documentation=man:openvpn(8)
510 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
511 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
512 # needed to continually restatr
513 JoinsNamespaceOf=mailnn.service
514 BindsTo=mailnn.service
515 StartLimitIntervalSec=0
516
517 [Service]
518 Type=notify
519 RuntimeDirectory=openvpn-client
520 RuntimeDirectoryMode=0710
521 WorkingDirectory=/etc/openvpn/client
522 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/mail.conf
523 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
524 LimitNPROC=10
525 # DeviceAllow=/dev/null rw
526 # DeviceAllow=/dev/net/tun rw
527 PrivateNetwork=true
528 # in the network namespace, we cant connect to systemd-resolved on 127.0.0.53,
529 # because of
530 # https://unix.stackexchange.com/questions/445782/how-to-allow-systemd-resolved-to-listen-to-an-interface-other-than-loopback
531 # there is a workaround there, but i dont think its really worth it,
532 # the mail server is fine with a static dns anyways.
533 # This thread is also interesting,
534 # https://github.com/slingamn/namespaced-openvpn/issues/7
535 # todo: the iptables rule at the bottom could be useful to prevent
536 # dns from leaking in my network namespaced vpn.
537 # I also like the idea of patching systemd-resolved so it
538 # will listen on other interfaces, but its not worth my time.
539 BindPaths=$bindpaths
540 Restart=always
541 # time to sleep before restarting a service
542 RestartSec=1
543
544 [Install]
545 WantedBy=multi-user.target
546 EOF
547
548 i /etc/systemd/system/mailnnroute.service <<'EOF'
549 [Unit]
550 Description=Network routing for mailnn
551 After=syslog.target network-online.target mailnn.service
552 Wants=network-online.target
553 JoinsNamespaceOf=mailnn.service
554 BindsTo=mailnn.service
555 StartLimitIntervalSec=0
556
557 [Service]
558 Type=simple
559 RemainAfterExit=true
560 PrivateNetwork=true
561 ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
562 ExecStop=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
563 Restart=always
564 RestartSec=10
565
566
567 [Install]
568 WantedBy=multi-user.target
569 EOF
570
571 #
572 i /etc/systemd/system/mailnn.service <<'EOF'
573 [Unit]
574 Description=Network Namespace for mail vpn service that will live forever and cant fail
575 After=syslog.target network-online.target
576 Wants=network-online.target
577
578 [Service]
579 Type=simple
580 PrivateNetwork=true
581 ExecStart=/bin/sleep infinity
582
583 [Install]
584 WantedBy=multi-user.target
585 EOF
586
587
588
589 # old service name
590 rm -fv /etc/systemd/system/openvpn-client-mail@.service
591
592 # We use a local unbound because systemd-resolved wont accept our
593 # request, it will only listen to 127.0.0.53 in the main network
594 # namespace, and rejected feature requests to change that (although I
595 # could change the code and recompile), but anyways, that could answer
596 # with things specific to the lan that aren't applicable in this
597 # namespace, and since unbound is a recursive resolver, it means we just
598 # use our own ip against dnsbl rate limits.
599 #
600 # If we ever notice this change, chattr +i on it
601 # trust-ad is used in t10+, glibc 2.31
602
603 i /etc/127.0.0.1-resolv/stub-resolv.conf <<'EOF'
604 nameserver 127.0.0.1
605 options edns0 trust-ad
606 EOF
607
608 i /etc/127.0.0.53-resolv/stub-resolv.conf <<'EOF'
609 nameserver 127.0.0.53
610 options edns0 trust-ad
611 EOF
612
613
614 i /etc/10.173.8.1-resolv/stub-resolv.conf <<'EOF'
615 nameserver 10.173.8.1
616 options edns0 trust-ad
617 EOF
618
619 # this is just a bug fix for trisquel.
620 f=/etc/apparmor.d/usr.sbin.unbound
621 line="/usr/sbin/unbound flags=(attach_disconnected) {"
622 if ! grep -qFx "$line" $f; then
623 badline="/usr/sbin/unbound {"
624 if ! grep -qFx "$badline" $f; then
625 err expected line in $f not found
626 fi
627 sed -i "s,^$badline$,$line," $f
628 if systemctl is-active apparmor &>/dev/null; then
629 m systemctl reload apparmor
630 fi
631 fi
632
633 # note: anything added to nn_progs needs corresponding rm
634 # down below in the host switch
635 nn_progs=(exim4)
636 if mailhost; then
637 # Note dovecots lmtp doesnt need to be in the same nn to accept delivery.
638 # Its in the nn so remote clients can connect to it.
639 nn_progs+=(spamassassin dovecot)
640 fi
641
642 case $HOSTNAME in
643 $MAIL_HOST)
644 i /etc/systemd/system/unbound.service.d/nn.conf <<EOF
645 [Unit]
646 After=mailnn.service
647 JoinsNamespaceOf=mailnn.service
648 BindsTo=mailnn.service
649 StartLimitIntervalSec=0
650
651 [Service]
652 PrivateNetwork=true
653 # note the nsswitch bind is actually not needed for bk, but
654 # its the same file so it does no harm.
655 BindPaths=$bindpaths
656
657 Restart=always
658 RestartSec=1
659 EOF
660
661 # sooo, there are a few ways to get traffic from the mail network
662 # namespace to go over the wghole.
663 #
664 #1: unify the mail vpn and wghole
665 # into 1 network. this seems simple and logical, so I'm doing it.
666 # One general downside is tying things together, if I need to mess
667 # with one thing, it breaks the other. Oh well for now.
668 #
669 # 2. We can route 10.5.3.0/24 out of the mail nn and nat it into wghole.
670 #
671 # 3. We can setup the routing to happen on li, which seemed like I
672 # just needed to add 10.8.0.4/24 to AllowedIPs in at least the
673 # wghole clients, but I think that is kind of hacky and breaks ipv4
674 # routing within the mailvpn, it happened to work just because exim
675 # prefers ipv6 and that was also available in the mailvpn.
676 #
677 # 4. Put the hole interface into the mail network namespace. This
678 # doesn't work if the mail vpn is wg. For openvpn, it bypasses the
679 # vpn routing and establishes a direct connection. I only use the
680 # hole vpn for randomish things, it should be fine to join the mail
681 # nn for that. There should be some way to fix the routing issue
682 # by doing manual routing, but that doesn't seem like a good use of time.
683 # relevant:
684 # https://www.wireguard.com/netns/#
685 #
686 # for wireguard debugging
687 # echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
688 # dmesg -w
689
690 ;;&
691 $MAIL_HOST|bk)
692 for unit in ${nn_progs[@]}; do
693 i /etc/systemd/system/$unit.service.d/nn.conf <<EOF
694 [Unit]
695 # commented for old openvpn
696 Requires=$vpnser
697 After=network.target mailnn.service $vpnser
698 JoinsNamespaceOf=mailnn.service
699 BindsTo=mailnn.service
700 StartLimitIntervalSec=0
701
702 [Service]
703 PrivateNetwork=true
704 # note the nsswitch bind is actually not needed for bk, but
705 # its the same file so it does no harm.
706 BindPaths=$bindpaths
707
708 Restart=always
709 RestartSec=1
710 EOF
711 done
712 ;;
713 *)
714 for unit in exim4 spamassassin dovecot unbound; do
715 f=/etc/systemd/system/$unit.service.d/nn.conf
716 if [[ -s $f ]]; then
717 rm -fv $f
718 reload=true
719 fi
720 done
721 ;;
722 esac
723
724 # * spamassassin config
725 i /etc/sysctl.d/80-iank-mail.conf <<'EOF'
726 # see exim spec
727 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 120
728 EOF
729 if $ir; then
730 m sysctl -p
731 fi
732
733 i /etc/spamassassin/mylocal.cf <<'EOF'
734 # this is mylocal.cf because the normal local.cf has a bunch of upstream stuff i dont want to mess with
735
736 # /usr/share/doc/exim4-base/README.Debian.gz:
737 # SpamAssassin's default report should not be used in a add_header
738 # statement since it contains empty lines. (This triggers e.g. Amavis'
739 # warning "BAD HEADER SECTION, Improper folded header field made up
740 # entirely of whitespace".) This is a safe, terse alternative:
741 clear_report_template
742 report (_SCORE_ / _REQD_ requ) _TESTSSCORES(,)_ autolearn=_AUTOLEARN
743 uridnsbl_skip_domain iankelling.org
744 uridnsbl_skip_domain amnimal.ninja
745 uridnsbl_skip_domain expertpathologyreview.com
746 uridnsbl_skip_domain zroe.org
747 EOF
748
749 # 2020-10-19 remove old file. remove this when all hosts updated
750 rm -fv /etc/systemd/system/spamddnsfix.{timer,service}
751
752 i /etc/default/spamassassin <<'EOF'
753 # defaults plus debugging flags for an issue im having
754 OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
755 PIDFILE="/var/run/spamd.pid"
756 # my additions
757 NICE="--nicelevel 15"
758 CRON=1
759 EOF
760 ##### end spamassassin config
761
762
763 # * Update mail cert
764 if [[ -e /p/c/filesystem ]]; then
765 # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
766 # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
767 # after my internet was down for a bit:
768 # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
769 m /a/exe/vpn-mk-client-cert -b mailclient -n mail li.iankelling.org
770 fi
771 case $HOSTNAME in
772 bk)
773 if [[ ! -e /etc/openvpn/client/mail.conf ]]; then
774 echo "$0: error: first, on a system with /p/c/filesystem, run mail-setup, or the vpn-mk-client-cert line above this err" 2>&2
775 exit 1
776 fi
777 ;;
778 esac
779
780 m rsync -aiSAX --chown=root:root --chmod=g-s /a/bin/ds/mail-cert-cron /usr/local/bin
781
782 i /etc/systemd/system/mailcert.service <<'EOF'
783 [Unit]
784 Description=Mail cert rsync
785 After=multi-user.target
786
787 [Service]
788 Type=oneshot
789 ExecStart=/usr/local/bin/sysd-mail-once mailcert /usr/local/bin/mail-cert-cron
790 EOF
791 i /etc/systemd/system/mailcert.timer <<'EOF'
792 [Unit]
793 Description=Run mail-cert once a day
794
795 [Timer]
796 OnCalendar=daily
797
798 [Install]
799 WantedBy=timers.target
800 EOF
801
802
803 wghost=${HOSTNAME}wg.b8.nz
804 if $bhost_t && [[ ! -e /etc/exim4/certs/$wghost/privkey.pem ]]; then
805 certbot -n --manual-public-ip-logging-ok --eff-email --agree-tos -m letsencrypt@iankelling.org \
806 certonly --manual --preferred-challenges=dns \
807 --manual-auth-hook /a/bin/ds/le-dns-challenge \
808 --manual-cleanup-hook /a/bin/ds/le-dns-challenge-cleanup \
809 --deploy-hook /a/bin/ds/le-exim-deploy -d $wghost
810 fi
811
812 # * common exim4 config
813
814
815 # Make all system users be aliases. preventative
816 # measure for things like cron mail for user without alias
817 awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc/passwd| while read -r user; do
818 if [[ ! $user ]]; then
819 continue
820 fi
821 if ! grep -q "^$user:" /etc/aliases; then
822 echo "$user: root" |m tee -a /etc/aliases
823 fi
824 done
825
826 if ! grep -q "^ncsoft:" /etc/aliases; then
827 echo "ncsoft: graceq2323@gmail.com" |m tee -a /etc/aliases
828 fi
829
830
831
832 m gpasswd -a iank adm #needed for reading logs
833
834 ### make local bounces go to normal maildir
835 # local mail that bounces goes to /Maildir or /root/Maildir
836 dirs=(/m/md/bounces/{cur,tmp,new})
837 m mkdir -p ${dirs[@]}
838 m chown iank:iank /m /m/md
839 m ln -sfT /m/md /m/iank
840 m chmod 771 /m /m/md
841 m chown -R $u:Debian-exim /m/md/bounces
842 m chmod 775 ${dirs[@]}
843 m usermod -a -G Debian-exim $u
844 for d in /Maildir /root/Maildir; do
845 if [[ ! -L $d ]]; then
846 m rm -rf $d
847 fi
848 m ln -sf -T /m/md/bounces $d
849 done
850
851 # dkim, client passwd file
852 files=(/p/c/machine_specific/$HOSTNAME/filesystem/etc/exim4/*)
853 f=/p/c/filesystem/etc/exim4/passwd.client
854 if [[ -e $f ]]; then
855 files+=($f)
856 fi
857 if (( ${#files[@]} )); then
858 m rsync -ahhi --chown=root:Debian-exim --chmod=0640 \
859 ${files[@]} /etc/exim4
860 fi
861
862 # by default, only 10 days of logs are kept. increase that.
863 m sed -ri 's/^(\s*rotate\s).*/\11000/' /etc/logrotate.d/exim4-base
864
865
866 ## https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
867 # i only need .forwards, so just doing that one.
868 cd /etc/exim4/conf.d/router
869 b=userforward_higher_priority
870 # replace the router name so it is unique
871 sed -r s/^\\S+:/$b:/ 600_exim4-config_userforward >175_$b
872
873 # todo, consider 'separate' in etc/exim4.conf, could it help on busy systems?
874
875 # alerts is basically the postmaster address
876 m sed -i --follow-symlinks -f - /etc/aliases <<EOF
877 \$a root: alerts@iankelling.org
878 /^root:/d
879 EOF
880
881 cat >/etc/exim4/conf.d/rewrite/34_iank_rewriting <<'EOF'
882 ncsoft@zroe.org graceq2323@gmail.com hE
883 EOF
884
885 # old name
886 rm -fv /etc/exim4/conf.d/retry/37_retry
887
888 cat >/etc/exim4/conf.d/retry/17_retry <<'EOF'
889 # Retry fast for my own domains
890 iankelling.org * F,1d,10m;F,14d,1h
891 amnimal.ninja * F,1d,10m;F,14d,1h
892 expertpathologyreview.com * F,1d,10m;F,14d,1h
893 je.b8.nz * F,1d,10m;F,14d,1h
894 zroe.org * F,1d,10m;F,14d,1h
895 eximbackup.b8.nz * F,1d,4m;F,14d,1h
896 EOF
897
898
899 rm -vf /etc/exim4/conf.d/main/000_localmacros # old filename
900 cat >/etc/exim4/conf.d/main/000_local <<EOF
901 MAIN_TLS_ENABLE = true
902
903 # require tls connections for all smarthosts
904 REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS = *
905
906 # debian exim config added this in 2016 or so?
907 # it's part of the smtp spec, to limit lines to 998 chars
908 # but a fair amount of legit mail does not adhere to it. I don't think
909 # this should be default, like it says in
910 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828801
911 # todo: the bug for introducing this was about headers, but
912 # the fix maybe is for all lines? one says gmail rejects, the
913 # other says gmail does not reject. figure out and open a new bug.
914 IGNORE_SMTP_LINE_LENGTH_LIMIT = true
915
916 # more verbose logs
917 MAIN_LOG_SELECTOR = +all
918
919 # Based on spec, seems like a good idea to be nice.
920 smtp_return_error_details = true
921
922 # normally empty, I set this so I can set the envelope address
923 # when doing mail redelivery to invoke filters. Also allows
924 # me exiqgrep and stuff.
925 MAIN_TRUSTED_GROUPS = $u
926
927 # default is 10. when exim has been down for a bit, fsf mailserver
928 # will do a big send in one connection, then exim decides to put
929 # the messages in the queue instead of delivering them, to avoid
930 # spawning too many delivery processes. This is the same as the
931 # fsfs value. And the corresponding one for how many messages
932 # to send out in 1 connection remote_max_parallel = 256
933 smtp_accept_queue_per_connection = 500
934
935
936 DKIM_CANON = relaxed
937 DKIM_SELECTOR = li
938
939 # from comments in
940 # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
941 # and its best for this to align https://tools.ietf.org/html/rfc7489#page-8
942 # There could be some circumstance when the
943 # from: isnt our domain, but the envelope sender is
944 # and so still want to sign, but I cant think of any case.
945 DKIM_DOMAIN = \${lc:\${domain:\$rh_from:}}
946 # The file is based on the outgoing domain-name in the from-header.
947 # sign if key exists
948 DKIM_PRIVATE_KEY = \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
949
950 # most of the ones that gmail seems to use.
951 # Exim has horrible default of signing unincluded
952 # list- headers since they got mentioned in an
953 # rfc, but this messes up mailing lists, like gnu/debian which want to
954 # keep your dkim signature intact but add list- headers.
955 DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
956
957 domainlist local_hostnames = ! je.b8.nz : ! bk.b8.nz : *.b8.nz : b8.nz
958
959 hostlist iank_trusted = <; \\
960 # veth0
961 10.173.8.1 ; \\
962 # li li_ip6
963 72.14.176.105 ; 2600:3c00::f03c:91ff:fe6d:baf8 ; \\
964 # li_vpn_net li_vpn_net_ip6s
965 10.8.0.0/24; 2600:3c00:e000:280::/64 ; 2600:3c00:e002:3800::/56 ; \\
966 # bk bk_ip6
967 85.119.83.50 ; 2001:ba8:1f1:f0c9::2 ; \\
968 # je je_ipv6
969 85.119.82.128 ; 2001:ba8:1f1:f09d::2 ; \\
970 # fsf_mit_net fsf_mit_net_ip6 fsf_net fsf_net_ip6 fsf_office_net
971 18.4.89.0/24 ; 2603:3005:71a:2e00::/64 ; 209.51.188.0/24 ; 2001:470:142::/48 ; 74.94.156.208/28
972 EOF
973
974 rm -fv /etc/exim4/rcpt_local_acl # old path
975
976 i /etc/exim4/conf.d/local_deny_exceptions_acl <<'EOF'
977 # This acl already exists in rcpt, this just makes it more widespread.
978 # See the comment there for its rationale. The reason it needs to be
979 # more widespread is that I've turned on sender verification, but cron
980 # emails can fail sender verification since I may be in a network that
981 # doesn't have my local dns.
982 accept
983 authenticated = *
984
985 # i setup a local programs smtp to mail.iankelling.org, this
986 # skips sender verification for it.
987 accept
988 hosts = 10.173.8.1
989 EOF
990
991 rm -fv /etc/exim4/data_local_acl # old path
992 i /etc/exim4/conf.d/data_local_acl <<'EOF'
993 # Except for the "condition =", this was
994 # a comment in the check_data acl. The comment about this not
995 # being suitable has been changed in newer exim versions. The only thing
996 # related I found was to
997 # add the condition =, cuz spamassassin has problems with big
998 # messages and spammers don't bother with big messages,
999 # but I've increased the size from 10k
1000 # suggested in official docs, and 100k in the wiki example because
1001 # those docs are rather old and I see a 110k spam message
1002 # pretty quickly looking through my spam folder.
1003
1004 warn
1005 !hosts = +iank_trusted
1006 remove_header = X-Spam_score: X-Spam_score_int : X-Spam_bar : X-Spam_report
1007
1008 warn
1009 !hosts = +iank_trusted
1010 condition = ${if < {$message_size}{5000K}}
1011 spam = Debian-exim:true
1012 add_header = X-Spam_score_int: $spam_score_int
1013 add_header = X-Spam_score: $spam_score
1014 add_header = X-Spam_bar: $spam_bar
1015 add_header = X-Spam_report: $spam_report
1016 add_header = X-Spam_action: $spam_action
1017
1018 warn
1019 condition = ${if def:malware_name}
1020 remove_header = Subject:
1021 add_header = Subject: [Clamav warning: $malware_name] $h_subject
1022 log_message = heuristic malware warning: $malware_name
1023
1024 #accept
1025 # spf = pass:fail:softfail:none:neutral:permerror:temperror
1026 # dmarc_status = reject:quarantine
1027 # add_header = Reply-to: dmarctest@iankelling.org
1028
1029 EOF
1030
1031 i /etc/exim4/conf.d/router/900_exim4-config_local_user <<EOF
1032 ### router/900_exim4-config_local_user
1033 #################################
1034
1035 # This router matches local user mailboxes. If the router fails, the error
1036 # message is "Unknown user".
1037 local_user:
1038 debug_print = "R: local_user for \$local_part@\$domain"
1039 driver = accept
1040 domains = +local_domains
1041 # ian: default file except where mentioned.
1042 # ian: commented this. I get all local parts. for bk, an rcpt
1043 # check handles checking with dovecot, and the only router
1044 # after this is root.
1045 # local_parts = ! root
1046 transport = LOCAL_DELIVERY
1047 cannot_route_message = Unknown user
1048 # ian: added for + addressing.
1049 local_part_suffix = +*
1050 local_part_suffix_optional
1051 EOF
1052 i /etc/exim4/conf.d/transport/30_exim4-config_dovecot_lmtp <<'EOF'
1053 dovecot_lmtp:
1054 driver = lmtp
1055 socket = /var/run/dovecot/lmtp
1056 #maximum number of deliveries per batch, default 1
1057 batch_max = 200
1058 envelope_to_add
1059 EOF
1060
1061 i /etc/exim4/conf.d/transport/30_remote_smtp_vpn <<'EOF'
1062 # same as debians 30_exim4-config_remote_smtp, but
1063 # with interface added at the end.
1064
1065 remote_smtp_vpn:
1066 debug_print = "T: remote_smtp_vpn for $local_part@$domain"
1067 driver = smtp
1068 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1069 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1070 .endif
1071 .ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
1072 hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
1073 .endif
1074 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1075 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1076 .endif
1077 .ifdef REMOTE_SMTP_RETURN_PATH
1078 return_path = REMOTE_SMTP_RETURN_PATH
1079 .endif
1080 .ifdef REMOTE_SMTP_HELO_DATA
1081 helo_data=REMOTE_SMTP_HELO_DATA
1082 .endif
1083 .ifdef DKIM_DOMAIN
1084 dkim_domain = DKIM_DOMAIN
1085 .endif
1086 .ifdef DKIM_SELECTOR
1087 dkim_selector = DKIM_SELECTOR
1088 .endif
1089 .ifdef DKIM_PRIVATE_KEY
1090 dkim_private_key = DKIM_PRIVATE_KEY
1091 .endif
1092 .ifdef DKIM_CANON
1093 dkim_canon = DKIM_CANON
1094 .endif
1095 .ifdef DKIM_STRICT
1096 dkim_strict = DKIM_STRICT
1097 .endif
1098 .ifdef DKIM_SIGN_HEADERS
1099 dkim_sign_headers = DKIM_SIGN_HEADERS
1100 .endif
1101 .ifdef TLS_DH_MIN_BITS
1102 tls_dh_min_bits = TLS_DH_MIN_BITS
1103 .endif
1104 .ifdef REMOTE_SMTP_TLS_CERTIFICATE
1105 tls_certificate = REMOTE_SMTP_TLS_CERTIFICATE
1106 .endif
1107 .ifdef REMOTE_SMTP_PRIVATEKEY
1108 tls_privatekey = REMOTE_SMTP_PRIVATEKEY
1109 .endif
1110 .ifdef REMOTE_SMTP_HOSTS_REQUIRE_TLS
1111 hosts_require_tls = REMOTE_SMTP_HOSTS_REQUIRE_TLS
1112 .endif
1113 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1114 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1115 .endif
1116 interface = <; 10.8.0.4 ; 2600:3c00:e002:3800::4
1117 EOF
1118
1119 i /etc/exim4/conf.d/transport/30_smarthost_dkim <<'EOF'
1120 # ian: this is remote_smtp_smarthost plus the dkim parts from remote_smtp
1121
1122 smarthost_dkim:
1123 debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
1124 driver = smtp
1125 multi_domain
1126 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1127 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1128 .endif
1129 hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
1130 {\
1131 ${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
1132 }\
1133 {} \
1134 }
1135 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1136 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1137 .endif
1138 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1139 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1140 .endif
1141 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1142 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1143 .endif
1144 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
1145 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
1146 .endif
1147 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1148 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1149 .endif
1150 .ifdef REMOTE_SMTP_RETURN_PATH
1151 return_path = REMOTE_SMTP_RETURN_PATH
1152 .endif
1153 .ifdef REMOTE_SMTP_HELO_DATA
1154 helo_data=REMOTE_SMTP_HELO_DATA
1155 .endif
1156 .ifdef TLS_DH_MIN_BITS
1157 tls_dh_min_bits = TLS_DH_MIN_BITS
1158 .endif
1159 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1160 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1161 .endif
1162 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1163 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1164 .endif
1165 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1166 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1167 .endif
1168 .ifdef DKIM_DOMAIN
1169 dkim_domain = DKIM_DOMAIN
1170 .endif
1171 .ifdef DKIM_SELECTOR
1172 dkim_selector = DKIM_SELECTOR
1173 .endif
1174 .ifdef DKIM_PRIVATE_KEY
1175 dkim_private_key = DKIM_PRIVATE_KEY
1176 .endif
1177 .ifdef DKIM_CANON
1178 dkim_canon = DKIM_CANON
1179 .endif
1180 .ifdef DKIM_STRICT
1181 dkim_strict = DKIM_STRICT
1182 .endif
1183 .ifdef DKIM_SIGN_HEADERS
1184 dkim_sign_headers = DKIM_SIGN_HEADERS
1185 .endif
1186 EOF
1187
1188
1189 cat >/etc/exim4/update-exim4.conf.conf <<'EOF'
1190 # default stuff, i havent checked if its needed
1191 dc_minimaldns='false'
1192 dc_relay_nets=''
1193 CFILEMODE='644'
1194 dc_use_split_config='true'
1195 dc_mailname_in_oh='true'
1196 EOF
1197
1198
1199 # * radicale
1200 if mailhost; then
1201 if ! mountpoint /o; then
1202 echo "error /o is not a mountpoint" >&2
1203 exit 1
1204 fi
1205
1206 # davx/davdroid setup instructions at the bottom
1207
1208 # main docs:
1209 # http://radicale.org/user_documentation/
1210 # https://davdroid.bitfire.at/configuration/
1211
1212 # note on debugging: if radicale can't bind to the address,
1213 # in the log it just says "Starting Radicale". If you run
1214 # it in the foreground, it will give more info. Background
1215 # plus debug does not help.
1216 # sudo -u radicale radicale -D -f
1217
1218 # created password file with:
1219 # htpasswd -c /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1220 # chmod 640 /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1221 # # setup chgrp www-data in ./conflink
1222
1223 pi-nostart radicale
1224
1225 i /etc/systemd/system/radicale.service.d/override.conf <<EOF
1226 [Unit]
1227 # this unit is configured to start and stop whenever
1228 # $vpnser does
1229
1230 After=network.target network-online.target mailnn.service $vpnser
1231 BindsTo=$vpnser
1232
1233 Wants=network-online.target
1234 JoinsNamespaceOf=mailnn.service
1235 StartLimitIntervalSec=0
1236
1237 [Service]
1238 PrivateNetwork=true
1239 BindPaths=$bindpaths
1240 Restart=always
1241 # time to sleep before restarting a service
1242 RestartSec=1000
1243
1244 [Install]
1245 # for openvpn
1246 RequiredBy=$vpnser
1247 EOF
1248
1249
1250 # use persistent uid/gid
1251 IFS=:; read -r _ _ uid _ < <(getent passwd radicale ); unset IFS
1252 IFS=:; read -r _ _ gid _ < <(getent group radicale ); unset IFS
1253 if [[ $uid != 609 ]]; then
1254 m systemctl stop radicale ||:
1255 m usermod -u 609 radicale
1256 m groupmod -g 609 radicale
1257 m usermod -g 609 radicale
1258 fi
1259 m find /o/radicale -xdev -exec chown -h 609 {} +
1260 m find /o/radicale -xdev -exec chgrp -h 609 {} +
1261
1262
1263 # I moved /var/lib/radicale after it's initialization.
1264 # I did a sudo -u radicale git init in the collections subfolder
1265 # after it gets created, per the git docs.
1266 m /a/exe/lnf -T /o/radicale /var/lib/radicale
1267
1268 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
1269
1270 # more config is for li in distro-end
1271
1272 # coment in this file says this is needed for it to run on startup
1273 sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc/default/radicale
1274
1275 # comments say default is 0.0.0.0:5232
1276 m setini hosts 10.8.0.4:5232 server
1277 # https://radicale.org/2.1.html
1278 m setini type http_x_remote_user auth
1279
1280
1281 # disable power management feature, set to 240 min sync interval,
1282 # so it shouldn't be bad.
1283
1284 # davdroid from f-druid.
1285 # login with url and user name
1286 # url https://cal.iankelling.org/ian
1287 # username ian
1288 # pass, see password manager for radicale
1289 #
1290 # add account dialog:
1291 #
1292 # set account name as ian@iankelling.org, per help text below the
1293 # field.
1294 #
1295 # switch to groups are per-contact categories,
1296 # per https://davdroid.bitfire.at/configuration/radicale/
1297 #
1298 #
1299 # After setting up account, I added one address book, named
1300 # ianaddr. calender was already created, named ian. checked boxes under
1301 # both. synced.
1302 #
1303 # To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
1304 #
1305 # ignorable background info:
1306 #
1307 # opentasks uses the calendar file.
1308 #
1309 # The address book I created got a uuid as a name for the file. Note
1310 # the .props file says if it's a calendar or addressbook.
1311 #
1312 # When debugging, tailed /var/log/radicale/radicale.log and apache log,
1313 # both show the requests happening. Without creating the address book,
1314 # after creating a contact, a sync would delete it.
1315 #
1316 # Address books correspond to .props files in the radicale dir.
1317 #
1318 # Some background is here,
1319 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1320 # which shows separate vcard option is from rfc 6350, the other is 2426,
1321 # radicale page says it implements the former not the latter,
1322 # which conflicts with the documentation of which to select, but whatever.
1323 # http://radicale.org/technical_choices/
1324 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1325 #
1326 # Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
1327
1328 # Note, radicale had built-in git support to track changes, but they
1329 # removed it in 2.0.
1330
1331 fi
1332
1333 # * dovecot
1334
1335 # ** $MAIL_HOST|bk|je)
1336 case $HOSTNAME in
1337 $MAIL_HOST|bk|je)
1338 # based on a little google and package search, just the dovecot
1339 # packages we need instead of dovecot-common.
1340 #
1341 # dovecot-lmtpd is for exim to deliver to dovecot instead of maildir
1342 # directly. The reason to do this is to use dovecot\'s sieve, which
1343 # can generally do more than exims filters (a few things less) and
1344 # sieve has the benefit of being supported in postfix and
1345 # proprietary/weird environments, so there is more examples on the
1346 # internet.
1347 pi dovecot-core dovecot-imapd dovecot-sieve dovecot-lmtpd dovecot-sqlite sqlite3
1348
1349 for f in /p/c{/machine_specific/$HOSTNAME,}/filesystem/etc/dovecot/users; do
1350 if [[ -e $f ]]; then
1351 m rsync -ahhi --chown=root:dovecot --chmod=0640 $f /etc/dovecot/
1352 break
1353 fi
1354 done
1355 for f in /p/c/subdir_files/sieve/*sieve /a/c/subdir_files/sieve/*sieve; do
1356 m sudo -u $u /a/exe/lnf -T $f $uhome/sieve/${f##*/}
1357 done
1358
1359 # https://wiki.dovecot.org/SSL/DovecotConfiguration
1360 i /etc/dovecot/dhparam <<'EOF'
1361 -----BEGIN DH PARAMETERS-----
1362 MIIBCAKCAQEAoleil6SBxGqQKk7j0y2vV3Oklv6XupZKn7PkPv485QuFeFagifeS
1363 A+Jz6Wquqk5zhGyCu63Hp4wzGs4TyQqoLjkaWL6Ra/Bw3g3ofPEzMGEsV1Qdqde4
1364 jorwiwtr2i9E6TXQp0noT/7VFeHulIkayTeW8JulINdMHs+oLylv16McGCIrxbkM
1365 8D1PuO0TP/CNDs2QbRvJ1RjY3CeGpxMhrSHVgBCUMwnA2cvz3bYjI7UMYMMDPNrE
1366 PLrwsYzXGGCdJsO2vsmmqqgLsZiapYJlUNjfiyWLt7E2H6WzkNB3VIhIPfLqFDPK
1367 xioE3sYKdjOt+p6mlg3l8+OLtODEFPHDqwIBAg==
1368 -----END DH PARAMETERS-----
1369 EOF
1370 {
1371 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
1372 cat <<'EOF'
1373 ssl_cert = </etc/exim4/fullchain.pem
1374 ssl_key = </etc/exim4/privkey.pem
1375 EOF
1376 else
1377 cat <<'EOF'
1378 ssl_cert = </etc/exim4/exim.crt
1379 ssl_key = </etc/exim4/exim.key
1380 EOF
1381 fi
1382 cat <<EOF
1383 # https://ssl-config.mozilla.org
1384 ssl = required
1385 # this is the same as the certbot list, in my cert cronjob, I check if that has changed upstream.
1386 ssl_cipher_list = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
1387 ssl_protocols = TLSv1.2
1388 ssl_prefer_server_ciphers = no
1389 ssl_dh_parameters_length = 2048
1390
1391 protocol lmtp {
1392 #per https://wiki2.dovecot.org/Pigeonhole/Sieve/Configuration
1393 # default is just \$mail_plugins
1394 mail_plugins = \$mail_plugins sieve
1395 }
1396 EOF
1397 if dpkg --compare-versions $(dpkg-query -f='${Version}\n' --show dovecot-core) ge 1:2.3; then
1398 cat <<EOF
1399 ssl_dh = </etc/dovecot/dhparam
1400 EOF
1401 fi
1402 } >/etc/dovecot/local.conf
1403
1404 ;;&
1405
1406 # ** $MAIL_HOST)
1407 $MAIL_HOST)
1408 # If we changed 90-sieve.conf and removed the active part of the
1409 # sieve option, we wouldn\'t need this, but I\'d rather not modify a
1410 # default config if not needed. This won\'t work as a symlink in /a/c
1411 # unfortunately.
1412 m sudo -u $u /a/exe/lnf -T sieve/main.sieve $uhome/.dovecot.sieve
1413
1414 if [[ ! -e $uhome/sieve/personal.sieve ]]; then
1415 m touch $uhome/sieve/personal{,end}{,test}.sieve
1416 fi
1417
1418 rm -fv /etc/dovecot/conf.d/20-lmtp.conf # file from prev version
1419 cat >>/etc/dovecot/local.conf <<EOF
1420 # simple password file based login
1421 !include conf.d/auth-passwdfile.conf.ext
1422
1423 # ian: %u is used for alerts user vs iank
1424 mail_location = maildir:/m/%u:LAYOUT=fs:INBOX=/m/%u/INBOX
1425 mail_uid = $u
1426 mail_gid = $u
1427
1428 protocol lmtp {
1429 # For a normal setup with exim, we need something like this, which
1430 # removes the domain part
1431 # auth_username_format = %Ln
1432 #
1433 # or else # Exim says something like
1434 # "LMTP error after RCPT ... 550 ... User doesn't exist someuser@somedomain"
1435 # Dovecot verbose log says something like
1436 # "auth-worker(9048): passwd(someuser@somedomain): unknown user"
1437 # reference: http://wiki.dovecot.org/LMTP/Exim
1438 #
1439 # However, I use this to direct all mail to the same inbox.
1440 # A normal way to do this, which I did at first is to have
1441 # a router in exim almost at the end, eg 950,
1442 #local_catchall:
1443 # debug_print = "R: catchall for \$local_part@\$domain"
1444 # driver = redirect
1445 # domains = +local_domains
1446 # data = $u
1447 # based on
1448 # http://blog.alteholz.eu/2015/04/exim4-and-catchall-email-address/
1449 # with superflous options removed.
1450 # However, this causes the envelope to be rewritten,
1451 # which makes filtering into mailboxes a little less robust or more complicated,
1452 # so I've done it this way instead. it also requires
1453 # modifying the local router in exim.
1454 auth_username_format = $u
1455 }
1456 EOF
1457 ;;&
1458 # ** bk|je)
1459 bk|je)
1460 chown -R mail.mail /m/md
1461
1462 f=/etc/dovecot/conf.d/10-auth.conf
1463 if [[ -e $f ]]; then
1464 mv $f $f-iank-disabled
1465 fi
1466
1467 cat >>/etc/dovecot/local.conf <<EOF
1468 !include /etc/dovecot/local.conf.ext
1469
1470 # for debugging info, uncomment these.
1471 # logs go to syslog and to /var/log/mail.log
1472 #auth_verbose=yes
1473 #mail_debug=yes
1474
1475
1476 protocol lmtp {
1477 # This downcases the localpart. default is case sensitive.
1478 # case sensitive local part will miss out on valid email when some person or system
1479 # mistakenly capitalizes things.
1480 auth_username_format = %Lu
1481 }
1482
1483 # make 147 only listen on localhost, plan to use for nextcloud.
1484 # copied from mailinabox
1485 service imap-login {
1486 inet_listener imap {
1487 address = 127.0.0.1
1488 }
1489 }
1490 # https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_dovecot_authenticator.html
1491 service auth {
1492 unix_listener auth-client {
1493 user = Debian-exim
1494 group = Debian-exim
1495 }
1496 }
1497
1498
1499 plugin {
1500 sieve_before = /etc/dovecot/sieve-spam.sieve
1501 # from mailinabox
1502 sieve = /m/sieve/%d/%n.sieve
1503 sieve_dir = /m/sieve/%d/%n
1504 }
1505
1506
1507 # all taken from mailinabox.
1508 mail_location = maildir:/m/md/%d/%n
1509 # meh, ok.
1510 mail_privileged_group = mail
1511 # By default Dovecot allows users to log in only with UID numbers 500 and above. mail is 8
1512 first_valid_uid = 1
1513
1514 # todo: test these changes in the universal config
1515 # mailboxes taken from mailinabox but removed
1516 # settings duplicate to defaults
1517 namespace inbox {
1518 mailbox INBOX {
1519 auto = subscribe
1520 }
1521 mailbox Spam {
1522 special_use = \Junk
1523 auto = subscribe
1524 }
1525 mailbox Drafts {
1526 auto = subscribe
1527 }
1528 mailbox Sent {
1529 auto = subscribe
1530 }
1531 mailbox Trash {
1532 auto = subscribe
1533 }
1534 mailbox Archive {
1535 special_use = \Archive
1536 auto = subscribe
1537 }
1538 }
1539 auth_mechanisms = plain login
1540 EOF
1541
1542 i /etc/dovecot/sieve-spam.sieve <<'EOF'
1543 require ["regex", "fileinto", "imap4flags"];
1544
1545 if allof (header :regex "X-Spam-Status" "^Yes") {
1546 fileinto "Spam";
1547 stop;
1548 }
1549 EOF
1550
1551 i /etc/dovecot/local.conf.ext <<'EOF'
1552 passdb {
1553 driver = sql
1554 args = /etc/dovecot/dovecot-sql.conf.ext
1555 }
1556 userdb {
1557 driver = sql
1558 args = /etc/dovecot/dovecot-sql.conf.ext
1559 }
1560
1561 EOF
1562
1563 i /etc/dovecot/dovecot-sql.conf.ext <<'EOF'
1564 # from mailinabox
1565 driver = sqlite
1566 connect = /m/rc/users.sqlite
1567 default_pass_scheme = SHA512-CRYPT
1568 password_query = SELECT email as user, password FROM users WHERE email='%u';
1569 user_query = SELECT email AS user, "mail" as uid, "mail" as gid, "/m/md/%d/%n" as home FROM users WHERE email='%u';
1570 iterate_query = SELECT email AS user FROM users;
1571 EOF
1572 m chmod 0600 /etc/dovecot/dovecot-sql.conf.ext # per Dovecot instructions
1573
1574 # db needs to be in a www-data writable directory
1575 db=/m/rc/users.sqlite
1576 if [[ ! -s $db ]]; then
1577 m mkdir -p /m/rc
1578 m sqlite3 $db <<'EOF'
1579 CREATE TABLE users (
1580 id INTEGER PRIMARY KEY AUTOINCREMENT,
1581 email TEXT NOT NULL UNIQUE,
1582 password TEXT NOT NULL,
1583 extra,
1584 privileges TEXT NOT NULL DEFAULT '');
1585 EOF
1586 fi
1587 # example of adding a user:
1588 # hash: doveadm pw -s SHA512-CRYPT -p passhere
1589 # sqlite3 /m/rc/users.sqlite <<'EOF'
1590 #insert into users (email, password) values ('testignore@bk.b8.nz', 'hash');
1591 #EOF
1592 # update users set password = 'hash' where email = 'testignore@bk.b8.nz';
1593
1594 # this should be at the end since it requires a valid dovecot config
1595 m sievec /etc/dovecot/sieve-spam.sieve
1596 ;;&
1597 # ** bk)
1598 bk)
1599 # roundcube uses this
1600 mkdir -p /m/sieve
1601 chown mail.mail /m/sieve
1602 m pi dovecot-managesieved
1603 ;;
1604 esac
1605
1606 # * thunderbird autoconfig setup
1607
1608 bkdomains=(expertpathologyreview.com amnimal.ninja)
1609 if [[ $HOSTNAME == bk ]]; then
1610 for domain in ${bkdomains[@]}; do
1611 m /a/exe/web-conf apache2 autoconfig.$domain
1612 dir=/var/www/autoconfig.$domain/html/mail
1613 m mkdir -p $dir
1614 # taken from mailinabox
1615 i $dir/config-v1.1.xml <<EOF
1616 <?xml version="1.0" encoding="UTF-8"?>
1617 <clientConfig version="1.1">
1618 <emailProvider id="$domain">
1619 <domain>$domain</domain>
1620
1621 <displayName>$domain Mail</displayName>
1622 <displayShortName>$domain</displayShortName>
1623
1624 <incomingServer type="imap">
1625 <hostname>mail2.iankelling.org</hostname>
1626 <port>993</port>
1627 <socketType>SSL</socketType>
1628 <username>%EMAILADDRESS%</username>
1629 <authentication>password-cleartext</authentication>
1630 </incomingServer>
1631
1632 <outgoingServer type="smtp">
1633 <hostname>mail2.iankelling.org</hostname>
1634 <port>587</port>
1635 <socketType>STARTTLS</socketType>
1636 <username>%EMAILADDRESS%</username>
1637 <authentication>password-cleartext</authentication>
1638 <addThisServer>true</addThisServer>
1639 <useGlobalPreferredServer>false</useGlobalPreferredServer>
1640 </outgoingServer>
1641
1642 <documentation url="https://$domain/">
1643 <descr lang="en">$domain website.</descr>
1644 </documentation>
1645 </emailProvider>
1646
1647 <webMail>
1648 <loginPage url="https://$domain/roundcube" />
1649 <loginPageInfo url="https://$domain/roundcube" >
1650 <username>%EMAILADDRESS%</username>
1651 <usernameField id="rcmloginuser" name="_user" />
1652 <passwordField id="rcmloginpwd" name="_pass" />
1653 <loginButton id="rcmloginsubmit" />
1654 </loginPageInfo>
1655 </webMail>
1656 <clientConfigUpdate url="https://autoconfig.$domain/mail/config-v1.1.xml" />
1657 </clientConfig>
1658 EOF
1659 done
1660 fi
1661
1662 # * roundcube setup
1663
1664 if [[ $HOSTNAME == bk ]]; then
1665
1666 # zip according to /installer
1667 # which requires adding a line to /usr/local/lib/roundcubemail/config/config.inc.php
1668 # $config['enable_installer'] = true;
1669 pi roundcube roundcube-sqlite3 php-zip apache2 php-fpm
1670
1671 ### begin composer install
1672 # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
1673 # cd $(mktemp -d)
1674 # sum="$(wget -q -O - https://composer.github.io/installer.sig)"
1675 # m php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
1676 # if [[ $sum != $(php -r "echo hash_file('sha384', 'composer-setup.php');") ]]; then
1677 # echo 'ERROR: Invalid composer installer checksum' >&2
1678 # rm -fv composer-setup.php
1679 # exit 1
1680 # fi
1681 # m php composer-setup.php --quiet
1682 # rm -fv composer-setup.php
1683 # m mv composer.phar /usr/local/bin
1684
1685 # the above method gets composer2, carddav plugin at least doesnt work with that
1686 # yet, it was just released 10-24-2020.
1687 m cd /usr/local/bin
1688 m wget -nv -N https://getcomposer.org/composer-1.phar
1689 chmod +x composer-1.phar
1690 ### end composer install
1691
1692 rcdirs=(/usr/local/lib/rcexpertpath /usr/local/lib/rcninja)
1693 ncdirs=(/var/www/ncexpertpath /var/www/ncninja)
1694 # point debian cronjob to our local install, preventing daily cron error
1695
1696 # debian's cronjob will fail, remove both paths it uses just to be sure
1697 rm -fv /usr/share/roundcube/bin/cleandb.sh /etc/cron.d/roundcube-core
1698
1699 #### begin dl roundcube
1700 # note, im r2e subbed to https://github.com/roundcube/roundcubemail/releases.atom
1701 v=1.4.11; f=roundcubemail-$v-complete.tar.gz
1702 cd /a/opt
1703 if [[ -e $f ]]; then
1704 timestamp=$(stat -c %Y $f)
1705 else
1706 timestamp=0
1707 fi
1708 m wget -nv -N https://github.com/roundcube/roundcubemail/releases/download/$v/$f
1709 new_timestamp=$(stat -c %Y $f)
1710 for rcdir in ${rcdirs[@]}; do
1711 if [[ $timestamp != "$new_timestamp" || ! -e "$rcdir/config/secret" ]]; then
1712 m tar -C /usr/local/lib --no-same-owner -zxf $f
1713 m rm -rf $rcdir
1714 m mv /usr/local/lib/roundcubemail-$v $rcdir
1715 fi
1716 done
1717 #### end dl roundcube
1718
1719 for ((i=0; i < ${#bkdomains[@]}; i++)); do
1720 domain=${bkdomains[i]}
1721 rcdir=${rcdirs[i]}
1722 rcbase=${rcdir##*/}
1723 ncdir=${ncdirs[i]}
1724
1725 # copied from debians cronjob
1726 i /etc/cron.d/$rcbase <<EOF
1727 # Roundcube database cleaning: finally removes all records that are
1728 # marked as deleted.
1729 0 5 * * * www-data $rcdir/bin/cleandb.sh >/dev/null
1730 EOF
1731
1732 m /a/exe/web-conf - apache2 $domain <<EOF
1733 Alias /roundcube $rcdir
1734 ### begin roundcube settings
1735 # taken from /etc/apache2/conf-available/roundcube.conf version 1.4.8+dfsg.1-1~bpo10+1
1736 <Directory $rcdir/>
1737 Options +FollowSymLinks
1738 # This is needed to parse $rcdir/.htaccess.
1739 AllowOverride All
1740 Require all granted
1741 </Directory>
1742 # Protecting basic directories:
1743 <Directory $rcdir/config>
1744 Options -FollowSymLinks
1745 AllowOverride None
1746 </Directory>
1747 ### end roundcube settings
1748
1749
1750 ### begin nextcloud settings
1751 Alias /nextcloud "$ncdir/"
1752 <Directory $ncdir/>
1753 Require all granted
1754 AllowOverride All
1755 Options FollowSymLinks MultiViews
1756
1757 <IfModule mod_dav.c>
1758 Dav off
1759 </IfModule>
1760
1761 </Directory>
1762
1763 # based on install checker, links to
1764 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
1765 # their example was a bit wrong, I figured it out by adding
1766 # LogLevel warn rewrite:trace5
1767 # then watching the apache logs
1768
1769 RewriteEngine on
1770 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
1771 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
1772 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
1773 RewriteRule ^/\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
1774 RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
1775 ### end nextcloud settings
1776 EOF
1777 if [[ ! -e $rcdir/config/secret ]]; then
1778 base64 </dev/urandom | head -c24 >$rcdir/config/secret || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]
1779 fi
1780 secret=$(cat $rcdir/config/secret)
1781
1782 rclogdir=/var/log/$rcbase
1783 rctmpdir=/var/tmp/$rcbase
1784 rcdb=/m/rc/$rcbase.sqlite
1785 # config from mailinabox
1786 i $rcdir/config/config.inc.php <<EOF
1787 <?php
1788 \$config = array();
1789 # debian creates this for us
1790 \$config['log_dir'] = '$rclogdir/';
1791 # debian also creates a temp dir, but it is under its install dir,
1792 # seems better to have our own.
1793 \$config['temp_dir'] = '$rctmpdir/';
1794 \$config['db_dsnw'] = 'sqlite:///$rcdb?mode=0640';
1795 \$config['default_host'] = 'ssl://localhost';
1796 \$config['default_port'] = 993;
1797 \$config['imap_conn_options'] = array(
1798 'ssl' => array(
1799 'verify_peer' => false,
1800 'verify_peer_name' => false,
1801 ),
1802 );
1803 \$config['imap_timeout'] = 15;
1804 \$config['smtp_server'] = 'tls://127.0.0.1';
1805 \$config['smtp_conn_options'] = array(
1806 'ssl' => array(
1807 'verify_peer' => false,
1808 'verify_peer_name' => false,
1809 ),
1810 );
1811 \$config['product_name'] = 'webmail';
1812 \$config['des_key'] = '$secret';
1813 \$config['plugins'] = array('archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'carddav', 'html5_notifier');
1814 \$config['skin'] = 'elastic';
1815 \$config['login_autocomplete'] = 2;
1816 \$config['password_charset'] = 'UTF-8';
1817 \$config['junk_mbox'] = 'Spam';
1818 # disable builtin addressbook
1819 \$config['address_book_type'] = '';
1820 ?>
1821 EOF
1822
1823 m mkdir -p $rclogdir
1824 m chmod 750 $rclogdir
1825 m chown www-data:adm $rclogdir
1826 # note: subscribed to updates:
1827 # r2e add rcmcarddav https://github.com/blind-coder/rcmcarddav/commits/master.atom ian@iankelling.org
1828 # r2e add roundcube https://github.com/roundcube/roundcubemail/releases.atom ian@iankelling.org
1829 m mkdir -p $rctmpdir /m/rc
1830 m chown -R www-data.www-data $rctmpdir /m/rc
1831 m chmod 750 $rctmpdir
1832 # Ensure the log file monitored by fail2ban exists, or else fail2ban can't start.
1833 # todo: setup fail2ban
1834 # todo: check for other mailinabox things
1835 m sudo -u www-data touch $rclogdir/errors.log
1836
1837 #### begin carddav install
1838 # This is the official roundcube carddav repo.
1839 # Install doc suggests downloading with composer, but that
1840 # didnt work, it said some ldap package for roundcube was missing,
1841 # but I dont want to download some extra ldap thing.
1842 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/INSTALL.md
1843 verf=$rcdir/plugins/carddav/myversion
1844 upgrade=false
1845 install=false
1846 v=4.0.0
1847 if [[ -e $verf ]]; then
1848 if [[ $(cat $verf) != "$v" ]]; then
1849 install=true
1850 upgrade=true
1851 fi
1852 else
1853 install=true
1854 fi
1855 if $install; then
1856 m rm -rf $rcdir/plugins/carddav
1857 tmpd=$(mktemp -d)
1858 m wget -nv -O $tmpd/t.tgz https://github.com/blind-coder/rcmcarddav/releases/download/v$v/carddav-v$v.tgz
1859 cd $rcdir/plugins
1860 tar xzf $tmpd/t.tgz
1861 rm -rf $tmpd
1862 m chown -R www-data:www-data $rcdir/plugins/carddav
1863 m cd $rcdir/plugins/carddav
1864 if $upgrade; then
1865 m sudo -u www-data composer-1.phar update --no-dev
1866 else
1867 m sudo -u www-data composer-1.phar install --no-dev
1868 fi
1869 m chown -R root:root $rcdir/plugins/carddav
1870 echo $v >$verf
1871 fi
1872
1873 # So, strangely, this worked in initial testing, but then
1874 # on first run it wouldn't show the existing contacts until
1875 # I went into the carddav settings and did "force immediate sync",
1876 # which seemed to fix things. Note, some of these settings
1877 # get initalized per/addressbook in the db, then need changing
1878 # there or through the settings menu.
1879
1880 # About categories, see https://www.davx5.com/tested-with/nextcloud
1881 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/GROUPS.md
1882 i $rcdir/plugins/carddav/config.inc.php <<EOF;
1883 <?php
1884 \$prefs['_GLOBAL']['hide_preferences'] = false;
1885 \$prefs['davserver'] = array(
1886 # name in the UI is kind of dumb. This is just something short that seems to fit ok.
1887 'name' => 'Main',
1888 'username' => '%u', // login username
1889 'password' => '%p', // login password
1890 'url' => 'https://$domain/nextcloud/remote.php/dav/addressbooks/users/%u/contacts',
1891 'active' => true,
1892 'readonly' => false,
1893 'refresh_time' => '00:10:00',
1894 'fixed' => array('username','password'),
1895 'use_categories' => false,
1896 'hide' => false,
1897 );
1898 ?>
1899 EOF
1900 #### end carddav install
1901
1902 cd $rcdir/plugins
1903 if [[ ! -d html5_notifier ]]; then
1904 m git clone https://github.com/stremlau/html5_notifier
1905 fi
1906 cd $rcdir/plugins/html5_notifier
1907 m git pull --rebase
1908
1909 # todo: try out roundcube plugins: thunderbird labels
1910
1911 # Password changing plugin settings
1912 cat $rcdir/plugins/password/config.inc.php.dist - >$rcdir/plugins/password/config.inc.php <<'EOF'
1913 # following are from mailinabox
1914 $config['password_minimum_length'] = 8;
1915 $config['password_db_dsn'] = 'sqlite:////m/rc/users.sqlite';
1916 $config['password_query'] = 'UPDATE users SET password=%D WHERE email=%u';
1917 $config['password_dovecotpw'] = '/usr/bin/doveadm pw';
1918 $config['password_dovecotpw_method'] = 'SHA512-CRYPT';
1919 $config['password_dovecotpw_with_method'] = true;
1920 EOF
1921 # so PHP can use doveadm, for the password changing plugin
1922 m usermod -a -G dovecot www-data
1923 m usermod -a -G mail $u
1924
1925 # so php can update passwords
1926 m chown www-data:dovecot /m/rc/users.sqlite
1927 m chmod 664 /m/rc/users.sqlite
1928
1929 # Run Roundcube database migration script (database is created if it does not exist)
1930 m $rcdir/bin/updatedb.sh --dir $rcdir/SQL --package roundcube
1931 m chown www-data:www-data $rcdb
1932 m chmod 664 $rcdb
1933 done # end loop over domains and rcdirs
1934
1935 ### begin php setup for rc ###
1936 # Enable PHP modules.
1937 m phpenmod -v php mcrypt imap
1938 # dpkg says this is required
1939 m a2enmod proxy_fcgi setenvif
1940 fpm=$(dpkg-query -s php-fpm | sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.3-fpm
1941 phpver=$(dpkg-query -s php-fpm | sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
1942 m a2enconf $fpm
1943 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
1944 # /etc/apache2/conf-enabled/php7.3-fpm.conf
1945 m a2dismod php$phpver
1946 # according to /install, we should set date.timezone,
1947 # but that is dumb, the system already has the right zone in
1948 # $rclogdir/errors.log
1949 # todo: consider other settings in
1950 # /a/opt/mailinabox/setup/nextcloud.sh
1951 i /etc/php/$phpver/cli/conf.d/30-local.ini <<'EOF'
1952 apc.enable_cli = 1
1953 EOF
1954
1955 i /etc/php/$phpver/fpm/conf.d/30-local.ini <<'EOF'
1956 date.timezone = "America/New_York"
1957 # for nextcloud
1958 upload_max_filesize = 2000M
1959 post_max_size = 2000M
1960 # install checker, nextcloud/settings/admin/overview
1961 memory_limit = 512M
1962 EOF
1963 m systemctl restart $fpm
1964 # dunno if reload/restart is needed
1965 m systemctl reload apache2
1966 # note bk backups are defined in crontab outside this file
1967 ### end php setup for rc ###
1968
1969 fi # end roundcube setup
1970
1971 # * nextcloud setup
1972
1973 if [[ $HOSTNAME == bk ]]; then
1974 # from install checker, nextcloud/settings/admin/overview and
1975 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1976 # curl from the web installer requirement, but i switched to cli
1977 # it recommends php-file info, but that is part of php7.3-common, already got installed
1978 # with roundcube.
1979 m pi php-curl php-bz2 php-gmp php-bcmath php-imagick php-apcu
1980
1981 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1982 cat >/etc/php/$phpver/fpm/pool.d/localwww.conf <<'EOF'
1983 [www]
1984 clear_env = no
1985 EOF
1986
1987 for ((i=0; i < ${#bkdomains[@]}; i++)); do
1988 domain=${bkdomains[i]}
1989 ncdir=${ncdirs[i]}
1990 ncbase=${ncdir##*/}
1991 m cd /var/www
1992 if [[ ! -e $ncdir/index.php ]]; then
1993 # if we wanted to only install a specific version, use something like
1994 # file=latest-22.zip
1995 file=latest.zip
1996 m wget -nv -N https://download.nextcloud.com/server/releases/$file
1997 m rm -rf nextcloud
1998 m unzip -q $file
1999 m rm -f $file
2000 m chown -R www-data.www-data nextcloud
2001 m mv nextcloud $ncdir
2002 m cd $ncdir
2003 m sudo -u www-data php occ maintenance:install --database sqlite --admin-user iank --admin-pass $nextcloud_admin_pass
2004 fi
2005 # note, strange this happend where updater did not increment the version var,
2006 # mine was stuck on 20. I manually updated it.
2007 m cd $ncdir/config
2008 if [[ ! -e config.php-orig ]]; then
2009 m cp -a config.php config.php-orig
2010 fi
2011 cat config.php-orig - >tmp.php <<EOF
2012 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
2013 \$CONFIG["mail_smtpmode"] = "sendmail";
2014 \$CONFIG["mail_smtphost"] = "127.0.0.1";
2015 \$CONFIG["mail_smtpport"] = 25;
2016 \$CONFIG["mail_smtptimeout"] = 10;
2017 \$CONFIG["mail_smtpsecure"] = "";
2018 \$CONFIG["mail_smtpauth"] = false;
2019 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
2020 \$CONFIG["mail_smtpname"] = "";
2021 \$CONFIG["mail_smtppassword"] = "";
2022 \$CONFIG["mail_domain"] = "$domain";
2023
2024 # https://github.com/nextcloud/user_external#readme
2025 # plus mailinabox example
2026 #\$CONFIG['user_backends'] = array(array('class' => 'OC_User_IMAP','arguments' => array('127.0.0.1', 143, null),),);
2027
2028
2029 # based on installer check
2030 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
2031 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
2032
2033 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
2034 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
2035 \$CONFIG['trusted_domains'] = array (
2036 0 => '$domain',
2037 );
2038 #\$CONFIG[''] = '';
2039 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
2040 var_export(\$CONFIG);
2041 fwrite(STDOUT, ";\n");
2042 EOF
2043 m php tmp.php >config.php
2044 m rm tmp.php
2045 m sudo -u www-data php $ncdir/occ maintenance:update:htaccess
2046 list=$(sudo -u www-data php $ncdir/occ --output=json_pretty app:list)
2047 # user_external not compaible with nc 23
2048 for app in contacts calendar; do
2049 if [[ $(printf "%s\n" "$list"| jq ".enabled.$app") == null ]]; then
2050 m sudo -u www-data php $ncdir/occ app:install $app
2051 fi
2052 done
2053 i /etc/systemd/system/$ncbase.service <<EOF
2054 [Unit]
2055 Description=ncup $ncbase
2056 After=multi-user.target
2057
2058 [Service]
2059 Type=oneshot
2060 ExecStart=/usr/local/bin/ncup $ncbase
2061 User=www-data
2062 IOSchedulingClass=idle
2063 CPUSchedulingPolicy=idle
2064 EOF
2065 i /etc/systemd/system/$ncbase.timer <<EOF
2066 [Unit]
2067 Description=ncup $ncbase timer
2068
2069 [Timer]
2070 OnCalendar=Daily
2071
2072 [Install]
2073 WantedBy=timers.target
2074 EOF
2075 systemctl enable --now $ncbase.timer
2076 i /usr/local/bin/ncup <<'EOFOUTER'
2077 #!/bin/bash
2078 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
2079 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
2080 set -eE -o pipefail
2081 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
2082
2083 ncbase=$1
2084 if ! php /var/www/$ncbase/updater/updater.phar -n; then
2085 echo failed nextcloud update for $ncbase >&2
2086 /sbin/exim -t <<EOF
2087 To: alerts@iankelling.org
2088 From: root@$(hostname -f)
2089 Subject: failed nextcloud update for $ncbase
2090
2091 For logs, run: jr -u $ncbase
2092 EOF
2093 fi
2094 EOFOUTER
2095
2096 mkdir -p /var/www/cron-errors
2097 chown www-data.www-data /var/www/cron-errors
2098 i /etc/cron.d/$ncbase <<EOF
2099 PATH=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/bin
2100 SHELL=/bin/bash
2101 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
2102 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
2103 EOF
2104
2105 done
2106 fi
2107
2108
2109 # * exim host conditional config
2110
2111 # ** exim certs
2112
2113 all_dirs=(/p/c/filesystem)
2114 for x in /p/c/machine_specific/*.hosts /a/bin/ds/machine_specific/*.hosts; do
2115 if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi
2116 done
2117 files=()
2118 for d in ${all_dirs[@]}; do
2119 f=$d/etc/exim4/passwd
2120 if [[ -e $f ]]; then
2121 files+=($f)
2122 fi
2123 tmp=($d/etc/exim4/*.pem)
2124 if (( ${#tmp[@]} )); then
2125 files+=(${tmp[@]})
2126 fi
2127 done
2128
2129 if (( ${#files[@]} )); then
2130 sudo rsync -ahhi --chown=root:Debian-exim --chmod=0640 ${files[@]} /etc/exim4/
2131 fi
2132
2133
2134 # ** auth
2135
2136 case $HOSTNAME in
2137 bk|je)
2138 # avoid accepting mail for invalid users
2139 # https://wiki.dovecot.org/LMTP/Exim
2140 cat >>/etc/exim4/conf.d/rcpt_local_acl <<'EOF'
2141 deny
2142 message = invalid recipient
2143 domains = +local_domains
2144 !verify = recipient/callout=no_cache
2145 EOF
2146 i /etc/exim4/conf.d/auth/29_exim4-config_auth <<'EOF'
2147 dovecot_plain:
2148 driver = dovecot
2149 public_name = PLAIN
2150 server_socket = /var/run/dovecot/auth-client
2151 server_set_id = $auth1
2152 EOF
2153 ;;
2154 esac
2155 if $bhost_t; then
2156 i /etc/exim4/conf.d/auth/29_exim4-config_auth <<'EOF'
2157 # from 30_exim4-config_examples
2158 plain_server:
2159 driver = plaintext
2160 public_name = PLAIN
2161 server_condition = "${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{CONFDIR/passwd}{$value}{*:*}}}}}{1}{0}}"
2162 server_set_id = $auth2
2163 server_prompts = :
2164 .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
2165 server_advertise_condition = ${if eq{$tls_in_cipher}{}{}{*}}
2166 .endif
2167 EOF
2168 fi
2169
2170 # ** main daemon use non-default config file
2171 case $HOSTNAME in
2172 bk|$MAIL_HOST)
2173 # to see the default comments in /etc/default/exim4:
2174 # s update-exim4defaults --force --init
2175 # which will overwrite any existing file
2176 i /etc/default/exim4 <<'EOF'
2177 QUEUERUNNER='combined'
2178 QUEUEINTERVAL='30m'
2179 COMMONOPTIONS='-C /etc/exim4/my.conf'
2180 UPEX4OPTS='-o /etc/exim4/my.conf'
2181 #E4BCD_PANICLOG_NOISE='malware acl condition: clamd /var/run/clamav/clamd\.ctl : unable to connect to UNIX socket'
2182 EOF
2183 i /etc/exim4/trusted_configs <<'EOF'
2184 /etc/exim4/my.conf
2185 EOF
2186 ;;
2187 *)
2188 # default file
2189 i /etc/default/exim4 <<'EOF'
2190 QUEUERUNNER='combined'
2191 QUEUEINTERVAL='30m'
2192 EOF
2193 ;;
2194 esac
2195
2196 case $HOSTNAME in
2197 # ** $MAIL_HOST|bk|je)
2198 $MAIL_HOST|bk|je)
2199
2200 echo|i /etc/exim4/conf.d/router/870_backup_local
2201
2202 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2203 # note: some things we don't set that are here by default because they are unused.
2204 dc_local_interfaces=''
2205 dc_eximconfig_configtype='internet'
2206 dc_localdelivery='dovecot_lmtp'
2207 EOF
2208 cat >>/etc/exim4/conf.d/main/000_local <<EOF
2209 # recommended if dns is expected to work
2210 CHECK_RCPT_VERIFY_SENDER = true
2211 # default config comment says: If you enable this, you might reject legitimate mail,
2212 # but eggs has had this a long time, so that seems unlikely.
2213 CHECK_DATA_VERIFY_HEADER_SYNTAX = true
2214 CHECK_RCPT_SPF = true
2215 CHECK_RCPT_REVERSE_DNS = true
2216 CHECK_MAIL_HELO_ISSUED = true
2217
2218 # enable 587 in addition to the default 25, so that
2219 # i can send mail where port 25 is firewalled by isp
2220 daemon_smtp_ports = 25 : 587
2221 # default of 25, can get stuck when catching up on mail
2222 smtp_accept_max = 400
2223 smtp_accept_reserve = 100
2224 smtp_reserve_hosts = +iank_trusted
2225
2226 # options exim has to avoid having to alter the default config files
2227 CHECK_RCPT_LOCAL_ACL_FILE = /etc/exim4/conf.d/rcpt_local_acl
2228 CHECK_DATA_LOCAL_ACL_FILE = /etc/exim4/conf.d/data_local_acl
2229 LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE = /etc/exim4/conf.d/local_deny_exceptions_acl
2230 # testing dmarc
2231 #dmarc_tld_file = /etc/public_suffix_list.dat
2232 EOF
2233 ;;&
2234
2235 # ** $MAIL_HOST|bk)
2236 $MAIL_HOST|bk)
2237
2238 cat >>/etc/exim4/conf.d/main/000_local <<EOF
2239 # je.b8.nz will run out of memory with freshclam
2240 av_scanner = clamd:/var/run/clamav/clamd.ctl
2241 EOF
2242
2243 cat >> /etc/exim4/conf.d/data_local_acl <<'EOF'
2244 deny
2245 malware = */defer_ok
2246 !condition = ${if match {$malware_name}{\N^Heuristic\N}}
2247 message = This message was detected as possible malware ($malware_name).
2248 EOF
2249
2250 cat >/etc/exim4/conf.d/main/000_local-nn <<EOF
2251 # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the
2252 # smarthost config type, not sure.
2253 # failing message on mail-tester.com:
2254 # We check if there is a server (A Record) behind your hostname kd.
2255 # You may want to publish a DNS record (A type) for the hostname kd or use a different hostname in your mail software
2256 # https://serverfault.com/questions/46545/how-do-i-change-exim4s-primary-hostname-on-a-debian-box
2257 # and this one seemed appropriate from grepping config.
2258 # I originally set this to li.iankelling.org, but then ended up with errors when li tried to send
2259 # mail to kd, so this should basically be a name that no host has as their
2260 # canonical hostname since the actual host sits behind a nat and changes.
2261 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail.iankelling.org
2262 # I used this to avoid sender verification, didnt work but it still
2263 # makes sense based on the spec.
2264 hosts_treat_as_local = defaultnn.b8.nz
2265
2266 # Outside nn, we get the default cert location from a debian macro,
2267 # and the cert file is put in place by a certbot hook.
2268 MAIN_TLS_CERTIFICATE = /etc/exim4/fullchain.pem
2269 MAIN_TLS_PRIVATEKEY = /etc/exim4/privkey.pem
2270 EOF
2271
2272 i /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost <<'EOF'
2273 gnusmarthost:
2274 debug_print = "R: smarthost for $local_part@$domain"
2275 driver = manualroute
2276 domains = ! +local_domains
2277 # send most mail through eggs, helps fsfs sender reputation.
2278 # uncomment and optionally move to 188 file to send through my own servers again
2279 senders = *@gnu.org
2280 transport = smarthost_dkim
2281 route_list = * fencepost.gnu.org::587 byname
2282 host_find_failed = ignore
2283 same_domain_copy_routing = yes
2284 no_more
2285 EOF
2286
2287 /a/exe/cedit defaultnn /etc/hosts <<'EOF' || [[ $? == 1 ]]
2288 10.173.8.1 defaultnn.b8.nz
2289 EOF
2290 ;;&
2291 # ** $MAIL_HOST)
2292 $MAIL_HOST)
2293
2294 i /etc/exim4/conf.d/router/195_dnslookup_vpn <<'EOF'
2295 # copied from /etc/exim4/conf.d/router/200_exim4-config_primary, but
2296 # use vpn transport. lower priority so it overrides the default route.
2297 # Use this in case our vpn fails, we dont send anything without it.
2298 .ifdef DCconfig_internet
2299 dnslookup_vpn:
2300 debug_print = "R: dnslookup for $local_part@$domain"
2301 driver = dnslookup
2302 domains = ! +local_domains
2303 transport = remote_smtp_vpn
2304 same_domain_copy_routing = yes
2305 ignore_target_hosts = <; 0.0.0.0 ; 127.0.0.0/8 ; 192.168.0.0/16 ; 172.16.0.0/12 ; 10.0.0.0/8 ; 169.254.0.0/16 ; 255.255.255.255 ; ::/128 ; ::1/128 ; fc00::/7 ; fe80::/10 ; 100::/64
2306 no_more
2307 .endif
2308 EOF
2309
2310
2311 # note on backups: I used to do an automatic sshfs and restricted
2312 # permissions to a specific directory on the remote server, /bu/mnt,
2313 # which required using a dedicated user, but realized smtp will be
2314 # more reliable and less fuss. If I ever need that again, see the
2315 # history of this file, and bum in brc2.
2316
2317 i /etc/exim4/conf.d/router/890_backup_copy <<EOF
2318 ### router/900_exim4-config_local_user
2319 #################################
2320
2321 # todo, it would be nice to save sent email too,
2322 # but its not so important, they still exist in my head
2323
2324 backup_redir:
2325 driver = redirect
2326 domains = +local_domains
2327 # b is just an arbirary short string
2328 data = b@eximbackup.b8.nz
2329 # note, to test this, i could temporarily allow testignore.
2330 # alerts avoids potential mail loop. root is already
2331 # redirected earlier, so that is just being overly cautious.
2332 local_parts = ! root : ! testignore : ! alerts
2333 unseen = true
2334
2335 backup_copy:
2336 driver = manualroute
2337 domains = eximbackup.b8.nz
2338 transport = backup_remote
2339 ignore_target_hosts = ${HOSTNAME}wg.b8.nz
2340 # note changes here also require change in passwd.client
2341 route_list = * eximbackup.b8.nz
2342 same_domain_copy_routing = yes
2343 no_more
2344 EOF
2345
2346
2347 i /etc/exim4/conf.d/transport/30_backup_remote <<'EOF'
2348 backup_remote:
2349 driver = smtp
2350 multi_domain
2351 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
2352 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
2353 .endif
2354 hosts_require_auth = *
2355 hosts_try_auth = *
2356 return_path = alerts@iankelling.org
2357 envelope_to_add
2358 # manual return path because we dont want it to be the envelope sender
2359 # we got not the one we are using in this smtp transport
2360 headers_add = "Return-path: $sender_address"
2361 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2362 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2363 .endif
2364 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2365 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2366 .endif
2367 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2368 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2369 .endif
2370 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
2371 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
2372 .endif
2373 .ifdef REMOTE_SMTP_HEADERS_REWRITE
2374 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
2375 .endif
2376 .ifdef REMOTE_SMTP_HELO_DATA
2377 helo_data=REMOTE_SMTP_HELO_DATA
2378 .endif
2379 .ifdef TLS_DH_MIN_BITS
2380 tls_dh_min_bits = TLS_DH_MIN_BITS
2381 .endif
2382 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2383 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2384 .endif
2385 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2386 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2387 .endif
2388 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2389 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2390 .endif
2391 EOF
2392
2393
2394 # this avoids some error. i cant remember what. todo:
2395 # test it out and document why/if its needed.
2396 i /etc/exim4/host_local_deny_exceptions <<'EOF'
2397 mail.fsf.org
2398 *.posteo.de
2399 EOF
2400
2401 # cron email from smarthost hosts will automatically be to
2402 # USER@FQDN. I redirect that to alerts@, on the smarthosts, but in
2403 # case that doesn't work, we still want to accept that mail, but not
2404 # from any host except the smarthosts. local_hostnames and this rule
2405 # is for that purpose.
2406 i /etc/exim4/conf.d/rcpt_local_acl <<'EOF'
2407 deny
2408 !authenticated = *
2409 domains = +local_hostnames
2410 message = no relay
2411 EOF
2412 echo|i /etc/exim4/conf.d/router/880_universal_forward
2413
2414 # for iank@fsf.org, i have mail.fsf.org forward it to fsf@iankelling.org.
2415 # and also have mail.iankelling.org whitelisted as a relay domain.
2416 # I could avoid that if I changed this to submit to 587 with a
2417 # password like a standard mua.
2418 i /etc/exim4/conf.d/router/188_exim4-config_smarthost <<'EOF'
2419 # ian: copied from /etc/exim4/conf.d/router/200_exim4-config_primary, and added senders = and
2420 # replaced DCsmarthost with hostname
2421 fsfsmarthost:
2422 debug_print = "R: smarthost for $local_part@$domain"
2423 driver = manualroute
2424 domains = ! +local_domains
2425 senders = *@fsf.org
2426 transport = remote_smtp_smarthost
2427 route_list = * mail.fsf.org::587 byname
2428 host_find_failed = ignore
2429 same_domain_copy_routing = yes
2430 no_more
2431
2432 posteosmarthost:
2433 debug_print = "R: smarthost for $local_part@$domain"
2434 driver = manualroute
2435 domains = ! +local_domains
2436 senders = *@posteo.net
2437 transport = remote_smtp_smarthost
2438 route_list = * posteo.de::587 byname
2439 host_find_failed = ignore
2440 same_domain_copy_routing = yes
2441 no_more
2442
2443 EOF
2444
2445 # Greping /etc/exim4, unqualified mails this would end up as
2446 # a return path, so it should go somewhere we will see.
2447 # The debconf output about mailname is as follows:
2448 # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
2449 # name.
2450 # This name will also be used by other programs. It should be the single, fully
2451 # qualified domain name (FQDN).
2452 # Thus, if a mail address on the local host is foo@example.org, the correct value for
2453 # this option would be example.org.
2454 # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
2455 echo iankelling.org > /etc/mailname
2456
2457
2458 # mail.iankelling.org so local imap clients can connect with tls and
2459 # when they happen to not be local.
2460 # todo: this should be 10.8.0.4
2461
2462 /a/exe/cedit nn /etc/hosts <<'EOF' || [[ $? == 1 ]]
2463 # note: i put nn.b8.nz into bind for good measure
2464 10.173.8.2 nn.b8.nz mx.iankelling.org
2465 EOF
2466
2467 # note: systemd-resolved will consult /etc/hosts, dnsmasq wont. this assumes
2468 # weve configured this file in dnsmasq if we are using it.
2469 /a/exe/cedit mail /etc/dnsmasq-servers.conf <<'EOF' || [[ $? == 1 ]]
2470 server=/mx.iankelling.org/127.0.1.1
2471 EOF
2472 # I used to use debconf-set-selections + dpkg-reconfigure,
2473 # which then updates this file
2474 # but the process is slower than updating it directly and then I want to set other things in
2475 # update-exim4.conf.conf, so there's no point.
2476 # The file is documented in man update-exim4.conf,
2477 # except the man page is not perfect, read the bash script to be sure about things.
2478
2479 # The debconf questions output is additional documentation that is not
2480 # easily accessible, but super long, along with the initial default comment in this
2481 # file, so I've saved that into ./mail-notes.conf.
2482 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2483 # man page: is used to build the local_domains list, together with "localhost"
2484 # this is duplicated in a later router.
2485 dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
2486 EOF
2487
2488
2489 # dmarc. not used currently
2490 f=/etc/cron.daily/refresh-dmarc-tld-file
2491 cat >$f <<'EOF'
2492 #!/bin/bash
2493 cd /etc
2494 wget -q -N https://publicsuffix.org/list/public_suffix_list.dat
2495 EOF
2496 m chmod 755 $f
2497
2498 ;;
2499 # ** bk
2500 ## we use this host to monitor MAIL_HOST and host a mail server for someone
2501 bk)
2502
2503 echo|i /etc/exim4/conf.d/rcpt_local_acl
2504 echo|i /etc/exim4/conf.d/router/880_universal_forward
2505
2506 echo amnimal.ninja > /etc/mailname
2507
2508 /a/exe/cedit nn /etc/hosts <<'EOF' || [[ $? == 1 ]]
2509 10.173.8.2 nn.b8.nz
2510 EOF
2511
2512 sed -r -f - /etc/init.d/exim4 <<'EOF' | i /etc/init.d/exim4in
2513 s,/etc/default/exim4,/etc/default/exim4in,g
2514 s,/run/exim4/exim.pid,/run/exim4/eximin.pid,g
2515 s,(^[ #]*Provides:).*,\1 exim4in,
2516 s,(^[ #]*NAME=).*,\1"exim4in",
2517 EOF
2518 chmod +x /etc/init.d/exim4in
2519 i /etc/systemd/system/exim4in.service.d/alwaysrestart.conf <<'EOF'
2520 [Unit]
2521 # needed to continually restart
2522 StartLimitIntervalSec=0
2523
2524 [Service]
2525 Restart=always
2526 # time to sleep before restarting a service
2527 RestartSec=1
2528 EOF
2529
2530 i /etc/default/exim4in <<'EOF'
2531 # defaults but no queue runner and alternate config dir
2532 QUEUERUNNER='no'
2533 COMMONOPTIONS='-oP /run/exim4/eximin.pid'
2534 UPEX4OPTS='-d /etc/myexim4'
2535 EOF
2536
2537 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2538 # man page: is used to build the local_domains list, together with "localhost"
2539 dc_other_hostnames='amnimal.ninja;expertpathologyreview.com'
2540 EOF
2541
2542 ;;
2543 # ** je
2544 je)
2545 echo je.b8.nz > /etc/mailname
2546 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2547 dc_other_hostnames='je.b8.nz'
2548 EOF
2549 echo|i /etc/exim4/conf.d/router/188_exim4-config_smarthost
2550 echo|i /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost
2551 echo|i /etc/exim4/conf.d/rcpt_local_acl
2552 echo|i /etc/exim4/conf.d/router/880_universal_forward
2553 ;;
2554 # ** not MAIL_HOST|bk|je
2555 *)
2556 # this one should be removed for all non mail hosts, but
2557 # bk and je never become mail_host
2558 echo|i /etc/exim4/conf.d/router/195_dnslookup_vpn
2559
2560 echo|i /etc/exim4/conf.d/router/188_exim4-config_smarthost
2561 echo|i /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost
2562 echo|i /etc/exim4/conf.d/rcpt_local_acl
2563 echo|i /etc/exim4/conf.d/router/890_backup_copy
2564 echo|i /etc/exim4/conf.d/main/000_local-nn
2565
2566
2567 if $bhost_t; then
2568 cat >>/etc/exim4/conf.d/main/000_local <<EOF
2569 MAIN_TLS_CERTIFICATE = /etc/exim4/certs/$wghost/fullchain.pem
2570 MAIN_TLS_PRIVATEKEY = /etc/exim4/certs/$wghost/privkey.pem
2571 # so we can maintiain the originals of the backups.
2572 # we wouldnt want this if we were dealing with any other
2573 # local deliveries, but we sent all others to the smarthost
2574 # which then strips the headers.
2575 envelope_to_remove = false
2576 return_path_remove = false
2577 EOF
2578 fi
2579
2580 # catches things like cronjob email
2581 i /etc/exim4/conf.d/router/880_universal_forward <<'EOF'
2582 universal_forward:
2583 driver = redirect
2584 domains = +local_domains
2585 data = alerts@iankelling.org
2586 EOF
2587
2588
2589 for unit in ${nn_progs[@]}; do
2590 f=/etc/systemd/system/$unit.service.d/nn.conf
2591 rm -fv $f
2592 done
2593
2594 # dont i dont care if defaultnn section gets left, it wont
2595 # get used.
2596 echo | /a/exe/cedit nn /etc/hosts || [[ $? == 1 ]]
2597 echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]]
2598
2599 if $bhost_t; then
2600 i /etc/exim4/conf.d/transport/30_backup_maildir <<EOF
2601 # modified debian maildir transport
2602 backup_maildir:
2603 driver = appendfile
2604 directory = /bu/md
2605 delivery_date_add
2606 # note, no return path or envelope added
2607 maildir_format
2608 directory_mode = 0700
2609 mode = 0644
2610 mode_fail_narrower = false
2611 user = $u
2612 EOF
2613
2614 i /etc/exim4/conf.d/router/870_backup_local <<EOF
2615 ### router/900_exim4-config_local_user
2616 #################################
2617
2618 backup_local:
2619 debug_print = "R: local_user for \$local_part@\$domain"
2620 driver = accept
2621 domains = eximbackup.b8.nz
2622 transport = backup_maildir
2623 EOF
2624
2625 wgholeip=$(sed -rn 's/^ *Address *= *([^/]+).*/\1/p' /etc/wireguard/wghole.conf)
2626 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2627 dc_other_hostnames='eximbackup.b8.nz'
2628 dc_local_interfaces='127.0.0.1;::1;$wgholeip'
2629
2630 EOF
2631 else
2632 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2633 # Note: If theres like a temporary problem where mail gets sent to
2634 # one of these hosts, if exim isnt listening, it will be a temporary error
2635 # instead of a permanent 5xx.
2636 dc_local_interfaces='127.0.0.1;::1'
2637 EOF
2638 fi
2639 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2640 dc_eximconfig_configtype='smarthost'
2641 dc_smarthost='$smarthost'
2642 EOF
2643
2644 hostname -f |i /etc/mailname
2645 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2646 # The manpage incorrectly states this will do header rewriting, but
2647 # that only happens if we have dc_hide_mailname is set.
2648 dc_readhost='iankelling.org'
2649 # Only used in case of bounces.
2650 dc_localdelivery='maildir_home'
2651 EOF
2652 ;;
2653 esac
2654
2655
2656
2657
2658 # ** $MAILHOST|bk, things that belong at the end
2659 case $HOSTNAME in
2660 $MAIL_HOST|bk)
2661 # config for the non-nn exim
2662 m rsync -ra --delete /etc/exim4/ /etc/myexim4
2663 cat >>/etc/myexim4/update-exim4.conf.conf <<'EOF'
2664 dc_eximconfig_configtype='smarthost'
2665 dc_smarthost='nn.b8.nz'
2666 EOF
2667 ;;&
2668 bk)
2669
2670 # config for the non-nn exim
2671 cat >/etc/myexim4/conf.d/main/000_local-nn <<'EOF'
2672 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail2.iankelling.org
2673 EOF
2674 ;;
2675 $MAIL_HOST)
2676 # for bk, we have a exim4in.service that will do this for us.
2677 m update-exim4.conf -d /etc/myexim4
2678 ;;
2679 esac
2680
2681 # * spool dir setup
2682
2683 # ** bind mount setup
2684 # put spool dir in directory that spans multiple distros.
2685 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
2686 #
2687 dir=/nocow/exim4
2688 sdir=/var/spool/exim4
2689 # we only do this if our system has $dir
2690
2691 # this used to do a symlink, but, in the boot logs, /nocow would get mounted succesfully,
2692 # about 2 seconds later, exim starts, and immediately puts into paniclog:
2693 # honVi-0000u3-82 Failed to create directory "/var/spool/exim4/input": No such file or directory
2694 # so, im trying a bind mount to get rid of that.
2695 if [[ -e /nocow ]]; then
2696 if ! grep -Fx "/nocow/exim4 /var/spool/exim4 none bind 0 0" /etc/fstab; then
2697 echo "/nocow/exim4 /var/spool/exim4 none bind 0 0" >>/etc/fstab
2698 fi
2699 i /etc/systemd/system/exim4.service.d/override.conf <<'EOF'
2700 [Unit]
2701 # without local-fs on exim, we get these kind of errors in paniclog on shutdown:
2702 # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
2703 After=local-fs.target
2704 EOF
2705 if ! mountpoint -q $sdir; then
2706 stopifactive exim4 exim4in
2707 if [[ -L $sdir ]]; then
2708 m rm $sdir
2709 fi
2710 if [[ ! -e $dir && -d $sdir ]]; then
2711 m mv $sdir $dir
2712 fi
2713 if [[ ! -d $sdir ]]; then
2714 m mkdir $sdir
2715 m chmod 000 $sdir # only want it to be used when its mounted
2716 fi
2717 m mount $sdir
2718 fi
2719 fi
2720
2721
2722
2723 # ** exim/spool uid setup
2724 # i have the spool directory be common to distro multi-boot, so
2725 # we need the uid to be the same. 608 cuz it's kind of in the middle
2726 # of the free system uids.
2727 IFS=:; read -r _ _ uid _ < <(getent passwd Debian-exim ||:) ||:; unset IFS
2728 IFS=:; read -r _ _ gid _ < <(getent group Debian-exim ||:) ||:; unset IFS
2729 if [[ ! $uid ]]; then
2730 # from /var/lib/dpkg/info/exim4-base.postinst, plus uid and gid options
2731 m adduser --uid 608 --system --group --quiet --home /var/spool/exim4 \
2732 --no-create-home --disabled-login --force-badname Debian-exim
2733 elif [[ $uid != 608 ]]; then
2734 stopifactive exim4 exim4in
2735 m usermod -u 608 Debian-exim
2736 m groupmod -g 608 Debian-exim
2737 m usermod -g 608 Debian-exim
2738 m find / /nocow -path ./var/tmp -prune -o -xdev -uid $uid -execdir chown -h 608 {} +
2739 m find / /nocow -path ./var/tmp -prune -o -xdev -gid $gid -execdir chgrp -h 608 {} +
2740 fi
2741
2742 # * start / stop services
2743
2744 reifactive dnsmasq nscd
2745
2746 if $reload; then
2747 m systemctl daemon-reload
2748 fi
2749
2750 sstart epanicclean.timer
2751
2752 case $HOSTNAME in
2753 je)
2754 /a/exe/web-conf apache2 je.b8.nz
2755 ;;
2756 bk)
2757 /a/exe/web-conf apache2 mail2.iankelling.org
2758 ;;
2759 esac
2760
2761 m /a/bin/ds/mail-cert-cron -1
2762 sre mailcert.timer
2763
2764 case $HOSTNAME in
2765 bk)
2766 # todo, this should be done in distro-begin
2767 soff systemd-resolved
2768 ln -sf 127.0.0.1-resolv/stub-resolv.conf /etc/resolv.conf
2769 ;;&
2770 $MAIL_HOST|bk)
2771 sstart mailnn mailnnroute
2772 ;;&
2773 $MAIL_HOST)
2774 # we use dns to start wg
2775 if $reload; then
2776 sre unbound
2777 else
2778 sstart unbound
2779 fi
2780 ;;&
2781 $MAIL_HOST|bk)
2782 # If these have changes, id rather manually restart it, id rather
2783 # not restart and cause temporary errors
2784 if $reload; then
2785 sre $vpnser
2786 else
2787 sstart $vpnser
2788 fi
2789 if ! systemctl is-active clamav-daemon >/dev/null; then
2790 sstart clamav-daemon
2791 out=$(rsync -aiSAX --chown=root:root --chmod=g-s /a/bin/ds/filesystem/etc/systemd/system/epanicclean.{timer,service} /etc/systemd/system)
2792 if [[ $out ]]; then
2793 reload=true
2794 fi
2795
2796 # note, this will cause paniclog entries because it takes like 45
2797 # seconds for clamav to start, i use ./epanic-clean to remove
2798 # them.
2799 fi
2800 ;;&
2801 $MAIL_HOST|bk|je)
2802 # start spamassassin/dovecot before exim.
2803 sre dovecot spamassassin
2804 # need to wait a bit before restarting exim, else I
2805 # get a paniclog entry like: spam acl condition: all spamd servers failed
2806 sleep 3
2807 sstart mailclean.timer
2808 ;;&
2809 $MAIL_HOST)
2810 # < 2.1 (eg: in t9), uses a different data format which required manual
2811 # migration. dont start if we are running an old version.
2812 if dpkg --compare-versions $(dpkg -s radicale | awk '$1 == "Version:" { print $2 }') ge 2.1; then
2813 sstart radicale
2814 fi
2815 ;;&
2816 esac
2817
2818 # last use of $reload happens in previous block
2819 rm -f /var/local/mail-setup-reload
2820
2821
2822 case $HOSTNAME in
2823 $MAIL_HOST|bk|je) : ;;
2824 *)
2825 soff radicale mailclean.timer dovecot spamassassin $vpnser mailnn clamav-daemon
2826 ;;
2827 esac
2828
2829 sre exim4
2830
2831 case $HOSTNAME in
2832 bk) sre exim4in ;;
2833 esac
2834
2835 # * mail monitoring / testing
2836
2837 # note, to test clamav, send an email with body that only contains
2838 # https://en.wikipedia.org/wiki/EICAR_test_file
2839 # which set malware_name to Eicar-Signature
2840 case $HOSTNAME in
2841 $MAIL_HOST|bk|je)
2842 # note: cronjob "ian" also does some important monitoring
2843 # todo: this will sometimes cause an alert because mailtest-check will run
2844 # before we have setup network namespace and spamassassin
2845 cat >/etc/cron.d/mailtest <<EOF
2846 SHELL=/bin/bash
2847 PATH=/usr/bin:/bin:/usr/local/bin
2848 MAILTO=alerts@iankelling.org
2849 */5 * * * * $u send-test-forward |& log-once send-test-forward
2850 */10 * * * * root chmod -R g+rw /m/md/bounces |& log-once -1 bounces-chmod
2851 # im seeing some intermittent failures on the slow check, do it all the time
2852 # for now. It looks like a dns failure.
2853 #5-59/5 * * * * root mailtest-check |& log-once -1 mailtest-check
2854 #0 * * * * root mailtest-check slow |& log-once -1 mailtest-slow
2855 */5 * * * * root timeout 290 mailtest-check slow |& log-once -12 mailtest-check
2856 EOF
2857 m sudo rsync -ahhi --chown=root:root --chmod=0755 \
2858 /b/ds/mailtest-check /b/ds/check-remote-mailqs /usr/local/bin/
2859 ;;&
2860 $MAIL_HOST)
2861 test_froms=(ian@iankelling.org z@zroe.org iank@gnu.org)
2862 test_to="testignore@expertpathologyreview.com, testignore@je.b8.nz, testignore@amnimal.ninja, jtuttle@gnu.org"
2863
2864 cat >>/etc/cron.d/mailtest <<EOF
2865 2 * * * * $u check-remote-mailqs |& log-once check-remote-mailqs
2866 EOF
2867 ;;&
2868 bk)
2869 test_froms=(testignore@expertpathologyreview.com testignore@amnimal.ninja)
2870 test_to="testignore@iankelling.org, testignore@zroe.org, testignore@je.b8.nz"
2871 ;;&
2872 je)
2873 test_froms=(testignore@je.b8.nz)
2874 test_to="testignore@iankelling.org, testignore@zroe.org, testignore@expertpathologyreview.com, testignore@amnimal.ninja"
2875 ;;&
2876 $MAIL_HOST|bk|je)
2877 cat >/usr/local/bin/send-test-forward <<'EOF'
2878 #!/bin/bash
2879 olds=(
2880 /sbin/exiqgrep -o 260 -i -r '^(testignore@(iankelling\.org|zroe\.org|expertpathologyreview\.com|amnimal\.ninja|je\.b8\.nz)|jtuttle@gnu\.org)$')
2881 if (( ${#olds[@]} )); then
2882 /sbin/exim -Mrm "${olds[@]}" >/dev/null
2883 fi
2884 EOF
2885 for test_from in ${test_froms[@]}; do
2886 cat >>/usr/local/bin/send-test-forward <<EOFOUTER
2887 /usr/sbin/exim -f $test_from -t <<EOF
2888 From: $test_from
2889 To: $test_to
2890 Subject: test \$(date +%Y-%m-%dT%H:%M:%S%z) \$(date +%s)
2891
2892 /usr/local/bin/send-test-forward
2893 EOF
2894 EOFOUTER
2895 done
2896 m chmod +x /usr/local/bin/send-test-forward
2897 ;;
2898 *)
2899 rm -fv /etc/cron.d/mailtest
2900 ;;
2901 esac
2902
2903
2904
2905 # * misc
2906 m sudo -u $u mkdir -p /home/$u/.cache
2907 set -- /m/mucache /home/$u/.cache/mu /m/.mu /home/$u/.mu
2908 while (($#)); do
2909 target=$1
2910 f=$2
2911 shift 2
2912 if [[ ! -L $f ]]; then
2913 if [[ -e $f ]]; then
2914 rm -rf $f
2915 fi
2916 m sudo -u $u ln -sf -T $target $f
2917 fi
2918 done
2919
2920
2921 # /etc/alias setup is debian specific, and exim postinst script sets up
2922 # an /etc/alias from root to the postmaster, based on the question
2923 # exim4-config exim4/dc_postmaster, as long as there exists an entry for
2924 # root, or there was no preexisting aliases file. postfix won\'t set up
2925 # a root to $postmaster alias if it\'s already installed. Easiest to
2926 # just set it ourselves.
2927
2928 # debconf question for postmaster:
2929 # Mail for the 'postmaster', 'root', and other system accounts needs to be redirected
2930 # to the user account of the actual system administrator.
2931 # If this value is left empty, such mail will be saved in /var/mail/mail, which is not
2932 # recommended.
2933 # Note that postmaster\'s mail should be read on the system to which it is directed,
2934 # rather than being forwarded elsewhere, so (at least one of) the users listed here
2935 # should not redirect their mail off this machine. A 'real-' prefix can be used to
2936 # force local delivery.
2937 # Multiple user names need to be separated by spaces.
2938 # Root and postmaster mail recipient:
2939
2940 m exit 0
2941 :
2942
2943 # Local Variables:
2944 # eval: (outline-minor-mode)
2945 # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
2946 # End:
2947 # this is combined with defining outline-level in init.el