Intermédiaire
This commit is contained in:
63
Sources/webAduc/www/ldap.php
Normal file
63
Sources/webAduc/www/ldap.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
function getBaseDnFromUserPrincipalName($userPrincipalName)
|
||||
{
|
||||
$BaseDn="";
|
||||
$domain = explode("@",$userPrincipalName)[1];
|
||||
$domainParts = explode(".",$domain);
|
||||
$BaseDn = "DC=".$domainParts[0].",DC=".$domainParts[1];
|
||||
return $BaseDn;
|
||||
}
|
||||
|
||||
function extractNameFromDn($dn)
|
||||
{
|
||||
//CN=Builtin,DC=easylinux,DC=lan
|
||||
return explode("=",explode(",",$dn)[0])[1];
|
||||
}
|
||||
|
||||
//$User = "CN=Administrator,CN=Users,DC=easylinux,DC=lan";
|
||||
$User = "administrator@easylinux.lan";
|
||||
$Pass = "1duB015!";
|
||||
$uri = "ldap://dc1:389";
|
||||
// $uri = "ldaps://dc1:636";
|
||||
|
||||
if( ! $cnx=ldap_connect($uri))
|
||||
die("erreur: ldap_connect");
|
||||
|
||||
if( ! ldap_bind ( $cnx , $User , $Pass ) )
|
||||
{
|
||||
echo ldap_errno($cnx).": ".ldap_error($cnx);
|
||||
die("<br />erreur: ldap_bind");
|
||||
}
|
||||
|
||||
|
||||
ldap_set_option($cnx, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_set_option($cnx, LDAP_OPT_REFERRALS, 0);
|
||||
|
||||
$sr = ldap_list($cnx, getBaseDnFromUserPrincipalName($User),"dn=*");
|
||||
|
||||
$info = ldap_get_entries($cnx, $sr);
|
||||
|
||||
for ($i=0; $i < $info["count"]; $i++) {
|
||||
//echo var_dump($info);
|
||||
|
||||
echo "show: ".var_dump($info[$i]["showinadvancedviewonly"][0]). "- ";
|
||||
if( $info[$i]["showinadvancedviewonly"][0] == "FALSE" )
|
||||
{
|
||||
echo extractNameFromDn($info[$i]["dn"]);
|
||||
}
|
||||
|
||||
// //echo $info[$i]["dn"];
|
||||
echo "<br/>";
|
||||
}
|
||||
ldap_close($cnx);
|
||||
|
||||
|
||||
echo "<br/><br/>".getBaseDnFromUserPrincipalName($User);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
objectCategory contient le type
|
||||
*/
|
||||
?>
|
||||
Reference in New Issue
Block a user