From 346a349ca48a77087f3698d011b58abadfd8d44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 9 Jan 2025 17:27:46 +0100 Subject: [PATCH 1/2] fail2ban helper doesn't have --use_template anymore --- helpers/helpers.v2.1.d/fail2ban | 7 ------- 1 file changed, 7 deletions(-) diff --git a/helpers/helpers.v2.1.d/fail2ban b/helpers/helpers.v2.1.d/fail2ban index 5b4bdea33b..7dbf57adde 100644 --- a/helpers/helpers.v2.1.d/fail2ban +++ b/helpers/helpers.v2.1.d/fail2ban @@ -100,13 +100,6 @@ ignoreregex = ynh_config_add --template="f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf" ynh_config_add --template="f2b_filter.conf" --destination="/etc/fail2ban/filter.d/$app.conf" - # if "$logpath" doesn't exist (as if using --use_template argument), assign - # "$logpath" using the one in the previously generated fail2ban conf file - if [ -z "${logpath:-}" ]; then - # the first sed deletes possibles spaces and the second one extract the path - logpath=$(grep "^logpath" "/etc/fail2ban/jail.d/$app.conf" | sed "s/ //g" | sed "s/logpath=//g") - fi - # Create the folder and logfile if they doesn't exist, # as fail2ban require an existing logfile before configuration mkdir -p "/var/log/$app" From 47675187e97dd9136e1baa0b317c4bb53b6e6c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 9 Jan 2025 17:30:51 +0100 Subject: [PATCH 2/2] fail2ban: logpath isn't always /var/log/$app... Also only apply permissions when it doesn't already exist --- helpers/helpers.v2.1.d/fail2ban | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/helpers/helpers.v2.1.d/fail2ban b/helpers/helpers.v2.1.d/fail2ban index 7dbf57adde..9eba988db3 100644 --- a/helpers/helpers.v2.1.d/fail2ban +++ b/helpers/helpers.v2.1.d/fail2ban @@ -102,13 +102,20 @@ ignoreregex = # Create the folder and logfile if they doesn't exist, # as fail2ban require an existing logfile before configuration - mkdir -p "/var/log/$app" + local logdir=$(dirname "$logpath") + if [ ! -d "$logdir" ]; then + mkdir -p "$logdir" + # Make sure log folder's permissions are correct + chown "$app:$app" "$logdir" + chmod u=rwX,g=rX,o= "$logdir" + fi + if [ ! -f "$logpath" ]; then touch "$logpath" + # Make sure log file's permissions are correct + chown "$app:$app" "$logpath" + chmod u=rwX,g=rX,o= "$logpath" fi - # Make sure log folder's permissions are correct - chown -R "$app:$app" "/var/log/$app" - chmod -R u=rwX,g=rX,o= "/var/log/$app" ynh_systemctl --service=fail2ban --action=reload --wait_until="(Started|Reloaded) fail2ban.service" --log_path=systemd