|
|
|
@ -190,4 +190,51 @@ ynh_remove_logrotate () { |
|
|
|
if [ -e "/etc/logrotate.d/$app" ]; then |
|
|
|
sudo rm "/etc/logrotate.d/$app" |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ynh_add_fail2ban_config () { |
|
|
|
# Process parameters |
|
|
|
logpath=$1 |
|
|
|
failregex=$2 |
|
|
|
max_retry=${3:-3} |
|
|
|
ports=${4:-http,https} |
|
|
|
|
|
|
|
test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." |
|
|
|
test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." |
|
|
|
|
|
|
|
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf" |
|
|
|
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf" |
|
|
|
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1 |
|
|
|
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1 |
|
|
|
|
|
|
|
echo | sudo tee $finalfail2banjailconf <<EOF |
|
|
|
[$app] |
|
|
|
enabled = true |
|
|
|
port = $ports |
|
|
|
filter = $app |
|
|
|
logpath = $logpath |
|
|
|
maxretry = $max_retry" |
|
|
|
EOF |
|
|
|
|
|
|
|
echo | sudo tee $finalfail2banfilterconf <<EOF |
|
|
|
[INCLUDES] |
|
|
|
before = common.conf |
|
|
|
[Definition] |
|
|
|
failregex = $failregex |
|
|
|
ignoreregrex =" |
|
|
|
EOF |
|
|
|
|
|
|
|
ynh_store_file_checksum "$finalfail2banjailconf" |
|
|
|
ynh_store_file_checksum "$finalfail2banfilterconf" |
|
|
|
|
|
|
|
sudo systemctl restart fail2ban |
|
|
|
} |
|
|
|
|
|
|
|
# Remove the dedicated fail2ban config (jail and filter conf files) |
|
|
|
# |
|
|
|
# usage: ynh_remove_fail2ban_config |
|
|
|
ynh_remove_fail2ban_config () { |
|
|
|
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" |
|
|
|
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" |
|
|
|
sudo systemctl restart fail2ban |
|
|
|
} |