2017-03-02 11:23:23 +01:00
#!/bin/bash
trap "postfix stop" EXIT
2017-03-06 10:33:44 +01:00
[ [ ! -d /opt/postfix/conf/sql/ ] ] && mkdir -p /opt/postfix/conf/sql/
2018-07-25 01:05:51 +02:00
2019-08-09 14:08:58 +02:00
# Wait for MySQL to warm-up
while ! mysqladmin status --socket= /var/run/mysqld/mysqld.sock -u${ DBUSER } -p${ DBPASS } --silent; do
echo "Waiting for database to come up..."
sleep 2
done
2021-04-01 15:24:55 +02:00
until dig +short mailcow.email > /dev/null; do
2019-11-26 21:09:12 +01:00
echo "Waiting for DNS..."
2020-07-11 13:31:48 +02:00
sleep 1
2019-11-26 21:09:12 +01:00
done
2018-07-29 00:35:54 +02:00
cat <<EOF > /etc/aliases
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2018-07-29 00:35:54 +02:00
null: /dev/null
2019-09-04 23:06:29 +02:00
watchdog: /dev/null
2018-07-29 00:35:54 +02:00
ham: "|/usr/local/bin/rspamd-pipe-ham"
spam: "|/usr/local/bin/rspamd-pipe-spam"
EOF
2018-07-25 01:05:51 +02:00
newaliases;
2017-03-06 10:33:44 +01:00
2019-10-19 12:48:56 +02:00
# create sni configuration
2021-01-08 12:39:40 +01:00
if [ [ " ${ SKIP_LETS_ENCRYPT } " = ~ ^( [ yY] [ eE] [ sS] | [ yY] ) +$ ] ] ; then
echo -n "" > /opt/postfix/conf/sni.map
else
echo -n "" > /opt/postfix/conf/sni.map;
for cert_dir in /etc/ssl/mail/*/ ; do
if [ [ ! -f ${ cert_dir } domains ] ] || [ [ ! -f ${ cert_dir } cert.pem ] ] || [ [ ! -f ${ cert_dir } key.pem ] ] ; then
continue ;
fi
IFS = " " read -r -a domains <<< " $( cat " ${ cert_dir } domains " ) "
for domain in " ${ domains [@] } " ; do
echo -n " ${ domain } ${ cert_dir } key.pem ${ cert_dir } cert.pem " >> /opt/postfix/conf/sni.map;
echo "" >> /opt/postfix/conf/sni.map;
done
2019-10-19 12:48:56 +02:00
done
2021-01-08 12:39:40 +01:00
fi
2019-10-19 12:48:56 +02:00
postmap -F hash:/opt/postfix/conf/sni.map;
2020-04-03 20:39:53 +02:00
cat <<EOF > /opt/postfix/conf/sql/mysql_relay_ne.cf
# Autogenerated by mailcow
user = ${ DBUSER }
password = ${ DBPASS }
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = ${ DBNAME }
query = SELECT IF( EXISTS( SELECT address, domain FROM alias
WHERE address = '%s'
AND domain IN (
SELECT domain FROM domain
WHERE backupmx = '1'
AND relay_all_recipients = '1'
AND relay_unknown_only = '1' )
) , 'lmtp:inet:dovecot:24' , NULL) AS 'transport'
EOF
2017-03-06 10:33:44 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_relay_recipient_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT DISTINCT
CASE WHEN '%d' IN (
SELECT domain FROM domain
WHERE relay_all_recipients = 1
AND domain = '%d'
AND backupmx = 1
)
THEN '%s' ELSE (
SELECT goto FROM alias WHERE address = '%s' AND active = '1'
)
END AS result;
2017-03-06 10:33:44 +01:00
EOF
2018-10-04 14:34:53 +02:00
cat <<EOF > /opt/postfix/conf/sql/mysql_tls_policy_override_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2018-10-04 14:34:53 +02:00
user = ${ DBUSER }
password = ${ DBPASS }
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = ${ DBNAME }
query = SELECT CONCAT( policy, ' ' , parameters) AS tls_policy FROM tls_policy_override WHERE active = '1' AND dest = '%s'
EOF
2017-03-06 10:33:44 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_tls_enforce_in_policy.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT IF( EXISTS(
SELECT 'TLS_ACTIVE' FROM alias
LEFT OUTER JOIN mailbox ON mailbox.username = alias.goto
WHERE ( address = '%s'
OR address IN (
SELECT CONCAT( '%u' , '@' , target_domain) FROM alias_domain
WHERE alias_domain = '%d'
)
2020-09-17 19:47:11 +02:00
) AND JSON_UNQUOTE( JSON_VALUE( attributes, '$.tls_enforce_in' ) ) = '1' AND mailbox.active = '1'
2017-10-11 11:22:48 +02:00
) , 'reject_plaintext_session' , NULL) AS 'tls_enforce_in' ;
2017-03-06 10:33:44 +01:00
EOF
2017-07-22 20:39:54 +02:00
cat <<EOF > /opt/postfix/conf/sql/mysql_sender_dependent_default_transport_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-07-22 20:39:54 +02:00
query = SELECT GROUP_CONCAT( transport SEPARATOR '' ) AS transport_maps
FROM (
2017-10-11 11:22:48 +02:00
SELECT IF( EXISTS( SELECT 'smtp_type' FROM alias
LEFT OUTER JOIN mailbox ON mailbox.username = alias.goto
WHERE ( address = '%s'
OR address IN (
SELECT CONCAT( '%u' , '@' , target_domain) FROM alias_domain
WHERE alias_domain = '%d'
)
)
2020-09-17 19:47:11 +02:00
AND JSON_UNQUOTE( JSON_VALUE( attributes, '$.tls_enforce_out' ) ) = '1'
2017-10-11 11:22:48 +02:00
AND mailbox.active = '1'
) , 'smtp_enforced_tls:' , 'smtp:' ) AS 'transport'
2017-07-22 20:39:54 +02:00
UNION ALL
2021-05-26 14:02:27 +02:00
SELECT COALESCE(
( SELECT hostname FROM relayhosts
LEFT OUTER JOIN mailbox ON JSON_UNQUOTE( JSON_VALUE( mailbox.attributes, '$.relayhost' ) ) = relayhosts.id
WHERE relayhosts.active = '1'
AND (
mailbox.username IN ( SELECT alias.goto from alias
JOIN mailbox ON mailbox.username = alias.goto
WHERE alias.active = '1'
AND alias.address = '%s'
AND alias.address NOT LIKE '@%%'
)
)
) ,
( SELECT hostname FROM relayhosts
2017-10-11 11:22:48 +02:00
LEFT OUTER JOIN domain ON domain.relayhost = relayhosts.id
WHERE relayhosts.active = '1'
2021-05-26 14:02:27 +02:00
AND ( domain.domain = '%d'
OR domain.domain IN (
SELECT target_domain FROM alias_domain
WHERE alias_domain = '%d'
)
2017-10-11 11:22:48 +02:00
)
2021-05-26 14:02:27 +02:00
)
)
) AS transport_view;
2017-07-22 20:39:54 +02:00
EOF
2018-12-19 09:38:56 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_transport_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2018-12-19 09:38:56 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = ${ DBNAME }
query = SELECT CONCAT( 'smtp_via_transport_maps:' , nexthop) AS transport FROM transports
WHERE active = '1'
AND destination = '%s' ;
EOF
2019-06-09 16:49:38 +02:00
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_resource_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2019-06-09 16:49:38 +02:00
user = ${ DBUSER }
password = ${ DBPASS }
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = ${ DBNAME }
query = SELECT 'null@localhost' FROM mailbox
WHERE kind REGEXP 'location|thing|group' AND username = '%s' ;
EOF
2018-12-19 09:38:56 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_sasl_passwd_maps_sender_dependent.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-07-22 20:39:54 +02:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-07-22 20:39:54 +02:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT CONCAT_WS( ':' , username, password) AS auth_data FROM relayhosts
WHERE id IN (
2021-08-17 16:51:06 +02:00
SELECT COALESCE(
( SELECT id FROM relayhosts
LEFT OUTER JOIN domain ON domain.relayhost = relayhosts.id
WHERE relayhosts.active = '1'
AND ( domain.domain = '%d'
OR domain.domain IN (
SELECT target_domain FROM alias_domain
WHERE alias_domain = '%d'
)
)
) ,
( SELECT id FROM relayhosts
LEFT OUTER JOIN mailbox ON JSON_UNQUOTE( JSON_VALUE( mailbox.attributes, '$.relayhost' ) ) = relayhosts.id
WHERE relayhosts.active = '1'
AND (
mailbox.username IN (
SELECT alias.goto from alias
JOIN mailbox ON mailbox.username = alias.goto
WHERE alias.active = '1'
AND alias.address = '%s'
AND alias.address NOT LIKE '@%%'
)
)
2017-12-17 17:45:12 +01:00
)
2021-08-17 16:51:06 +02:00
)
2017-12-25 10:18:46 +01:00
)
2018-12-19 09:38:56 +01:00
AND active = '1'
AND username != '' ;
2019-03-09 12:30:36 +01:00
EOF
2018-12-19 09:38:56 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_sasl_passwd_maps_transport_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2018-12-19 09:38:56 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = ${ DBNAME }
query = SELECT CONCAT_WS( ':' , username, password) AS auth_data FROM transports
WHERE nexthop = '%s'
AND active = '1'
2018-12-25 15:02:50 +01:00
AND username != ''
LIMIT 1;
2017-03-06 10:33:44 +01:00
EOF
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_alias_domain_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT username FROM mailbox, alias_domain
WHERE alias_domain.alias_domain = '%d'
AND mailbox.username = CONCAT( '%u' , '@' , alias_domain.target_domain)
2020-04-29 11:00:00 +02:00
AND ( mailbox.active = '1' OR mailbox.active = '2' )
2017-10-11 11:22:48 +02:00
AND alias_domain.active= '1'
2017-03-06 10:33:44 +01:00
EOF
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_alias_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT goto FROM alias
WHERE address = '%s'
2020-06-06 01:12:31 +02:00
AND ( active = '1' OR active = '2' ) ;
2017-03-06 10:33:44 +01:00
EOF
2017-11-19 15:13:43 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_recipient_bcc_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-11-19 15:13:43 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-11-19 15:13:43 +01:00
dbname = ${ DBNAME }
query = SELECT bcc_dest FROM bcc_maps
WHERE local_dest = '%s'
AND type = 'rcpt'
AND active = '1' ;
EOF
cat <<EOF > /opt/postfix/conf/sql/mysql_sender_bcc_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-11-19 15:13:43 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-11-19 15:13:43 +01:00
dbname = ${ DBNAME }
query = SELECT bcc_dest FROM bcc_maps
WHERE local_dest = '%s'
AND type = 'sender'
AND active = '1' ;
EOF
2018-01-23 19:59:06 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_recipient_canonical_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2018-01-23 19:59:06 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2018-01-23 19:59:06 +01:00
dbname = ${ DBNAME }
query = SELECT new_dest FROM recipient_maps
WHERE old_dest = '%s'
AND active = '1' ;
EOF
2017-03-06 10:33:44 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_domains_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT alias_domain from alias_domain WHERE alias_domain = '%s' AND active = '1'
UNION
SELECT domain FROM domain
WHERE domain = '%s'
AND active = '1'
AND backupmx = '0'
2017-03-06 10:33:44 +01:00
EOF
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_mailbox_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2020-09-17 19:47:11 +02:00
query = SELECT CONCAT( JSON_UNQUOTE( JSON_VALUE( attributes, '$.mailbox_format' ) ) , mailbox_path_prefix, '%d/%u/' ) FROM mailbox WHERE username = '%s' AND ( active = '1' OR active = '2' )
2017-03-06 10:33:44 +01:00
EOF
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_relay_domain_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
query = SELECT domain FROM domain WHERE domain = '%s' AND backupmx = '1' AND active = '1'
EOF
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_sender_acl.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
# First select queries domain and alias_domain to determine if domains are active.
query = SELECT goto FROM alias
2022-08-04 01:37:26 +02:00
WHERE id IN (
SELECT COALESCE (
(
SELECT id FROM alias
WHERE address = '%s'
AND ( active = '1' OR active = '2' )
) , (
SELECT id FROM alias
WHERE address = '@%d'
AND ( active = '1' OR active = '2' )
)
)
)
2017-10-11 11:22:48 +02:00
AND active = '1'
AND ( domain IN
( SELECT domain FROM domain
WHERE domain = '%d'
AND active = '1' )
OR domain in (
SELECT alias_domain FROM alias_domain
WHERE alias_domain = '%d'
AND active = '1'
)
)
UNION
SELECT logged_in_as FROM sender_acl
WHERE send_as = '@%d'
OR send_as = '%s'
2018-08-02 12:15:04 +02:00
OR send_as = '*'
2017-10-11 11:22:48 +02:00
OR send_as IN (
SELECT CONCAT( '@' ,target_domain) FROM alias_domain
WHERE alias_domain = '%d' )
OR send_as IN (
SELECT CONCAT( '%u' ,'@' ,target_domain) FROM alias_domain
WHERE alias_domain = '%d' )
AND logged_in_as NOT IN (
SELECT goto FROM alias
WHERE address = '%s' )
UNION
SELECT username FROM mailbox, alias_domain
WHERE alias_domain.alias_domain = '%d'
AND mailbox.username = CONCAT( '%u' ,'@' ,alias_domain.target_domain)
2020-04-29 11:00:00 +02:00
AND ( mailbox.active = '1' OR mailbox.active = '2' )
2022-08-04 01:37:26 +02:00
AND alias_domain.active= '1' ;
2017-03-06 10:33:44 +01:00
EOF
2021-05-28 10:40:41 +02:00
# MX based routing
cat <<EOF > /opt/postfix/conf/sql/mysql_mbr_access_maps.cf
# Autogenerated by mailcow
user = ${ DBUSER }
password = ${ DBPASS }
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = ${ DBNAME }
query = SELECT CONCAT( 'FILTER smtp_via_transport_maps:' , nexthop) as transport FROM transports
WHERE '%s' REGEXP destination
AND active = '1'
AND is_mx_based = '1' ;
EOF
2017-03-06 10:33:44 +01:00
cat <<EOF > /opt/postfix/conf/sql/mysql_virtual_spamalias_maps.cf
2019-07-08 07:56:41 +02:00
# Autogenerated by mailcow
2017-03-06 10:33:44 +01:00
user = ${ DBUSER }
password = ${ DBPASS }
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-29 22:01:23 +02:00
hosts = unix:/var/run/mysqld/mysqld.sock
2017-03-06 10:33:44 +01:00
dbname = ${ DBNAME }
2017-10-11 11:22:48 +02:00
query = SELECT goto FROM spamalias
WHERE address = '%s'
AND validity >= UNIX_TIMESTAMP( )
2017-03-06 10:33:44 +01:00
EOF
2017-03-02 11:23:23 +01:00
2023-08-02 16:36:59 +02:00
if [ ! -f /opt/postfix/conf/dns_blocklists.cf ] ; then
cat <<EOF > /opt/postfix/conf/dns_blocklists.cf
# This file can be edited.
# Delete this file and restart postfix container to revert any changes.
postscreen_dnsbl_sites = wl.mailspike.net= 127.0.0.[ 18; 19; 20] *-2
hostkarma.junkemailfilter.com= 127.0.0.1*-2
list.dnswl.org= 127.0.[ 0..255] .0*-2
list.dnswl.org= 127.0.[ 0..255] .1*-4
list.dnswl.org= 127.0.[ 0..255] .2*-6
list.dnswl.org= 127.0.[ 0..255] .3*-8
ix.dnsbl.manitu.net*2
bl.spamcop.net*2
bl.suomispam.net*2
hostkarma.junkemailfilter.com= 127.0.0.2*3
hostkarma.junkemailfilter.com= 127.0.0.4*2
hostkarma.junkemailfilter.com= 127.0.1.2*1
backscatter.spameatingmonkey.net*2
bl.ipv6.spameatingmonkey.net*2
bl.spameatingmonkey.net*2
b.barracudacentral.org= 127.0.0.2*7
bl.mailspike.net= 127.0.0.2*5
bl.mailspike.net= 127.0.0.[ 10; 11; 12] *4
dnsbl.sorbs.net= 127.0.0.10*8
dnsbl.sorbs.net= 127.0.0.5*6
dnsbl.sorbs.net= 127.0.0.7*3
dnsbl.sorbs.net= 127.0.0.8*2
dnsbl.sorbs.net= 127.0.0.6*2
dnsbl.sorbs.net= 127.0.0.9*2
EOF
fi
DNSBL_CONFIG = $( grep -v '^#' /opt/postfix/conf/dns_blocklists.cf | grep '\S' )
2023-08-02 16:48:22 +02:00
if [ ! -z " $DNSBL_CONFIG " ] ; then
echo -e "\e[33mChecking if ASN for your IP is listed for Spamhaus Bad ASN List...\e[0m"
if [ -n " $SPAMHAUS_DQS_KEY " ] ; then
echo -e "\e[32mDetected SPAMHAUS_DQS_KEY variable from mailcow.conf...\e[0m"
echo -e "\e[33mUsing DQS Blocklists from Spamhaus!\e[0m"
SPAMHAUS_DNSBL_CONFIG = $( cat <<EOF
2023-07-31 12:03:07 +02:00
${ SPAMHAUS_DQS_KEY } .zen.dq.spamhaus.net= 127.0.0.[ 4..7] *6
2023-07-31 13:50:36 +02:00
${ SPAMHAUS_DQS_KEY } .zen.dq.spamhaus.net= 127.0.0.[ 10; 11] *8
${ SPAMHAUS_DQS_KEY } .zen.dq.spamhaus.net= 127.0.0.3*4
${ SPAMHAUS_DQS_KEY } .zen.dq.spamhaus.net= 127.0.0.2*3
2023-08-03 09:00:08 +02:00
postscreen_dnsbl_reply_map = texthash:/opt/postfix/conf/dnsbl_reply.map
2023-08-01 16:12:44 +02:00
EOF
2023-08-03 09:00:08 +02:00
cat <<EOF > /opt/postfix/conf/dnsbl_reply.map
2023-08-02 20:20:18 +02:00
# Autogenerated by mailcow, using Spamhaus DQS reply domains
2023-08-01 16:12:44 +02:00
${ SPAMHAUS_DQS_KEY } .sbl.dq.spamhaus.net sbl.spamhaus.org
${ SPAMHAUS_DQS_KEY } .xbl.dq.spamhaus.net xbl.spamhaus.org
${ SPAMHAUS_DQS_KEY } .pbl.dq.spamhaus.net pbl.spamhaus.org
${ SPAMHAUS_DQS_KEY } .zen.dq.spamhaus.net zen.spamhaus.org
${ SPAMHAUS_DQS_KEY } .dbl.dq.spamhaus.net dbl.spamhaus.org
${ SPAMHAUS_DQS_KEY } .zrd.dq.spamhaus.net zrd.spamhaus.org
2023-06-23 14:25:07 +02:00
EOF
2023-08-02 16:48:22 +02:00
)
else
2023-08-03 09:00:08 +02:00
if [ -f "/opt/postfix/conf/dnsbl_reply.map" ] ; then
rm /opt/postfix/conf/dnsbl_reply.map
fi
2023-08-02 16:48:22 +02:00
response = $( curl --connect-timeout 15 --max-time 30 -s -o /dev/null -w "%{http_code}" "https://asn-check.mailcow.email" )
if [ " $response " -eq 503 ] ; then
echo -e "\e[31mThe AS of your IP is listed as a banned AS from Spamhaus!\e[0m"
echo -e "\e[33mNo SPAMHAUS_DQS_KEY found... Skipping Spamhaus blocklists entirely!\e[0m"
SPAMHAUS_DNSBL_CONFIG = ""
elif [ " $response " -eq 200 ] ; then
echo -e "\e[32mThe AS of your IP is NOT listed as a banned AS from Spamhaus!\e[0m"
echo -e "\e[33mUsing the open Spamhaus blocklists.\e[0m"
SPAMHAUS_DNSBL_CONFIG = $( cat <<EOF
2023-07-31 12:03:07 +02:00
zen.spamhaus.org= 127.0.0.[ 10; 11] *8
zen.spamhaus.org= 127.0.0.[ 4..7] *6
zen.spamhaus.org= 127.0.0.3*4
zen.spamhaus.org= 127.0.0.2*3
2023-06-23 14:25:07 +02:00
EOF
2023-08-02 16:48:22 +02:00
)
2023-07-28 20:27:38 +02:00
2023-08-02 16:48:22 +02:00
else
echo -e " \e[31mWe couldn't determine your AS... (maybe DNS/Network issue?) Response Code: $response \e[0m "
echo -e "\e[33mDeactivating Spamhaus DNS Blocklists to be on the safe site!\e[0m"
SPAMHAUS_DNSBL_CONFIG = ""
fi
2023-06-23 15:48:13 +02:00
fi
2023-06-23 14:25:07 +02:00
fi
2023-08-02 16:36:59 +02:00
# Reset main.cf
sed -i '/Overrides/q' /opt/postfix/conf/main.cf
2019-09-02 18:37:05 +02:00
echo >> /opt/postfix/conf/main.cf
2023-08-01 10:49:26 +02:00
# Append postscreen dnsbl sites to main.cf
2023-08-02 16:48:22 +02:00
if [ ! -z " $DNSBL_CONFIG " ] ; then
echo -e " ${ DNSBL_CONFIG } \n ${ SPAMHAUS_DNSBL_CONFIG } " >> /opt/postfix/conf/main.cf
fi
2023-08-01 13:59:23 +02:00
# Append user overrides
2023-08-02 16:36:59 +02:00
echo -e "\n# User Overrides" >> /opt/postfix/conf/main.cf
2020-12-09 14:41:19 +01:00
touch /opt/postfix/conf/extra.cf
sed -i '/myhostname/d' /opt/postfix/conf/extra.cf
echo -e " myhostname = ${ MAILCOW_HOSTNAME } \n $( cat /opt/postfix/conf/extra.cf) " > /opt/postfix/conf/extra.cf
cat /opt/postfix/conf/extra.cf >> /opt/postfix/conf/main.cf
2019-09-02 18:37:05 +02:00
2019-11-12 20:44:43 +01:00
if [ ! -f /opt/postfix/conf/custom_transport.pcre ] ; then
echo "Creating dummy custom_transport.pcre"
touch /opt/postfix/conf/custom_transport.pcre
fi
2020-02-06 08:28:48 +01:00
if [ [ ! -f /opt/postfix/conf/custom_postscreen_whitelist.cidr ] ] ; then
echo "Creating dummy custom_postscreen_whitelist.cidr"
2021-01-11 19:23:32 +01:00
cat <<EOF > /opt/postfix/conf/custom_postscreen_whitelist.cidr
# Autogenerated by mailcow
# Rules are evaluated in the order as specified.
# Blacklist 192.168.* except 192.168.0.1.
# 192.168.0.1 permit
# 192.168.0.0/16 reject
EOF
2020-02-06 08:28:48 +01:00
fi
2017-04-05 22:19:41 +02:00
# Fix Postfix permissions
2019-11-12 20:44:43 +01:00
chown -R root:postfix /opt/postfix/conf/sql/ /opt/postfix/conf/custom_transport.pcre
chmod 640 /opt/postfix/conf/sql/*.cf /opt/postfix/conf/custom_transport.pcre
2017-04-05 22:19:41 +02:00
chgrp -R postdrop /var/spool/postfix/public
chgrp -R postdrop /var/spool/postfix/maildrop
postfix set-permissions
2017-04-08 23:36:46 +02:00
# Check Postfix configuration
2019-09-02 18:37:05 +02:00
postconf -c /opt/postfix/conf > /dev/null
2017-04-08 23:36:46 +02:00
2017-03-02 11:23:23 +01:00
if [ [ $? != 0 ] ] ; then
2017-10-11 11:22:48 +02:00
echo "Postfix configuration error, refusing to start."
exit 1
2017-03-02 11:23:23 +01:00
else
2017-10-11 11:22:48 +02:00
postfix -c /opt/postfix/conf start
sleep 126144000
2023-08-03 09:00:08 +02:00
fi