Move logFailedAccess into Activity

This commit is contained in:
benrubson 2020-05-23 15:37:38 +02:00
parent 8f1f73defa
commit 9d7ce59b18
2 changed files with 20 additions and 19 deletions

View File

@ -183,4 +183,21 @@ class ActivityService
session()->flash('success', $message);
}
}
/**
* Log failed accesses, for further processing by tools like Fail2Ban
*
* @param username
* @return void
*/
public function logFailedAccess($username)
{
$log_msg = config('logging.failed_access_message');
if (!is_string($username) || !is_string($log_msg) || strlen($log_msg)<1)
return;
$log_msg = str_replace("%u", $username, $log_msg);
error_log($log_msg, 4);
}
}

View File

@ -2,6 +2,7 @@
namespace BookStack\Http\Controllers\Auth;
use Activity;
use BookStack\Auth\Access\SocialAuthService;
use BookStack\Exceptions\LoginAttemptEmailNeededException;
use BookStack\Exceptions\LoginAttemptException;
@ -102,7 +103,7 @@ class LoginController extends Controller
$this->fireLockoutEvent($request);
// Also log some error message
$this->logFailedAccess($request);
Activity::logFailedAccess($request->get($this->username()));
return $this->sendLockoutResponse($request);
}
@ -121,7 +122,7 @@ class LoginController extends Controller
$this->incrementLoginAttempts($request);
// Also log some error message
$this->logFailedAccess($request);
Activity::logFailedAccess($request->get($this->username()));
return $this->sendFailedLoginResponse($request);
}
@ -168,21 +169,4 @@ class LoginController extends Controller
return redirect('/login');
}
/**
* Log failed accesses, for further processing by tools like Fail2Ban
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function logFailedAccess($request)
{
$log_msg = config('logging.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);
}
}