fix(listmailuser): Don't query quota, if ENABLE_QUOTAS is not 1

Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
This commit is contained in:
Casper 2021-11-01 12:09:47 +01:00 committed by GitHub
parent 71082cb19e
commit c7dec1e330
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 27 deletions

View file

@ -3,6 +3,9 @@
# shellcheck source=../scripts/helper-functions.sh
. /usr/local/bin/helper-functions.sh
# suppress error output, e.g. when listmailuser runs in a fresh container (DMS not running)
. /etc/dms-settings 2> /dev/null
function dovecot_quota_to_hr()
{
if [ "${1}" == "-" ]
@ -23,12 +26,16 @@ while read -r LINE
do
USER=$(echo "${LINE}" | cut -d'|' -f1)
# ${QUOTA[0]} => current size
# ${QUOTA[1]} => configured size limit
# ${QUOTA[2]} => usage in percent
IFS=' ' read -r -a QUOTA <<< "$(doveadm quota get -u "${USER}" | tail +2 | awk '{ if ($3 == "STORAGE") { print $4" "$5" "$6 } }')"
echo "* ${USER} ( $(dovecot_quota_to_hr "${QUOTA[0]}") / $(dovecot_quota_to_hr "${QUOTA[1]}") ) [${QUOTA[2]}%]"
if [[ "${ENABLE_QUOTAS}" -eq 1 ]]
then
# ${QUOTA[0]} => current size
# ${QUOTA[1]} => configured size limit
# ${QUOTA[2]} => usage in percent
IFS=' ' read -r -a QUOTA <<< "$(doveadm quota get -u "${USER}" | tail +2 | awk '{ if ($3 == "STORAGE") { print $4" "$5" "$6 } }')"
echo "* ${USER} ( $(dovecot_quota_to_hr "${QUOTA[0]}") / $(dovecot_quota_to_hr "${QUOTA[1]}") ) [${QUOTA[2]}%]"
else
echo "* ${USER}"
fi
if [[ -f ${ALIASES} ]] && grep -q "${USER}" "${ALIASES}"
then

View file

@ -4,4 +4,4 @@
. /usr/local/bin/helper-functions.sh
_notify 'inf' 'Printing environment variables. Make sure no sensitive data is copied.'
grep ^export /root/.bashrc | sed 's|export ||'
cat /etc/dms-settings

View file

@ -67,20 +67,22 @@ function _setup_default_vars
PFLOGSUMM_RECIPIENT="${PFLOGSUMM_RECIPIENT:=${REPORT_RECIPIENT}}"
LOGWATCH_RECIPIENT="${LOGWATCH_RECIPIENT:=${REPORT_RECIPIENT}}"
VARS[LOGWATCH_RECIPIENT]="${LOGWATCH_RECIPIENT}"
VARS[PFLOGSUMM_RECIPIENT]="${PFLOGSUMM_RECIPIENT}"
VARS[PFLOGSUMM_SENDER]="${PFLOGSUMM_SENDER}"
VARS[PFLOGSUMM_TRIGGER]="${PFLOGSUMM_TRIGGER}"
VARS[POSTMASTER_ADDRESS]="${POSTMASTER_ADDRESS}"
VARS[REPORT_RECIPIENT]="${REPORT_RECIPIENT}"
VARS[REPORT_SENDER]="${REPORT_SENDER}"
: >/root/.bashrc # make DMS variables available in login shells and their subprocesses
: >/etc/dms-settings # this file can be sourced by other scripts
local VAR
for VAR in "${!VARS[@]}"
do
echo "export ${VAR}='${VARS[${VAR}]}'" >>/root/.bashrc
echo "${VAR}='${VARS[${VAR}]}'" >>/etc/dms-settings
done
{
echo "export PFLOGSUMM_SENDER='${PFLOGSUMM_SENDER}'"
echo "export PFLOGSUMM_TRIGGER='${PFLOGSUMM_TRIGGER}'"
echo "export PFLOGSUMM_RECIPIENT='${PFLOGSUMM_RECIPIENT}'"
echo "export POSTMASTER_ADDRESS='${POSTMASTER_ADDRESS}'"
echo "export REPORT_RECIPIENT='${REPORT_RECIPIENT}'"
echo "export REPORT_SENDER='${REPORT_SENDER}'"
} >>/root/.bashrc
}
# File/folder permissions are fine when using docker volumes, but may be wrong

View file

@ -17,23 +17,24 @@ setup_file() {
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
-v "$(pwd)/test/onedir":/var/mail-state \
-e AMAVIS_LOGLEVEL=2 \
-e DMS_DEBUG=0 \
-e ENABLE_CLAMAV=1 \
-e SPOOF_PROTECTION=1 \
-e ENABLE_MANAGESIEVE=1 \
-e ENABLE_QUOTAS=1 \
-e ENABLE_SPAMASSASSIN=1 \
-e ENABLE_SRS=1 \
-e PERMIT_DOCKER=host \
-e REPORT_RECIPIENT=user1@localhost.localdomain \
-e REPORT_SENDER=report1@mail.my-domain.com \
-e SA_KILL=3.0 \
-e SA_SPAM_SUBJECT="SPAM: " \
-e SA_TAG=-5.0 \
-e SA_TAG2=2.0 \
-e SA_KILL=3.0 \
-e AMAVIS_LOGLEVEL=2 \
-e SA_SPAM_SUBJECT="SPAM: " \
-e VIRUSMAILS_DELETE_DELAY=7 \
-e ENABLE_SRS=1 \
-e SASL_PASSWD="external-domain.com username:password" \
-e ENABLE_MANAGESIEVE=1 \
-e PERMIT_DOCKER=host \
-e DMS_DEBUG=0 \
-e SPOOF_PROTECTION=1 \
-e SSL_TYPE='snakeoil' \
-e VIRUSMAILS_DELETE_DELAY=7 \
-h mail.my-domain.com \
--cap-add=SYS_PTRACE \
--tty \
@ -660,8 +661,14 @@ EOF
assert_success
}
@test "checking accounts: listmailuser" {
run docker exec mail /bin/sh -c "listmailuser | head -n 1"
@test "checking accounts: listmailuser (quotas disabled)" {
run docker exec mail /bin/sh -c "echo 'ENABLE_QUOTAS=0' >> /etc/dms-settings && listmailuser | head -n 1"
assert_success
assert_output '* user1@localhost.localdomain'
}
@test "checking accounts: listmailuser (quotas enabled)" {
run docker exec mail /bin/sh -c "sed -i '/ENABLE_QUOTAS=0/d' /etc/dms-settings; listmailuser | head -n 1"
assert_success
assert_output '* user1@localhost.localdomain ( 12K / ~ ) [0%]'
}