display attempts to admin

This commit is contained in:
2025-03-26 20:48:39 +01:00
parent db2079e0b3
commit 45b9cc7dfa
9 changed files with 443 additions and 26 deletions

View File

@@ -1,5 +1,7 @@
<?php
$admin_account = "Administrateur";
function PrintListFirsts(string $title, array $liste): string
{
$result = '<div class="list-group-item"><h5>' . $title . '</h5>';
@@ -13,7 +15,11 @@ function PrintListFirsts(string $title, array $liste): string
function PrintLoginInfo($info)
{
global $admin_account;
$body = '<h2 class="text-center pt-3">Bienvenue ' . $info->fullName . " !</h2>";
if ($info->fullName == $admin_account) {
return $body .= PrintAdminInterface();
}
$body .= '<div class="list-group ">';
foreach ($info->ous as $ou) {
$body .= '<div class="list-group-item"><h3>' . $ou . "</h3>";
@@ -22,8 +28,48 @@ function PrintLoginInfo($info)
$body .= PrintListFirsts("Groupes", LdapGetGroupsInOU($ou));
$body .= "</div>";
$body .= "</div>";
}
$body .= "</div>";
return $body;
}
function translateSuccess(string $success) {
return $success == "success" ? "Succès" : "Échec";
}
function PrintAdminInterface(): string
{
$auth_attempts = GetLines();
$body = '<h5 class="text-center">Historique des connexions</h5>';
$body .= '<table id="attempts" class="table table-striped table-bordered">
<thead class="thead-light">
<tr>
<th scope="col">Utilisateur</th>
<th scope="col">Status</th>
<th scope="col">Date</th>
<th scope="col">Adresse IP</th>
</tr>
</thead>';
foreach ($auth_attempts as $attempt) {
$body .= '<tr>';
$body .= '<td>' . $attempt->username . '</td>';
$body .= '<td>' . translateSuccess($attempt->status) . '</td>';
$body .= '<td>' . $attempt->timestamp . '</td>';
$body .= '<td>' . $attempt->ip_address . '</td>';
$body .= '</tr>';
}
$body .= "</table>";
$body .= '
<script src="/js/datatables.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
let table = new DataTable("#attempts", {
language: {
url: "/lang/fr.json",
},
});
});
</script>
';
return $body;
}