diff options
author | Daniel Hansson <github@hanssonit.se> | 2021-01-16 23:22:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 23:22:48 +0300 |
commit | 8e73f9ce8004c07037259a3276ef8fbc11d0bba8 (patch) | |
tree | 6d1ad5a79506d916be3ba73eb49a39a12bee5677 /apps/fail2ban.sh | |
parent | ff0da09870627050a2a286a7f6ceeffb09b08da5 (diff) |
fix race condition (#1771)
Diffstat (limited to 'apps/fail2ban.sh')
-rw-r--r-- | apps/fail2ban.sh | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/apps/fail2ban.sh b/apps/fail2ban.sh index f6b87cbe..83c96fe2 100644 --- a/apps/fail2ban.sh +++ b/apps/fail2ban.sh @@ -57,6 +57,24 @@ fi # Create $VMLOGS dir mkdir -p "$VMLOGS" +find_log() { + NCLOG=$(find / -type f -name "nextcloud.log" 2> /dev/null) + if [ "$NCLOG" != "$VMLOGS/nextcloud.log" ] + then + # Might enter here if no OR multiple logs already exist, tidy up any existing logs and set the correct path + print_text_in_color "$ICyan" "Unexpected or non-existent logging configuration - \ +deleting any discovered nextcloud.log files and creating a new one at $VMLOGS/nextcloud.log..." + xargs rm -f <<< "$NCLOG" + # Set logging + nextcloud_occ config:system:set log_type --value=file + nextcloud_occ config:system:set logfile --value="$VMLOGS/nextcloud.log" + nextcloud_occ config:system:set loglevel --value=2 + touch "$VMLOGS/nextcloud.log" + chown www-data:www-data "$VMLOGS/nextcloud.log" + return + fi +} + ### Local variables ### # location of Nextcloud logs print_text_in_color "$ICyan" "Finding nextcloud.log..." @@ -70,6 +88,8 @@ do nextcloud_occ config:system:set log_type --value=file nextcloud_occ config:system:set loglevel --value=2 break + else + find_log fi elif [ -n "$(nextcloud_occ_no_check config:system:get logfile)" ] then @@ -81,25 +101,13 @@ do chown www-data:www-data "$VMLOGS/nextcloud.log" break else - NCLOG=$(find / -type f -name "nextcloud.log" 2> /dev/null) - if [ "$NCLOG" != "$VMLOGS/nextcloud.log" ] - then - # Might enter here if no OR multiple logs already exist, tidy up any existing logs and set the correct path - print_text_in_color "$ICyan" "Unexpected or non-existent logging configuration - \ -deleting any discovered nextcloud.log files and creating a new one at $VMLOGS/nextcloud.log..." - xargs rm -f <<< "$NCLOG" - # Set logging - nextcloud_occ config:system:set log_type --value=file - nextcloud_occ config:system:set logfile --value="$VMLOGS/nextcloud.log" - nextcloud_occ config:system:set loglevel --value=2 - touch "$VMLOGS/nextcloud.log" - chown www-data:www-data "$VMLOGS/nextcloud.log" - break - fi + find_log fi done + # remove ncdata, else it will be used rm -f $NCDATA/nextcloud.log + # time to ban an IP that exceeded attempts BANTIME_=1209600 # cooldown time for incorrect passwords |