]> BookStack Code Mirror - bookstack/commitdiff
Log failed accesses option
authorbenrubson <redacted>
Sun, 3 May 2020 14:20:02 +0000 (16:20 +0200)
committerbenrubson <redacted>
Sun, 3 May 2020 14:20:02 +0000 (16:20 +0200)
.env.example.complete
app/Http/Controllers/Auth/LoginController.php

index 04cd73b90cd378d2b105f3b99f3ba01d813c5c08..5b62b1a2a150a24f98f318b85f2b0a522b11c228 100644 (file)
@@ -266,4 +266,10 @@ API_DEFAULT_ITEM_COUNT=100
 API_MAX_ITEM_COUNT=500
 
 # The number of API requests that can be made per minute by a single user.
-API_REQUESTS_PER_MIN=180
\ No newline at end of file
+API_REQUESTS_PER_MIN=180
+
+# Failed access
+# message to log into webserver logs in case of failed access, for further processing by tools like Fail2Ban
+# Apache users should use : user "%u" authentication failure for "BookStack"
+# Nginx  users should use : user "%u" was not found in "BookStack"
+FAILED_ACCESS_MESSAGE=''
index 75ade74e716aa35cb544092ef5fa7ff933c100b6..c000af49e13c9e6ce8e26b413bd7cf56a949f014 100644 (file)
@@ -169,15 +169,20 @@ class LoginController extends Controller
     }
 
     /**
-     * Log failed accesses, matching the default fail2ban nginx/apache auth rules.
-     */
-    protected function logFailedAccess(Request $request)
+     * Log failed accesses, for further processing by tools like Fail2Ban
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return void
+      */
+    protected function logFailedAccess($request)
     {
-        if (isset($_SERVER['SERVER_SOFTWARE']) && preg_match('/nginx/i', $_SERVER['SERVER_SOFTWARE'])) {
-             error_log('user "' . $request->get($this->username()) . '" was not found in "BookStack"', 4);
-         } else {
-             error_log('user "' . $request->get($this->username()) . '" authentication failure for "BookStack"', 4);
-         }
+        $log_msg = env('FAILED_ACCESS_MESSAGE', '');
+
+        if (!is_string($request->get($this->username())) || !is_string($log_msg) || strlen($log_msg)<1)
+            return;
+
+        $log_msg = str_replace("%u", $request->get($this->username()), $log_msg);
+        error_log($log_msg, 4);
     }
 
 }