diff --git a/Dockerfiles/prod/data/docker-entrypoint.d/301-postfix.sh b/Dockerfiles/prod/data/docker-entrypoint.d/301-postfix.sh index 5631f98..fe9d377 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.d/301-postfix.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.d/301-postfix.sh @@ -22,70 +22,83 @@ set_postfix() { local debug="${7}" local php_ini_file="${php_ini_dir}/devilbox-runtime-sendmail.ini" - local catch_all= + local enable_mail= + # Verify env value if ! env_set "${env_varname}"; then log "info" "\$${env_varname} not set." "${debug}" log "info" "Postfix will not be started." "${debug}" echo "" > "${php_ini_file}" - else - catch_all="$( env_get "${env_varname}" )" - if [ "${catch_all}" = "1" ]; then - log "info" "\$${env_varname} set to 1. Enabling postfix catch-all" "${debug}" + return + fi - # Configure PHP - { - echo "[mail function]"; - echo "sendmail_path = $( which sendmail ) -t -i"; - echo ";mail.force_extra_parameters ="; - echo "mail.add_x_header = On"; - echo "mail.log = ${php_mail_log}"; - } > "${php_ini_file}" + # Retrieve env value + enable_mail="$( env_get "${env_varname}" )" - # PHP mail function logs to file - if [ "${docker_logs}" != "1" ]; then - # Fix PHP mail log file dir/file and permissions - if [ ! -d "$( dirname "${php_mail_log}" )" ]; then - run "mkdir -p $( dirname "${php_mail_log}" )" "${debug}" - fi - if [ ! -f "${php_mail_log}" ]; then - run "touch ${php_mail_log}" "${debug}" - fi - run "chown ${username}:${groupname} $( dirname "${php_mail_log}" )" "${debug}" - run "chown ${username}:${groupname} ${php_mail_log}" "${debug}" - run "chmod 0644 ${php_mail_log}" "${debug}" + # Enable postfix + if [ "${enable_mail}" = "1" ] || [ "${enable_mail}" = "2" ]; then + + if [ "${enable_mail}" = "1" ]; then + log "info" "\$${env_varname} set to 1. Enabling postfix" "${debug}" + else + log "info" "\$${env_varname} set to 2. Enabling postfix catch-all" "${debug}" + fi + + # Configure PHP + { + echo "[mail function]"; + echo "sendmail_path = $( command -v sendmail ) -t -i"; + echo ";mail.force_extra_parameters ="; + echo "mail.add_x_header = On"; + echo "mail.log = ${php_mail_log}"; + } > "${php_ini_file}" + + # PHP mail function logs to file + if [ "${docker_logs}" != "1" ]; then + # Fix PHP mail log file dir/file and permissions + if [ ! -d "$( dirname "${php_mail_log}" )" ]; then + run "mkdir -p $( dirname "${php_mail_log}" )" "${debug}" fi - - # Add Mail dir/file if it does not exist - if [ ! -d "/var/mail" ]; then - run "mkdir /var/mail" "${debug}" - fi - if [ ! -f "/var/mail/${username}" ]; then - run "touch /var/mail/${username}" "${debug}" + if [ ! -f "${php_mail_log}" ]; then + run "touch ${php_mail_log}" "${debug}" fi + run "chown ${username}:${groupname} $( dirname "${php_mail_log}" )" "${debug}" + run "chown ${username}:${groupname} ${php_mail_log}" "${debug}" + run "chmod 0644 ${php_mail_log}" "${debug}" + fi - # Fix mail dir/file permissions after mount - run "chmod 0644 /var/mail/${username}" "${debug}" - run "chown ${username}:${groupname} /var/mail" "${debug}" - run "chown ${username}:${groupname} /var/mail/${username}" "${debug}" + # Add Mail dir/file if it does not exist + if [ ! -d "/var/mail" ]; then + run "mkdir /var/mail" "${debug}" + fi + if [ ! -f "/var/mail/${username}" ]; then + run "touch /var/mail/${username}" "${debug}" + fi - # warning: specify "strict_mailbox_ownership = no" to ignore mailbox ownership mismatch - run "postconf -e 'strict_mailbox_ownership=no'" "${debug}" + # Fix mail dir/file permissions after mount + run "chmod 0644 /var/mail/${username}" "${debug}" + run "chown ${username}:${groupname} /var/mail" "${debug}" + run "chown ${username}:${groupname} /var/mail/${username}" "${debug}" - # Postfix configuration - run "postconf -e 'inet_protocols=ipv4'" "${debug}" + # warning: specify "strict_mailbox_ownership = no" to ignore mailbox ownership mismatch + run "postconf -e 'strict_mailbox_ownership=no'" "${debug}" + + # Postfix configuration + run "postconf -e 'inet_protocols=ipv4'" "${debug}" + + # Postfix catch-all + if [ "${enable_mail}" = "2" ]; then run "postconf -e 'virtual_alias_maps=pcre:/etc/postfix/virtual'" "${debug}" run "echo '/.*@.*/ ${username}' >> /etc/postfix/virtual" "${debug}" - run "newaliases" "${debug}" - - elif [ "${catch_all}" = "0" ]; then - log "info" "\$${env_varname} set to 0. Disabling postfix catch-all" "${debug}" - - else - log "err" "Invalid value for \$${env_varname}. Can only be 0 or 1. Prodived: ${catch_all}" "${debug}" - exit 1 fi + + elif [ "${enable_mail}" = "0" ]; then + log "info" "\$${env_varname} set to 0. Disabling postfix" "${debug}" + + else + log "err" "Invalid value for \$${env_varname}. Can only be 0, 1 or 2. Prodived: ${enable_mail}" "${debug}" + exit 1 fi } diff --git a/Dockerfiles/prod/data/docker-entrypoint.sh b/Dockerfiles/prod/data/docker-entrypoint.sh index b539011..01e10e7 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.sh @@ -24,9 +24,6 @@ DVL_PHP_INI_DIR="/usr/local/etc/php/conf.d" # php-fpm conf.d directory DVL_PHP_FPM_DIR="/usr/local/etc/php-fpm.d" -# This is the log file for any mail related functions -DVL_PHP_MAIL_LOG="/var/log/mail.log" - # This file holds error and access log definitions DVL_PHP_FPM_CONF_LOGFILE="${DVL_PHP_FPM_DIR}/zzz-entrypoint-logfiles.conf" DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini" @@ -34,6 +31,9 @@ DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini" # PHP-FPM log dir DVL_FPM_LOG_DIR="/var/log/php" +# This is the log file for any mail related functions +DVL_PHP_MAIL_LOG="${DVL_FPM_LOG_DIR}/mail.log" + # Custom ini dir (to be copied to actual ini dir) DVL_PHP_CUST_INI_DIR="/etc/php-custom.d" @@ -138,7 +138,7 @@ done ### ### Supervisor: rsyslogd & postfix ### -if [ "$( env_get "ENABLE_MAIL" )" = "1" ]; then +if [ "$( env_get "ENABLE_MAIL" )" = "1" ] || [ "$( env_get "ENABLE_MAIL" )" = "2" ]; then supervisor_add_service "rsyslogd" "/usr/sbin/rsyslogd -n" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}" "1" supervisor_add_service "postfix" "/usr/local/sbin/postfix.sh" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}" fi diff --git a/Dockerfiles/prod/data/postfix.sh b/Dockerfiles/prod/data/postfix.sh index 48d1b0d..694db2a 100755 --- a/Dockerfiles/prod/data/postfix.sh +++ b/Dockerfiles/prod/data/postfix.sh @@ -22,14 +22,7 @@ set -o pipefail ### ### Variables ### -if [ -f "/etc/alpine-release" ]; then - MAILLOG="/var/log/maillog" -elif [ -f "/etc/debian_version" ]; then - MAILLOG="/var/log/mail.log" -else - MAILLOG="/var/log/maillog" -fi - +MAILLOG="/var/log/mail.log" MAILPID="/var/spool/postfix/pid/master.pid" diff --git a/Dockerfiles/work/Dockerfile-5.2 b/Dockerfiles/work/Dockerfile-5.2 index 1b14043..7282231 100644 --- a/Dockerfiles/work/Dockerfile-5.2 +++ b/Dockerfiles/work/Dockerfile-5.2 @@ -191,7 +191,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-5.3 b/Dockerfiles/work/Dockerfile-5.3 index 960426e..4a2908a 100644 --- a/Dockerfiles/work/Dockerfile-5.3 +++ b/Dockerfiles/work/Dockerfile-5.3 @@ -208,7 +208,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-5.4 b/Dockerfiles/work/Dockerfile-5.4 index 0e2006c..bff346d 100644 --- a/Dockerfiles/work/Dockerfile-5.4 +++ b/Dockerfiles/work/Dockerfile-5.4 @@ -237,7 +237,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-5.5 b/Dockerfiles/work/Dockerfile-5.5 index 7cf129b..9405d6a 100644 --- a/Dockerfiles/work/Dockerfile-5.5 +++ b/Dockerfiles/work/Dockerfile-5.5 @@ -241,7 +241,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-5.6 b/Dockerfiles/work/Dockerfile-5.6 index 8fce4d6..a53e64b 100644 --- a/Dockerfiles/work/Dockerfile-5.6 +++ b/Dockerfiles/work/Dockerfile-5.6 @@ -254,7 +254,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-7.0 b/Dockerfiles/work/Dockerfile-7.0 index 2482e2a..891b32b 100644 --- a/Dockerfiles/work/Dockerfile-7.0 +++ b/Dockerfiles/work/Dockerfile-7.0 @@ -254,7 +254,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-7.1 b/Dockerfiles/work/Dockerfile-7.1 index afd2dfe..fd6013d 100644 --- a/Dockerfiles/work/Dockerfile-7.1 +++ b/Dockerfiles/work/Dockerfile-7.1 @@ -254,7 +254,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-7.2 b/Dockerfiles/work/Dockerfile-7.2 index b9a2684..5e315ea 100644 --- a/Dockerfiles/work/Dockerfile-7.2 +++ b/Dockerfiles/work/Dockerfile-7.2 @@ -254,7 +254,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-7.3 b/Dockerfiles/work/Dockerfile-7.3 index 9fecf52..3a2907e 100644 --- a/Dockerfiles/work/Dockerfile-7.3 +++ b/Dockerfiles/work/Dockerfile-7.3 @@ -254,7 +254,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-7.4 b/Dockerfiles/work/Dockerfile-7.4 index 09d47c3..bf39729 100644 --- a/Dockerfiles/work/Dockerfile-7.4 +++ b/Dockerfiles/work/Dockerfile-7.4 @@ -254,7 +254,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/Dockerfile-8.0 b/Dockerfiles/work/Dockerfile-8.0 index 786f5d8..61cfdb5 100644 --- a/Dockerfiles/work/Dockerfile-8.0 +++ b/Dockerfiles/work/Dockerfile-8.0 @@ -197,7 +197,7 @@ RUN set -eux \ \ \ # -------------------- mhsendmail -------------------- - && wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + && wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ \ diff --git a/Dockerfiles/work/data/docker-entrypoint.sh b/Dockerfiles/work/data/docker-entrypoint.sh index 75f38b1..d1ef1c6 100755 --- a/Dockerfiles/work/data/docker-entrypoint.sh +++ b/Dockerfiles/work/data/docker-entrypoint.sh @@ -24,9 +24,6 @@ DVL_PHP_INI_DIR="/usr/local/etc/php/conf.d" # php-fpm conf.d directory DVL_PHP_FPM_DIR="/usr/local/etc/php-fpm.d" -# This is the log file for any mail related functions -DVL_PHP_MAIL_LOG="/var/log/mail.log" - # This file holds error and access log definitions DVL_PHP_FPM_CONF_LOGFILE="${DVL_PHP_FPM_DIR}/zzz-entrypoint-logfiles.conf" DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini" @@ -34,6 +31,9 @@ DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini" # PHP-FPM log dir DVL_FPM_LOG_DIR="/var/log/php" +# This is the log file for any mail related functions +DVL_PHP_MAIL_LOG="${DVL_FPM_LOG_DIR}/mail.log" + # Custom ini dir (to be copied to actual ini dir) DVL_PHP_CUST_INI_DIR="/etc/php-custom.d" @@ -138,7 +138,7 @@ done ### ### Supervisor: rsyslogd & postfix ### -if [ "$( env_get "ENABLE_MAIL" )" = "1" ]; then +if [ "$( env_get "ENABLE_MAIL" )" = "1" ] || [ "$( env_get "ENABLE_MAIL" )" = "2" ]; then supervisor_add_service "rsyslogd" "/usr/sbin/rsyslogd -n" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}" "1" supervisor_add_service "postfix" "/usr/local/sbin/postfix.sh" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}" fi diff --git a/README.md b/README.md index 820011d..d36db46 100644 --- a/README.md +++ b/README.md @@ -798,7 +798,7 @@ Have a look at the following table to see all supported environment variables fo ENABLE_MAIL bool 0 - Enable local email catch-all.
Postfix will be configured for local delivery and all mails sent (even to real domains) will be catched locally. No email will ever go out. They will all be stored in a local devilbox account.
Value: 0 or 1 + Start local postfix with or without email catch-all.
0: Postfix service disabled.
1: Postfix service started normally.
2: Postfix service started configured for local delivery and all mails sent (even to real domains) will be catched locally. No email will ever go out. They will all be stored in a local devilbox account.
Value: 0, 1 or 2 FORWARD_PORTS_TO_LOCALHOST @@ -871,7 +871,7 @@ Have a look at the following table to see all offered volumes for each Docker im /var/mail - Emails caught be the postfix catch-all (ENABLE_MAIL=1) will be available in this directory. + Emails caught be the postfix catch-all (ENABLE_MAIL=2) will be available in this directory. @@ -1186,12 +1186,12 @@ $ docker run -d \ #### Launch Postfix for mail-catching -Once you set `$ENABLE_MAIL=1`, all mails sent via any of your PHP applications no matter to which domain, are catched locally into the `devilbox` account. You can also mount the mail directory locally to hook in with mutt and read those mails. +Once you set `$ENABLE_MAIL=2`, all mails sent via any of your PHP applications no matter to which domain, are catched locally into the `devilbox` account. You can also mount the mail directory locally to hook in with mutt and read those mails. ```shell $ docker run -d \ -p 127.0.0.1:9000:9000 \ -v /tmp/mail:/var/mail \ - -e ENABLE_MAIL=1 \ + -e ENABLE_MAIL=2 \ -t devilbox/php-fpm:7.2-prod ``` diff --git a/build/ansible/group_vars/all/work.yml b/build/ansible/group_vars/all/work.yml index bdd4ebf..c211b22 100644 --- a/build/ansible/group_vars/all/work.yml +++ b/build/ansible/group_vars/all/work.yml @@ -571,7 +571,7 @@ software_available: mhsendmail: all: command: | - wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ + wget https://github.com/devilbox/mhsendmail/releases/download/v0.3.0/mhsendmail_linux_amd64 \ && chmod +x mhsendmail_linux_amd64 \ && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail \ mysqldumpsecure: diff --git a/tests/prod/04-test-env-enable_mail.sh b/tests/prod/04-test-env-enable_mail.sh index 30669e3..75a1166 100755 --- a/tests/prod/04-test-env-enable_mail.sh +++ b/tests/prod/04-test-env-enable_mail.sh @@ -23,7 +23,7 @@ FLAVOUR="${3}" ### Postfix ### MOUNTPOINT="$( mktemp --directory )" -did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABLE_MAIL=1 -v ${MOUNTPOINT}:/var/mail" )" +did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABLE_MAIL=2 -v ${MOUNTPOINT}:/var/mail" )" run "sleep 10" if ! run "docker logs ${did} 2>&1 | grep -q 'ENABLE_MAIL'"; then @@ -36,7 +36,7 @@ fi if [ ! -f "${MOUNTPOINT}/devilbox" ]; then echo "Mail file does not exist: ${MOUNTPOINT}/devilbox" - ls -lap ${MOUNTPOINT}/ + ls -lap "${MOUNTPOINT}/" docker_logs "${did}" || true docker_stop "${did}" || true rm -rf "${MOUNTPOINT}" @@ -45,7 +45,7 @@ if [ ! -f "${MOUNTPOINT}/devilbox" ]; then fi if [ ! -r "${MOUNTPOINT}/devilbox" ]; then echo "Mail file is not readable" - ls -lap ${MOUNTPOINT}/ + ls -lap "${MOUNTPOINT}/" docker_logs "${did}" || true docker_stop "${did}" || true rm -rf "${MOUNTPOINT}"