Forum

PHP ile Active Dire...
 
Bildirimler
Hepsini Temizle

PHP ile Active Directory Üzerine Kullanıcı Açma

3 Yazılar
2 Üyeler
0 Likes
1,210 Görüntüleme
Selim GÜRAKSIN
(@selimguraksin)
Gönderiler: 438
Reputable Member
Konu başlatıcı
 

Merhabalar,

Kurumda yazılmakta olan bir projemiz için Windows Server 2008 R2' de duran Active Directory üzerine PHP ile kullanıcı eklemek istiyoruz. Denemelerimiz sonucunda, PHP formdan gönderilen kullanıcı Active Directory üzerinde oluşturuluyor. Fakat, form ile göndermiş olduğumuz password ve uac değerleri Active Directory üzerinde set etmiyor (kullanıcı şifresiz ve pasif olarak oluşturuluyor).

Daha önceden PHP - AD üzerinde böyle bir çalışma yapan arkadaşlar var mıdır? Yardımcı olabilirseniz sevinirim.

Kolay gelsin.

 
Gönderildi : 03/10/2013 12:58

(@AhmetKoseoglu)
Gönderiler: 108
Estimable Member
 

Şurdaki projeyi bi incelermisiniz? Sanki işinizi  çözecek gibi. Kolay gelsin

 

http://adldap.sourceforge.net/

 
Gönderildi : 03/10/2013 13:21

Selim GÜRAKSIN
(@selimguraksin)
Gönderiler: 438
Reputable Member
Konu başlatıcı
 

Merhabalar,

Bu projeyi daha önceden de indirmiştim. Tekrar indirip denedim fakat çalışmıyor. Kodum aşağıdaki gibi.

<?php
// Connects to our LDAP server.
$ldapconn = ldap_connect("xxx.xxx.xxx.xxx");

if($ldapconn)
{
  ////////////////////////////////
  // Bind connection with admin
  ////////////////////////////////
  $admin_account = "cn=administrator,cn=Users,dc=xxxxx,dc=xxxxx";
  $admin_pwd = "xxxxx";
  $ldapbind = ldap_bind($ldapconn, $admin_account, $admin_pwd);

 
 $newuser_md5hashed_password="P/-\ssw0rd"; //Kullanıcı İçin Şifre
 
 
  // Check to make sure the BIND worked.
  // If it didn't then nothing will work, AD needs a user that is fully qualified to make additions to the AD stucture.  Someone in the Administrtors group would do the trick.
  if(ldap_bind($ldapconn, $admin_account, $admin_pwd) == true)
  {
    // prepare data
    $adduserAD["cn"] = "Yeni_CN";
 $adduserAD["sn"] = "Yeni_SN";
 $adduserAD["givenname"] = "Yeni_GIVEN_NAME";
    $adduserAD["samaccountname"] = "Yeni_SAN";
 $adduserAD["userPrincipalName"] = "[email protected]";
    $adduserAD["objectClass"] = "user";
    $adduserAD["displayname"] = "Yeni_DN";
    $adduserAD["mail"] = "[email protected]";
 //$adduserAD["useraccountcontrol"]="512"; // Bu alanda bir türlü çalışmıyor.
 $adduserAD['userPassword'] = '{MD5}' . base64_encode(pack('H*',$newuser_md5hashed_password)); //Şifreyi yukarda alıyor. Ama çalışmıyor.

    $base_dn = "cn=Yeni_CN,ou=xxx,ou=xxx,ou=xxx,DC=xxx,DC=xxx";

    // add data to directory
    echo "Trying to add the user to the system ...<br>";
    if(@ldap_add($ldapconn, $base_dn, $adduserAD) == true)
    {
      // Now start dancing on the table.  It added the user!
      echo "User added!<br>";
    }else{
      // You did something wrong.  It was not able to add
      // the user.  Check the error number and why.  It might
      // give some insight into why it didn't work.
      echo "Sorry, the user was not added.<br>Reason:";
      echo ldap_errno($ldapconn);
      echo ldap_error($ldapconn);
    }
  }else{
    // It could not bind to the server.  Did you type the password right?
    // How about making sure it's a valid user?
    // Did the internet eat your password?  Hate when that happens.
    echo "Sorry could not bind to the server.<br>Reason: ";
    echo ldap_errno($ldapconn);
    echo ldap_error($ldapconn);
  }
}else{
  // This error should NEVER show up.  Type in the ldap://server
  // or just the IP address.
  echo "Sorry could not find the server.<br>";
}
ldap_close($ldapconn);
?>

 
Gönderildi : 03/10/2013 16:54

Paylaş: