-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fail2ban: email notification (Closes #232)
- Loading branch information
1 parent
a4e5df7
commit dcbafb2
Showing
3 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,17 @@ FINDTIME_=600 | |
# bad attempts before banning an IP | ||
MAXRETRY_=6 | ||
|
||
# email to send notifications to | ||
[email protected] | ||
|
||
MAILALERTS_=no | ||
|
||
DESCRIPTION="Brute force protection for SSH and NextCloud" | ||
|
||
install() | ||
{ | ||
apt-get update | ||
apt-get install --no-install-recommends -y fail2ban | ||
apt-get install --no-install-recommends -y fail2ban whois | ||
update-rc.d fail2ban disable | ||
rm -f /etc/fail2ban/jail.d/defaults-debian.conf | ||
|
||
|
@@ -54,6 +59,12 @@ exit 0 | |
EOF | ||
chmod +x /etc/cont-init.d/100-fail2ban-run.sh | ||
} | ||
|
||
# tweak fail2ban email | ||
local F=/etc/fail2ban/action.d/sendmail-common.conf | ||
sed -i 's|Fail2Ban|NextCloudPi|' /etc/fail2ban/action.d/sendmail-whois-lines.conf | ||
grep -q actionstart_ "$F" || sed -i 's|actionstart|actionstart_|' "$F" | ||
grep -q actionstop_ "$F" || sed -i 's|actionstop|actionstop_|' "$F" | ||
} | ||
|
||
configure() | ||
|
@@ -89,6 +100,7 @@ failregex = Login failed.*Remote IP.*'<HOST>' | |
ignoreregex = | ||
EOF | ||
|
||
[[ "$MAILALERTS_" == "yes" ]] && local ACTION=action_mwl || local ACTION=action_ | ||
|
||
cat > /etc/fail2ban/jail.conf <<EOF | ||
# The DEFAULT allows a global definition of the options. They can be overridden | ||
|
@@ -111,13 +123,13 @@ maxretry = $MAXRETRY_ | |
# | ||
# ACTIONS | ||
# | ||
banaction = iptables-multiport | ||
protocol = tcp | ||
chain = INPUT | ||
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"] | ||
action_mw = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"] | ||
banaction = iptables-multiport | ||
protocol = tcp | ||
chain = INPUT | ||
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"] | ||
action_mwl = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"] | ||
action = %(action_)s | ||
sendmail-whois-lines[name=%(__name__)s, dest=$EMAIL_, [email protected]] | ||
action = %($ACTION)s | ||
# | ||
# SSH | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters