mirror of
https://github.com/YunoHost-Apps/piwigo_ynh.git
synced 2024-09-03 20:06:03 +02:00
commit
fcb65c4dd4
2 changed files with 23 additions and 13 deletions
|
@ -29,27 +29,33 @@ ynh_add_fail2ban_config () {
|
||||||
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
|
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
|
||||||
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
|
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
|
||||||
|
|
||||||
cat > $finalfail2banjailconf <<EOF
|
sudo tee $finalfail2banjailconf <<EOF
|
||||||
[$app]
|
[$app]
|
||||||
enabled = true
|
enabled = true
|
||||||
port = $ports
|
port = $ports
|
||||||
filter = $app
|
filter = $app
|
||||||
logpath = $logpath
|
logpath = $logpath
|
||||||
maxretry = $max_retry"
|
maxretry = $max_retry
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > $finalfail2banfilterconf <<EOF
|
sudo tee $finalfail2banfilterconf <<EOF
|
||||||
[INCLUDES]
|
[INCLUDES]
|
||||||
before = common.conf
|
before = common.conf
|
||||||
[Definition]
|
[Definition]
|
||||||
failregex = $failregex
|
failregex = $failregex
|
||||||
ignoreregrex ="
|
ignoreregex =
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
ynh_store_file_checksum "$finalfail2banjailconf"
|
ynh_store_file_checksum "$finalfail2banjailconf"
|
||||||
ynh_store_file_checksum "$finalfail2banfilterconf"
|
ynh_store_file_checksum "$finalfail2banfilterconf"
|
||||||
|
|
||||||
systemctl restart fail2ban
|
systemctl restart fail2ban
|
||||||
|
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
||||||
|
if [ -n "$fail2ban_error" ]
|
||||||
|
then
|
||||||
|
echo "[ERR] Fail2ban failed to load the jail for $app" >&2
|
||||||
|
echo "WARNING${fail2ban_error#*WARNING}" >&2
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the dedicated fail2ban config (jail and filter conf files)
|
# Remove the dedicated fail2ban config (jail and filter conf files)
|
||||||
|
@ -58,7 +64,7 @@ EOF
|
||||||
ynh_remove_fail2ban_config () {
|
ynh_remove_fail2ban_config () {
|
||||||
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
|
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
|
||||||
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
|
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
|
||||||
systemctl restart fail2ban
|
sudo systemctl restart fail2ban
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete a file checksum from the app settings
|
# Delete a file checksum from the app settings
|
||||||
|
|
|
@ -91,6 +91,10 @@ chown -R $app: /home/yunohost.app/${app}
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
|
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
|
||||||
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
|
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
|
||||||
|
|
||||||
|
touch "/var/log/${app}FailedLogins.log"
|
||||||
|
chown $app: "/var/log/${app}FailedLogins.log"
|
||||||
|
|
||||||
systemctl restart fail2ban
|
systemctl restart fail2ban
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue