Skip to content

Commit

Permalink
fail2ban: autodetect log path
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Sep 12, 2017
1 parent 05a3895 commit b390652
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions etc/nextcloudpi-config.d/fail2ban.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

ACTIVE_=no

# location of Nextcloud logs
NCLOG_=/var/www/nextcloud/data/nextcloud.log

# time to ban an IP that exceeded attempts
BANTIME_=600

Expand All @@ -39,18 +36,27 @@ install()

configure()
{
[[ $ACTIVE_ != "yes" ]] && { service fail2ban stop; update-rc.d fail2ban disable; return; }
[[ $ACTIVE_ != "yes" ]] && {
service fail2ban stop
update-rc.d fail2ban disable
echo "fail2ban disabled"
return
}

local NCLOG="/var/www/nextcloud/data/nextcloud.log"
local NCLOG1="$( sudo -u www-data /var/www/nextcloud/occ config:system:get logfile )"

[[ "$NCLOG1" != "" ]] && NCLOG="$NCLOG1"

local BASEDIR=$( dirname "$NCLOG_" )
local BASEDIR=$( dirname "$NCLOG" )
[ -d "$BASEDIR" ] || { echo -e "directory $BASEDIR not found"; return 1; }

sudo -u www-data touch "$NCLOG_" || { echo -e "ERROR: user www-data does not have write permissions on $NCLOG_"; return 1; }
sudo -u www-data touch "$NCLOG" || { echo -e "ERROR: user www-data does not have write permissions on $NCLOG"; return 1; }
chown -R www-data "$BASEDIR"

cd /var/www/nextcloud
sudo -u www-data php occ config:system:set loglevel --value=2
sudo -u www-data php occ config:system:set log_type --value=file
sudo -u www-data php occ config:system:set logfile --value="$NCLOG_"

cat > /etc/fail2ban/filter.d/nextcloud.conf <<'EOF'
[INCLUDES]
Expand Down Expand Up @@ -112,12 +118,13 @@ maxretry = $MAXRETRY_
enabled = true
port = http,https
filter = nextcloud
logpath = $NCLOG_
logpath = $NCLOG
maxretry = $MAXRETRY_
EOF
update-rc.d fail2ban defaults
update-rc.d fail2ban enable
service fail2ban restart
echo "fail2ban enabled"
}

cleanup()
Expand Down
4 changes: 2 additions & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ source /usr/local/etc/library.sh

# fix automount, reinstall if its old version
AMFILE=/usr/local/etc/nextcloudpi-config.d/nc-automount.sh
grep -q inotify-tools $AMFILE || rm $AMFILE
test -e $AMFILE && { grep -q inotify-tools $AMFILE || rm $AMFILE; }

# fix modsecurity, reinstall if its old verion
MSFILE=/usr/local/etc/nextcloudpi-config.d/modsecurity.sh
grep -q "NextCloudPi:" $MSFILE || rm $MSFILE
test -e $MSFILE && { grep -q "NextCloudPi:" $MSFILE || rm $MSFILE; }

# copy all files in bin and etc
for file in bin/* etc/*; do
Expand Down

0 comments on commit b390652

Please sign in to comment.