diff --git a/db_test.php b/db_test.php new file mode 100644 index 0000000..3d7651f --- /dev/null +++ b/db_test.php @@ -0,0 +1,15 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "Connexion réussie � MariaDB avec PDO!"; +} catch (PDOException $e) { + echo "�chec de la connexion : " . $e->getMessage(); +} +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..d2b25e4 --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/ldap.php b/ldap.php new file mode 100644 index 0000000..7624c76 --- /dev/null +++ b/ldap.php @@ -0,0 +1,106 @@ +fullName = $fullName; + $this->ous = $ous; + } +} + +function LdapConnect(string $domain, string $username, string $password, ?array $controls): LDAP\Result|false +{ + global $handle; + $bind = ldap_bind_ext($handle, $username . '@' . $domain, $password, $controls); + LogConnection(); + return $bind; +} + +function LogConnection() {} + +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; +} + +function LdapGetUserInfo(string $user): ?UserInfo +{ + global $handle; + global $ldap_domain_name; + $search_base = "DC=$ldap_domain_name,DC=local"; + $search_filter = "(sAMAccountName=$user)"; + $search_attributes = ["distinguishedname"]; + $result = ldap_search($handle, $search_base, $search_filter, $search_attributes); + $entries = ldap_get_entries($handle, $result); + + if ($entries['count'] > 0) { + $dn = $entries[0]['distinguishedname'][0]; + return new UserInfo(GetValue($dn, "CN")[0], GetValue($dn, "OU")); + } + + return null; +} + +function GetValue(string $dnStr, string $key): array +{ + preg_match_all("/$key=([^,]+)/", $dnStr, $matches); + return isset($matches[1]) ? $matches[1] : []; +} + +function LdapGetObjectsInOU(string $ou, string $objectType, string $field): array +{ + global $ldap_domain_name; + global $handle; + // $handle = LdapConnectAndBind(); + $searchBase = "DC=$ldap_domain_name,DC=local"; + $filter = "(objectClass=$objectType)"; + $attributes = []; + + $object_values = []; + + $result = ldap_search($handle, $searchBase, $filter, $attributes); + $entries = ldap_get_entries($handle, $result); + + if ($entries['count'] > 0) { + foreach ($entries as $key => $entry) { + if (!isset($entry["dn"])) + continue; + $dn = $entry["dn"]; + $ous = GetValue($dn, "OU"); + + $res = array_search($ou, $ous); + if (!is_numeric($res)) + continue; + + $cn = GetValue($dn, $field); + array_push($object_values, $cn); + } + } + + return $object_values; +} + +function LdapGetUsersInOU(string $ou): array +{ + return LdapGetObjectsInOU($ou, "user", "CN"); +} + +function LdapGetGroupsInOU(string $ou): array +{ + return LdapGetObjectsInOU($ou, "group", "CN"); +} diff --git a/login.php b/login.php new file mode 100644 index 0000000..1519ab0 --- /dev/null +++ b/login.php @@ -0,0 +1,33 @@ + +
+ + +Erreur lors de la connexion !
+ +