Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
feature(Admin/Cli): add ldapUserSearchQuery
Browse files Browse the repository at this point in the history
... for querying ldap accounts with given filters and baseDn

usage:
  --method Admin.ldapUserSearchQuery
  • Loading branch information
pschuele committed Mar 29, 2023
1 parent d58c7eb commit f684f45
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tine20/Admin/Frontend/Cli.php
Expand Up @@ -814,4 +814,49 @@ public function copyGroupmembersToDifferentGroup(Zend_Console_Getopt $opts)
echo "Args are missing\n";
}
}

public function ldapUserSearchQuery(Zend_Console_Getopt $opts)
{
// TODO make this work with '=' in filter param ...
// $args = $this->_parseArgs($opts, array(),'other', false);
// $userFilter = $args['filter'] ?? 'objectclass=posixaccount';

$userFilter = 'objectclass=posixaccount';
// $userFilter = 'memberof=cn=somegroup,cn=groups,dc=something,dc=lan';

$ldapOptions = Tinebase_User::getBackendConfiguration();
// show LDAP settings
// unset($ldapOptions['syncOptions']);
// print_r($ldapOptions);
$ldap = new Tinebase_Ldap($ldapOptions);

$filter = Zend_Ldap_Filter::andFilter(
Zend_Ldap_Filter::string($userFilter)
);
$userSearchScope = $ldapOptions['userSearchScope'];
$baseDn = $ldapOptions['userDn'];
$attributes = [
'displayname',
'cn',
'givenname',
'sn',
'uid',
// TODO add more attributes if required
];
echo "userFilter = $userFilter\n";
// echo "userSearchScope = $userSearchScope\n";
echo "baseDn = $baseDn\n";

$counter = 0;
foreach ($ldap->search(
$filter,
$baseDn,
$userSearchScope,
$attributes
) as $account) {
print_r($account);
$counter++;
}
echo "found $counter accounts\n";
}
}

0 comments on commit f684f45

Please sign in to comment.