5 define(
'IL_LDAP_BIND_ANONYMOUS',0);
6 define(
'IL_LDAP_BIND_USER',1);
8 define(
'IL_LDAP_SCOPE_SUB',0);
9 define(
'IL_LDAP_SCOPE_ONE',1);
10 define(
'IL_LDAP_SCOPE_BASE',2);
48 $this->server_id = $a_server_id;
55 if(isset(self::$instances[$a_server_id]))
57 return self::$instances[$a_server_id];
59 return self::$instances[$a_server_id] =
new ilLDAPServer($a_server_id);
70 if(!$this->fallback_urls)
75 $all_urls = array_merge($this->fallback_urls);
76 $all_urls[] = $this->
getUrl();
78 $query =
'UPDATE ldap_server_settings SET '.
79 'url = '.$ilDB->quote(implode(
',', $all_urls),
'text').
' '.
80 'WHERE server_id = '.$ilDB->quote($this->
getServerId(),
'integer');
92 return function_exists(
'ldap_bind');
104 $query =
"SELECT server_id FROM ldap_server_settings ".
105 "WHERE active = 1 AND authentication = 1 ".
108 $server_ids = array();
109 while(
$row = $ilDB->fetchObject(
$res))
111 $server_ids[] =
$row->server_id;
125 $query =
"SELECT server_id FROM ldap_server_settings ".
127 "AND sync_per_cron = 1 ".
131 while(
$row = $ilDB->fetchObject(
$res))
133 $server_ids[] =
$row->server_id;
135 return $server_ids ? $server_ids : array();
149 $query =
"SELECT server_id FROM ldap_server_settings ".
151 "AND role_sync_active = 1 ";
154 $server_ids = array();
155 while(
$row = $ilDB->fetchObject(
$res))
157 $server_ids[] =
$row->server_id;
199 $query =
"SELECT server_id FROM ldap_server_settings ORDER BY name";
202 while(
$row = $ilDB->fetchObject(
$res))
204 $server_ids[] =
$row->server_id;
206 return $server_ids ? $server_ids : array();
230 $query =
"SELECT server_id FROM ldap_server_settings ".
231 "WHERE active = ".$ilDB->quote(1,
'integer').
" ".
232 "AND authentication = ".$ilDB->quote(0,
'integer').
" ".
233 "AND ( authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
234 "OR authentication_type = ".$ilDB->quote(0,
'integer').
")";
237 $server_ids = array();
240 $server_ids[] =
$row->server_id;
255 $query =
"SELECT server_id FROM ldap_server_settings ".
256 "WHERE authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
257 "AND authentication = ".$ilDB->quote(0,
'integer');
270 $query =
"SELECT server_id FROM ldap_server_settings ".
271 "WHERE authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
272 "AND authentication = ".$ilDB->quote(0,
'integer');
276 return $row->server_id;
293 $query =
"UPDATE ldap_server_settings ".
294 "SET authentication_type = ".$ilDB->quote($a_auth_mode,
'integer').
" ".
295 "WHERE authentication = ".$ilDB->quote(0,
'integer');
300 $query =
"UPDATE ldap_server_settings ".
301 "SET authentication_type = ".$ilDB->quote(0,
'integer').
" ".
302 "WHERE authentication = ".$ilDB->quote(0,
'integer');
320 $this->enabled_authentication = (bool) $a_status;
338 $this->authentication_mapping = $a_map;
366 $this->active = $a_status;
370 return $this->active;
378 $this->url_string = $a_url;
381 $urls = explode(
',',$a_url);
384 foreach($urls as $url)
393 $this->fallback_urls[] = $url;
399 return $this->url_string;
413 include_once(
'Services/LDAP/classes/class.ilLDAPQuery.php');
415 foreach(array_merge(array(0 => $this->url),$this->fallback_urls) as $url)
423 $ilLog->write(__METHOD__.
': Using url: '.$url.
'.');
429 $ilLog->write(__METHOD__.
': Cannot connect to LDAP server: '.$url.
' '. $exc->getCode().
': '.$exc->getMessage());
432 $ilLog->write(__METHOD__.
': No valid LDAP server found.');
443 $this->name = $a_name;
451 $this->version = $a_version;
455 return $this->base_dn;
459 $this->base_dn = $a_base_dn;
463 return $this->referrals ?
true :
false;
467 $this->referrals = $a_status;
471 return $this->tls ?
true :
false;
475 $this->tls = $a_status;
479 return $this->binding_type;
494 return $this->bind_user;
498 $this->bind_user = $a_user;
502 return $this->bind_password;
506 $this->bind_password = $a_password;
510 return $this->search_base;
514 $this->search_base = $a_search_base;
518 return $this->user_attribute;
522 $this->user_attribute = $a_user_attr;
530 $this->filter = $a_filter;
534 return $this->group_dn;
538 $this->group_dn = $a_value;
546 $this->group_filter = $a_value;
550 return $this->group_member;
554 $this->group_member = $a_value;
558 return $this->group_name;
562 $this->group_name = $a_value;
575 if(!is_array($names))
579 foreach($names as $name)
581 $new_names[] = trim($name);
589 return $this->group_attribute;
593 $this->group_attribute = $a_value;
598 $this->group_optional = (bool) $a_status;
602 return (
bool) $this->group_optional;
606 $this->group_user_filter = $a_filter;
610 return $this->group_user_filter;
615 return (
bool) $this->memberisdn;
619 $this->memberisdn = (bool) $a_value;
623 $this->group_scope = $a_value;
627 return $this->group_scope;
631 $this->user_scope = $a_value;
635 return $this->user_scope;
639 return $this->sync_on_login;
643 $this->sync_on_login = (int) $a_value;
647 return $this->sync_per_cron;
651 $this->sync_per_cron = (int) $a_value;
655 $this->global_role = $a_role;
663 $this->role_bind_dn = $a_value;
671 $this->role_bind_pass = $a_value;
679 $this->role_sync_active = $a_value;
691 $this->account_migration = $a_status;
702 return $this->account_migration ?
true :
false;
715 $ilErr->setMessage(
'');
716 if(!strlen($this->
getName()) ||
717 !strlen($this->
getUrl()) ||
721 $ilErr->setMessage($this->lng->txt(
'fill_out_all_required_fields'));
727 $ilErr->appendMessage($this->lng->txt(
'ldap_missing_bind_user'));
732 $ilErr->appendMessage($this->lng->txt(
'ldap_missing_role_assignment'));
736 $ilErr->appendMessage($this->lng->txt(
'ldap_tls_conflict'));
739 return strlen($ilErr->getMessage()) ?
false :
true;
746 $next_id = $ilDB->nextId(
'ldap_server_settings');
748 $query =
'INSERT INTO ldap_server_settings (server_id,active,name,url,version,base_dn,referrals,tls,bind_type,bind_user,bind_pass,'.
749 'search_base,user_scope,user_attribute,filter,group_dn,group_scope,group_filter,group_member,group_memberisdn,group_name,'.
750 'group_attribute,group_optional,group_user_filter,sync_on_login,sync_per_cron,role_sync_active,role_bind_dn,role_bind_pass,migration, '.
751 'authentication,authentication_type) '.
752 '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,%s,%s)';
755 'integer',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
'text',
'text',
'text',
'integer',
756 'text',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
757 'text',
'text',
'integer',
'integer',
'integer'),
800 $query =
"UPDATE ldap_server_settings SET ".
801 "active = ".$this->db->quote($this->
isActive(),
'integer').
", ".
802 "name = ".$this->db->quote($this->
getName(),
'text').
", ".
803 "url = ".$this->db->quote($this->
getUrlString(),
'text').
", ".
804 "version = ".$this->db->quote($this->
getVersion(),
'integer').
", ".
805 "base_dn = ".$this->db->quote($this->
getBaseDN(),
'text').
", ".
807 "tls = ".$this->db->quote($this->
isActiveTLS(),
'integer').
", ".
808 "bind_type = ".$this->db->quote($this->
getBindingType(),
'integer').
", ".
809 "bind_user = ".$this->db->quote($this->
getBindUser(),
'text').
", ".
811 "search_base = ".$this->db->quote($this->
getSearchBase(),
'text').
", ".
812 "user_scope = ".$this->db->quote($this->
getUserScope(),
'integer').
", ".
813 "user_attribute = ".$this->db->quote($this->
getUserAttribute(),
'text').
", ".
814 "filter = ".$this->db->quote($this->
getFilter(),
'text').
", ".
815 "group_dn = ".$this->db->quote($this->
getGroupDN(),
'text').
", ".
816 "group_scope = ".$this->db->quote($this->
getGroupScope(),
'integer').
", ".
817 "group_filter = ".$this->db->quote($this->
getGroupFilter(),
'text').
", ".
818 "group_member = ".$this->db->quote($this->
getGroupMember(),
'text').
", ".
820 "group_name = ".$this->db->quote($this->
getGroupName(),
'text').
", ".
824 "sync_on_login = ".$this->db->quote(($this->
enabledSyncOnLogin() ? 1 : 0),
'integer').
", ".
825 "sync_per_cron = ".$this->db->quote(($this->
enabledSyncPerCron() ? 1 : 0),
'integer').
", ".
827 "role_bind_dn = ".$this->db->quote($this->
getRoleBindDN(),
'text').
", ".
832 "WHERE server_id = ".$this->db->quote($this->
getServerId(),
'integer');
873 if(@include_once(
'Log.php'))
875 if(@include_once(
'Log/observer.php'))
912 $filter = trim($a_filter);
919 if(strpos($filter,
'(') !== 0)
921 $filter = (
'('.$filter);
923 if(substr($filter,-1) !=
')')
925 $filter = ($filter.
')');
941 include_once(
'Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
942 include_once(
'Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php');
946 $mapping->getFields(),
965 if(!$this->server_id)
969 $query =
"SELECT * FROM ldap_server_settings WHERE server_id = ".$this->db->quote($this->server_id).
"";