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);
 
   44                 $this->server_id = $a_server_id;
 
   51                 if(isset(self::$instances[$a_server_id]))
 
   53                         return self::$instances[$a_server_id];
 
   55                 return self::$instances[$a_server_id] = 
new ilLDAPServer($a_server_id);
 
   64                 return function_exists(
'ldap_bind');
 
   76                 $query = 
"SELECT server_id FROM ldap_server_settings ".
 
   80                 $server_ids = array();
 
   81                 while(
$row = $ilDB->fetchObject(
$res))
 
   83                         $server_ids[] = 
$row->server_id;
 
   97                 $query = 
"SELECT server_id FROM ldap_server_settings ".
 
   99                         "AND sync_per_cron = 1 ".
 
  103                 while(
$row = $ilDB->fetchObject(
$res))
 
  105                         $server_ids[] = 
$row->server_id;
 
  107                 return $server_ids ? $server_ids : array();
 
  121                 $query = 
"SELECT server_id FROM ldap_server_settings ".
 
  123                         "AND role_sync_active = 1 ";
 
  126                 $server_ids = array();
 
  127                 while(
$row = $ilDB->fetchObject(
$res))
 
  129                         $server_ids[] = 
$row->server_id;
 
  171                 $query = 
"SELECT server_id FROM ldap_server_settings ORDER BY name";
 
  174                 while(
$row = $ilDB->fetchObject(
$res))
 
  176                         $server_ids[] = 
$row->server_id;
 
  178                 return $server_ids ? $server_ids : array();
 
  206         $this->active = $a_status;
 
  210                 return $this->active;
 
  218         $this->url_string = $a_url;
 
  221                 $urls = explode(
',',$a_url);
 
  224                 foreach($urls as $url)
 
  233                                 $this->fallback_urls[] = $url;
 
  239         return $this->url_string;
 
  253                 include_once(
'Services/LDAP/classes/class.ilLDAPQuery.php');
 
  255                 foreach(array_merge(array(0 => $this->url),$this->fallback_urls) as $url)
 
  263                                 $ilLog->write(__METHOD__.
': Using url: '.$url.
'.');
 
  268                                 $ilLog->write(__METHOD__.
': Cannot connect to LDAP server: '.$url.
'. Trying fallback...');
 
  271                 $ilLog->write(__METHOD__.
': No valid LDAP server found.');
 
  282         $this->name = $a_name;
 
  290         $this->version = $a_version;
 
  294         return $this->base_dn;
 
  298         $this->base_dn = $a_base_dn;
 
  302                 return $this->referrals ? 
true : 
false;
 
  306                 $this->referrals = $a_status; 
 
  310                 return $this->tls ? 
true : 
false;
 
  314                 $this->tls = $a_status;
 
  318                 return $this->binding_type;
 
  333                 return $this->bind_user;
 
  337                 $this->bind_user = $a_user;
 
  341                 return $this->bind_password;
 
  345                 $this->bind_password = $a_password;
 
  349                 return $this->search_base;
 
  353                 $this->search_base = $a_search_base;
 
  357                 return $this->user_attribute;
 
  361                 $this->user_attribute = $a_user_attr;
 
  369                 $this->filter = $a_filter;
 
  373                 return $this->group_dn;
 
  377                 $this->group_dn = $a_value;
 
  385                 $this->group_filter = $a_value;
 
  389                 return $this->group_member;
 
  393                 $this->group_member = $a_value;
 
  397                 return $this->group_name;
 
  401                 $this->group_name = $a_value;
 
  414                 if(!is_array($names))
 
  418                 foreach($names as $name)
 
  420                         $new_names[] = trim($name);
 
  428                 return $this->group_attribute;
 
  432                 $this->group_attribute = $a_value;
 
  437                 $this->group_optional = (bool) $a_status;               
 
  441                 return (
bool) $this->group_optional;
 
  445                 $this->group_user_filter = $a_filter;
 
  449                 return $this->group_user_filter;
 
  454                 return (
bool) $this->memberisdn;
 
  458                 $this->memberisdn = (bool) $a_value;
 
  462                 $this->group_scope = $a_value;
 
  466                 return $this->group_scope;
 
  470                 $this->user_scope = $a_value;
 
  474                 return $this->user_scope;
 
  478                 return $this->sync_on_login;
 
  482                 $this->sync_on_login = (int) $a_value;
 
  486                 return $this->sync_per_cron;
 
  490                 $this->sync_per_cron = (int) $a_value;
 
  494                 $this->global_role = $a_role;
 
  502                 $this->role_bind_dn = $a_value;
 
  510                 $this->role_bind_pass = $a_value;
 
  518                 $this->role_sync_active = $a_value;
 
  530                 $this->account_migration = $a_status;
 
  541                 return $this->account_migration ? 
true : 
false;
 
  554                 $ilErr->setMessage(
'');
 
  555                 if(!strlen($this->
getName()) ||
 
  556                         !strlen($this->
getUrl()) ||
 
  560                         $ilErr->setMessage($this->lng->txt(
'fill_out_all_required_fields'));
 
  566                         $ilErr->appendMessage($this->lng->txt(
'ldap_missing_bind_user'));
 
  571                         $ilErr->appendMessage($this->lng->txt(
'ldap_missing_role_assignment'));
 
  575                         $ilErr->appendMessage($this->lng->txt(
'ldap_tls_conflict'));
 
  578                 return strlen($ilErr->getMessage()) ? 
false : 
true;
 
  585                 $next_id = $ilDB->nextId(
'ldap_server_settings');
 
  587                 $query = 
'INSERT INTO ldap_server_settings (server_id,active,name,url,version,base_dn,referrals,tls,bind_type,bind_user,bind_pass,'.
 
  588                         'search_base,user_scope,user_attribute,filter,group_dn,group_scope,group_filter,group_member,group_memberisdn,group_name,'.
 
  589                         'group_attribute,group_optional,group_user_filter,sync_on_login,sync_per_cron,role_sync_active,role_bind_dn,role_bind_pass,migration) '.
 
  590                         '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)';
 
  593                                 'integer',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
'text',
'text',
'text',
'integer',
 
  594                                 'text',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'text',
'integer',
'text',
'integer',
'integer',
'integer',
 
  595                                 'text',
'text', 
'integer'),
 
  636                 $query = 
"UPDATE ldap_server_settings SET ".
 
  637                         "active = ".$this->db->quote($this->
isActive(),
'integer').
", ".
 
  638                         "name = ".$this->db->quote($this->
getName(),
'text').
", ".
 
  639                         "url = ".$this->db->quote($this->
getUrlString(),
'text').
", ".
 
  640                         "version = ".$this->db->quote($this->
getVersion(),
'integer').
", ".
 
  641                         "base_dn = ".$this->db->quote($this->
getBaseDN(),
'text').
", ".
 
  643                         "tls = ".$this->db->quote($this->
isActiveTLS(),
'integer').
", ".
 
  644                         "bind_type = ".$this->db->quote($this->
getBindingType(),
'integer').
", ".
 
  645                         "bind_user = ".$this->db->quote($this->
getBindUser(),
'text').
", ".
 
  647                         "search_base = ".$this->db->quote($this->
getSearchBase(),
'text').
", ".
 
  648                         "user_scope = ".$this->db->quote($this->
getUserScope(),
'integer').
", ".
 
  649                         "user_attribute = ".$this->db->quote($this->
getUserAttribute(),
'text').
", ".
 
  650                         "filter = ".$this->db->quote($this->
getFilter(),
'text').
", ".
 
  651                         "group_dn = ".$this->db->quote($this->
getGroupDN(),
'text').
", ".
 
  652                         "group_scope = ".$this->db->quote($this->
getGroupScope(),
'integer').
", ".
 
  653                         "group_filter = ".$this->db->quote($this->
getGroupFilter(),
'text').
", ".
 
  654                         "group_member = ".$this->db->quote($this->
getGroupMember(),
'text').
", ".
 
  656                         "group_name = ".$this->db->quote($this->
getGroupName(),
'text').
", ".
 
  660                         "sync_on_login = ".$this->db->quote(($this->
enabledSyncOnLogin() ? 1 : 0),
'integer').
", ".
 
  661                         "sync_per_cron = ".$this->db->quote(($this->
enabledSyncPerCron() ? 1 : 0),
'integer').
", ".
 
  663                         "role_bind_dn = ".$this->db->quote($this->
getRoleBindDN(),
'text').
", ".
 
  666                         "WHERE server_id = ".$this->db->quote($this->
getServerId(),
'integer');
 
  690                 $options[
'start_tls'] = (bool) $this->
isActiveTLS();
 
  695                                 $options[
'userscope'] = 
'one';
 
  698                                 $options[
'userscope'] = 
'sub';
 
  703                 $options[
'userfilter'] = $this->
getFilter();
 
  707                 if(@include_once(
'Log.php'))
 
  709                         if(@include_once(
'Log/observer.php'))
 
  711                                 $options[
'enableLogging'] = 
true;
 
  717                                 $options[
'groupscope'] = 
'base';
 
  720                                 $options[
'groupscope'] = 
'one';
 
  723                                 $options[
'groupscope'] = 
'sub';
 
  746                 $filter = trim($a_filter);
 
  753                 if(strpos($filter,
'(') !== 0)
 
  755                         $filter = (
'('.$filter);
 
  757                 if(substr($filter,-1) != 
')')
 
  759                         $filter = ($filter.
')');
 
  775                         include_once(
'Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
 
  776                         include_once(
'Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php');
 
  780                                 $mapping->getFields(),
 
  799                 if(!$this->server_id)
 
  803                 $query = 
"SELECT * FROM ldap_server_settings WHERE server_id = ".$this->db->quote($this->server_id).
"";
 
  804 #               var_dump("<pre>",$query,"</pre>");