Instalace dobře fungujícího a řádně zabezpečeného poštovního serveru není triviální úloha.
Zde je popis instalace mailserveru na OpenBSD od A do Z: opensmtpd, dovecot, rspamd, relayd, webmail Roundcube.
Zde popsaný postup instalace a konfigurace je vyzkoušen na OpenBSD 7.9. OpenBSD 8.0 má jinou verzi Roundcube, kterou ještě pořádně neumím.
Plánování a DNS
Mailserver nebude instalován jako první, ale jako druhý, který se po přetažení dat ze starého mailserveru stane prvním a potom bude starý mailserver odstaven.
Instalace OpenBSD proběhne do virtuálu s diskem 500G, rozdělení disku asi takto:
$ doas disklabel -p G sd0)# /dev/rsd0c:
type: SCSI
disk: SCSI disk
label: QEMU HARDDISK
duid: 55292983127fd195
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 65270
total sectors: 1048576000 # total bytes: 500.0G
boundstart: 64
boundend: 1048576000
16 partitions:
# size offset fstype [fsize bsize cpg]
a: 1.0G 64 4.2BSD 2048 16384 12960 # /
b: 4.2G 2097216 swap # none
c: 500.0G 0 unused
d: 4.0G 10977088 4.2BSD 2048 16384 12960 # /tmp
e: 40.0G 19365664 4.2BSD 2048 16384 12960 # /var
f: 30.0G 103265792 4.2BSD 2048 16384 12960 # /usr
g: 1.0G 166192416 4.2BSD 2048 16384 12960 # /usr/X11R6
h: 20.0G 168296928 4.2BSD 2048 16384 12960 # /usr/local
i: 5.0G 210242624 4.2BSD 2048 16384 12960 # /usr/src
j: 10.0G 220733088 4.2BSD 2048 16384 12960 # /usr/obj
k: 384.7G 241713984 4.2BSD 4096 32768 26062 # /home
Do DNS budeme potřebovat udělat záznamy typu A, AAAA, MX a TXT záznamy pro SPF, DKIM a DMARC.
mx2.billcom.cz. IN A 46.253.96.226
mx2.billcom.cz. IN AAAA 2a0e:5340:4:400::5001
; zatím druhý MX (1)
billcom.cz. IN MX 20 mx2.billcom.cz.
| 1 | první MX je groupware.billcom.cz (billcom.cz. IN MX 1 groupware.billcom.cz) |
Po instalaci systému
Instalace OpenBSD je standardní, IP adresy se nastavují pevné, rozdělení disku je uvedeno výše.
Vedle roota si vytvořím uživatele jirka, který bude spravovat systém pomocí doas.
Nastaveni doas
permit persist :wheel as root
permit nopass jirka as root
Software co potřebuji
pkg_add htop mc nano wget rsync
Nastavení sshd
Rootovi a jirkovi nahraju do ~/.ssh/authorized_keys veřejný ssh klíč a zakážu přihlašování roota heslem
#LoginGraceTime 2m
PermitRootLogin prohibit-password
#StrictModes yes
doas rcctl restart sshd
Úpravy profilu
# $OpenBSD: dot.profile,v 1.8 2022/08/10 07:40:37 tb Exp $
#
# sh/ksh initialization
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
HISTFILE=~/.sh_history
export PATH HOME TERM HISTFILE
LANG=cs_CZ.UTF-8
export LANG
Vystavení certifikátů pro server
Nakonfiguruji web server httpd a acme-client. DNS záznamy již v zóně jsou.
Certifikát bude používat jak smtpd, tak httpd, dovecot, relayd
#
# $OpenBSD: acme-client.conf,v 1.6 2025/08/18 15:51:57 job Exp $
#
authority letsencrypt {
api url "https://acme-v02.api.letsencrypt.org/directory"
account key "/etc/acme/letsencrypt-privkey.pem"
}
authority letsencrypt-staging {
api url "https://acme-staging-v02.api.letsencrypt.org/directory"
account key "/etc/acme/letsencrypt-staging-privkey.pem"
}
domain mx2.billcom.cz {
# alternative names { secure.mx2.billcom.cz }
domain key "/etc/ssl/private/mx2.billcom.cz.key"
domain certificate "/etc/ssl/mx2.billcom.cz.crt"
domain full chain certificate "/etc/ssl/mx2.billcom.cz.fullchain.pem"
# Test with the staging server to avoid aggressive rate-limiting.
#sign with letsencrypt-staging
sign with letsencrypt
}
Zatím nemám vystavené certifikáty, tudíž bez zakomentované https části.
# $OpenBSD: httpd.conf,v 1.23 2025/02/21 10:19:52 mbuhl Exp $
server "mx2.billcom.cz" {
listen on * port 80
location "/.well-known/acme-challenge/*" {
root "/acme"
request strip 2
}
location * {
block return 302 "https://$HTTP_HOST$REQUEST_URI"
}
}
#server "mx2.billcom.cz" {
# listen on * tls port 443
# tls {
# certificate "/etc/ssl/mx2.billcom.cz.fullchain.pem"
# key "/etc/ssl/private/mx2.billcom.cz.key"
# }
# location "/.well-known/acme-challenge/*" {
# root "/acme"
# request strip 2
# }
# location "/pub/*" {
# directory auto index
# }
#}
doas httpd -n (1)
doas rcctl enable httpd (2)
doas rcctl start httpd (3)
doas acme-client -v mx2.billcom.cz (4)
| 1 | Test správnosti konfigurace |
| 2 | Nastavení, aby httpd automaticky staroval po startu operačního systému |
| 3 | Spuštění httpd serveru |
| 4 | Vystavení a podepsání certifikátu |
Pokud se vše podařilo, upravím konfiguraci httpd. Šifrovaný web je odkomentovaný.
# $OpenBSD: httpd.conf,v 1.23 2025/02/21 10:19:52 mbuhl Exp $
server "mx2.billcom.cz" {
listen on * port 80
location "/.well-known/acme-challenge/*" {
root "/acme"
request strip 2
}
location * {
block return 302 "https://$HTTP_HOST$REQUEST_URI"
}
}
server "mx2.billcom.cz" {
listen on * tls port 443
tls {
certificate "/etc/ssl/mx2.billcom.cz.fullchain.pem"
key "/etc/ssl/private/mx2.billcom.cz.key"
}
location "/.well-known/acme-challenge/*" {
root "/acme"
request strip 2
}
location "/pub/*" {
directory auto index
}
}
Skript pro automatickou odnovu certifikátu
#!/bin/sh
acme-client -v mx2.billcom.cz
if [ $? == 0 ]; then
rcctl reload httpd
rcctl restart dovecot
rcctl restart smtpd
rcctl restart relayd
fi
doas chmod a+x /root/bin/certifikat.sh
Do crontabu umístím spouštění obnovy certifikátu
doas crontab -e
#
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute hour mday month wday [flags] command
#
# rotate log files every hour, if necessary
0 * * * * /usr/bin/newsyslog
# send log file notifications, if necessary
#1-59 * * * * /usr/bin/newsyslog -m
#
# do daily/weekly/monthly maintenance
30 1 * * * /bin/sh /etc/daily
30 3 * * 6 /bin/sh /etc/weekly
30 5 1 * * /bin/sh /etc/monthly
~ * * * * /root/bin/certifikat.sh
Software pro poštu
doas pkg_add sqlite
doas pkg_add rspamd
doas pkg_add opensmtpd-filter-rspamd
#doas pkg_add opensmtpd-extras
doas pkg_add opensmtpd-filter-dkimsign
doas pkg_add opensmtpd-filter-dnsbl
doas pkg_add opensmtpd-filter-senderscore
doas pkg_add dovecot
doas pkg_add dovecot-pigeonhole
doas pkg_add php
doas pkg_add mariadb-server php-pdo_mysql
doas pkg_add php-curl
doas pkg_add php-intl
doas pkg_add php-gd
doas pkg_add php-zip
doas pkg_add pecl84-imagick
doas pkg_add roundcubemail
Konfigurace smtpd
Úpravy aliasů
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# $OpenBSD: aliases,v 1.73 2025/08/05 19:06:49 sobrado Exp $
#
# Aliases in this file will NOT be expanded in the header from
# Mail, but WILL be visible over networks or from /usr/libexec/mail.local.
#
# >>>>>>>>>> The program "newaliases" must be run after
# >> NOTE >> this file is updated for any changes to
# >>>>>>>>>> show through to smtpd.
#
# Basic system aliases -- these MUST be present
MAILER-DAEMON: postmaster
postmaster: jirka (1)
# General redirections for important pseudo accounts
daemon: jirka (1)
ftp-bugs: jirka (1)
operator: jirka (1)
www: jirka (1)
# Redirections for pseudo accounts that should not receive mail
_bgpd: /dev/null
_bgplgd: /dev/null
_dhcp: /dev/null
_dpb: /dev/null
_dvmrpd: /dev/null
_eigrpd: /dev/null
_fc-cache: /dev/null
_file: /dev/null
_fingerd: /dev/null
_ftp: /dev/null
_hostapd: /dev/null
_identd: /dev/null
_iked: /dev/null
_isakmpd: /dev/null
_iscsid: /dev/null
_ldapd: /dev/null
_ldpd: /dev/null
_lldpd: /dev/null
_mopd: /dev/null
_nsd: /dev/null
_ntp: /dev/null
_ospfd: /dev/null
_ospf6d: /dev/null
_pbuild: /dev/null
_pfetch: /dev/null
_pflogd: /dev/null
_ping: /dev/null
_pkgfetch: /dev/null
_pkguntar: /dev/null
_portmap: /dev/null
_ppp: /dev/null
_rad: /dev/null
_radiusd: /dev/null
_rbootd: /dev/null
_relayd: /dev/null
_ripd: /dev/null
_rstatd: /dev/null
_rusersd: /dev/null
_rwalld: /dev/null
_smtpd: /dev/null
_smtpq: /dev/null
_sndio: /dev/null
_snmpd: /dev/null
_spamd: /dev/null
_syslogd: /dev/null
_tcpdump: /dev/null
_traceroute: /dev/null
_tftpd: /dev/null
_unbound: /dev/null
_unwind: /dev/null
_vmd: /dev/null
_x11: /dev/null
_ypldap: /dev/null
bin: /dev/null
build: /dev/null
nobody: /dev/null
_tftp_proxy: /dev/null
_ftp_proxy: /dev/null
_sndiop: /dev/null
_syspatch: /dev/null
_slaacd: /dev/null
sshd: /dev/null
# Well-known aliases -- these should be filled in!
# root:
# manager:
# dumper:
# RFC 2142: NETWORK OPERATIONS MAILBOX NAMES
abuse: jirka (1)
# noc: root
security: jirka (1)
# RFC 2142: SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES
# hostmaster: root
# usenet: root
# news: usenet
# webmaster: root
# ftp: root
| 1 | Zde jsou změny, důležité maily bude dostávat jirka. |
Připravím si podepisovací klíč do DKIM
#!/bin/sh
NAME="billcom.cz"
openssl genrsa -out /etc/mail/dkim/$NAME.key 1024
openssl rsa -in /etc/mail/dkim/$NAME.key -pubout -out /etc/mail/dkim/$NAME.pub
openssl rsa -in /etc/mail/dkim/$NAME.key -pubout | sed '1s/.*/v=DKIM1;k=ŕsa;p=/;:nl;${s/-----.*//;q;};N;s/\\n//g;b nl;' >dkim-$NAME.pubmail
doas mkdir /etc/mail/dkim
doas ./dkim-klic.sh
Generating RSA private key, 1024 bit long modulus
...............
e is 65537 (0x010001)
writing RSA key
writing RSA key
doas chown -R _dkimsign:_rspamd /etc/mail/dkim
Veřejný DKIM klíč musím nahrát do DNS
v=DKIM1;k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6JnuNpY46PQE+MChC7mXvM8bDdufPSTSgrlNBW5jBK5fFg0iVtIvKjCNKn9+BBZdkXaFvY+TYeefQOtcjaXifxTVzfBY69jP4cq+1Dwo/sySvG4yMz/jfFTlGK8LE0qVDC3WB2IOlt6vZjqYvaoBugsmOYKC8dErlCeuurgUqVwIDAQAB
Bude v TXT záznamu default._domainkey
default._domainkey.billcom.cz. IN TXT veřejný klíč
Konfigurační soubor pro smptd
# klice
pki mx2.billcom.cz cert "/etc/ssl/mx2.billcom.cz.fullchain.pem"
pki mx2.billcom.cz key "/etc/ssl/private/mx2.billcom.cz.key"
table aliases file:/etc/mail/aliases
smtp max-message-size 50M
# filtry
filter check_dyndns phase connect match rdns regex { '.*\.dyn\..', '.*\.dsl\..*' } disconnect "550 no residential connections"
filter check_rdns phase connect match !rdns junk
filter check_fcrdns phase connect match !fcrdns junk
filter senderscore proc-exec "filter-senderscore -blockBelow 10 -junkBelow 70 -slowFactor 5000"
filter rspamd proc-exec "filter-rspamd"
filter dkimsign proc-exec "filter-dkimsign -d billcom.cz -s default -k /etc/mail/dkim/billcom.cz.key" user _dkimsign group _rspamd
listen on lo0 filter dkimsign
listen on em0 tls pki mx2.billcom.cz filter { check_dyndns, check_rdns, check_fcrdns, senderscore, rspamd }
listen on em0 port submission tls-require pki mx2.billcom.cz auth filter rspamd
listen on em0 smtps pki mx2.billcom.cz auth filter rspamd
action "local_mail" maildir junk alias <aliases>
action "outbound" relay helo mx2.billcom.cz
match from any for domain "billcom.cz" action "local_mail"
match for local action "local_mail"
match from any auth for any action "outbound"
match for any action "outbound"
doas smtpd -n
doas rcctl restart smtpd
Pokud jsou problémy s konfigurací, tak je lze zjistit z logu:
tail -f /var/log/maillog
openssl s_client -connect mx2.billcom.cz:465
openssl s_client -connect mx2.billcom.cz:587 -starttls smtp
Konfigurace dovecota
Generování Diffie Hellmanova klíče (trvá poměrně dlouho)
doas openssl dhparam -out /etc/dovecot/dh.pem 4096
Konfigurační soubory dovecota jsou rozsáhlé, proto budu zobrazovat jenom změny.
# odstranit doménu z uživatele
auth_username_format = %Lu
ssl = yes
ssl_cert = </etc/ssl/mx2.billcom.cz.crt
ssl_key = </etc/ssl/private/mx2.billcom.cz.key
ssl_dh = </etc/dovecot/dh.pem
ssl_min_protocol = TLSv1.2
Dovecot bude automaticky vytvářet složky Sent, Thrash, Drafts a Junk.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
##
## Mailbox locations and namespaces
##
# Location for users' mailboxes. The default is empty, which means that Dovecot
# tries to find the mailboxes automatically. This won't work if the user
# doesn't yet have any mail, so you should explicitly tell Dovecot the full
# location.
#
# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn't enough. You'll also need to tell Dovecot where the other mailboxes are
# kept. This is called the "root mail directory", and it must be the first
# path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if there's no domain
# %h - home directory
#
# See doc/wiki/Variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
#mail_location =
# If you need to set multiple mailbox locations or want to change default
# namespace settings, you can do it by defining namespace sections.
#
# You can have private, shared and public namespaces. Private namespaces
# are for user's personal mails. Shared namespaces are for accessing other
# users' mailboxes that have been shared. Public namespaces are for shared
# mailboxes that are managed by sysadmin. If you create any shared or public
# namespaces you'll typically want to enable ACL plugin also, otherwise all
# users can access all the shared mailboxes, assuming they have permissions
# on filesystem level to do so.
namespace inbox {
# Namespace type: private, shared or public
#type = private
# Hierarchy separator to use. You should use the same separator for all
# namespaces or some clients get confused. '/' is usually a good one.
# The default however depends on the underlying mail storage format.
#separator =
# Prefix required to access this namespace. This needs to be different for
# all namespaces. For example "Public/".
#prefix =
# Physical location of the mailbox. This is in same format as
# mail_location, which is also the default for it.
#location =
# There can be only one INBOX, and this setting defines which namespace
# has it.
inbox = yes
# If namespace is hidden, it's not advertised to clients via NAMESPACE
# extension. You'll most likely also want to set list=no. This is mostly
# useful when converting from another server with different namespaces which
# you want to deprecate but still keep working. For example you can create
# hidden namespaces with prefixes "~/mail/", "~%u/mail/" and "mail/".
#hidden = no
# Show the mailboxes under this namespace with LIST command. This makes the
# namespace visible for clients that don't support NAMESPACE extension.
# "children" value lists child mailboxes, but hides the namespace prefix.
#list = yes
# Namespace handles its own subscriptions. If set to "no", the parent
# namespace handles them (empty prefix should always have this as "yes")
#subscriptions = yes
# See 15-mailboxes.conf for definitions of special mailboxes. (1)
mailbox Trash {
auto = create
special_use = \Thrash
autoexpunge = 14d
}
mailbox Drafts {
auto = subscribe
special_use = \Drafts
}
mailbox Sent {
auto = subscribe
special_use = \Sent
}
mailbox Junk {
auto = subscribe
special_use = \Junk
autoexpunge = 14d
}
}
# Example shared namespace configuration
#namespace {
#type = shared
#separator = /
# Mailboxes are visible under "shared/user@domain/"
# %%n, %%d and %%u are expanded to the destination user.
#prefix = shared/%%u/
# Mail location for other users' mailboxes. Note that %variables and ~/
# expands to the logged in user's data. %%n, %%d, %%u and %%h expand to the
# destination user's data.
#location = maildir:%%h/Maildir:INDEX=~/Maildir/shared/%%u
# Use the default namespace for saving subscriptions.
#subscriptions = no
# List the shared/ namespace only if there are visible shared mailboxes.
#list = children
#}
# Should shared INBOX be visible as "shared/user" or "shared/user/INBOX"?
#mail_shared_explicit_inbox = no
# System user and group used to access mails. If you use multiple, userdb
# can override these by returning uid or gid fields. You can use either numbers
# or names. <doc/wiki/UserIds.txt>
#mail_uid =
#mail_gid =
# Group to enable temporarily for privileged operations. Currently this is
# used only with INBOX when either its initial creation or dotlocking fails.
# Typically this is set to "mail" to give access to /var/mail.
#mail_privileged_group =
# Grant access to these supplementary groups for mail processes. Typically
# these are used to set up access to shared mailboxes. Note that it may be
# dangerous to set these if users can create symlinks (e.g. if "mail" group is
# set here, ln -s /var/mail ~/mail/var could allow a user to delete others'
# mailboxes, or ln -s /secret/shared/box ~/mail/mybox would allow reading it).
#mail_access_groups =
# Allow full filesystem access to clients. There's no access checks other than
# what the operating system does for the active UID/GID. It works with both
# maildir and mboxes, allowing you to prefix mailboxes names with eg. /path/
# or ~user/.
#mail_full_filesystem_access = no
# Dictionary for key=value mailbox attributes. This is used for example by
# URLAUTH and METADATA extensions.
#mail_attribute_dict =
# A comment or note that is associated with the server. This value is
# accessible for authenticated users through the IMAP METADATA server
# entry "/shared/comment".
#mail_server_comment = ""
# Indicates a method for contacting the server administrator. According to
# RFC 5464, this value MUST be a URI (e.g., a mailto: or tel: URL), but that
# is currently not enforced. Use for example mailto:admin@example.com. This
# value is accessible for authenticated users through the IMAP METADATA server
# entry "/shared/admin".
#mail_server_admin =
##
## Mail processes
##
# Don't use mmap() at all. This is required if you store indexes to shared
# filesystems (NFS or clustered filesystem) or for some operating systems
# which use a separate cache for mmap, such as OpenBSD.
mmap_disable = yes
# Rely on O_EXCL to work when creating dotlock files. NFS supports O_EXCL
# since version 3, so this should be safe to use nowadays by default.
#dotlock_use_excl = yes
# When to use fsync() or fdatasync() calls:
# optimized (default): Whenever necessary to avoid losing important data
# always: Useful with e.g. NFS when write()s are delayed
# never: Never use it (best performance, but crashes can lose data)
#mail_fsync = optimized
# Locking method for index files. Alternatives are fcntl, flock and dotlock.
# Dotlocking uses some tricks which may create more disk I/O than other locking
# methods. NFS users: flock doesn't work, remember to change mmap_disable.
#lock_method = fcntl
# Directory where mails can be temporarily stored. Usually it's used only for
# mails larger than >= 128 kB. It's used by various parts of Dovecot, for
# example LDA/LMTP while delivering large mails or zlib plugin for keeping
# uncompressed mails.
#mail_temp_dir = /tmp
# Valid UID range for users, defaults to 500 and above. This is mostly
# to make sure that users can't log in as daemons or other system users.
# Note that denying root logins is hardcoded to dovecot binary and can't
# be done even if first_valid_uid is set to 0.
first_valid_uid = 1000
#last_valid_uid = 0
# Valid GID range for users, defaults to non-root/wheel. Users having
# non-valid GID as primary group ID aren't allowed to log in. If user
# belongs to supplementary groups with non-valid GIDs, those groups are
# not set.
#first_valid_gid = 1
#last_valid_gid = 0
# Maximum allowed length for mail keyword name. It's only forced when trying
# to create new keywords.
#mail_max_keyword_length = 50
# ':' separated list of directories under which chrooting is allowed for mail
# processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too).
# This setting doesn't affect login_chroot, mail_chroot or auth chroot
# settings. If this setting is empty, "/./" in home dirs are ignored.
# WARNING: Never add directories here which local users can modify, that
# may lead to root exploit. Usually this should be done only if you don't
# allow shell access for users. <doc/wiki/Chrooting.txt>
#valid_chroot_dirs =
# Default chroot directory for mail processes. This can be overridden for
# specific users in user database by giving /./ in user's home directory
# (eg. /home/./user chroots into /home). Note that usually there is no real
# need to do chrooting, Dovecot doesn't allow users to access files outside
# their mail directory anyway. If your home directories are prefixed with
# the chroot directory, append "/." to mail_chroot. <doc/wiki/Chrooting.txt>
#mail_chroot =
# UNIX socket path to master authentication server to find users.
# This is used by imap (for shared users) and lda.
#auth_socket_path = /var/dovecot/auth-userdb
# Directory where to look up mail plugins.
mail_plugin_dir = /usr/local/lib/dovecot
# Space separated list of plugins to load for all services. Plugins specific to
# IMAP, LDA, etc. are added to this list in their own .conf files.
#mail_plugins =
##
## Mailbox handling optimizations
##
# Mailbox list indexes can be used to optimize IMAP STATUS commands. They are
# also required for IMAP NOTIFY extension to be enabled.
#mailbox_list_index = yes
# Trust mailbox list index to be up-to-date. This reduces disk I/O at the cost
# of potentially returning out-of-date results after e.g. server crashes.
# The results will be automatically fixed once the folders are opened.
#mailbox_list_index_very_dirty_syncs = yes
# Should INBOX be kept up-to-date in the mailbox list index? By default it's
# not, because most of the mailbox accesses will open INBOX anyway.
#mailbox_list_index_include_inbox = no
# The minimum number of mails in a mailbox before updates are done to cache
# file. This allows optimizing Dovecot's behavior to do less disk writes at
# the cost of more disk reads.
#mail_cache_min_mail_count = 0
# When IDLE command is running, mailbox is checked once in a while to see if
# there are any new mails or other changes. This setting defines the minimum
# time to wait between those checks. Dovecot can also use inotify and
# kqueue to find out immediately when changes occur.
#mailbox_idle_check_interval = 30 secs
# Save mails with CR+LF instead of plain LF. This makes sending those mails
# take less CPU, especially with sendfile() syscall with Linux and FreeBSD.
# But it also creates a bit more disk I/O which may just make it slower.
# Also note that if other software reads the mboxes/maildirs, they may handle
# the extra CRs wrong and cause problems.
#mail_save_crlf = no
# Max number of mails to keep open and prefetch to memory. This only works with
# some mailbox formats and/or operating systems.
#mail_prefetch_count = 0
# How often to scan for stale temporary files and delete them (0 = never).
# These should exist only after Dovecot dies in the middle of saving mails.
#mail_temp_scan_interval = 1w
# How many slow mail accesses sorting can perform before it returns failure.
# With IMAP the reply is: NO [LIMIT] Requested sort would have taken too long.
# The untagged SORT reply is still returned, but it's likely not correct.
#mail_sort_max_read_count = 0
protocol !indexer-worker {
# If folder vsize calculation requires opening more than this many mails from
# disk (i.e. mail sizes aren't in cache already), return failure and finish
# the calculation via indexer process. Disabled by default. This setting must
# be 0 for indexer-worker processes.
#mail_vsize_bg_after_count = 0
}
##
## Maildir-specific settings
##
# By default LIST command returns all entries in maildir beginning with a dot.
# Enabling this option makes Dovecot return only entries which are directories.
# This is done by stat()ing each entry, so it causes more disk I/O.
# (For systems setting struct dirent->d_type, this check is free and it's
# done always regardless of this setting)
#maildir_stat_dirs = no
# When copying a message, do it with hard links whenever possible. This makes
# the performance much better, and it's unlikely to have any side effects.
#maildir_copy_with_hardlinks = yes
# Assume Dovecot is the only MUA accessing Maildir: Scan cur/ directory only
# when its mtime changes unexpectedly or when we can't find the mail otherwise.
#maildir_very_dirty_syncs = no
# If enabled, Dovecot doesn't use the S=<size> in the Maildir filenames for
# getting the mail's physical size, except when recalculating Maildir++ quota.
# This can be useful in systems where a lot of the Maildir filenames have a
# broken size. The performance hit for enabling this is very small.
#maildir_broken_filename_sizes = no
# Always move mails from new/ directory to cur/, even when the \Recent flags
# aren't being reset.
#maildir_empty_new = no
##
## mbox-specific settings
##
# Which locking methods to use for locking mbox. There are four available:
# dotlock: Create <mailbox>.lock file. This is the oldest and most NFS-safe
# solution. If you want to use /var/mail/ like directory, the users
# will need write access to that directory.
# dotlock_try: Same as dotlock, but if it fails because of permissions or
# because there isn't enough disk space, just skip it.
# fcntl : Use this if possible. Works with NFS too if lockd is used.
# flock : May not exist in all systems. Doesn't work with NFS.
# lockf : May not exist in all systems. Doesn't work with NFS.
#
# You can use multiple locking methods; if you do the order they're declared
# in is important to avoid deadlocks if other MTAs/MUAs are using multiple
# locking methods as well. Some operating systems don't allow using some of
# them simultaneously.
#mbox_read_locks = fcntl
mbox_write_locks = fcntl
# Maximum time to wait for lock (all of them) before aborting.
#mbox_lock_timeout = 5 mins
# If dotlock exists but the mailbox isn't modified in any way, override the
# lock file after this much time.
#mbox_dotlock_change_timeout = 2 mins
# When mbox changes unexpectedly we have to fully read it to find out what
# changed. If the mbox is large this can take a long time. Since the change
# is usually just a newly appended mail, it'd be faster to simply read the
# new mails. If this setting is enabled, Dovecot does this but still safely
# fallbacks to re-reading the whole mbox file whenever something in mbox isn't
# how it's expected to be. The only real downside to this setting is that if
# some other MUA changes message flags, Dovecot doesn't notice it immediately.
# Note that a full sync is done with SELECT, EXAMINE, EXPUNGE and CHECK
# commands.
#mbox_dirty_syncs = yes
# Like mbox_dirty_syncs, but don't do full syncs even with SELECT, EXAMINE,
# EXPUNGE or CHECK commands. If this is set, mbox_dirty_syncs is ignored.
#mbox_very_dirty_syncs = no
# Delay writing mbox headers until doing a full write sync (EXPUNGE and CHECK
# commands and when closing the mailbox). This is especially useful for POP3
# where clients often delete all mails. The downside is that our changes
# aren't immediately visible to other MUAs.
#mbox_lazy_writes = yes
# If mbox size is smaller than this (e.g. 100k), don't write index files.
# If an index file already exists it's still read, just not updated.
#mbox_min_index_size = 0
# Mail header selection algorithm to use for MD5 POP3 UIDLs when
# pop3_uidl_format=%m. For backwards compatibility we use apop3d inspired
# algorithm, but it fails if the first Received: header isn't unique in all
# mails. An alternative algorithm is "all" that selects all headers.
#mbox_md5 = apop3d
##
## mdbox-specific settings
##
# Maximum dbox file size until it's rotated.
#mdbox_rotate_size = 10M
# Maximum dbox file age until it's rotated. Typically in days. Day begins
# from midnight, so 1d = today, 2d = yesterday, etc. 0 = check disabled.
#mdbox_rotate_interval = 0
# When creating new mdbox files, immediately preallocate their size to
# mdbox_rotate_size. This setting currently works only in Linux with some
# filesystems (ext4, xfs).
#mdbox_preallocate_space = no
##
## Mail attachments
##
# sdbox and mdbox support saving mail attachments to external files, which
# also allows single instance storage for them. Other backends don't support
# this for now.
# Directory root where to store mail attachments. Disabled, if empty.
#mail_attachment_dir =
# Attachments smaller than this aren't saved externally. It's also possible to
# write a plugin to disable saving specific attachments externally.
#mail_attachment_min_size = 128k
# Filesystem backend to use for saving attachments:
# posix : No SiS done by Dovecot (but this might help FS's own deduplication)
# sis posix : SiS with immediate byte-by-byte comparison during saving
# sis-queue posix : SiS with delayed comparison and deduplication
#mail_attachment_fs = sis posix
# Hash format to use in attachment filenames. You can add any text and
# variables: %{md4}, %{md5}, %{sha1}, %{sha256}, %{sha512}, %{size}.
# Variables can be truncated, e.g. %{sha256:80} returns only first 80 bits
#mail_attachment_hash = %{sha1}
# Settings to control adding $HasAttachment or $HasNoAttachment keywords.
# By default, all MIME parts with Content-Disposition=attachment, or inlines
# with filename parameter are consired attachments.
# add-flags - Add the keywords when saving new mails or when fetching can
# do it efficiently.
# content-type=type or !type - Include/exclude content type. Excluding will
# never consider the matched MIME part as attachment. Including will only
# negate an exclusion (e.g. content-type=!foo/* content-type=foo/bar).
# exclude-inlined - Exclude any Content-Disposition=inline MIME part.
#mail_attachment_detection_options =
| 1 | Přidání automatického vytváření složek Koš(Thrash), Koncepty (Drafts), Odeslaná pošta (Sent), a Nevyžádaná pošta (Junk). Koš a Nevyžádaná se budou automaticky vysypávat po 14 dnech. |
Dovecot plugin pro učení spamu
Plugin pro učení spamu.
Pokud uživatel přesune do poštovní složky "Nevyžádaná pošta" (Junk) nějakou poštovní zprávu, tak se to rspamd naučí.
## ....
protocol imap {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $mail_plugins imap_sieve
# Maximum number of IMAP connections allowed for a user from each IP address.
# NOTE: The username is compared case-sensitively.
#mail_max_userip_connections = 10
}
##
## Plugin settings
##
# All wanted plugins must be listed in mail_plugins setting before any of the
# settings take effect. See <doc/wiki/Plugins.txt> for list of plugins and
# their configuration. Note that %variable expansion is done for all values.
plugin {
sieve_plugins = sieve_imapsieve sieve_extprograms
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
imapsieve_mailbox1_name = Junk
imapsieve_mailbox1_causes = COPY APPEND
imapsieve_mailbox1_before = file:/usr/local/lib/dovecot/sieve/report-spam.sieve
imapsieve_mailbox2_name = *
imapsieve_mailbox2_from = Junk
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/usr/local/lib/dovecot/sieve/report-ham.sieve
imapsieve_mailbox3_name = Inbox
imapsieve_mailbox3_causes = APPEND
imapsieve_mailbox3_before = file:/usr/local/lib/dovecot/sieve/report-ham.sieve
sieve_pipe_bin_dir = /usr/local/lib/dovecot/sieve
}
V adresáři /usr/local/lib/dovecot/sieve musíme mít soubory
#!/bin/sh
exec /usr/local/bin/rspamc -d "${1}" learn_ham
#!/bin/sh
exec /usr/local/bin/rspamc -d "${1}" learn_spam
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" "Trash" {
stop;
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "sa-learn-ham.sh" [ "${username}" ];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "sa-learn-spam.sh" [ "${username}" ];
Sieve soubory je třeba přeložit překladačem sievec
doas cd /usr/local/lib/dovecot/sieve
doas sievec report-ham.sieve
doas sievec report-spam.sieve
Konfigurace relayd
Relayd potřebujeme kvůli tomu, že ovládání rspamd je nezabezpečeným http protokolem. Rspamd poslouhá na localhost TCP portu 11334.
Relayd udělá zabezpečení a budeme moci ovládat rspamd pomocí https://mx2.billcom.cz:8080/.
V adresáři /etc/ssl/ a /etc/ssl/private musíme udělat symlinky na certifikát a privátní klíč stroje
doas ln -s /etc/ssl/mx2.billcom.cz.crt /etc/ssl/https:8080.crt
doas ln -s /etc/ssl/private/mx2.billcom.cz.key /etc/ssl/private/https:8080.key
Relayd bude fungovat jak pro protokol IPv4, tak i pro IPv6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# /etc/relayd.conf
#
# SSL accelerated reverse proxy na rspamd
#
relayd_addr="46.253.96.226"
relayd_addr6="2a0e:5340:4:400::5001"
relayd_port="8080"
local_addr="127.0.0.1"
local_addr6="::1"
local_port="11334"
http protocol "https" {
tcp { nodelay, sack, socket buffer 65536, backlog 100 }
return error
match header set "X-Forwarded-For" value "$REMOTE_ADDR"
match header set "X-Forwarded-By" value "$SERVER_ADDR:$SERVER_PORT"
match header set "Keep-Alive" value "$TIMEOUT"
match query hash "sessid"
match response header remove "Server"
match response header set "Strict-Transport-Security" value "max-age=31536000; includeSubDomains"
match response header set "X-Frame-Options" value "SAMEORIGIN"
match response header set "X-XSS-Protection" value "1; mode=block"
match response header set "X-Content-Type-Options" value "nosniff"
# match response header set "Content-Security-Policy" value "default-src 'self'"
match response header set "Feature-Policy" value "accelerometer 'none'; camerea 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'"
tcp { nodelay, sack, socket buffer 65536, backlog 100 }
tls { no tlsv1.0, ciphers "HIGH", keypair https:8080 } (1)
}
relay "tlsaccel" {
listen on $relayd_addr port $relayd_port tls
protocol "https"
forward to $local_addr port $local_port
}
relay "tlsaccel6" {
listen on $relayd_addr6 port $relayd_port tls
protocol "https"
forward to $local_addr6 port $local_port
}
| 1 | keypair https:8080 musí odpovídat symlinkům na certifikát a klíč |
Konfigurace rspamd
Konfiguraci rspamd budeme provádět výhradně v adresáři /etc/rsapmd/local.d
Potřebujeme soubory:
ls -l /etc/rspamd/local.d/
total 111800
-rw-r--r-- 1 _rspamd _rspamd 126 Jun 25 07:26 dkim_signing.conf # podepisování pošty
-rw-r--r-- 1 _rspamd _rspamd 31244 Oct 16 19:07 local_bl_domain.map.inc # zalokované domény
-rw-r--r-- 1 _rspamd _rspamd 68837 Oct 9 23:35 local_bl_from.map.inc # zablokovan- odesílatelé
-rw-r--r-- 1 _rspamd _rspamd 57065472 Jun 25 06:51 local_bl_ip.map.inc # zablokované IP
-rw-r--r-- 1 _rspamd _rspamd 1 Nov 9 2020 local_bl_rcpt.map.inc # zablokovaní příjemci
-rw-r--r-- 1 _rspamd _rspamd 93 May 12 15:57 local_bl_rip.map.inc
-rw-r--r-- 1 _rspamd _rspamd 7 Feb 3 2021 local_wl_domain.map.inc #
-rw-r--r-- 1 _rspamd _rspamd 199 Mar 20 2023 local_wl_from.map.inc
-rw-r--r-- 1 _rspamd _rspamd 57 Feb 28 2021 local_wl_ip.map.inc
-rw-r--r-- 1 _rspamd _rspamd 15 Nov 18 2020 local_wl_rcpt.map.inc
-rw-r--r-- 1 _rspamd _rspamd 1470 May 12 15:52 multimap.conf
-rw-r--r-- 1 _rspamd _rspamd 481 Sep 29 2023 rbl.conf
-rw-r--r-- 1 _rspamd _rspamd 690 Sep 29 2023 rbl_group.conf
-rw-r--r-- 1 root _rspamd 23 Oct 22 13:01 redis.conf
-rw-r--r-- 1 _rspamd _rspamd 670 Jun 25 07:22 worker-controller.inc # nastavení rspamu
# Controller worker setup
# Please don't modify this file as your changes might be overwritten with
# the next update.
#
# You can modify 'local.d/worker-controller.inc' to add and merge
# parameters defined inside this section
#
# You can modify 'override.d/worker-controller.inc' to strictly override all
# parameters defined inside this section
#
# See https://rspamd.com/doc/faq.html#what-are-the-locald-and-overrided-directories
# for details
# Module documentation: https://rspamd.com/doc/workers/controller.html
count = 1;
password = "heslo";
enable_password = "Heslo pro změny"
secure_ip = "127.0.0.1";
secure_ip = "::1";
static_dir = "${WWWDIR}";
allow_username_mismatch = true;
domain {
billcom.cz {
path = "/etc/mail/dkim/billcom.cz.key";
selector = "default";
}
}
Konfigurace roundcube
Web server běží v chrootovaném prostředí /var/www kvůli bezpečnosti, proto je potřeba některý software upravit pro toto chroot prostředí.
Chroot znamená, že programy httpd php-fpm a další mají adresář `/var/www' jako kořenový a nevidí jinam.
Jedná se o mariadb server (nebo lze použít také mysqld server, který je velmi podobný).
Instalace a nastavení mariadb
Je dobré najeprve nastavit provést implicitní nastavení mariadb (nebo mysql) bez chrootu a potom ho upravit pro chroot.
Databázový server běží pod uživatelem _mysql, skupina _mysql.
doas pkg_add mariadb-server
Spolu s balíkem mariadb-server se nainstalují i další balíky, které jsou potřeba:
doas pkg_add mariadb-server
quirks-7.227 signed on 2026-10-28T17:12:24Z
mariadb-server-12.3.3p3v1:findutils-4.10.0p0: ok
mariadb-server-12.3.3p3v1:ngtcp2-1.25.0: ok
mariadb-server-12.3.3p3v1:nghttp2-1.70.0: ok
mariadb-server-12.3.3p3v1:nghttp3-1.18.0: ok
mariadb-server-12.3.3p3v1:curl-8.23.0: ok
mariadb-server-12.3.3p3v1:snappy-1.1.10p3: ok
mariadb-server-12.3.3p3v1:mariadb-client-12.3.3p3v1: ok
mariadb-server-12.3.3p3v1:p5-Params-Util-1.102: ok
mariadb-server-12.3.3p3v1:p5-Math-Base-Convert-0.13: ok
mariadb-server-12.3.3p3v1:p5-Module-Runtime-0.018: ok
mariadb-server-12.3.3p3v1:p5-Clone-0.50: ok
mariadb-server-12.3.3p3v1:p5-SQL-Statement-1.414: ok
mariadb-server-12.3.3p3v1:p5-FreezeThaw-0.5001p0: ok
mariadb-server-12.3.3p3v1:p5-MLDBM-2.05p0: ok
mariadb-server-12.3.3p3v1:p5-Net-Daemon-0.52: ok
mariadb-server-12.3.3p3v1:p5-PlRPC-0.2020p0: ok
mariadb-server-12.3.3p3v1:p5-DBI-1.654: ok
mariadb-server-12.3.3p3v1:p5-DBD-MariaDB-1.23: ok
mariadb-server-12.3.3p3v1:coreutils-9.11: ok
mariadb-server-12.3.3p3v1:libxml-2.15.4: ok
mariadb-server-12.3.3p3v1:lzo2-2.10p2: ok
mariadb-server-12.3.3p3v1: ok
Running tags: ok
The following new rcscripts were installed: /etc/rc.d/mysqld
See rcctl(8) for details.
New and changed readme(s):
/usr/local/share/doc/pkg-readmes/mariadb-server
[client-server]
# socket později upravíme pro chroot /var/www
socket=/var/run/mysql/mysql.sock
port=3306
# This will be passed to all MariaDB clients
[client]
#password=my_password
# The MariaDB server
[mysqld]
# To listen to all network addresses, use "bind-address = *"
bind-address=localhost
# Directory where you want to put your data
data=/var/mysql
# This is the prefix name to be used for all log, error and replication files
#log-basename=mysqld
# Logging
#general-log
#slow_query_log
mariadb-install-dbdoas mariadb-install-db
WARNING: The host 'piskoviste.jr.lixis.cz' could not be looked up with /usr/local/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mariadbd, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in '/var/mysql' ...
2026-10-29 20:37:58 0 [Note] Using unique option prefix 'data' is error-prone and can break in the future. Please use the full name 'datadir' instead.
OK
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mariadb
The second is _mysql@localhost, it has no password either, but
you need to be the system '_mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Documentation at https://mariadb.com/docs
You can start the MariaDB daemon with:
/etc/rc.d/mysqld start
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
doas rcctl enable mysqld
doas rcctl start mysqld
doas mariadb-secure-installation
NOTE: MariaDB is secure by default. Running this script is mostly
unecessary and it will likely be removed in a future release,
but it is for now preserved for backwards compatibility.
Enter root user password or leave blank:
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully (or at least no errors was emitted)!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
Query OK, 2 rows affected
SQL executed without errors!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
Query OK, 0 rows affected
SQL executed without errors!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
Query OK, 0 rows affected
SQL executed without errors!
- Removing privileges on test database...
Query OK, 2 rows affected
SQL executed without errors!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
doas mkdir -p /var/www/var/run/mysql
doas chown _mysql:_mysql /var/www/var/run/mysql
rcctl stop mysqld
Upravíme konfigurační soubor my.cnf tak, aby mysql socket byl přístupný v chrootovaném prostředí webu.
Web v chrootu uvidí socket jako /var/run/mysql/mysql.sock.
[client-server]
socket=/var/www/var/run/mysql/mysql.sock
port=3306
# This will be passed to all MariaDB clients
[client]
#password=my_password
# The MariaDB server
[mysqld]
# To listen to all network addresses, use "bind-address = *"
bind-address=localhost
# Directory where you want to put your data
data=/var/mysql
# This is the prefix name to be used for all log, error and replication files
#log-basename=mysqld
# Logging
#general-log
#slow_query_log
Po úpravě spustíme mysqld server.
doas rcctl start mysqld
Instalace roundcube
Roundcubemail se instaluje do adresáře /var/www/roundcubemail/, v chrootovaném prostředí webu to bude /roundcubemail.
Vytvoříme databázi a uživatele, který bude mít plná práva na tuto databázi.
$ doas mysql -u root -p
create database roundcube;
grant all privileges on roundcube.* to roundcube@localhost identified by 'heslo';
flush privileges;
Vytvoříme adresář etc v chrootovaném prostředí /var/www a nakopírujeme do něj soubory /etc/hosts, /etc/resolv.conf a /etc/ssl/cert.pem.
doas mkdir -p /var/www/etc/ssl
doas cp /etc/hosts /var/www/etc/
doas cp /etc/resolv.conf /var/www/etc/
doas cp /etc/ssl/cert.pem /var/www/etc/ssl/
Upravíme konfiguraci httpd serveru /etc/httpd.conf
.
# $OpenBSD: httpd.conf,v 1.23 2025/02/21 10:19:52 mbuhl Exp $
server "mx2.billcom.cz" {
listen on * port 80
location "/.well-known/acme-challenge/*" {
root "/acme"
request strip 2
}
location * {
block return 302 "https://$HTTP_HOST$REQUEST_URI"
}
}
server "mx2.billcom.cz" {
listen on * tls port 443
tls {
certificate "/etc/ssl/mx2.billcom.cz.fullchain.pem"
key "/etc/ssl/private/mx2.billcom.cz.key"
}
connection max request body 4000000000
location "/.well-known/acme-challenge/*" {
root "/acme"
request strip 2
}
root "/roundcubemail" (1)
directory index index.php (2)
location "*.php" { (3)
fastcgi socket "/run/php-fpm.sock"
}
}
| 1 | Root webu |
| 2 | Directory index bude ne index.html ale index.php. |
| 3 | Všechny URI, které budou mít příponu .php se proženou přes PHP interpretr php-fpm. |
Do konfiguračního souboru /var/www/roundcubemail/config/config.inc.php napíšeme konfiguraci přístupu databáze
<?php
/*
+-----------------------------------------------------------------------+
| Local configuration for the Roundcube Webmail installation. |
| |
| This is a sample configuration file only containing the minimum |
| setup required for a functional installation. Copy more options |
| from defaults.inc.php to this file to override the defaults. |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
+-----------------------------------------------------------------------+
*/
$config = [];
// Database connection string (DSN) for read+write operations
// Format (compatible with PEAR MDB2): db_provider://user:password@host/database
// Currently supported db_providers: mysql, pgsql, sqlite, mssql, sqlsrv, oracle
// For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
// NOTE: for SQLite use absolute path (Linux): 'sqlite:////full/path/to/sqlite.db?mode=0646'
// or (Windows): 'sqlite:///C:/full/path/to/sqlite.db'
// $config['db_dsnw'] = 'mysql://roundcube:pass@localhost/roundcubemail';
$config['db_dsnw'] = 'mysql://roundcube:heslo@localhost/roundcube'; (1)
// IMAP host chosen to perform the log-in.
// See defaults.inc.php for the option description.
$config['imap_host'] = 'mx2.billcom.cz:143'; (2)
// SMTP server host (for sending mails).
// See defaults.inc.php for the option description.
$config['smtp_host'] = 'tls://mx2.billcom.cz:587'; (3)
// SMTP username (if required) if you use %u as the username Roundcube
// will use the current username for login
$config['smtp_user'] = '%u'; (4)
// SMTP password (if required) if you use %p as the password Roundcube
// will use the current user's password for login
$config['smtp_pass'] = '%p';
// provide an URL where a user can get support for this Roundcube installation
// PLEASE DO NOT LINK TO THE ROUNDCUBE.NET WEBSITE HERE!
$config['support_url'] = '';
// Name your service. This is displayed on the login screen and in the window title
$config['product_name'] = 'Roundcube Webmail Billcom s.r.o.';
// This key is used to encrypt the users imap password which is stored
// in the session record. For the default cipher method it must be
// exactly 24 characters long.
// YOUR KEY MUST BE DIFFERENT THAN THE SAMPLE VALUE FOR SECURITY REASONS
$config['des_key'] = 'oirwjelskdfjioweirwelj34'; (5)
// List of active plugins (in plugins/ directory)
$config['plugins'] = [
'archive',
'zipdownload',
];
// skin name: folder from skins/
$config['skin'] = 'elastic';
$config['mail_domain'] = 'billcom.cz'; (6)
$config['enable_installer'] = true; (7)
| 1 | Konfigurace přístupu k databázi |
| 2 | Kde je implicitní IMAP server (příjem pošty) |
| 3 | Kde je implicitní SMTP server (odesílání pošty) |
| 4 | Uživatelské jméno (z přihlašovacího dialogu ) |
| 5 | Klíč pro komunikaci musíte změnit a musí mít 24 bajtů. |
| 6 | Implicitní doména |
| 7 | Po instalaci je potřeba vrátit hodnotu na false. |
V prohlížeči spustíme instalační program https://mx2.billcom.cz/installer/index.php a dokončíme instalaci.
| Po dokončení instalace musíme vrátit v konfiguraci rouncube `$config['enable_installer'] = false; `. Jinak nám může provést konfiguraci kdokoliv z internetu. |