add doc
This commit is contained in:
@@ -1,14 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$table_name = "authentification_attempts";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connexion à la base de données
|
||||||
|
*/
|
||||||
function GetDbConnection(): ?PDO
|
function GetDbConnection(): ?PDO
|
||||||
{
|
{
|
||||||
$host = 'localhost'; // ou l'adresse IP du serveur MariaDB
|
$host = 'localhost';
|
||||||
$dbname = 'ldap'; // nom de votre base de donn<6E>es
|
$dbname = 'ldap';
|
||||||
$username = 'root'; // nom d'utilisateur MariaDB
|
$username = 'root';
|
||||||
$password = '4321'; // mot de passe pour l'utilisateur
|
$password = '4321';
|
||||||
try {
|
try {
|
||||||
// Cr<EFBFBD>ation d'une instance PDO pour la connexion <EFBFBD> la base de donn<EFBFBD>es
|
// Création d'une instance PDO pour la connexion à la base de données
|
||||||
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
|
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
|
||||||
// Configuration du mode d'erreur de PDO pour les exceptions
|
// Configuration du mode d'erreur de PDO pour les exceptions
|
||||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
@@ -39,9 +43,12 @@ class AuthAttempt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute une entrée dans la table des tentatives de connexion
|
||||||
|
*/
|
||||||
function InsertLine(AuthAttempt $attempt)
|
function InsertLine(AuthAttempt $attempt)
|
||||||
{
|
{
|
||||||
$table_name = "authentification_attempts";
|
global $table_name;
|
||||||
$pdo = GetDbConnection();
|
$pdo = GetDbConnection();
|
||||||
|
|
||||||
$query = $pdo->prepare("INSERT INTO $table_name(`username`, `status`, `ip_address`) VALUES (:user, :status, :ip);");
|
$query = $pdo->prepare("INSERT INTO $table_name(`username`, `status`, `ip_address`) VALUES (:user, :status, :ip);");
|
||||||
@@ -53,8 +60,11 @@ function InsertLine(AuthAttempt $attempt)
|
|||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère toutes les lignes de tentative de connexion
|
||||||
|
*/
|
||||||
function GetLines() : array {
|
function GetLines() : array {
|
||||||
$table_name = "authentification_attempts";
|
global $table_name;
|
||||||
$pdo = GetDbConnection();
|
$pdo = GetDbConnection();
|
||||||
|
|
||||||
$query = $pdo->prepare("SELECT * FROM $table_name;");
|
$query = $pdo->prepare("SELECT * FROM $table_name;");
|
||||||
|
|||||||
36
src/ldap.php
36
src/ldap.php
@@ -23,6 +23,9 @@ class UserInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connexion avec des identifiants
|
||||||
|
*/
|
||||||
function LdapConnect(string $domain, string $username, string $password): LDAP\Result|false
|
function LdapConnect(string $domain, string $username, string $password): LDAP\Result|false
|
||||||
{
|
{
|
||||||
global $handle;
|
global $handle;
|
||||||
@@ -30,7 +33,10 @@ function LdapConnect(string $domain, string $username, string $password): LDAP\R
|
|||||||
return $bind;
|
return $bind;
|
||||||
}
|
}
|
||||||
|
|
||||||
function LdapIsConnected(string $domain, string $username, string $password) {
|
/**
|
||||||
|
* Se connecte à l'AD et vérifie la validité des identifiants
|
||||||
|
*/
|
||||||
|
function LdapIsConnected(string $domain, string $username, string $password) : bool {
|
||||||
global $handle;
|
global $handle;
|
||||||
$result = LdapConnect($domain, $username, $password);
|
$result = LdapConnect($domain, $username, $password);
|
||||||
ldap_parse_result($handle, $result, $error_code, $matched_dn, $error_message, $referrals, $controls);
|
ldap_parse_result($handle, $result, $error_code, $matched_dn, $error_message, $referrals, $controls);
|
||||||
@@ -39,20 +45,16 @@ function LdapIsConnected(string $domain, string $username, string $password) {
|
|||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enregistre la tentative de connexion dans la base de données
|
||||||
|
*/
|
||||||
function LogConnection(string $username, bool $success) {
|
function LogConnection(string $username, bool $success) {
|
||||||
InsertLine(new AuthAttempt($username, $success ? "success" : "failure", $_SERVER['REMOTE_ADDR']));
|
InsertLine(new AuthAttempt($username, $success ? "success" : "failure", $_SERVER['REMOTE_ADDR']));
|
||||||
}
|
}
|
||||||
|
|
||||||
function LdapConnectAndBind()
|
/**
|
||||||
{
|
* Retourne les informations d'un utilisateur
|
||||||
global $ldap_domain_name;
|
*/
|
||||||
$ldap_instance = ldap_connect("ldap://$ldap_domain_name.local");
|
|
||||||
ldap_set_option($ldap_instance, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
||||||
ldap_set_option($ldap_instance, LDAP_OPT_REFERRALS, 0);
|
|
||||||
ldap_bind($ldap_instance, "Administrateur@woodywood", "3AFISE+25");
|
|
||||||
return $ldap_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
function LdapGetUserInfo(string $user): ?UserInfo
|
function LdapGetUserInfo(string $user): ?UserInfo
|
||||||
{
|
{
|
||||||
global $handle;
|
global $handle;
|
||||||
@@ -71,12 +73,18 @@ function LdapGetUserInfo(string $user): ?UserInfo
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de retourner les valeur dans une chaîne de caractère de type dn
|
||||||
|
*/
|
||||||
function GetValue(string $dnStr, string $key): array
|
function GetValue(string $dnStr, string $key): array
|
||||||
{
|
{
|
||||||
preg_match_all("/$key=([^,]+)/", $dnStr, $matches);
|
preg_match_all("/$key=([^,]+)/", $dnStr, $matches);
|
||||||
return isset($matches[1]) ? $matches[1] : [];
|
return isset($matches[1]) ? $matches[1] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne tous les objets du type spécifié dans l'ou souhaitée et filtre le résultat
|
||||||
|
*/
|
||||||
function LdapGetObjectsInOU(string $ou, string $objectType, string $field): array
|
function LdapGetObjectsInOU(string $ou, string $objectType, string $field): array
|
||||||
{
|
{
|
||||||
global $ldap_domain_name;
|
global $ldap_domain_name;
|
||||||
@@ -110,11 +118,17 @@ function LdapGetObjectsInOU(string $ou, string $objectType, string $field): arra
|
|||||||
return $object_values;
|
return $object_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne la liste des utilisateurs d'une OU
|
||||||
|
*/
|
||||||
function LdapGetUsersInOU(string $ou): array
|
function LdapGetUsersInOU(string $ou): array
|
||||||
{
|
{
|
||||||
return LdapGetObjectsInOU($ou, "user", "CN");
|
return LdapGetObjectsInOU($ou, "user", "CN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne la liste des groupes d'une OU
|
||||||
|
*/
|
||||||
function LdapGetGroupsInOU(string $ou): array
|
function LdapGetGroupsInOU(string $ou): array
|
||||||
{
|
{
|
||||||
return LdapGetObjectsInOU($ou, "group", "CN");
|
return LdapGetObjectsInOU($ou, "group", "CN");
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
$admin_account = "Administrateur";
|
$admin_account = "Administrateur";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche les éléments d'une liste
|
||||||
|
*/
|
||||||
function PrintListFirsts(string $title, array $liste): string
|
function PrintListFirsts(string $title, array $liste): string
|
||||||
{
|
{
|
||||||
$result = '<div class="list-group-item"><h5>' . $title . '</h5>';
|
$result = '<div class="list-group-item"><h5>' . $title . '</h5>';
|
||||||
@@ -13,6 +16,9 @@ function PrintListFirsts(string $title, array $liste): string
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche les informations de l'utilisateur
|
||||||
|
*/
|
||||||
function PrintLoginInfo($info)
|
function PrintLoginInfo($info)
|
||||||
{
|
{
|
||||||
global $admin_account;
|
global $admin_account;
|
||||||
@@ -33,10 +39,16 @@ function PrintLoginInfo($info)
|
|||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne la chaîne traduite de l'état d'une tentative de connexion
|
||||||
|
*/
|
||||||
function translateSuccess(string $success) {
|
function translateSuccess(string $success) {
|
||||||
return $success == "success" ? "Succès" : "Échec";
|
return $success == "success" ? "Succès" : "Échec";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche l'interface administrateur
|
||||||
|
*/
|
||||||
function PrintAdminInterface(): string
|
function PrintAdminInterface(): string
|
||||||
{
|
{
|
||||||
$auth_attempts = GetLines();
|
$auth_attempts = GetLines();
|
||||||
|
|||||||
Reference in New Issue
Block a user