diff --git a/src/database.php b/src/database.php index 7481e09..ed1f0ea 100644 --- a/src/database.php +++ b/src/database.php @@ -1,14 +1,18 @@ 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) { - $table_name = "authentification_attempts"; + global $table_name; $pdo = GetDbConnection(); $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(); } +/** + * Récupère toutes les lignes de tentative de connexion + */ function GetLines() : array { - $table_name = "authentification_attempts"; + global $table_name; $pdo = GetDbConnection(); $query = $pdo->prepare("SELECT * FROM $table_name;"); diff --git a/src/ldap.php b/src/ldap.php index 5446f12..7c0ebe1 100644 --- a/src/ldap.php +++ b/src/ldap.php @@ -23,6 +23,9 @@ class UserInfo } } +/** + * Connexion avec des identifiants + */ function LdapConnect(string $domain, string $username, string $password): LDAP\Result|false { global $handle; @@ -30,7 +33,10 @@ function LdapConnect(string $domain, string $username, string $password): LDAP\R 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; $result = LdapConnect($domain, $username, $password); 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; } +/** + * Enregistre la tentative de connexion dans la base de données + */ function LogConnection(string $username, bool $success) { InsertLine(new AuthAttempt($username, $success ? "success" : "failure", $_SERVER['REMOTE_ADDR'])); } -function LdapConnectAndBind() -{ - 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; -} - +/** + * Retourne les informations d'un utilisateur + */ function LdapGetUserInfo(string $user): ?UserInfo { global $handle; @@ -71,12 +73,18 @@ function LdapGetUserInfo(string $user): ?UserInfo return null; } +/** + * Permet de retourner les valeur dans une chaîne de caractère de type dn + */ function GetValue(string $dnStr, string $key): array { preg_match_all("/$key=([^,]+)/", $dnStr, $matches); 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 { global $ldap_domain_name; @@ -110,11 +118,17 @@ function LdapGetObjectsInOU(string $ou, string $objectType, string $field): arra return $object_values; } +/** + * Retourne la liste des utilisateurs d'une OU + */ function LdapGetUsersInOU(string $ou): array { return LdapGetObjectsInOU($ou, "user", "CN"); } +/** + * Retourne la liste des groupes d'une OU + */ function LdapGetGroupsInOU(string $ou): array { return LdapGetObjectsInOU($ou, "group", "CN"); diff --git a/view/View.php b/view/View.php index 8617bcf..48b4a8e 100644 --- a/view/View.php +++ b/view/View.php @@ -2,6 +2,9 @@ $admin_account = "Administrateur"; +/** + * Affiche les éléments d'une liste + */ function PrintListFirsts(string $title, array $liste): string { $result = '