Skip to content

Commit

Permalink
Merge pull request #2024 from YunoHost/fail2banhelper
Browse files Browse the repository at this point in the history
Fix fail2ban helper for non-/var/log/$app paths
  • Loading branch information
alexAubin authored Jan 9, 2025
2 parents 4a07a83 + 4767518 commit 9fcc09a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions helpers/helpers.v2.1.d/fail2ban
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ 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"
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

Expand Down

0 comments on commit 9fcc09a

Please sign in to comment.