From 320156439fd00ed92d342159ea5949e65cf01803 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Thu, 16 Jul 2015 19:35:11 +0200 Subject: [PATCH] Fixes #8 - BC BREAK - User configuration is no longer in docker-compose.yml to make it easier to maintain --- Dockerfile | 2 +- README.md | 25 +++++++++++++------------ docker-compose.yml.dist | 11 +++-------- postfix/accounts.cf | 1 + spamassassin/rules.cf | 1 + start-mailserver.sh | 32 ++++++++++++++------------------ 6 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 postfix/accounts.cf create mode 100644 spamassassin/rules.cf diff --git a/Dockerfile b/Dockerfile index 566d16b1..9dad19b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:14.04 MAINTAINER Thomas VIAL # Packages -RUN apt-get update -q +RUN apt-get update -q --fix-missing RUN apt-get -y upgrade RUN DEBIAN_FRONTEND=noninteractive apt-get -y install vim postfix sasl2-bin courier-imap courier-imap-ssl courier-authdaemon supervisor libfam0 fam amavisd-new spamassassin clamav-daemon libnet-dns-perl libmail-spf-perl pyzor razor arj bzip2 cabextract cpio file gzip nomarch pax unzip zip zoo rsyslog RUN apt-get autoclean diff --git a/README.md b/README.md index e0640c9e..4c2bf662 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,13 @@ Additional informations: ## run - docker run -p "25:25" -p "143:143" -p "587:587" -p "993:993" -e docker_mail_users="username1@my-domain.com|username1password" -h mail.my-domain.com -e docker_mail_domain=my-domain.com -t tvial/docker-mailserver + docker run -p "25:25" -p "143:143" -p "587:587" -p "993:993" -e docker_mail_domain=my-domain.com -t tvial/docker-mailserver ## docker-compose template (recommended) mail: - image: tvial/docker-mailserver + # image: tvial/docker-mailserver + build: . hostname: mail domainname: my-domain.com ports: @@ -45,17 +46,17 @@ Additional informations: - "993:993" environment: docker_mail_domain: "my-domain.com" - # format is user@domain.tld|clear_password - docker_mail_users: - - "username1@my-domain.com|username1password" - - "username2@my-domain.com|username2password" - # format is user@domain.tld|list,of,aliases,comma,separated - docker_mail_aliases: - - "username1@my-domain.com|alias1,alias2,alias3" - - "username2@my-domain.com|alias4" + volumes: + - ./spamassassin:/tmp/spamassassin/:ro + - ./postfix:/tmp/postfix/:ro - # usage - docker-compose up -d mail +Volumes allow to: + +- Insert custom antispam rules +- Manage mail users, passwords and aliases + +# usage +docker-compose up -d mail # client configuration diff --git a/docker-compose.yml.dist b/docker-compose.yml.dist index 7b89291f..2dc2afe6 100644 --- a/docker-compose.yml.dist +++ b/docker-compose.yml.dist @@ -10,11 +10,6 @@ mail: - "993:993" environment: docker_mail_domain: "my-domain.com" - # format is user@domain.tld|clear_password - docker_mail_users: - - "username1@my-domain.com|username1password" - - "username2@my-domain.com|username2password" - # format is user@domain.tld|list,of,aliases,comma,separated - docker_mail_aliases: - - "username1@my-domain.com|alias1,alias2,alias3" - - "username2@my-domain.com|alias4" \ No newline at end of file + volumes: + - ./spamassassin:/tmp/spamassassin/:ro + - ./postfix:/tmp/postfix/:ro diff --git a/postfix/accounts.cf b/postfix/accounts.cf new file mode 100644 index 00000000..1489b4d7 --- /dev/null +++ b/postfix/accounts.cf @@ -0,0 +1 @@ +user@domain.tld|mypassword|alias1,alias2 \ No newline at end of file diff --git a/spamassassin/rules.cf b/spamassassin/rules.cf new file mode 100644 index 00000000..891e84ff --- /dev/null +++ b/spamassassin/rules.cf @@ -0,0 +1 @@ +# Place you custom Spamassasin rules here \ No newline at end of file diff --git a/start-mailserver.sh b/start-mailserver.sh index ff7f3dfe..d4f07b01 100644 --- a/start-mailserver.sh +++ b/start-mailserver.sh @@ -1,17 +1,20 @@ #!/bin/sh -echo "Regenerating 'vmailbox' for given users" - +echo "Regenerating postfix 'vmailbox' and 'virtual' for given users" +# rm /etc/postfix/virtual +# rm /etc/postfix/virtual.db +# rm /etc/postfix/vmailbox +# rm /etc/postfix/vmailbox.db echo "# WARNING: this file is auto-generated. Do not modify locally" > /etc/postfix/vmailbox -echo $docker_mail_users | sed -r 's/\[|\]|\x27| //g' | sed -r 's/,/\n/g' > /tmp/docker_mail_users -while IFS=$'|' read -r login pass +while IFS=$'|' read -r login pass aliases do + # Setting variables for better readability user=$(echo ${login} | cut -d @ -f1) domain=$(echo ${login} | cut -d @ -f2) # Let's go! - echo "user '${user}' for domain '${domain}' with password '${pass}'" + echo "user '${user}' for domain '${domain}' with password '********'" echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user} echo "${pass}" | userdbpw -md5 | userdb ${login} set systempw @@ -20,28 +23,20 @@ do maildirmake /var/mail/${domain}/${user} echo ${domain} >> /tmp/vhost.tmp -done < /tmp/docker_mail_users -rm /tmp/docker_mail_users -makeuserdb - -echo "Regenerating 'virtual' for given aliases" -echo $docker_mail_aliases | sed -r 's/\[|\]|\x27|//g' | sed -r 's/, /\n/g' > /tmp/docker_mail_aliases -while IFS=$'|' read -r login aliases -do + # Aliases arr=$(echo $aliases | tr "," "\n") for alias in $arr do - user=$(echo ${login} | cut -d @ -f1) - domain=$(echo ${login} | cut -d @ -f2) echo "$alias@$domain redirects to $login" echo "$alias@$domain\t$login" >> /etc/postfix/virtual done -done < /tmp/docker_mail_aliases -rm /tmp/docker_mail_aliases + +done < /tmp/postfix/accounts.cf +makeuserdb echo "Postfix configurations" postmap /etc/postfix/vmailbox -touch /etc/postfix/virtual && postmap /etc/postfix/virtual +postmap /etc/postfix/virtual sed -i -r 's/DOCKER_MAIL_DOMAIN/'"$docker_mail_domain"'/g' /etc/postfix/main.cf cat /tmp/vhost.tmp | sort | uniq >> /etc/postfix/vhost && rm /tmp/vhost.tmp @@ -57,6 +52,7 @@ echo "required_hits 5.0" >> /etc/mail/spamassassin/local.cf echo "report_safe 0" >> /etc/mail/spamassassin/local.cf echo "required_score 5" >> /etc/mail/spamassassin/local.cf echo "rewrite_header Subject ***SPAM***" >> /etc/mail/spamassassin/local.cf +cp /tmp/spamassassin/rules.cf /etc/spamassassin/ echo "Starting daemons" /etc/init.d/rsyslog start