25 define(
'IL_LDAP_BIND_ANONYMOUS',0);
26 define(
'IL_LDAP_BIND_USER',1);
28 define(
'IL_LDAP_SCOPE_SUB',0);
29 define(
'IL_LDAP_SCOPE_ONE',1);
30 define(
'IL_LDAP_SCOPE_BASE',2);
64 $this->server_id = $a_server_id;
71 if(isset(self::$instances[$a_server_id]))
73 return self::$instances[$a_server_id];
75 return self::$instances[$a_server_id] =
new ilLDAPServer($a_server_id);
87 $query =
"SELECT server_id FROM ldap_server_settings ".
91 while(
$row = $ilDB->fetchObject(
$res))
93 $server_ids[] =
$row->server_id;
95 return $server_ids ? $server_ids : array();
107 $query =
"SELECT server_id FROM ldap_server_settings ".
109 "AND sync_per_cron = 1 ".
113 while(
$row = $ilDB->fetchObject(
$res))
115 $server_ids[] =
$row->server_id;
117 return $server_ids ? $server_ids : array();
131 $query =
"SELECT server_id FROM ldap_server_settings ".
133 "AND role_sync_active = 1 ";
136 while(
$row = $ilDB->fetchObject(
$res))
138 $server_ids[] =
$row->server_id;
140 return $server_ids ? $server_ids : array();
180 $query =
"SELECT server_id FROM ldap_server_settings ORDER BY name";
183 while(
$row = $ilDB->fetchObject(
$res))
185 $server_ids[] =
$row->server_id;
187 return $server_ids ? $server_ids : array();
215 $this->active = $a_status;
219 return $this->active;
227 $this->url_string = $a_url;
230 $urls = explode(
',',$a_url);
233 foreach($urls as $url)
242 $this->fallback_urls[] = $url;
248 return $this->url_string;
262 include_once(
'Services/LDAP/classes/class.ilLDAPQuery.php');
264 foreach(array_merge(array(0 => $this->url),$this->fallback_urls) as $url)
272 $ilLog->write(__METHOD__.
': Using url: '.$url.
'.');
277 $ilLog->write(__METHOD__.
': Cannot connect to LDAP server: '.$url.
'. Trying fallback...');
280 $ilLog->write(__METHOD__.
': No valid LDAP server found.');
291 $this->name = $a_name;
299 $this->version = $a_version;
303 return $this->base_dn;
307 $this->base_dn = $a_base_dn;
311 return $this->referrals ?
true :
false;
315 $this->referrals = $a_status;
319 return $this->tls ?
true :
false;
323 $this->tls = $a_status;
327 return $this->binding_type;
342 return $this->bind_user;
346 $this->bind_user = $a_user;
350 return $this->bind_password;
354 $this->bind_password = $a_password;
358 return $this->search_base;
362 $this->search_base = $a_search_base;
366 return $this->user_attribute;
370 $this->user_attribute = $a_user_attr;
378 $this->filter = $a_filter;
382 return $this->group_dn;
386 $this->group_dn = $a_value;
394 $this->group_filter = $a_value;
398 return $this->group_member;
402 $this->group_member = $a_value;
406 return $this->group_name;
410 $this->group_name = $a_value;
423 if(!is_array($names))
427 foreach($names as
$name)
429 $new_names[] = trim($name);
437 return $this->group_attribute;
441 $this->group_attribute = $a_value;
446 $this->group_optional = (bool) $a_status;
450 return (
bool) $this->group_optional;
454 $this->group_user_filter = $a_filter;
458 return $this->group_user_filter;
463 return (
bool) $this->memberisdn;
467 $this->memberisdn = (bool) $a_value;
471 $this->group_scope = $a_value;
475 return $this->group_scope;
479 $this->user_scope = $a_value;
483 return $this->user_scope;
487 return $this->sync_on_login;
491 $this->sync_on_login = (int) $a_value;
495 return $this->sync_per_cron;
499 $this->sync_per_cron = (int) $a_value;
503 $this->global_role = $a_role;
511 $this->role_bind_dn = $a_value;
519 $this->role_bind_pass = $a_value;
527 $this->role_sync_active = $a_value;
539 $this->account_migration = $a_status;
550 return $this->account_migration ?
true :
false;
563 $ilErr->setMessage(
'');
564 if(!strlen($this->
getName()) ||
565 !strlen($this->
getUrl()) ||
569 $ilErr->setMessage($this->lng->txt(
'fill_out_all_required_fields'));
575 $ilErr->appendMessage($this->lng->txt(
'ldap_missing_bind_user'));
580 $ilErr->appendMessage($this->lng->txt(
'ldap_missing_role_assignment'));
584 $ilErr->appendMessage($this->lng->txt(
'ldap_tls_conflict'));
587 return strlen($ilErr->getMessage()) ?
false :
true;
594 $next_id = $ilDB->nextId(
'ldap_server_settings');
596 $query =
'INSERT INTO ldap_server_settings (server_id,active,name,url,version,base_dn,referrals,tls,bind_type,bind_user,bind_pass,'.
597 'search_base,user_scope,user_attribute,filter,group_dn,group_scope,group_filter,group_member,group_memberisdn,group_name,'.
598 'group_attribute,group_optional,group_user_filter,sync_on_login,sync_per_cron,role_sync_active,role_bind_dn,role_bind_pass,migration) '.
599 'VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)';
602 'integer',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
'text',
'text',
'text',
'integer',
603 'text',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
604 'text',
'text',
'integer'),
645 $query =
"UPDATE ldap_server_settings SET ".
646 "active = ".$this->db->quote($this->
isActive(),
'integer').
", ".
647 "name = ".$this->db->quote($this->
getName(),
'text').
", ".
648 "url = ".$this->db->quote($this->
getUrlString(),
'text').
", ".
649 "version = ".$this->db->quote($this->
getVersion(),
'integer').
", ".
650 "base_dn = ".$this->db->quote($this->
getBaseDN(),
'text').
", ".
652 "tls = ".$this->db->quote($this->
isActiveTLS(),
'integer').
", ".
653 "bind_type = ".$this->db->quote($this->
getBindingType(),
'integer').
", ".
654 "bind_user = ".$this->db->quote($this->
getBindUser(),
'text').
", ".
656 "search_base = ".$this->db->quote($this->
getSearchBase(),
'text').
", ".
657 "user_scope = ".$this->db->quote($this->
getUserScope(),
'integer').
", ".
658 "user_attribute = ".$this->db->quote($this->
getUserAttribute(),
'text').
", ".
659 "filter = ".$this->db->quote($this->
getFilter(),
'text').
", ".
660 "group_dn = ".$this->db->quote($this->
getGroupDN(),
'text').
", ".
661 "group_scope = ".$this->db->quote($this->
getGroupScope(),
'integer').
", ".
662 "group_filter = ".$this->db->quote($this->
getGroupFilter(),
'text').
", ".
663 "group_member = ".$this->db->quote($this->
getGroupMember(),
'text').
", ".
665 "group_name = ".$this->db->quote($this->
getGroupName(),
'text').
", ".
669 "sync_on_login = ".$this->db->quote(($this->
enabledSyncOnLogin() ? 1 : 0),
'integer').
", ".
670 "sync_per_cron = ".$this->db->quote(($this->
enabledSyncPerCron() ? 1 : 0),
'integer').
", ".
672 "role_bind_dn = ".$this->db->quote($this->
getRoleBindDN(),
'text').
", ".
675 "WHERE server_id = ".$this->db->quote($this->
getServerId(),
'integer');
699 $options[
'start_tls'] = (bool) $this->
isActiveTLS();
704 $options[
'userscope'] =
'one';
707 $options[
'userscope'] =
'sub';
712 $options[
'userfilter'] = $this->
getFilter();
716 if(@include_once(
'Log.php'))
718 if(@include_once(
'Log/observer.php'))
720 $options[
'enableLogging'] =
true;
726 $options[
'groupscope'] =
'base';
729 $options[
'groupscope'] =
'one';
732 $options[
'groupscope'] =
'sub';
784 include_once(
'Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
785 include_once(
'Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php');
789 $mapping->getFields(),
808 if(!$this->server_id)
812 $query =
"SELECT * FROM ldap_server_settings WHERE server_id = ".$this->db->quote($this->server_id).
"";
813 # var_dump("<pre>",$query,"</pre>");