46 static function ls ($types, $attrs = NULL,
string $ou = NULL,
string $filter =
'',
bool $checkAcl = FALSE,
string $scope =
'subtree',
bool $templateSearch = FALSE,
bool $sizeLimit = FALSE): array
51 $ou = $config->current[
'BASE'];
54 if (!is_array($types)) {
59 if (
count($types) > 1) {
62 $infos = static::infos(reset($types));
63 $acl = $infos[
'aclCategory'].
'/'.$infos[
'mainTab'];
64 $tplAcl = $infos[
'aclCategory'].
'/template';
68 if ($attrs === NULL) {
69 if ($templateSearch) {
73 foreach ($types as $type) {
74 $infos = static::infos($type);
75 if ($infos[
'mainAttr']) {
76 $attrs[] = $infos[
'mainAttr'];
79 $attrs = array_unique($attrs);
80 if (
count($attrs) == 1) {
82 } elseif (
count($attrs) == 0) {
83 $attrs = [
'dn' =>
'raw'];
86 } elseif ($checkAcl) {
87 if (is_array($attrs)) {
88 $search_attrs = array_keys($attrs);
90 $search_attrs = [$attrs];
92 foreach ($search_attrs as $search_attr) {
94 $search_attr = preg_replace(
'/;x-.*/',
'', $search_attr);
95 $category = $ui->getAttributeCategory($types[0], $search_attr);
96 if ($category === FALSE) {
99 if ($category === TRUE) {
102 if (strpos($ui->get_permissions($ou, $category, $search_attr),
'r') === FALSE) {
103 $attrsAcls[$search_attr] = [$category, $search_attr];
108 if (is_array($attrs)) {
109 $search_attrs = array_keys($attrs);
111 $search_attrs = [$attrs];
113 if ($templateSearch) {
114 $search_attrs[] =
'fdTemplateField';
115 $search_attrs[] =
'cn';
119 $ldap = static::search($types, $search_attrs, $ou, $filter, $checkAcl, $scope, $templateSearch, $partialFilterAcls, $sizeLimit);
124 while ($fetched_attrs = $ldap->fetch()) {
125 $key = $fetched_attrs[
'dn'];
127 if (strpos($ui->get_permissions($key, $acl),
'r') === FALSE) {
130 foreach ($partialFilterAcls as $partialFilterAcl) {
131 if (strpos($ui->get_permissions($key, $partialFilterAcl[0], $partialFilterAcl[1]),
'r') === FALSE) {
136 if (is_array($attrs)) {
138 foreach ($attrs as $attr => $mode) {
139 if (isset($fetched_attrs[$attr])) {
140 if (isset($attrsAcls[$attr]) &&
141 (strpos($ui->get_permissions($key, $attrsAcls[$attr][0], $attrsAcls[$attr][1]),
'r') === FALSE)) {
146 unset($fetched_attrs[$attr][
'count']);
148 $result[$key][$attr] = $fetched_attrs[$attr];
151 unset($fetched_attrs[$attr][
'count']);
152 $result[$key][$attr] = array_map(
'base64_encode', $fetched_attrs[$attr]);
156 $result[$key][$attr] = $fetched_attrs[$attr][0];
160 if ($templateSearch) {
162 isset($fetched_attrs[
'cn']) &&
163 (!$checkAcl || (strpos($ui->get_permissions($key, $tplAcl,
'template_cn'),
'r') !== FALSE))
165 $result[$key][
'cn'] = $fetched_attrs[
'cn'][0];
167 $result[$key][
'fdTemplateField'] = [];
168 foreach ($fetched_attrs[
'fdTemplateField'] as $templateField) {
169 $attr = explode(
':', $templateField, 2)[0];
170 if (isset($attrs[$attr])) {
171 if (isset($attrsAcls[$attr]) &&
172 (strpos($ui->get_permissions($key, $attrsAcls[$attr][0], $attrsAcls[$attr][1]),
'r') === FALSE)) {
175 $result[$key][
'fdTemplateField'][] = $templateField;
178 if (empty($result[$key][
'fdTemplateField'])) {
179 unset($result[$key][
'fdTemplateField']);
182 if (
count($result[$key]) === 0) {
183 unset($result[$key]);
185 } elseif ($templateSearch) {
186 if ($attrs ==
'cn') {
188 isset($fetched_attrs[
'cn']) &&
189 (!$checkAcl || (strpos($ui->get_permissions($key, $tplAcl,
'template_cn'),
'r') !== FALSE))
191 $result[$key] = $fetched_attrs[
'cn'][0];
194 if (isset($attrsAcls[$attrs]) &&
195 (strpos($ui->get_permissions($key, $attrsAcls[$attrs][0], $attrsAcls[$attrs][1]),
'r') === FALSE)) {
198 foreach ($fetched_attrs[
'fdTemplateField'] as $templateField) {
199 list($attr, $value) = explode(
':', $templateField, 2);
200 if ($attrs == $attr) {
201 $result[$key] = $value;
206 } elseif (isset($fetched_attrs[$attrs])) {
207 if (isset($attrsAcls[$attrs]) &&
208 (strpos($ui->get_permissions($key, $attrsAcls[$attrs][0], $attrsAcls[$attrs][1]),
'r') === FALSE)) {
211 $result[$key] = $fetched_attrs[$attrs][0];
227 static function count ($types,
string $ou = NULL,
string $filter =
'',
bool $checkAcl = FALSE,
bool $templateSearch = FALSE): int
230 $ldap = static::search($types, [
'dn'], $ou, $filter, $checkAcl,
'subtree', $templateSearch, $partialFilterAcls);
231 if (!empty($partialFilterAcls)) {
239 return $ldap->count();
242 private static function search ($types, $search_attrs,
string $ou = NULL,
string $filter =
'',
bool $checkAcl = FALSE,
string $scope =
'subtree',
bool $templateSearch = FALSE, &$partialFilterAcls = [],
bool $sizeLimit = FALSE):
ldapMultiplexer 246 $partialFilterAcls = [];
248 if (!is_array($types)) {
253 $ou = $config->current[
'BASE'];
257 foreach ($types as $type) {
258 $infos = static::infos($type);
260 if ($infos[
'filter'] ==
'') {
261 if ($infos[
'filterRDN'] ==
'') {
264 $typeFilters[] = $infos[
'filterRDN'];
266 } elseif ($infos[
'filterRDN'] ==
'') {
267 $typeFilters[] = $infos[
'filter'];
269 $typeFilters[] =
'(&'.$infos[
'filter'].$infos[
'filterRDN'].
')';
272 if (empty($typeFilters)) {
276 $ldap = $config->get_ldap_link($sizeLimit);
277 if (!$ldap->dn_exists($ou)) {
280 if (empty($filter)) {
281 $filter =
'(|'.implode($typeFilters).
')';
284 if (
count($types) > 1) {
287 $filterObject = ldapFilter::parse($filter);
288 $filterAttributes = $filterObject->listUsedAttributes();
289 unset($filterAttributes[
'_template_cn']);
290 foreach ($filterAttributes as $acl) {
291 $category = $ui->getAttributeCategory($types[0], $acl);
292 if ($category === FALSE) {
295 if ($category === TRUE) {
298 if (strpos($ui->get_permissions($ou, $category, $acl),
'r') === FALSE) {
299 $partialFilterAcls[] = [$category, $acl];
303 if (!preg_match(
'/^\(.*\)$/', $filter)) {
304 $filter =
'('.$filter.
')';
306 $filter =
'(&'.$filter.
'(|'.implode($typeFilters).
'))';
308 if ($templateSearch) {
313 fdTemplateFilter(ldapFilter::parse($filter)),
316 $filter =
"$templateFilterObject";
318 $filterObject = fdNoTemplateFilter(ldapFilter::parse($filter));
319 $filter =
"$filterObject";
322 $ldap->search($filter, $search_attrs, $scope);
323 if (!$ldap->success()) {
324 if ($sizeLimit && $ldap->hitSizeLimit()) {
326 $ui->getSizeLimitHandler()->setLimitExceeded();
344 $infos = static::infos($type);
345 $tabClass = $infos[
'tabClass'];
347 $tabObject =
new $tabClass($type, $dn);
348 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn,
"Openned as $type object");
356 static function link (
string $dn,
string $type,
string $subaction =
'', $text = NULL,
bool $icon = TRUE,
bool $link = TRUE): string
360 $infos = static::infos($type);
362 if (!isset($infos[
'management'])) {
365 $pInfos = pluglist::pluginInfos($infos[
'management']);
366 $index = $pInfos[
'INDEX'];
368 if ($subaction !=
'') {
369 $action .=
'_'.$subaction;
371 $href =
"main.php?plug=$index&reset=1&act=listing_$action&dn=".urlencode($dn);
374 if ($text === NULL) {
375 $ldap = $config->get_ldap_link();
376 $ldap->cat($dn, [$infos[
'nameAttr']]);
377 if ($attrs = $ldap->fetch()) {
378 if (isset($attrs[$infos[
'nameAttr']][0])) {
379 $text = $attrs[$infos[
'nameAttr']][0];
386 } elseif (is_array($text)) {
387 $text = $text[$infos[
'nameAttr']][0];
392 if ($icon && isset($infos[
'icon'])) {
393 $text =
'<img alt="'.htmlescape($infos[
'name']).
'" title="'.
htmlescape($dn).
'" src="'.
htmlescape($infos[
'icon']).
'" class="center"/> '.$text;
397 $text =
'<a href="'.$href.
'">'.$text.
'</a>';
403 static function create (
string $type):
simpleTabs 405 return static::open(
'new', $type);
408 static function delete (
string $dn,
string $type,
bool $checkAcl = TRUE): array
410 $tabObject = static::open($dn, $type);
411 return $tabObject->delete($checkAcl);
414 static function createTemplate (
string $type):
simpleTabs 416 $infos = static::infos($type);
417 $tabClass = $infos[
'tabClass'];
420 $attrsObject =
new stdClass();
421 $attrsObject->attrs = [];
422 $attrsObject->is_template = TRUE;
424 $tabObject =
new $tabClass($type,
'new', $attrsObject);
425 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $type,
'Create template of type');
430 static function &infos (
string $type): array
434 if (!isset($config->data[
'OBJECTS'][strtoupper($type)])) {
438 $infos =& $config->data[
'OBJECTS'][strtoupper($type)];
440 if (!isset($infos[
'filterRDN'])) {
441 if (empty($infos[
'ou'])) {
442 $infos[
'filterRDN'] =
'';
444 $parts = ldap_explode_dn(preg_replace(
'/,$/',
'', $infos[
'ou']), 0);
445 if ($parts !== FALSE) {
446 unset($parts[
'count']);
448 foreach ($parts as $part) {
449 preg_match(
'/([^=]+)=(.*)$/', $part, $m);
450 $dnFilter[] =
'('.$m[1].
':dn:='.$m[2].
')';
452 if (
count($dnFilter) > 1) {
453 $infos[
'filterRDN'] =
'(&'.implode(
'', $dnFilter).
')';
455 $infos[
'filterRDN'] = $dnFilter[0];
464 static function isOfType ($attrs,
string $type):
bool 466 $filter = static::getFilterObject($type);
467 return $filter($attrs);
471 static function getFilterObject (
string $type):
ldapFilter 475 $infos =& static::infos($type);
477 if (!isset($infos[
'filterObject'])) {
478 $infos[
'filterObject'] = ldapFilter::parse($infos[
'filter']);
480 return $infos[
'filterObject'];
484 static function getSearchedAttributes (
string $type): array
488 $infos =& static::infos($type);
490 if (!isset($infos[
'searchAttributes'])) {
492 if (!empty($infos[
'mainAttr'])) {
493 $searchAttrs[$infos[
'mainAttr']] = $infos[
'aclCategory'].
'/'.$infos[
'mainTab'];
495 if (!empty($infos[
'nameAttr'])) {
496 $searchAttrs[$infos[
'nameAttr']] = $infos[
'aclCategory'].
'/'.$infos[
'mainTab'];
498 foreach ($config->data[
'TABS'][$infos[
'tabGroup']] as $tab) {
502 $plInfos = pluglist::pluginInfos($tab[
'CLASS']);
503 if (isset($plInfos[
'plSearchAttrs'])) {
504 foreach ($plInfos[
'plSearchAttrs'] as $attr) {
505 $searchAttrs[$attr] = $infos[
'aclCategory'].
'/'.$tab[
'CLASS'];
509 $infos[
'searchAttributes'] = $searchAttrs;
512 return $infos[
'searchAttributes'];
515 static function types (): array
518 return array_keys($config->data[
'OBJECTS']);
523 static function getTemplates (
string $type,
string $requiredPermissions =
'r',
string $filter =
''): array
527 $infos = static::infos($type);
530 $departments = $config->getDepartmentList();
531 foreach ($departments as $key => $value) {
534 $ldap = static::search($type, [
'cn'], $infos[
'ou'].$value, $filter, FALSE,
'subtree', TRUE);
538 if ($ldap->count() != 0) {
539 while ($attrs = $ldap->fetch()) {
541 if (($requiredPermissions !=
'')
542 && !preg_match(
'/'.$requiredPermissions.
'/', $ui->get_permissions($dn, $infos[
'aclCategory'].
'/'.
'template'))) {
545 $templates[$dn] = $attrs[
'cn'][0].
' - '.$key;
549 natcasesort($templates);
htmlescape(string $str)
Escape string for HTML output.
This class contains all function to manage tabs classes.
Leaf of an LDAP filter, for instance (objectClass=*)
This class allows to parse and execute on a array an LDAP filter Example: $filter = ldapFilter::parse...
static ls($types, $attrs=NULL, string $ou=NULL, string $filter='', bool $checkAcl=FALSE, string $scope='subtree', bool $templateSearch=FALSE, bool $sizeLimit=FALSE)
Get list of object of objectTypes from $types in $ou.
static count($types, string $ou=NULL, string $filter='', bool $checkAcl=FALSE, bool $templateSearch=FALSE)
Get count of objects of objectTypes from $types in $ou.
static open(string $dn, string $type)
Create the tab object for the given dn.
static debug(int $level, int $line, string $function, string $file, $data, string $info='')
Debug output method.
Parent class for all exceptions thrown in FusionDirectory.
Class for handling objects and their types.
plugin_available($plugin)
Check if plugin is available.
static link(string $dn, string $type, string $subaction='', $text=NULL, bool $icon=TRUE, bool $link=TRUE)