Probleme active directory

Résolu/Fermé
yossra - 25 sept. 2020 à 16:53
 yossra - 25 sept. 2020 à 16:55
Bonjour,
je veux que l'interface affiche toute les informations sur les users selon le choix de l'utilisateur
<code php><?php
$var=$_POST['username'];
//LDAP Bind paramters, need to be a normal AD User account.
$ldap_password = 'Stage2020';
$ldap_username = '***@***';
$ldap_connection = ldap_connect("onas.local");

if (FALSE === $ldap_connection){
// Uh-oh, something is wrong...
echo 'Unable to connect to the ldap server';
}

// We have to set this option for the version of Active Directory we are using.
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search.

if (TRUE === ldap_bind($ldap_connection, $ldap_username, $ldap_password)){

//Your domains DN to query
$ldap_base_dn = 'DC=onas,DC=local';

//Get standard users and contacts
$search_filter = "sAMAccountName=".$var;

//Connect to LDAP
$result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter);

if (FALSE !== $result){
$entries = ldap_get_entries($ldap_connection, $result);

// Uncomment the below if you want to write all entries to debug somethingthing
//var_dump($entries);

//Create a table to display the output
echo '<h2>AD User Results</h2></br>';
echo '<table border = "1"><tr bgcolor="#cccccc"><td>Username</td><td>Last Name</td><td>First Name</td><td>Company</td><td>Department</td><td>Office Phone</td><td>Fax</td><td>Mobile</td><td>DDI</td><td>E-Mail Address</td><td>Home Phone</td></tr>';

//For each account returned by the search
for ($x=0; $x<$entries['count']; $x++){

//
//Retrieve values from Active Directory
//

//Windows Usernaame
$LDAP_samaccountname = "";

if (!empty($entries[$x]['samaccountname'][0])) {
$LDAP_samaccountname = $entries[$x]['samaccountname'][0];
if ($LDAP_samaccountname == "NULL"){
$LDAP_samaccountname= "";
}
} else {
//#There is no samaccountname s0 assume this is an AD contact record so generate a unique username

$LDAP_uSNCreated = $entries[$x]['usncreated'][0];
$LDAP_samaccountname= "CONTACT_" . $LDAP_uSNCreated;
}

//Last Name
$LDAP_LastName = "";

if (!empty($entries[$x]['sn'][0])) {
$LDAP_LastName = $entries[$x]['sn'][0];
if ($LDAP_LastName == "NULL"){
$LDAP_LastName = "";
}
}

//First Name
$LDAP_FirstName = "";

if (!empty($entries[$x]['givenname'][0])) {
$LDAP_FirstName = $entries[$x]['givenname'][0];
if ($LDAP_FirstName == "NULL"){
$LDAP_FirstName = "";
}
}

//Company
$LDAP_CompanyName = "";

if (!empty($entries[$x]['company'][0])) {
$LDAP_CompanyName = $entries[$x]['company'][0];
if ($LDAP_CompanyName == "NULL"){
$LDAP_CompanyName = "";
}
}

//Department
$LDAP_Department = "";

if (!empty($entries[$x]['department'][0])) {
$LDAP_Department = $entries[$x]['department'][0];
if ($LDAP_Department == "NULL"){
$LDAP_Department = "";
}
}

//Job Title
$LDAP_JobTitle = "";

if (!empty($entries[$x]['title'][0])) {
$LDAP_JobTitle = $entries[$x]['title'][0];
if ($LDAP_JobTitle == "NULL"){
$LDAP_JobTitle = "";
}
}

//IPPhone
$LDAP_OfficePhone = "";

if (!empty($entries[$x]['ipphone'][0])) {
$LDAP_OfficePhone = $entries[$x]['ipphone'][0];
if ($LDAP_OfficePhone == "NULL"){
$LDAP_OfficePhone = "";
}
}

//FAX Number
$LDAP_OfficeFax = "";

if (!empty($entries[$x]['facsimiletelephonenumber'][0])) {
$LDAP_OfficeFax = $entries[$x]['facsimiletelephonenumber'][0];
if ($LDAP_OfficeFax == "NULL"){
$LDAP_OfficeFax = "";
}
}

//Mobile Number
$LDAP_CellPhone = "";

if (!empty($entries[$x]['mobile'][0])) {
$LDAP_CellPhone = $entries[$x]['mobile'][0];
if ($LDAP_CellPhone == "NULL"){
$LDAP_CellPhone = "";
}
}

//Telephone Number
$LDAP_DDI = "";

if (!empty($entries[$x]['telephonenumber'][0])) {
$LDAP_DDI = $entries[$x]['telephonenumber'][0];
if ($LDAP_DDI == "NULL"){
$LDAP_DDI = "";
}
}

//Email address
$LDAP_InternetAddress = "";

if (!empty($entries[$x]['mail'][0])) {
$LDAP_InternetAddress = $entries[$x]['mail'][0];
if ($LDAP_InternetAddress == "NULL"){
$LDAP_InternetAddress = "";
}
}

//Home phone
$LDAP_HomePhone = "";

if (!empty($entries[$x]['homephone'][0])) {
$LDAP_HomePhone = $entries[$x]['homephone'][0];
if ($LDAP_HomePhone == "NULL"){
$LDAP_HomePhone = "";
}
}

echo "<tr><td><strong>" . $LDAP_samaccountname ."</strong></td><td>" .$LDAP_LastName."</td><td>".$LDAP_FirstName."</td><td>".$LDAP_CompanyName."</td><td>".$LDAP_Department."</td><td>".$LDAP_OfficePhone."</td><td>".$LDAP_OfficeFax."</td><td>".$LDAP_CellPhone."</td><td>".$LDAP_DDI."</td><td>".$LDAP_InternetAddress."</td><td>".$LDAP_HomePhone."</td></tr>";


} //END for loop
} //END FALSE !== $result

ldap_unbind($ldap_connection); // Clean up after ourselves.
echo("</table>"); //close the table

} //END ldap_bind

?></php>


Configuration: Windows / Edge 85.0.564.51
A voir également:

1 réponse

<!DOCTYPE html>
<html>
    <head>
     <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
    box-sizing: border-box;
}
body{
    margin:0;
    height:100vh;
    width:100vw;
    overflow:hidden;
    font-family:'Lato' ,sans-serif;
    font-weight: 700;
    display: flex;
    align-items:center;
    justify-content:center;
    color:#555;
    background:#ecf0f3;

}
.login-div {
    width:430px;
    height:500px;
    padding:60px 35px 35px 35px;
    border-radius:40px;
    background:#ecf0f3;
    box-shadow:13px 13px 20px #cbced1,
                -13px -13px 20px #ffffff;
  }
  .fields {
    width:100%;
    padding:75px 5px 5px 5px;
  }
  .fields input {
    border:none;
    outline:none;
    background:none;
    font-size: 18px;
    color:#555;
    padding:20px 10px 20px 5px;
  }
  .user{
    margin-bottom:30px;
    border-radius:25px;
    box-shadow: inset 8px 8px 8px #cbced1,
                inset -8px -8px 8px #ffffff;
  }
  .fields svg {
    height:22px;
    margin:0 10px -3px 25px;
  }
 button{
    outline:none;
    border:none;
    cursor: pointer;
    width:100%;
    height: 60px;
    border-radius:30px;
    font-size: 20px;
    font-weight: 700;
    font-family:'Lato',sans-serif;
    color:#fff;
    text-align:center;
    background:#24cfaa;
    box-shadow:3px 3px 8px #b1b1b1,
                -3px -3px 8px #ffffff;
    transition:0.5s;
  }
button:hover {
    background:#2fdbb6;
  }
 button:active {
    background:#1da88a;
 }
.label {
  text-align: center;
  font-size: 28px;
  padding-top: 24px;
  letter-spacing: 0.5px;
}
</style>
  </head>
    <body>
        
        <div class="login-div">
            <form action="connect1.php" method="post">
            <div class="fields" >
              <div class="user"><svg class="svg-icon" viewBox="0 0 20 20">
							<path d="M17.388,4.751H2.613c-0.213,0-0.389,0.175-0.389,0.389v9.72c0,0.216,0.175,0.389,0.389,0.389h14.775c0.214,0,0.389-0.173,0.389-0.389v-9.72C17.776,4.926,17.602,4.751,17.388,4.751 M16.448,5.53L10,11.984L3.552,5.53H16.448zM3.002,6.081l3.921,3.925l-3.921,3.925V6.081z M3.56,14.471l3.914-3.916l2.253,2.253c0.153,0.153,0.395,0.153,0.548,0l2.253-2.253l3.913,3.916H3.56z M16.999,13.931l-3.921-3.925l3.921-3.925V13.931z"></path></svg>
		<input type="username" name="username" placeholder="username"/></div>
           </div>
            <button type="submit">submit</button>
</form>


          </div>
    </body>
0