/** * Get contact information. Returned in a raw array format from AD * * @param string $distinguishedName The full DN of a contact * @param null $fields Array of parameters to query * @return array|bool */ public function info($distinguishedName, $fields = NULL) { if ($distinguishedName === NULL) { return false; } if (!$this->adldap->getLdapBind()) { return false; } $filter = "distinguishedName=" . $this->adldap->utilities()->ldapSlashes($distinguishedName); if ($fields === NULL) { $fields = array("distinguishedname", "mail", "memberof", "department", "displayname", "telephonenumber", "primarygroupid", "objectsid"); } $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); if ($entries[0]['count'] >= 1) { // AD does not return the primary group in the ldap query, we may need to fudge it if ($this->adldap->getRealPrimaryGroup() && isset($entries[0]["primarygroupid"][0]) && isset($entries[0]["primarygroupid"][0])) { //$entries[0]["memberof"][]=$this->group_cn($entries[0]["primarygroupid"][0]); $entries[0]["memberof"][] = $this->adldap->group()->getPrimaryGroup($entries[0]["primarygroupid"][0], $entries[0]["objectsid"][0]); } else { $entries[0]["memberof"][] = "CN=Domain Users,CN=Users," . $this->adldap->getBaseDn(); } } $entries[0]["memberof"]["count"]++; return $entries; }
/** * Find information about the users. Returned in a raw array format from AD * * @param string $username The username to query * @param array $fields Array of parameters to query * @param bool $isGUID Is the username passed a GUID or a samAccountName * @return array */ public function info($username, $fields = NULL, $isGUID = false) { if ($username === NULL) { return false; } if (!$this->adldap->getLdapBind()) { return false; } $filter = "(&(objectClass=posixAccount)(uid={$username}))"; $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); if (isset($entries[0])) { if ($entries[0]['count'] >= 1) { if (in_array("memberof", $fields)) { // AD does not return the primary group in the ldap query, we may need to fudge it if ($this->adldap->getRealPrimaryGroup() && isset($entries[0]["primarygroupid"][0]) && isset($entries[0]["objectsid"][0])) { //$entries[0]["memberof"][]=$this->group_cn($entries[0]["primarygroupid"][0]); $entries[0]["memberof"][] = $this->adldap->group()->getPrimaryGroup($entries[0]["primarygroupid"][0], $entries[0]["objectsid"][0]); } else { $entries[0]["memberof"][] = "CN=Domain Users,CN=Users," . $this->adldap->getBaseDn(); } if (!isset($entries[0]["memberof"]["count"])) { $entries[0]["memberof"]["count"] = 0; } $entries[0]["memberof"]["count"]++; } } return $entries; } return false; }
/** * Find information about the users. Returned in a raw array format from AD * * @param string $username The username to query * @param array $fields Array of parameters to query * @param bool $isGUID Is the username passed a GUID or a samAccountName * @return array */ public function info($username, $fields = NULL, $isGUID = false) { if ($username === NULL) { return false; } if (!$this->adldap->getLdapBind()) { return false; } if ($isGUID === true) { $username = $this->adldap->utilities()->strGuidToHex($username); $filter = "objectguid=" . $username; } else { if (strstr($username, "@")) { $filter = "userPrincipalName=" . $username; } else { $filter = "samaccountname=" . $username; } } $filter = "(&(objectCategory=person)({$filter}))"; if ($fields === NULL) { $fields = array("samaccountname", "mail", "memberof", "department", "displayname", "telephonenumber", "primarygroupid", "objectsid"); } if (!in_array("objectsid", $fields)) { $fields[] = "objectsid"; } $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); if (isset($entries[0])) { if ($entries[0]['count'] >= 1) { if (in_array("memberof", $fields)) { // AD does not return the primary group in the ldap query, we may need to fudge it if ($this->adldap->getRealPrimaryGroup() && isset($entries[0]["primarygroupid"][0]) && isset($entries[0]["objectsid"][0])) { //$entries[0]["memberof"][]=$this->group_cn($entries[0]["primarygroupid"][0]); $entries[0]["memberof"][] = $this->adldap->group()->getPrimaryGroup($entries[0]["primarygroupid"][0], $entries[0]["objectsid"][0]); } else { $entries[0]["memberof"][] = "CN=Domain Users,CN=Users," . $this->adldap->getBaseDn(); } if (!isset($entries[0]["memberof"]["count"])) { $entries[0]["memberof"]["count"] = 0; } $entries[0]["memberof"]["count"]++; } } return $entries; } return false; }
/** * Get the groups a computer is in * * @param string $computerName The name of the computer * @param null $recursive Whether to check recursively * @return array|bool */ public function groups($computerName, $recursive = NULL) { if ($computerName === NULL) { return false; } if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it if (!$this->adldap->getLdapBind()) { return false; } //search the directory for their information $info = @$this->info($computerName, array("memberof", "primarygroupid")); $groups = $this->adldap->utilities()->niceNames($info[0]["memberof"]); //presuming the entry returned is our guy (unique usernames) if ($recursive === true) { foreach ($groups as $id => $groupName) { $extraGroups = $this->adldap->group()->recursiveGroups($groupName); $groups = array_merge($groups, $extraGroups); } } return $groups; }
try { $adldap = new adLDAP($options); } catch (adLDAPException $e) { echo $e; exit; } //var_dump($ldap); echo "<pre>\n"; // authenticate a username/password if (0) { $result = $adldap->authenticate('username', 'password'); var_dump($result); } // add a group to a group if (0) { $result = $adldap->group()->addGroup('Parent Group Name', 'Child Group Name'); var_dump($result); } // add a user to a group if (0) { $result = $adldap->group()->addUser('Group Name', 'username'); var_dump($result); } // create a group if (0) { $attributes = array('group_name' => 'Test Group', 'description' => 'Just Testing', 'container' => array('Groups', 'A Container')); $result = $adldap->group()->create($attributes); var_dump($result); } // retrieve information about a group if (0) {
try { $adldap = new adLDAP($options); } catch (adLDAPException $e) { echo $e; exit; } //var_dump($ldap); echo "<pre>\n"; // authenticate a username/password if (0) { $result = $adldap->authenticate("username", "password"); var_dump($result); } // add a group to a group if (0) { $result = $adldap->group()->addGroup("Parent Group Name", "Child Group Name"); var_dump($result); } // add a user to a group if (0) { $result = $adldap->group()->addUser("Group Name", "username"); var_dump($result); } // create a group if (0) { $attributes = array("group_name" => "Test Group", "description" => "Just Testing", "container" => array("Groups", "A Container")); $result = $adldap->group()->create($attributes); var_dump($result); } // retrieve information about a group if (0) {