From 805506fbea02ddf57bb5e2fb379298dd67b2c136 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Wed, 11 Jan 2017 10:52:39 +0100 Subject: [PATCH] Fixes #468: cron (virus wiper) (#469) * Fixes #468: cron (virus wiper) --- Dockerfile | 4 ++-- target/bin/virus-wiper | 4 ++++ test/tests.bats | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 target/bin/virus-wiper diff --git a/Dockerfile b/Dockerfile index b9fa1c1b..91483e6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,7 +74,7 @@ RUN sed -i -r 's/^(CRON)=0/\1=1/g' /etc/default/spamassassin RUN sed -i -r 's/#(@| \\%)bypass/\1bypass/g' /etc/amavis/conf.d/15-content_filter_mode RUN adduser clamav amavis && adduser amavis clamav RUN useradd -u 5000 -d /home/docker -s /bin/bash -p $(echo docker | openssl passwd -1 -stdin) docker -RUN (echo "0 4 * * * find /var/lib/amavis/virusmails/ -type f -mtime +\$VIRUSMAILS_DELETE_DELAY -delete" ; crontab -l) | crontab - +RUN (echo "0 4 * * * /usr/local/bin/virus-wiper" ; crontab -l) | crontab - # Configure Fail2ban COPY target/fail2ban/jail.conf /etc/fail2ban/jail.conf @@ -118,7 +118,7 @@ RUN sed -i -r "/^#?compress/c\compress\ncopytruncate" /etc/logrotate.conf && \ sed -i -r 's|/var/log/mail|/var/log/mail/mail|g' /etc/logrotate.d/rsyslog # Get LetsEncrypt signed certificate -RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > /etc/ssl/certs/lets-encrypt-x3-cross-signed.pem +RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > /etc/ssl/certs/lets-encrypt-x3-cross-signed.pem COPY ./target/bin /usr/local/bin # Start-mailserver script diff --git a/target/bin/virus-wiper b/target/bin/virus-wiper new file mode 100644 index 00000000..c9a5f336 --- /dev/null +++ b/target/bin/virus-wiper @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Wipping virus older than $VIRUSMAILS_DELETE_DELAY days" +find /var/lib/amavis/virusmails/ -type f -mtime +$VIRUSMAILS_DELETE_DELAY -delete diff --git a/test/tests.bats b/test/tests.bats index 0e0fdebd..45e9a63f 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -567,7 +567,7 @@ load 'test_helper/bats-assert/load' } @test "checking amavis: virusmail wiper cron exists" { - run docker exec mail bash -c "crontab -l | grep '/var/lib/amavis/virusmails/'" + run docker exec mail bash -c "crontab -l | grep '/usr/local/bin/virus-wiper'" assert_success } @@ -578,7 +578,7 @@ load 'test_helper/bats-assert/load' @test "checking amavis: old virusmail is wipped by cron" { docker exec mail bash -c 'touch -d "`date --date=2000-01-01`" /var/lib/amavis/virusmails/should-be-deleted' - run docker exec -ti mail bash -c 'find /var/lib/amavis/virusmails/ -type f -mtime +$VIRUSMAILS_DELETE_DELAY -delete' + run docker exec -ti mail bash -c '/usr/local/bin/virus-wiper' assert_success run docker exec mail bash -c 'ls -la /var/lib/amavis/virusmails/ | grep should-be-deleted' assert_failure @@ -586,7 +586,7 @@ load 'test_helper/bats-assert/load' @test "checking amavis: recent virusmail is not wipped by cron" { docker exec mail bash -c 'touch -d "`date`" /var/lib/amavis/virusmails/should-not-be-deleted' - run docker exec -ti mail bash -c 'find /var/lib/amavis/virusmails/ -type f -mtime +$VIRUSMAILS_DELETE_DELAY -delete' + run docker exec -ti mail bash -c '/usr/local/bin/virus-wiper' assert_success run docker exec mail bash -c 'ls -la /var/lib/amavis/virusmails/ | grep should-not-be-deleted' assert_success