blob: a764725cb7ca5a9ee350ec648dea730e89a7738d [file] [log] [blame]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001#!/bin/bash
2
3until nc phpfpm 9001 -z; do
4 echo "Waiting for PHP on port 9001..."
5 sleep 3
6done
7
8until nc phpfpm 9002 -z; do
9 echo "Waiting for PHP on port 9002..."
10 sleep 3
11done
12
13mkdir -p /etc/rspamd/plugins.d \
14 /etc/rspamd/custom
15
16touch /etc/rspamd/rspamd.conf.local \
17 /etc/rspamd/rspamd.conf.override
18
19chmod 755 /var/lib/rspamd
20
21
22[[ ! -f /etc/rspamd/override.d/worker-controller-password.inc ]] && echo '# Autogenerated by mailcow' > /etc/rspamd/override.d/worker-controller-password.inc
23
24echo ${IPV4_NETWORK}.0/24 > /etc/rspamd/custom/mailcow_networks.map
25echo ${IPV6_NETWORK} >> /etc/rspamd/custom/mailcow_networks.map
26
27DOVECOT_V4=
28DOVECOT_V6=
29until [[ ! -z ${DOVECOT_V4} ]]; do
30 DOVECOT_V4=$(dig a dovecot +short)
31 DOVECOT_V6=$(dig aaaa dovecot +short)
32 [[ ! -z ${DOVECOT_V4} ]] && break;
33 echo "Waiting for Dovecot..."
34 sleep 3
35done
36echo ${DOVECOT_V4}/32 > /etc/rspamd/custom/dovecot_trusted.map
37if [[ ! -z ${DOVECOT_V6} ]]; then
38 echo ${DOVECOT_V6}/128 >> /etc/rspamd/custom/dovecot_trusted.map
39fi
40
41RSPAMD_V4=
42RSPAMD_V6=
43until [[ ! -z ${RSPAMD_V4} ]]; do
44 RSPAMD_V4=$(dig a rspamd +short)
45 RSPAMD_V6=$(dig aaaa rspamd +short)
46 [[ ! -z ${RSPAMD_V4} ]] && break;
47 echo "Waiting for Rspamd..."
48 sleep 3
49done
50echo ${RSPAMD_V4}/32 > /etc/rspamd/custom/rspamd_trusted.map
51if [[ ! -z ${RSPAMD_V6} ]]; then
52 echo ${RSPAMD_V6}/128 >> /etc/rspamd/custom/rspamd_trusted.map
53fi
54
55if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then
56 cat <<EOF > /etc/rspamd/local.d/redis.conf
57read_servers = "redis:6379";
58write_servers = "${REDIS_SLAVEOF_IP}:${REDIS_SLAVEOF_PORT}";
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020059password = "${REDISPASS}";
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010060timeout = 10;
61EOF
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020062 until [[ $(redis-cli -h redis-mailcow -a ${REDISPASS} --no-auth-warning PING) == "PONG" ]]; do
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010063 echo "Waiting for Redis @redis-mailcow..."
64 sleep 2
65 done
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020066 until [[ $(redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT} -a ${REDISPASS} --no-auth-warning PING) == "PONG" ]]; do
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010067 echo "Waiting for Redis @${REDIS_SLAVEOF_IP}..."
68 sleep 2
69 done
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020070 redis-cli -h redis-mailcow -a ${REDISPASS} --no-auth-warning SLAVEOF ${REDIS_SLAVEOF_IP} ${REDIS_SLAVEOF_PORT}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010071else
72 cat <<EOF > /etc/rspamd/local.d/redis.conf
73servers = "redis:6379";
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020074password = "${REDISPASS}";
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010075timeout = 10;
76EOF
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020077 until [[ $(redis-cli -h redis-mailcow -a ${REDISPASS} --no-auth-warning PING) == "PONG" ]]; do
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010078 echo "Waiting for Redis slave..."
79 sleep 2
80 done
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020081 redis-cli -h redis-mailcow -a ${REDISPASS} --no-auth-warning SLAVEOF NO ONE
82fi
83
84if [[ "${SKIP_OLEFY}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
85 if [[ -f /etc/rspamd/local.d/external_services.conf ]]; then
86 rm /etc/rspamd/local.d/external_services.conf
87 fi
88else
89 if [[ ! -f /etc/rspamd/local.d/external_services.conf ]]; then
90 cat <<EOF > /etc/rspamd/local.d/external_services.conf
91oletools {
92 # default olefy settings
93 servers = "olefy:10055";
94 # needs to be set explicitly for Rspamd < 1.9.5
95 scan_mime_parts = true;
96 # mime-part regex matching in content-type or filename
97 # block all macros
98 extended = true;
99 max_size = 3145728;
100 timeout = 20.0;
101 retransmits = 1;
102}
103EOF
104 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100105fi
106
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100107# Provide additional lua modules
108ln -s /usr/lib/$(uname -m)-linux-gnu/liblua5.1-cjson.so.0.0.0 /usr/lib/rspamd/cjson.so
109
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100110chown -R _rspamd:_rspamd /var/lib/rspamd \
111 /etc/rspamd/local.d \
112 /etc/rspamd/override.d \
113 /etc/rspamd/rspamd.conf.local \
114 /etc/rspamd/rspamd.conf.override \
115 /etc/rspamd/plugins.d
116
117# Fix missing default global maps, if any
118# These exists in mailcow UI and should not be removed
119touch /etc/rspamd/custom/global_mime_from_blacklist.map \
120 /etc/rspamd/custom/global_rcpt_blacklist.map \
121 /etc/rspamd/custom/global_smtp_from_blacklist.map \
122 /etc/rspamd/custom/global_mime_from_whitelist.map \
123 /etc/rspamd/custom/global_rcpt_whitelist.map \
124 /etc/rspamd/custom/global_smtp_from_whitelist.map \
125 /etc/rspamd/custom/bad_languages.map \
126 /etc/rspamd/custom/sa-rules \
127 /etc/rspamd/custom/dovecot_trusted.map \
128 /etc/rspamd/custom/rspamd_trusted.map \
129 /etc/rspamd/custom/mailcow_networks.map \
130 /etc/rspamd/custom/ip_wl.map \
131 /etc/rspamd/custom/fishy_tlds.map \
132 /etc/rspamd/custom/bad_words.map \
133 /etc/rspamd/custom/bad_asn.map \
134 /etc/rspamd/custom/bad_words_de.map \
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200135 /etc/rspamd/custom/bulk_header.map \
136 /etc/rspamd/custom/bad_header.map
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100137
138# www-data (82) group needs to write to these files
139chown _rspamd:_rspamd /etc/rspamd/custom/
140chmod 0755 /etc/rspamd/custom/.
141chown -R 82:82 /etc/rspamd/custom/*
142chmod 644 -R /etc/rspamd/custom/*
143
144# Run hooks
145for file in /hooks/*; do
146 if [ -x "${file}" ]; then
147 echo "Running hook ${file}"
148 "${file}"
149 fi
150done
151
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200152# If DQS KEY is set in mailcow.conf add Spamhaus DQS RBLs
153if [[ ! -z ${SPAMHAUS_DQS_KEY} ]]; then
154 cat <<EOF > /etc/rspamd/custom/dqs-rbl.conf
155 # Autogenerated by mailcow. DO NOT TOUCH!
156 spamhaus {
157 rbl = "${SPAMHAUS_DQS_KEY}.zen.dq.spamhaus.net";
158 from = false;
159 }
160 spamhaus_from {
161 from = true;
162 received = false;
163 rbl = "${SPAMHAUS_DQS_KEY}.zen.dq.spamhaus.net";
164 returncodes {
165 SPAMHAUS_ZEN = [ "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6", "127.0.0.7", "127.0.0.9", "127.0.0.10", "127.0.0.11" ];
166 }
167 }
168 spamhaus_authbl_received {
169 # Check if the sender client is listed in AuthBL (AuthBL is *not* part of ZEN)
170 rbl = "${SPAMHAUS_DQS_KEY}.authbl.dq.spamhaus.net";
171 from = false;
172 received = true;
173 ipv6 = true;
174 returncodes {
175 SH_AUTHBL_RECEIVED = "127.0.0.20"
176 }
177 }
178 spamhaus_dbl {
179 # Add checks on the HELO string
180 rbl = "${SPAMHAUS_DQS_KEY}.dbl.dq.spamhaus.net";
181 helo = true;
182 rdns = true;
183 dkim = true;
184 disable_monitoring = true;
185 returncodes {
186 RBL_DBL_SPAM = "127.0.1.2";
187 RBL_DBL_PHISH = "127.0.1.4";
188 RBL_DBL_MALWARE = "127.0.1.5";
189 RBL_DBL_BOTNET = "127.0.1.6";
190 RBL_DBL_ABUSED_SPAM = "127.0.1.102";
191 RBL_DBL_ABUSED_PHISH = "127.0.1.104";
192 RBL_DBL_ABUSED_MALWARE = "127.0.1.105";
193 RBL_DBL_ABUSED_BOTNET = "127.0.1.106";
194 RBL_DBL_DONT_QUERY_IPS = "127.0.1.255";
195 }
196 }
197 spamhaus_dbl_fullurls {
198 ignore_defaults = true;
199 no_ip = true;
200 rbl = "${SPAMHAUS_DQS_KEY}.dbl.dq.spamhaus.net";
201 selector = 'urls:get_host'
202 disable_monitoring = true;
203 returncodes {
204 DBLABUSED_SPAM_FULLURLS = "127.0.1.102";
205 DBLABUSED_PHISH_FULLURLS = "127.0.1.104";
206 DBLABUSED_MALWARE_FULLURLS = "127.0.1.105";
207 DBLABUSED_BOTNET_FULLURLS = "127.0.1.106";
208 }
209 }
210 spamhaus_zrd {
211 # Add checks on the HELO string also for DQS
212 rbl = "${SPAMHAUS_DQS_KEY}.zrd.dq.spamhaus.net";
213 helo = true;
214 rdns = true;
215 dkim = true;
216 disable_monitoring = true;
217 returncodes {
218 RBL_ZRD_VERY_FRESH_DOMAIN = ["127.0.2.2", "127.0.2.3", "127.0.2.4"];
219 RBL_ZRD_FRESH_DOMAIN = [
220 "127.0.2.5", "127.0.2.6", "127.0.2.7", "127.0.2.8", "127.0.2.9", "127.0.2.10", "127.0.2.11", "127.0.2.12", "127.0.2.13", "127.0.2.14", "127.0.2.15", "127.0.2.16", "127.0.2.17", "127.0.2.18", "127.0.2.19", "127.0.2.20", "127.0.2.21", "127.0.2.22", "127.0.2.23", "127.0.2.24"
221 ];
222 RBL_ZRD_DONT_QUERY_IPS = "127.0.2.255";
223 }
224 }
225 "SPAMHAUS_ZEN_URIBL" {
226 enabled = true;
227 rbl = "${SPAMHAUS_DQS_KEY}.zen.dq.spamhaus.net";
228 resolve_ip = true;
229 checks = ['urls'];
230 replyto = true;
231 emails = true;
232 ipv4 = true;
233 ipv6 = true;
234 emails_domainonly = true;
235 returncodes {
236 URIBL_SBL = "127.0.0.2";
237 URIBL_SBL_CSS = "127.0.0.3";
238 URIBL_XBL = ["127.0.0.4", "127.0.0.5", "127.0.0.6", "127.0.0.7"];
239 URIBL_PBL = ["127.0.0.10", "127.0.0.11"];
240 URIBL_DROP = "127.0.0.9";
241 }
242 }
243 SH_EMAIL_DBL {
244 ignore_defaults = true;
245 replyto = true;
246 emails_domainonly = true;
247 disable_monitoring = true;
248 rbl = "${SPAMHAUS_DQS_KEY}.dbl.dq.spamhaus.net";
249 returncodes = {
250 SH_EMAIL_DBL = [
251 "127.0.1.2",
252 "127.0.1.4",
253 "127.0.1.5",
254 "127.0.1.6"
255 ];
256 SH_EMAIL_DBL_ABUSED = [
257 "127.0.1.102",
258 "127.0.1.104",
259 "127.0.1.105",
260 "127.0.1.106"
261 ];
262 SH_EMAIL_DBL_DONT_QUERY_IPS = [ "127.0.1.255" ];
263 }
264 }
265 SH_EMAIL_ZRD {
266 ignore_defaults = true;
267 replyto = true;
268 emails_domainonly = true;
269 disable_monitoring = true;
270 rbl = "${SPAMHAUS_DQS_KEY}.zrd.dq.spamhaus.net";
271 returncodes = {
272 SH_EMAIL_ZRD_VERY_FRESH_DOMAIN = ["127.0.2.2", "127.0.2.3", "127.0.2.4"];
273 SH_EMAIL_ZRD_FRESH_DOMAIN = [
274 "127.0.2.5", "127.0.2.6", "127.0.2.7", "127.0.2.8", "127.0.2.9", "127.0.2.10", "127.0.2.11", "127.0.2.12", "127.0.2.13", "127.0.2.14", "127.0.2.15", "127.0.2.16", "127.0.2.17", "127.0.2.18", "127.0.2.19", "127.0.2.20", "127.0.2.21", "127.0.2.22", "127.0.2.23", "127.0.2.24"
275 ];
276 SH_EMAIL_ZRD_DONT_QUERY_IPS = [ "127.0.2.255" ];
277 }
278 }
279 "DBL" {
280 # override the defaults for DBL defined in modules.d/rbl.conf
281 rbl = "${SPAMHAUS_DQS_KEY}.dbl.dq.spamhaus.net";
282 disable_monitoring = true;
283 }
284 "ZRD" {
285 ignore_defaults = true;
286 rbl = "${SPAMHAUS_DQS_KEY}.zrd.dq.spamhaus.net";
287 no_ip = true;
288 dkim = true;
289 emails = true;
290 emails_domainonly = true;
291 urls = true;
292 returncodes = {
293 ZRD_VERY_FRESH_DOMAIN = ["127.0.2.2", "127.0.2.3", "127.0.2.4"];
294 ZRD_FRESH_DOMAIN = ["127.0.2.5", "127.0.2.6", "127.0.2.7", "127.0.2.8", "127.0.2.9", "127.0.2.10", "127.0.2.11", "127.0.2.12", "127.0.2.13", "127.0.2.14", "127.0.2.15", "127.0.2.16", "127.0.2.17", "127.0.2.18", "127.0.2.19", "127.0.2.20", "127.0.2.21", "127.0.2.22", "127.0.2.23", "127.0.2.24"];
295 }
296 }
297 spamhaus_sbl_url {
298 ignore_defaults = true
299 rbl = "${SPAMHAUS_DQS_KEY}.sbl.dq.spamhaus.net";
300 checks = ['urls'];
301 disable_monitoring = true;
302 returncodes {
303 SPAMHAUS_SBL_URL = "127.0.0.2";
304 }
305 }
306
307 SH_HBL_EMAIL {
308 ignore_defaults = true;
309 rbl = "_email.${SPAMHAUS_DQS_KEY}.hbl.dq.spamhaus.net";
310 emails_domainonly = false;
311 selector = "from('smtp').lower;from('mime').lower";
312 ignore_whitelist = true;
313 checks = ['emails', 'replyto'];
314 hash = "sha1";
315 returncodes = {
316 SH_HBL_EMAIL = [
317 "127.0.3.2"
318 ];
319 }
320 }
321
322 spamhaus_dqs_hbl {
323 symbol = "HBL_FILE_UNKNOWN";
324 rbl = "_file.${SPAMHAUS_DQS_KEY}.hbl.dq.spamhaus.net.";
325 selector = "attachments('rbase32', 'sha256')";
326 ignore_whitelist = true;
327 ignore_defaults = true;
328 returncodes {
329 SH_HBL_FILE_MALICIOUS = "127.0.3.10";
330 SH_HBL_FILE_SUSPICIOUS = "127.0.3.15";
331 }
332 }
333EOF
334else
335 rm -rf /etc/rspamd/custom/dqs-rbl.conf
336fi
337
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100338exec "$@"