[Postfix] only apply DNSBL if dns_blocklists.cf is not empty

This commit is contained in:
FreddleSpl0it 2023-08-02 16:48:22 +02:00
parent c45684b986
commit 5d3491c801
No known key found for this signature in database
GPG Key ID: 00E14E7634F4BEC5

View File

@ -425,6 +425,7 @@ EOF
fi fi
DNSBL_CONFIG=$(grep -v '^#' /opt/postfix/conf/dns_blocklists.cf | grep '\S') DNSBL_CONFIG=$(grep -v '^#' /opt/postfix/conf/dns_blocklists.cf | grep '\S')
if [ ! -z "$DNSBL_CONFIG" ]; then
echo -e "\e[33mChecking if ASN for your IP is listed for Spamhaus Bad ASN List...\e[0m" echo -e "\e[33mChecking if ASN for your IP is listed for Spamhaus Bad ASN List...\e[0m"
if [ -n "$SPAMHAUS_DQS_KEY" ]; then if [ -n "$SPAMHAUS_DQS_KEY" ]; then
echo -e "\e[32mDetected SPAMHAUS_DQS_KEY variable from mailcow.conf...\e[0m" echo -e "\e[32mDetected SPAMHAUS_DQS_KEY variable from mailcow.conf...\e[0m"
@ -438,7 +439,6 @@ if [ -n "$SPAMHAUS_DQS_KEY" ]; then
${SPAMHAUS_DQS_KEY}.zrd.dq.spamhaus.net=127.0.0.2*3 ${SPAMHAUS_DQS_KEY}.zrd.dq.spamhaus.net=127.0.0.2*3
EOF EOF
) )
else else
response=$(curl --connect-timeout 15 --max-time 30 -s -o /dev/null -w "%{http_code}" "https://asn-check.mailcow.email") response=$(curl --connect-timeout 15 --max-time 30 -s -o /dev/null -w "%{http_code}" "https://asn-check.mailcow.email")
if [ "$response" -eq 503 ]; then if [ "$response" -eq 503 ]; then
@ -462,12 +462,15 @@ EOF
SPAMHAUS_DNSBL_CONFIG="" SPAMHAUS_DNSBL_CONFIG=""
fi fi
fi fi
fi
# Reset main.cf # Reset main.cf
sed -i '/Overrides/q' /opt/postfix/conf/main.cf sed -i '/Overrides/q' /opt/postfix/conf/main.cf
echo >> /opt/postfix/conf/main.cf echo >> /opt/postfix/conf/main.cf
# Append postscreen dnsbl sites to main.cf # Append postscreen dnsbl sites to main.cf
if [ ! -z "$DNSBL_CONFIG" ]; then
echo -e "${DNSBL_CONFIG}\n${SPAMHAUS_DNSBL_CONFIG}" >> /opt/postfix/conf/main.cf echo -e "${DNSBL_CONFIG}\n${SPAMHAUS_DNSBL_CONFIG}" >> /opt/postfix/conf/main.cf
fi
# Append user overrides # Append user overrides
echo -e "\n# User Overrides" >> /opt/postfix/conf/main.cf echo -e "\n# User Overrides" >> /opt/postfix/conf/main.cf
touch /opt/postfix/conf/extra.cf touch /opt/postfix/conf/extra.cf