|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
declare(strict_types=1); |
|
5
|
|
|
|
|
6
|
|
|
namespace Chamilo\CoreBundle\Controller\Admin; |
|
7
|
|
|
|
|
8
|
|
|
use Chamilo\CoreBundle\Controller\BaseController; |
|
9
|
|
|
use Chamilo\CoreBundle\Repository\TrackELoginRecordRepository; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted; |
|
14
|
|
|
|
|
15
|
|
|
#[Route('/admin/security')] |
|
16
|
|
|
final class SecurityController extends BaseController |
|
17
|
|
|
{ |
|
18
|
|
|
public function __construct(private readonly TrackELoginRecordRepository $repo) {} |
|
19
|
|
|
|
|
20
|
|
|
#[IsGranted('ROLE_ADMIN')] |
|
21
|
|
|
#[Route('/login-attempts', name: 'admin_security_login_attempts', methods: ['GET'])] |
|
22
|
|
|
public function loginAttempts(Request $r): Response |
|
23
|
|
|
{ |
|
24
|
|
|
$page = max(1, $r->query->getInt('page', 1)); |
|
25
|
|
|
$pageSize = min(100, max(1, $r->query->getInt('pageSize', 25))); |
|
26
|
|
|
$filters = [ |
|
27
|
|
|
'username' => trim((string) $r->query->get('username', '')), |
|
28
|
|
|
'ip' => trim((string) $r->query->get('ip', '')), |
|
29
|
|
|
'from' => $r->query->get('from'), |
|
30
|
|
|
'to' => $r->query->get('to'), |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
$list = $this->repo->findFailedPaginated($page, $pageSize, $filters); |
|
34
|
|
|
|
|
35
|
|
|
$stats = [ |
|
36
|
|
|
'byDay' => $this->repo->failedByDay(7), |
|
37
|
|
|
'byMonth' => $this->repo->failedByMonth(12), |
|
38
|
|
|
'topUsernames' => $this->repo->topUsernames(30, 5), |
|
39
|
|
|
'topIps' => $this->repo->topIps(30, 5), |
|
40
|
|
|
'successVsFailed' => $this->repo->successVsFailedByDay(30), |
|
41
|
|
|
'byHour' => $this->repo->failedByHourOfDay(7), |
|
42
|
|
|
'uniqueIps' => $this->repo->uniqueIpsByDay(30), |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
return $this->render('@ChamiloCore/Admin/Security/login_attempts.html.twig', [ |
|
46
|
|
|
'items' => $list['items'], |
|
47
|
|
|
'total' => $list['total'], |
|
48
|
|
|
'page' => $list['page'], |
|
49
|
|
|
'pageSize' => $list['pageSize'], |
|
50
|
|
|
'filters' => $filters, |
|
51
|
|
|
'stats' => $stats, |
|
52
|
|
|
]); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|