Установите флажок в пользовательских полях Active Directory, используя PHP - PullRequest
0 голосов
/ 05 августа 2020

Я создаю пользователя в Active Directory, используя PHP, и создаю его правильно, но теперь мне нужно проверить параметры, показанные на изображении, с тем же кодом PHP, я также прилагаю пример того, как пользователь создал в Active Directory, используя PHP.

Проверяет, что мне нужно сделать, используя PHP

введите описание изображения здесь

Код создания пользователя

<?php   
   
// Username used to connect to the server
$username = "administrator";

// Password of the user.
$password = "Password01";

// Domain used to connect to.
$domain = "nagara.ca";

// Proper username to connect with.
$domain_username = "$username" . "@" . $domain;

// User directory. Such as all users are placed in
// the Users directory by default.
$user_dir = "OU=Students,DC=nagara,DC=ca";

// Either an IP or a domain.
$ldap_server = "192.168.100.2";

// Get a connection
$ldap_conn = ldap_connect($ldap_server);

// Set LDAP_OPT_PROTOCOL_VERSION to 3
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set LDAP Protocol version");

// Authenticate the user and link the resource_id with
// the authentication.
if($ldapbind = ldap_bind($ldap_conn, $domain_username, $password) == true)
{
// Setup the data that will be used to create the user
// This is in the form of a multi-dimensional
// array that will be passed to AD to insert.

$adduserAD["cn"] = "testuser";
$adduserAD["givenname"] = "Test";
$adduserAD["sn"] = "User";
$adduserAD["sAMAccountName"] = "testuser";
$adduserAD['userPrincipalName'] = "testuser@nagara.ca";
$adduserAD["objectClass"] = "user";
$adduserAD["displayname"] = "Test User";
$adduserAD["userPassword"] = "Password01";
$adduserAD["userAccountControl"] = "544";

$base_dn = "cn=testuser,ou=students,DC=nagara,DC=ca";

// Attempt to add the user with ldap_add()
if(ldap_add($ldap_conn, $base_dn, $adduserAD) == true)
{

// The user is added and should be ready to be logged
// in to the domain.
echo "User added!<br>";
}else{

// This error message will be displayed if the user
// was not able to be added to the AD structure.
echo "Sorry, the user was not added.<br>Error Number: ";
echo ldap_errno($ldap_conn) . "<br />Error Description: ";
echo ldap_error($ldap_conn) . "<br />";
}
}else{
echo "Could not bind to the server. Check the username/password.<br />";
echo "Server Response:"

// Error number.
. "<br />Error Number: " . ldap_errno($ldap_conn)

// Error description.
. "<br />Description: " . ldap_error($ldap_conn);
}

// Always make sure you close the server after
// your script is finished.
ldap_close($ldap_conn);
?>

Надеюсь, вы сможете меня поддержать.

Большое спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...