feat: add MVC base, with auth to ldap
This commit is contained in:
60
controllers/controllerAdmin.php
Normal file
60
controllers/controllerAdmin.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
function listAllOU()
|
||||
{
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Vérifier si le token est présent dans la session
|
||||
if (!isset($_SESSION['ldap_token'])) {
|
||||
die("Token d'authentification manquant. Veuillez vous reconnecter.");
|
||||
}
|
||||
|
||||
$ldapconn = ldap_connect("ldap://intranet.epul3a.local")
|
||||
or die("Could not connect to LDAP server.");
|
||||
|
||||
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
|
||||
|
||||
// Décoder le token et extraire les informations
|
||||
$token = base64_decode($_SESSION['ldap_token']);
|
||||
if ($token === false) {
|
||||
die("Token d'authentification invalide.");
|
||||
}
|
||||
|
||||
list($ldap_user, $ldap_password) = explode(':', $token);
|
||||
if (count(explode(':', $token)) !== 2) {
|
||||
die("Format de token invalide.");
|
||||
}
|
||||
|
||||
$ldap_user = "CN=$ldap_user,CN=Users,DC=epul3a,DC=local";
|
||||
|
||||
if (!@ldap_bind($ldapconn, $ldap_user, $ldap_password)) {
|
||||
die("Could not bind to LDAP server: " . ldap_error($ldapconn));
|
||||
}
|
||||
|
||||
$searchBase = "DC=epul3a,DC=local";
|
||||
$filter = "(objectClass=organizationalUnit)";
|
||||
$attributes = array("ou", "distinguishedName");
|
||||
|
||||
$result = @ldap_search($ldapconn, $searchBase, $filter, $attributes);
|
||||
|
||||
if ($result) {
|
||||
$entries = ldap_get_entries($ldapconn, $result);
|
||||
echo "<h3>Liste des OUs:</h3>";
|
||||
if ($entries['count'] > 0) {
|
||||
foreach ($entries as $key => $entry) {
|
||||
if (is_numeric($key)) {
|
||||
echo "OU: " . $entry['ou'][0] . "<br>";
|
||||
echo "DN: " . $entry['distinguishedname'][0] . "<br><br>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "Aucune OU trouvée.";
|
||||
}
|
||||
} else {
|
||||
echo "Error: " . ldap_error($ldapconn);
|
||||
}
|
||||
|
||||
ldap_close($ldapconn);
|
||||
}
|
||||
Reference in New Issue
Block a user