44use BookStack \Auth \User ;
55use BookStack \Entities \Entity ;
66use Illuminate \Support \Collection ;
7+ use Illuminate \Support \Facades \Log ;
78
89class ActivityService
910{
@@ -49,7 +50,7 @@ public function addMessage(string $activityKey, string $message, ?int $bookId =
4950 protected function newActivityForUser (string $ key , ?int $ bookId = null ): Activity
5051 {
5152 return $ this ->activity ->newInstance ()->forceFill ([
52- 'key ' => strtolower ($ key ),
53+ 'key ' => strtolower ($ key ),
5354 'user_id ' => $ this ->user ->id ,
5455 'book_id ' => $ bookId ?? 0 ,
5556 ]);
@@ -64,8 +65,8 @@ public function removeEntity(Entity $entity): Collection
6465 {
6566 $ activities = $ entity ->activity ()->get ();
6667 $ entity ->activity ()->update ([
67- 'extra ' => $ entity ->name ,
68- 'entity_id ' => 0 ,
68+ 'extra ' => $ entity ->name ,
69+ 'entity_id ' => 0 ,
6970 'entity_type ' => '' ,
7071 ]);
7172 return $ activities ;
@@ -99,7 +100,7 @@ public function entityActivity(Entity $entity, int $count = 20, int $page = 1):
99100 $ query = $ this ->activity ->newQuery ()->where ('entity_type ' , '= ' , $ entity ->getMorphClass ())
100101 ->where ('entity_id ' , '= ' , $ entity ->id );
101102 }
102-
103+
103104 $ activity = $ this ->permissionService
104105 ->filterRestrictedEntityRelations ($ query , 'activities ' , 'entity_id ' , 'entity_type ' )
105106 ->orderBy ('created_at ' , 'desc ' )
@@ -161,19 +162,18 @@ protected function setNotification(string $activityKey)
161162 }
162163
163164 /**
164- * Log failed accesses, for further processing by tools like Fail2Ban
165- *
166- * @param username
167- * @return void
168- */
169- public function logFailedAccess ($ username )
165+ * Log out a failed login attempt, Providing the given username
166+ * as part of the message if the '%u' string is used.
167+ */
168+ public function logFailedLogin (string $ username )
170169 {
171- $ log_msg = config ('logging.failed_access_message ' );
172-
173- if (!is_string ($ username ) || !is_string ($ log_msg ) || strlen ($ log_msg )<1 )
170+ $ message = config ('logging.failed_login.message ' );
171+ if (!$ message ) {
174172 return ;
173+ }
175174
176- $ log_msg = str_replace ("%u " , $ username , $ log_msg );
177- error_log ($ log_msg , 4 );
175+ $ message = str_replace ("%u " , $ username , $ message );
176+ $ channel = config ('logging.failed_login.channel ' );
177+ Log::channel ($ channel )->warning ($ message );
178178 }
179179}
0 commit comments