From dd0b399f3316de1d41928effe6e840777b92c133 Mon Sep 17 00:00:00 2001 From: Casper Date: Sun, 28 Mar 2021 15:37:48 +0200 Subject: [PATCH] feat: Introduce ENABLE_AMAVIS env (#1866) * Introduce ENABLE_AMAVIS env * missing 'fi' added * documentation added * add condition for amavis fix function * Fix spelling Co-authored-by: William Desportes * Fix spelling Co-authored-by: William Desportes Co-authored-by: William Desportes Co-authored-by: Frederic Werner <20406381+wernerfred@users.noreply.github.com> --- ENVIRONMENT.md | 7 +++++++ mailserver.env | 5 +++++ target/scripts/start-mailserver.sh | 6 +++--- target/scripts/startup/setup-stack.sh | 24 +++++++++++++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md index ae3c0089..f9d8d6ab 100644 --- a/ENVIRONMENT.md +++ b/ENVIRONMENT.md @@ -27,6 +27,13 @@ Here you can adjust the [log-level for Supervisor](http://supervisord.org/loggin The log-level will show everything in its class and above. +##### ENABLE_AMAVIS + +Amavis content filter (used for ClamAV & SpamAssassin) + +- 0 => Amavis is disabled +- **1** => Amavis is enabled + ##### ENABLE_CLAMAV - **0** => Clamav is disabled diff --git a/mailserver.env b/mailserver.env index a039a779..2981451c 100644 --- a/mailserver.env +++ b/mailserver.env @@ -64,6 +64,11 @@ ENABLE_SRS=0 ENABLE_POP3= ENABLE_CLAMAV=0 +# Amavis content filter (used for ClamAV & SpamAssassin) +# 0 => Disabled +# 1 => Enabled +ENABLE_AMAVIS=1 + # If you enable Fail2Ban, don't forget to add the following lines to your `docker-compose.yml`: # cap_add: # - NET_ADMIN diff --git a/target/scripts/start-mailserver.sh b/target/scripts/start-mailserver.sh index 238bcb5b..a3b3d8f0 100755 --- a/target/scripts/start-mailserver.sh +++ b/target/scripts/start-mailserver.sh @@ -20,6 +20,7 @@ VARS[DEFAULT_RELAY_HOST]="${DEFAULT_RELAY_HOST:=}" VARS[DMS_DEBUG]="${DMS_DEBUG:=0}" VARS[DOVECOT_MAILBOX_FORMAT]="${DOVECOT_MAILBOX_FORMAT:=maildir}" VARS[DOVECOT_TLS]="${DOVECOT_TLS:=no}" +VARS[ENABLE_AMAVIS]="${ENABLE_AMAVIS:=1}" VARS[ENABLE_CLAMAV]="${ENABLE_CLAMAV:=0}" VARS[ENABLE_FAIL2BAN]="${ENABLE_FAIL2BAN:=0}" VARS[ENABLE_FETCHMAIL]="${ENABLE_FETCHMAIL:=0}" @@ -149,7 +150,7 @@ function register_functions # ? >> Fixes _register_fix_function '_fix_var_mail_permissions' - _register_fix_function '_fix_var_amavis_permissions' + [[ ${ENABLE_AMAVIS} -eq 1 ]] && _register_fix_function '_fix_var_amavis_permissions' [[ ${ENABLE_CLAMAV} -eq 0 ]] && _register_fix_function '_fix_cleanup_clamav' [[ ${ENABLE_SPAMASSASSIN} -eq 0 ]] && _register_fix_function '_fix_cleanup_spamassassin' @@ -180,8 +181,7 @@ function register_functions [[ ${ENABLE_FETCHMAIL} -eq 1 ]] && _register_start_daemon '_start_daemons_fetchmail' [[ ${ENABLE_CLAMAV} -eq 1 ]] && _register_start_daemon '_start_daemons_clamav' [[ ${ENABLE_LDAP} -eq 0 ]] && _register_start_daemon '_start_changedetector' - - _register_start_daemon '_start_daemons_amavis' + [[ ${ENABLE_AMAVIS} -eq 1 ]] && _register_start_daemon '_start_daemons_amavis' } function _register_start_daemon diff --git a/target/scripts/startup/setup-stack.sh b/target/scripts/startup/setup-stack.sh index a90c3aa7..e404c542 100644 --- a/target/scripts/startup/setup-stack.sh +++ b/target/scripts/startup/setup-stack.sh @@ -128,10 +128,16 @@ function _setup_mailname function _setup_amavis { - _notify 'task' 'Setting up Amavis' - sed -i \ - "s|^#\$myhostname = \"mail.example.com\";|\$myhostname = \"${HOSTNAME}\";|" \ - /etc/amavis/conf.d/05-node_id + if [[ ${ENABLE_AMAVIS} -eq 1 ]] + then + _notify 'task' 'Setting up Amavis' + sed -i \ + "s|^#\$myhostname = \"mail.example.com\";|\$myhostname = \"${HOSTNAME}\";|" \ + /etc/amavis/conf.d/05-node_id + else + _notify 'task' 'Remove Amavis from postfix configuration' + sed -i 's|content_filter =.*|content_filter =|' /etc/postfix/main.cf + fi } function _setup_dmarc_hostname @@ -1475,10 +1481,14 @@ function _setup_security_stack # fix cron.daily for spamassassin sed -i -e 's|invoke-rc.d spamassassin reload|/etc/init\.d/spamassassin reload|g' /etc/cron.daily/spamassassin - # copy user provided configuration files if provided - if [[ -f /tmp/docker-mailserver/amavis.cf ]] + # Amavis + if [[ ${ENABLE_AMAVIS} -eq 1 ]] then - cp /tmp/docker-mailserver/amavis.cf /etc/amavis/conf.d/50-user + _notify 'inf' 'Amavis enabled' + if [[ -f /tmp/docker-mailserver/amavis.cf ]] + then + cp /tmp/docker-mailserver/amavis.cf /etc/amavis/conf.d/50-user + fi fi }