Skip to content

Commit

Permalink
Issue 747 (#748)
Browse files Browse the repository at this point in the history
* fix for issue #747 (NOT TESTED YET)

Need to test this. Dont merge it yet.

* Small Cleanup and bug fixes Not done Yet!

Not done yet. Dont merge. See comment in issue #747

* Add --ignore-missing. Now is fixed.
  • Loading branch information
kamuri authored and johansmitsnl committed Oct 18, 2017
1 parent 420e774 commit 835939d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > /et

COPY ./target/bin /usr/local/bin
# Start-mailserver script
COPY ./target/check_for_changes.sh ./target/start-mailserver.sh ./target/fail2ban-wrapper.sh ./target/postfix-wrapper.sh ./target/docker-configomat/configomat.sh /usr/local/bin/
COPY ./target/check-for-changes.sh ./target/start-mailserver.sh ./target/fail2ban-wrapper.sh ./target/postfix-wrapper.sh ./target/docker-configomat/configomat.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*

# Configure supervisor
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fixtures:
docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve
docker exec mail /bin/sh -c "maildirmake.dovecot /var/mail/localhost.localdomain/user1/.INBOX.spam"
docker exec mail /bin/sh -c "chown 5000:5000 -R /var/mail/localhost.localdomain/user1/.INBOX.spam"
sleep 20
sleep 30
# Sending test mails
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
Expand All @@ -194,7 +194,7 @@ fixtures:

docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
# Wait for mails to be analyzed
sleep 75
sleep 80

tests:
# Start tests
Expand Down
50 changes: 31 additions & 19 deletions target/check_for_changes.sh → target/check-for-changes.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
#! /bin/bash

# create date for log output
log_date=$(date +"%Y-%m-%d %H:%M:%S ")
# Prevent a start too early
sleep 5
echo "${log_date} Start check-for-changes script."

# change directory
cd /tmp/docker-mailserver

# Update / generate after start
echo 'Makeing new chksum'
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum

# Run forever
while true; do

# Check postfix-virtual.cf exist else break
if [ ! -f postfix-virtual.cf ]; then
echo 'postfix-virtual.cf is missing! exit!'
break;
fi

# Check postfix-accounts.cf exist else break
if [ ! -f postfix-accounts.cf ]; then
echo 'postfix-accounts.cf is missing! exit!'
break;
echo "${log_date} postfix-accounts.cf is missing! This should not run! Exit!"
exit
fi

# Update / generate after start
echo "${log_date} Makeing new checksum file."
if [ -f postfix-virtual.cf ]; then
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum
else
sha512sum --tag postfix-accounts.cf > chksum
fi
# Run forever
while true; do

# recreate logdate
log_date=$(date +"%Y-%m-%d %H:%M:%S ")

# Get chksum and check it.
chksum=$(sha512sum -c chksum)
chksum=$(sha512sum -c --ignore-missing chksum)
resu_acc=${chksum:21:2}
resu_vir=${chksum:44:2}
if [ -f postfix-virtual.cf ]; then
resu_vir=${chksum:44:2}
else
resu_vir="OK"
fi

if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
echo "CHANGE DETECT"
echo "${log_date} Change detected"
#regen postfix accounts.
echo -n > /etc/postfix/vmailbox
echo -n > /etc/dovecot/userdb
Expand Down Expand Up @@ -74,6 +80,7 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
echo ${domain} >> /tmp/vhost.tmp
done
fi
if [ -f postfix-virtual.cf ]; then
# regen postfix aliases
echo -n > /etc/postfix/virtual
echo -n > /etc/postfix/regexp
Expand All @@ -97,6 +104,7 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
s/$/ regexp:\/etc\/postfix\/regexp/
}' /etc/postfix/main.cf
fi
fi
# Set vhost
if [ -f /tmp/vhost.tmp ]; then
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
Expand All @@ -115,8 +123,12 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
supervisorctl restart dovecot
fi

echo 'Update chksum'
echo "${log_date} Update checksum"
if [ -f postfix-virtual.cf ]; then
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum
else
sha512sum --tag postfix-accounts.cf > chksum
fi
fi

sleep 1
Expand Down
2 changes: 1 addition & 1 deletion target/supervisor/conf.d/supervisor-app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
command=/usr/local/bin/check_for_changes.sh
command=/usr/local/bin/check-for-changes.sh

0 comments on commit 835939d

Please sign in to comment.