File: //etc/fail2ban/action.d/postfix-spam.conf
# Fail2ban confiuration file
# Custom mail spam filter - fh
[INCLUDES]
[Definition]
# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
# Values: CMD
#
actionstart = touch /etc/postfix/denied_sender
postmap hash:/etc/postfix/denied_sender
# Option: actionstop
# Notes.: command executed once at the end of Fail2Ban
# Values: CMD
#
actionstop = echo `cat /dev/null` > /etc/postfix/denied_sender
postmap hash:/etc/postfix/denied_sender
# Option: actioncheck
# Notes.: command executed once before each actionban command
# Values: CMD
#
actioncheck =
# Option: actionban
# Notes.: command executed when banning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionban = uid=<ip>
user=$(echo $uid)
echo "csh$user REJECT" >> /etc/postfix/denied_sender
postmap hash:/etc/postfix/denied_sender
echo -e "Subject: [Fail2Ban-Mail] $domain Banned\n\nDomain $domain has sent more than 300 mails. Denied $user from sending mail on `uname -n`.\nPlease inform the customer they will be unable to send mail\nTo re-enable:\nfail2ban-client set mail-spam unbanip <ip>\n\n" | sendmail -f linuxadmin@fasthosts.co.uk linuxadmin@fasthosts.co.uk
# Option: actionunban
# Notes.: command executed when unbanning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionunban = uid=<ip>
user=$(echo $uid)
sed -i /$user/d /etc/postfix/denied_sender
postmap hash:/etc/postfix/denied_sender
[Init]