Skip to content

Commit 120366f

Browse files
Merge pull request #6291 from mailcow/staging
Update 2025-01a
2 parents 244d4b8 + 3544a22 commit 120366f

File tree

11 files changed

+141
-35
lines changed

11 files changed

+141
-35
lines changed

data/Dockerfiles/nginx/bootstrap.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def includes_conf(env, template_vars):
77
listen_plain = "listen_plain.active"
88
listen_ssl = "listen_ssl.active"
99

10-
server_name_config = f"server_name {template_vars['MAILCOW_HOSTNAME']} autodiscover.* autoconfig.* {template_vars['ADDITIONAL_SERVER_NAMES']};"
10+
server_name_config = f"server_name {template_vars['MAILCOW_HOSTNAME']} autodiscover.* autoconfig.* {' '.join(template_vars['ADDITIONAL_SERVER_NAMES'])};"
1111
listen_plain_config = f"listen {template_vars['HTTP_PORT']};"
1212
listen_ssl_config = f"listen {template_vars['HTTPS_PORT']};"
1313
if not template_vars['DISABLE_IPv6']:
@@ -42,20 +42,23 @@ def nginx_conf(env, template_vars):
4242

4343
def prepare_template_vars():
4444
ipv4_network = os.getenv("IPV4_NETWORK", "172.22.1")
45+
additional_server_names = os.getenv("ADDITIONAL_SERVER_NAMES", "")
46+
4547
template_vars = {
4648
'IPV4_NETWORK': ipv4_network,
4749
'TRUSTED_NETWORK': os.getenv("TRUSTED_NETWORK", False),
4850
'SKIP_RSPAMD': os.getenv("SKIP_RSPAMD", "n").lower() in ("y", "yes"),
4951
'SKIP_SOGO': os.getenv("SKIP_SOGO", "n").lower() in ("y", "yes"),
5052
'NGINX_USE_PROXY_PROTOCOL': os.getenv("NGINX_USE_PROXY_PROTOCOL", "n").lower() in ("y", "yes"),
5153
'MAILCOW_HOSTNAME': os.getenv("MAILCOW_HOSTNAME", ""),
52-
'ADDITIONAL_SERVER_NAMES': os.getenv("ADDITIONAL_SERVER_NAMES", "").replace(',', ' '),
54+
'ADDITIONAL_SERVER_NAMES': [item.strip() for item in additional_server_names.split(",") if item.strip()],
5355
'HTTP_PORT': os.getenv("HTTP_PORT", "80"),
5456
'HTTPS_PORT': os.getenv("HTTPS_PORT", "443"),
5557
'SOGOHOST': os.getenv("SOGOHOST", ipv4_network + ".248"),
5658
'RSPAMDHOST': os.getenv("RSPAMDHOST", "rspamd-mailcow"),
5759
'PHPFPMHOST': os.getenv("PHPFPMHOST", "php-fpm-mailcow"),
5860
'DISABLE_IPv6': os.getenv("DISABLE_IPv6", "n").lower() in ("y", "yes"),
61+
'HTTP_REDIRECT': os.getenv("HTTP_REDIRECT", "n").lower() in ("y", "yes"),
5962
}
6063

6164
ssl_dir = '/etc/ssl/mail/'

data/Dockerfiles/nginx/docker-entrypoint.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ until ping ${PHPFPMHOST} -c1 > /dev/null; do
88
echo "Waiting for PHP..."
99
sleep 1
1010
done
11-
if printf "%s\n" "${SKIP_SOGO}" | grep -E '^([yY][eE][sS]|[yY])+$' >/dev/null; then
11+
if ! printf "%s\n" "${SKIP_SOGO}" | grep -E '^([yY][eE][sS]|[yY])+$' >/dev/null; then
1212
until ping ${SOGOHOST} -c1 > /dev/null; do
1313
echo "Waiting for SOGo..."
1414
sleep 1
1515
done
1616
fi
17-
if printf "%s\n" "${SKIP_RSPAMD}" | grep -E '^([yY][eE][sS]|[yY])+$' >/dev/null; then
17+
if ! printf "%s\n" "${SKIP_RSPAMD}" | grep -E '^([yY][eE][sS]|[yY])+$' >/dev/null; then
1818
until ping ${RSPAMDHOST} -c1 > /dev/null; do
1919
echo "Waiting for Rspamd..."
2020
sleep 1

data/Dockerfiles/postfix/postfix.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,14 @@ EOF
395395

396396
if [ ! -f /opt/postfix/conf/dns_blocklists.cf ]; then
397397
cat <<EOF > /opt/postfix/conf/dns_blocklists.cf
398-
# This file can be edited.
398+
# This file can be edited.
399399
# Delete this file and restart postfix container to revert any changes.
400400
postscreen_dnsbl_sites = wl.mailspike.net=127.0.0.[18;19;20]*-2
401401
hostkarma.junkemailfilter.com=127.0.0.1*-2
402402
list.dnswl.org=127.0.[0..255].0*-2
403403
list.dnswl.org=127.0.[0..255].1*-4
404404
list.dnswl.org=127.0.[0..255].2*-6
405405
list.dnswl.org=127.0.[0..255].3*-8
406-
ix.dnsbl.manitu.net*2
407406
bl.spamcop.net*2
408407
bl.suomispam.net*2
409408
hostkarma.junkemailfilter.com=127.0.0.2*3
@@ -419,6 +418,9 @@ EOF
419418
fi
420419
DNSBL_CONFIG=$(grep -v '^#' /opt/postfix/conf/dns_blocklists.cf | grep '\S')
421420

421+
# Remove discontinued Nixspam DNSBL from existing dns_blocklists.cf
422+
sed -i '/ix\.dnsbl\.manitu\.net\*2/d' /opt/postfix/conf/dns_blocklists.cf
423+
422424
if [ ! -z "$DNSBL_CONFIG" ]; then
423425
echo -e "\e[33mChecking if ASN for your IP is listed for Spamhaus Bad ASN List...\e[0m"
424426
if [ -n "$SPAMHAUS_DQS_KEY" ]; then
@@ -507,6 +509,11 @@ chgrp -R postdrop /var/spool/postfix/public
507509
chgrp -R postdrop /var/spool/postfix/maildrop
508510
postfix set-permissions
509511

512+
# Checking if there is a leftover of a crashed postfix container before starting a new one
513+
if [ -e /var/spool/postfix/pid/master.pid ]; then
514+
rm -rf /var/spool/postfix/pid/master.pid
515+
fi
516+
510517
# Check Postfix configuration
511518
postconf -c /opt/postfix/conf > /dev/null
512519

data/Dockerfiles/postfix/supervisord.conf

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ stdout_logfile_maxbytes=0
1818
stderr_logfile=/dev/stderr
1919
stderr_logfile_maxbytes=0
2020
autorestart=true
21+
startsecs=10
2122

2223
[eventlistener:processes]
2324
command=/usr/local/sbin/stop-supervisor.sh

data/conf/nginx/templates/nginx.conf.j2

+63-2
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,80 @@ http {
4141
https https;
4242
}
4343

44-
# Default
44+
{% if HTTP_REDIRECT %}
45+
# HTTP to HTTPS redirect
46+
server {
47+
root /web;
48+
listen {{ HTTP_PORT }} default_server;
49+
listen [::]:{{ HTTP_PORT }} default_server;
50+
51+
server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.* {{ ADDITIONAL_SERVER_NAMES | join(' ') }};
52+
53+
if ( $request_uri ~* "%0A|%0D" ) { return 403; }
54+
location ^~ /.well-known/acme-challenge/ {
55+
allow all;
56+
default_type "text/plain";
57+
}
58+
location / {
59+
return 301 https://$host$uri$is_args$args;
60+
}
61+
}
62+
{%endif%}
63+
64+
# Default Server Name
4565
server {
4666
listen 127.0.0.1:65510; # sogo-auth verify internal
67+
68+
{% if not HTTP_REDIRECT %}
4769
listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
70+
{%endif%}
4871
listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
72+
4973
{% if not DISABLE_IPv6 %}
74+
{% if not HTTP_REDIRECT %}
5075
listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
76+
{%endif%}
5177
listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
5278
{%endif%}
79+
5380
http2 on;
5481

5582
ssl_certificate /etc/ssl/mail/cert.pem;
5683
ssl_certificate_key /etc/ssl/mail/key.pem;
5784

58-
server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.* {{ ADDITIONAL_SERVER_NAMES }};
85+
server_name {{ MAILCOW_HOSTNAME }} autodiscover.* autoconfig.*;
5986

6087
include /etc/nginx/includes/sites-default.conf;
6188
}
6289

90+
# Additional Server Names
91+
{% for SERVER_NAME in ADDITIONAL_SERVER_NAMES %}
92+
server {
93+
listen 127.0.0.1:65510; # sogo-auth verify internal
94+
95+
{% if not HTTP_REDIRECT %}
96+
listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
97+
{%endif%}
98+
listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
99+
100+
{% if not DISABLE_IPv6 %}
101+
{% if not HTTP_REDIRECT %}
102+
listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
103+
{%endif%}
104+
listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
105+
{%endif%}
106+
107+
http2 on;
108+
109+
ssl_certificate /etc/ssl/mail/cert.pem;
110+
ssl_certificate_key /etc/ssl/mail/key.pem;
111+
112+
server_name {{ SERVER_NAME }};
113+
114+
include /etc/nginx/includes/sites-default.conf;
115+
}
116+
{% endfor %}
117+
63118
# rspamd dynmaps:
64119
server {
65120
listen 8081;
@@ -106,12 +161,18 @@ http {
106161

107162
{% for cert in valid_cert_dirs %}
108163
server {
164+
{% if not HTTP_REDIRECT %}
109165
listen {{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
166+
{%endif%}
110167
listen {{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
168+
111169
{% if not DISABLE_IPv6 %}
170+
{% if not HTTP_REDIRECT %}
112171
listen [::]:{{ HTTP_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%};
172+
{%endif%}
113173
listen [::]:{{ HTTPS_PORT }}{% if NGINX_USE_PROXY_PROTOCOL %} proxy_protocol{%endif%} ssl;
114174
{%endif%}
175+
115176
http2 on;
116177

117178
ssl_certificate {{ cert.cert_path }}cert.pem;

data/conf/nginx/templates/sites-default.conf.j2

+11-2
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,22 @@ location ~ /(?:m|M)ail/(?:c|C)onfig-v1.1.xml {
137137

138138
{% if not SKIP_RSPAMD %}
139139
location /rspamd/ {
140+
location /rspamd/auth {
141+
# proxy_pass is not inherited
142+
proxy_pass http://{{ RSPAMDHOST }}:11334/auth;
143+
proxy_intercept_errors on;
144+
proxy_set_header Host $http_host;
145+
proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
146+
proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
147+
proxy_redirect off;
148+
error_page 401 /_rspamderror.php;
149+
}
150+
140151
proxy_pass http://{{ RSPAMDHOST }}:11334/;
141152
proxy_set_header Host $http_host;
142153
proxy_set_header X-Forwarded-For {% if not NGINX_USE_PROXY_PROTOCOL %}$proxy_add_x_forwarded_for{% else %}$proxy_protocol_addr{%endif%};
143154
proxy_set_header X-Real-IP {% if not NGINX_USE_PROXY_PROTOCOL %}$remote_addr{% else %}$proxy_protocol_addr{%endif%};
144155
proxy_redirect off;
145-
proxy_intercept_errors on;
146-
error_page 401 /_rspamderror.php;
147156
}
148157
{% endif %}
149158

data/conf/postfix/postscreen_access.cidr

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Whitelist generated by Postwhite v3.4 on Wed Jan 1 00:18:52 UTC 2025
1+
# Whitelist generated by Postwhite v3.4 on Sat Feb 1 00:18:03 UTC 2025
22
# https://github.com/stevejenkins/postwhite/
3-
# 2014 total rules
3+
# 1984 total rules
44
2a00:1450:4000::/36 permit
55
2a01:111:f400::/48 permit
66
2a01:111:f403:8000::/50 permit
@@ -19,10 +19,6 @@
1919
8.20.114.31 permit
2020
8.25.194.0/23 permit
2121
8.25.196.0/23 permit
22-
8.39.54.0/23 permit
23-
8.39.54.250/31 permit
24-
8.40.222.0/23 permit
25-
8.40.222.250/31 permit
2622
10.162.0.0/16 permit
2723
12.130.86.238 permit
2824
13.110.208.0/21 permit
@@ -98,6 +94,7 @@
9894
27.123.206.76/30 permit
9995
27.123.206.80/28 permit
10096
31.25.48.222 permit
97+
31.47.251.17 permit
10198
34.195.217.107 permit
10299
34.212.163.75 permit
103100
34.215.104.144 permit
@@ -110,6 +107,7 @@
110107
35.191.0.0/16 permit
111108
35.205.92.9 permit
112109
35.242.169.159 permit
110+
37.188.97.188 permit
113111
37.218.248.47 permit
114112
37.218.249.47 permit
115113
37.218.251.62 permit
@@ -448,6 +446,7 @@
448446
69.171.244.0/23 permit
449447
70.37.151.128/25 permit
450448
70.42.149.35 permit
449+
72.3.185.0/24 permit
451450
72.14.192.0/18 permit
452451
72.21.192.0/19 permit
453452
72.21.217.142 permit
@@ -508,6 +507,9 @@
508507
72.30.239.228/31 permit
509508
72.30.239.244/30 permit
510509
72.30.239.248/31 permit
510+
72.32.154.0/24 permit
511+
72.32.217.0/24 permit
512+
72.32.243.0/24 permit
511513
72.52.72.32/28 permit
512514
74.6.128.0/24 permit
513515
74.6.129.0/24 permit
@@ -623,6 +625,7 @@
623625
89.22.108.0/24 permit
624626
91.211.240.0/22 permit
625627
94.169.2.0/23 permit
628+
94.236.119.0/26 permit
626629
94.245.112.0/27 permit
627630
94.245.112.10/31 permit
628631
95.131.104.0/21 permit
@@ -1121,6 +1124,7 @@
11211124
103.28.42.0/24 permit
11221125
103.151.192.0/23 permit
11231126
103.168.172.128/27 permit
1127+
103.237.104.0/22 permit
11241128
104.43.243.237 permit
11251129
104.44.112.128/25 permit
11261130
104.47.0.0/17 permit
@@ -1335,6 +1339,8 @@
13351339
130.61.9.72 permit
13361340
130.162.39.83 permit
13371341
130.211.0.0/22 permit
1342+
130.248.172.0/24 permit
1343+
130.248.173.0/24 permit
13381344
131.253.30.0/24 permit
13391345
131.253.121.0/26 permit
13401346
132.145.13.209 permit
@@ -1476,9 +1482,6 @@
14761482
163.114.135.16 permit
14771483
164.152.23.32 permit
14781484
164.177.132.168/30 permit
1479-
165.173.128.0/24 permit
1480-
165.173.180.250/31 permit
1481-
165.173.182.250/31 permit
14821485
166.78.68.0/22 permit
14831486
166.78.68.221 permit
14841487
166.78.69.169 permit
@@ -1507,12 +1510,6 @@
15071510
168.245.12.252 permit
15081511
168.245.46.9 permit
15091512
168.245.127.231 permit
1510-
169.148.129.0/24 permit
1511-
169.148.131.0/24 permit
1512-
169.148.142.10 permit
1513-
169.148.144.0/25 permit
1514-
169.148.144.10 permit
1515-
169.148.146.0/23 permit
15161513
170.10.128.0/24 permit
15171514
170.10.129.0/24 permit
15181515
170.10.132.56/29 permit
@@ -1553,6 +1550,7 @@
15531550
183.240.219.64/29 permit
15541551
185.4.120.0/22 permit
15551552
185.12.80.0/22 permit
1553+
185.28.196.0/22 permit
15561554
185.58.84.93 permit
15571555
185.80.93.204 permit
15581556
185.80.93.227 permit
@@ -1618,6 +1616,7 @@
16181616
192.18.139.154 permit
16191617
192.18.145.36 permit
16201618
192.18.152.58 permit
1619+
192.28.128.0/18 permit
16211620
192.29.103.128/25 permit
16221621
192.30.252.0/22 permit
16231622
192.161.144.0/20 permit
@@ -1658,6 +1657,7 @@
16581657
198.244.60.0/22 permit
16591658
198.245.80.0/20 permit
16601659
198.245.81.0/24 permit
1660+
199.15.212.0/22 permit
16611661
199.15.213.187 permit
16621662
199.15.226.37 permit
16631663
199.16.156.0/22 permit
@@ -1972,9 +1972,6 @@
19721972
2603:1030:20e:3::23c permit
19731973
2603:1030:b:3::152 permit
19741974
2603:1030:c02:8::14 permit
1975-
2607:13c0:0001:0000:0000:0000:0000:7000/116 permit
1976-
2607:13c0:0002:0000:0000:0000:0000:1000/116 permit
1977-
2607:13c0:0004:0000:0000:0000:0000:0000/116 permit
19781975
2607:f8b0:4000::/36 permit
19791976
2620:109:c003:104::/64 permit
19801977
2620:109:c003:104::215 permit

data/web/inc/functions.inc.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -2275,9 +2275,25 @@ function cors($action, $data = null) {
22752275
break;
22762276
}
22772277
}
2278-
function getBaseURL() {
2279-
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
2280-
$host = $_SERVER['HTTP_HOST'];
2278+
function getBaseURL($protocol = null) {
2279+
// Get current server name
2280+
$host = strtolower($_SERVER['SERVER_NAME']);
2281+
2282+
// craft allowed server name list
2283+
$mailcow_hostname = strtolower(getenv("MAILCOW_HOSTNAME"));
2284+
$additional_server_names = strtolower(getenv("ADDITIONAL_SERVER_NAMES")) ?: "";
2285+
$additional_server_names = preg_replace('/\s+/', '', $additional_server_names);
2286+
$allowed_server_names = $additional_server_names !== "" ? explode(',', $additional_server_names) : array();
2287+
array_push($allowed_server_names, $mailcow_hostname);
2288+
2289+
// Fallback to MAILCOW HOSTNAME if current server name is not in allowed list
2290+
if (!in_array($host, $allowed_server_names)) {
2291+
$host = $mailcow_hostname;
2292+
}
2293+
2294+
if (!isset($protocol)) {
2295+
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
2296+
}
22812297
$base_url = $protocol . '://' . $host;
22822298

22832299
return $base_url;

0 commit comments

Comments
 (0)