Quota Info and URIBL_BLOCKED with SpamAssassin for Virtualmin

Virtualmin is a web-based management interface for servers based on the Linux operating system. The software offers a wide range of features that allow users to manage their servers efficiently. Thus, Virtualmin can be used to install and configure various types of web applications, databases and email services on a server. The software supports a wide range of operating systems, including CentOS, Debian, Ubuntu and Fedora. Virtualmin is especially useful for web hosting providers who want to host many websites on a single server and still provide high performance for each site. The user interface is easy to use and allows users to manage their servers without any programming knowledge. To this end, the software also provides tools for monitoring system performance.

Virtualmin is open-source software and can be downloaded and used for free. There is also a paid version called Virtualmin Pro, which offers additional features and support. One crucial feature that the free version of Virtualmin lacks, in my opinion, is the ability to notify users about their disk space usage.

This feature can be upgraded with two simple scripts. Virtualmin uses Dovecot to provide mailboxes via IMAP or POP3. The Dovecot server is aware of the space limitations (quotas) set via Virtualmin. The script first cleans up the Spam and Trash folders in each user account. Then the current fill level in each mailbox is calculated by Doveadm. The output is parsed and users with more than 70% used space are passed to another script.

#!/bin/bash  
doveadm expunge -A mailbox spam savedbefore 10d
doveadm expunge -A mailbox Trash savedbefore 10d
doveadm quota recalc -A

# Run the dovecot command and save the output to a variable 
output=$(doveadm -f flow quota get -A)  
# Process each line of the output 
while IFS= read -r line; do 
# Check if the line contains an @ symbol, a percentage, and does not contain "error" 
if [[ $line =~ "@" ]] && [[ $line =~ "%=" ]] && [[ ! $line =~ "error" ]]; then 
# Extract the email, percentage, and domain from the line 
email=$(echo "$line" | awk '{print $1}') 
percent=$(echo "$line" | awk -F'%=' '{print $2}')  
# Check if the percentage contains an integer value 
if [[ $percent =~ ^[0-9]+ ]]; then 
# Check if the percentage is greater than 70 
if [ "$percent" -gt 70 ]; then 
# Call the quota-warning.sh script with the percentage and email 
./quotaemail.sh "$percent" "$email" 
#printf "\n\n"
#echo -n "percent: $percent email: $email"
fi 
fi 
fi 
done <<< "$output"

The additional script is responsible for sending mail to the users. For example, the first script can be called once a week via cron.

#!/bin/sh
PERCENT=$1
USER=$2
ADMIN="admin@domain.tld"
FROM="admin@domain.tld"

msg="From: $FROM
To: $USER
Subject: Speicherplatz-Warnung $PERCENT% 

Sehr geehrte Nutzerin,
sehr geehrter Nutzer,

Ihr Postfach $USER belegt inzwischen $PERCENT% des moeglichen Speicherplatzes.
Bitte loeschen Sie einige Elemente aus diesem Postfach oder speichern Sie diese lokal, um Speicherplatz freizugeben. 



Dear user,

Your mailbox $USER currently allocates $PERCENT% of the possible disk space.
Please delete some items from this mailbox or save them to your local machine to free up disk space.

"

echo "$msg" | /usr/sbin/sendmail -t -f $FROM "$USER"

exit 0

Improve spam filtering with Virtualmin and avoid “URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked”.

Virtualmin relies on SpamAssassin Mail Filter for spam filtering. SpamAssassin contacts several DNS blacklists, which work with a kind of fair-use policy. From a certain number of queries, a paid membership is required. Now at first you might think that a small mail server will not be affected by this. However, it is problematic if the queries are made via a large name server of the data center operator or providers such as Google DNS or Cloudflare. To avoid this, you can use dnsmasq to set up your own DNS caching server on the same machine. To do this, remove a possibly installed BIND DNS server or move it to another port (add listen-on port xxxx and listen-on-v6 port xxxx to /etc/bind/named.conf.options) and restart.

Then install and configure dnsmasq and use the current DNS configuration for dnsmasq by copying it. By adding the appropriate lines to uribl.com these servers will be addressed directly. The matching IP addresses can be found out with the commands “host -t ns multi.uribl.com” and then for example “host ee.uribl.com”.

apt-get install dnsmasq

nano /etc/dnsmasq.conf
user=www-data
group=www-data

resolv-file=/etc/resolv.conf.dnsmasq
server=/multi.uribl.com/54.93.83.147
server=/multi.uribl.com/54.93.185.237
listen-address=127.0.0.1
bind-interfaces

mv /etc/resolv.conf /etc/resolv.conf.dnsmasq

nano /etc/resolv.conf
nameserver 127.0.0.1

nano /etc/spamassassin/local.cf
dns_server 127.0.0.1

Now DNS queries are sent directly from the local machine to the blocklist. Finally, SpamAssassin is configured to use the local dnsmasq server for queries, thus fixing the URIBL_BLOCKED problem.

Leave a Comment