ISPmail (8): Quotas

Quota là hạn mức dung lượng đĩa cho người dùng, để người dùng không lãng phí dung lượng ổ đĩa vô hạn mà buộc phải dọn sạch các email cũ mỗi giờ.
Cài đặt ở hai nơi. Postfix cần từ chối các email mới nếu hộp thư của người dùng vượt quá dung lượng. Và Dovecot cần theo dõi hạn ngạch và số lượng người dùng đã sử dụng hết.

Script

#!/bin/bash
# Tên script: 07.quotas.sh
# Cấu hình hạn mức dùng đĩa
# © 2020 LNT <lnt@lyle.info>
# version 20200801
#
echo 'Cấu hình hạn mức dùng đĩa...'
HOSTNAME=$(hostname)
DOMAIN=${HOSTNAME#*.}

## Dovecot quota policy service ##
grep -q '\s*quota_status_success' /etc/dovecot/conf.d/90-quota.conf || sed '/plugin {/ { a\
  quota = maildir:User quota \
  quota_status_success = DUNNO \
  quota_status_nouser = DUNNO \
  quota_status_overquota = "452 4.2.2 Mailbox is full and cannot receive any more emails"
:loop; n; b loop }' -i /etc/dovecot/conf.d/90-quota.conf

grep -q '^service quota\-status' /etc/dovecot/conf.d/90-quota.conf || cat >>  /etc/dovecot/conf.d/90-quota.conf <<EOF
service quota-status {
  executable = /usr/lib/dovecot/quota-status -p postfix
  unix_listener /var/spool/postfix/private/quota-status {
    user = postfix
  }
}
EOF
## Postfix recipient restrictions ##
postconf "smtpd_recipient_restrictions=reject_unauth_destination,check_policy_service unix:private/quota-status"

## Automatic warning emails ##
grep -q '^service quota\-warning' /etc/dovecot/conf.d/90-quota.conf || cat >> /etc/dovecot/conf.d/90-quota.conf <<EOF
plugin {
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning2 = storage=80%% quota-warning 80 %u
  quota_warning3 = -storage=100%% quota-warning below %u
}
service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  unix_listener quota-warning {
    group = dovecot
    mode = 0660
  }
}
EOF
cat > /usr/local/bin/quota-warning.sh <<EOT
#!/bin/sh
PERCENT=\$1
USER=\$2
cat <<EOF | /usr/lib/dovecot/dovecot-lda -d \$USER -o "plugin/quota=maildir:User quota:noenforcing"
From: postmaster@${DOMAIN}
Subject: Quota warning - \$PERCENT% reached

Your mailbox can only store a limited amount of emails.
Currently it is \$PERCENT% full. If you reach 100% then
new emails cannot be stored. Thanks for your understanding.
EOF
EOT
chmod +x /usr/local/bin/quota-warning.sh
systemctl restart dovecot

Comments Off on ISPmail (8): Quotas

Filed under Software

Comments are closed.