display attempts to admin
This commit is contained in:
73
database.php
Normal file
73
database.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
|
||||
function GetDbConnection(): ?PDO
|
||||
{
|
||||
$host = 'localhost'; // ou l'adresse IP du serveur MariaDB
|
||||
$dbname = 'ldap'; // nom de votre base de donn<6E>es
|
||||
$username = 'root'; // nom d'utilisateur MariaDB
|
||||
$password = '4321'; // mot de passe pour l'utilisateur
|
||||
try {
|
||||
// Cr<43>ation d'une instance PDO pour la connexion <20> la base de donn<6E>es
|
||||
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
|
||||
// Configuration du mode d'erreur de PDO pour les exceptions
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
return $pdo;
|
||||
} catch (PDOException $e) {
|
||||
echo "Échec de la connexion : " . $e->getMessage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class AuthAttempt
|
||||
{
|
||||
public string $username;
|
||||
public string $status;
|
||||
public string $timestamp;
|
||||
public string $ip_address;
|
||||
|
||||
public function __construct(
|
||||
string $username,
|
||||
string $status,
|
||||
string $ip_address,
|
||||
string $timestamp = "",
|
||||
) {
|
||||
$this->username = $username;
|
||||
$this->status = $status;
|
||||
$this->ip_address = $ip_address;
|
||||
$this->timestamp = $timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
function InsertLine(AuthAttempt $attempt)
|
||||
{
|
||||
$table_name = "authentification_attempts";
|
||||
$pdo = GetDbConnection();
|
||||
|
||||
$query = $pdo->prepare("INSERT INTO $table_name(`username`, `status`, `ip_address`) VALUES (:user, :status, :ip);");
|
||||
|
||||
$query->bindValue(":user", $attempt->username, PDO::PARAM_STR);
|
||||
$query->bindValue(":status", $attempt->status, PDO::PARAM_STR);
|
||||
$query->bindValue(":ip", $attempt->ip_address, PDO::PARAM_STR);
|
||||
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
function GetLines() : array {
|
||||
$table_name = "authentification_attempts";
|
||||
$pdo = GetDbConnection();
|
||||
|
||||
$query = $pdo->prepare("SELECT * FROM $table_name;");
|
||||
|
||||
$query->execute();
|
||||
|
||||
$lines = $query->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach($lines as $line) {
|
||||
array_push($result, new AuthAttempt($line["username"], $line["status"], $line["ip_address"], $line["timestamp"]));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
Reference in New Issue
Block a user