Changeset 29135
- Timestamp:
- Aug 1, 2014, 12:56:27 PM (10 years ago)
- Location:
- extensions/Ldap_Login
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Ldap_Login/class.ldap.php
r28534 r29135 41 41 } 42 42 43 public function load_default_config() 44 { 43 public function load_default_config(){ 45 44 $this->config['host'] = 'localhost'; 46 45 $this->config['basedn'] = 'dc=example,dc=com'; // racine ! … … 65 64 } 66 65 67 function load_config() 66 function load_config(){ 68 67 $this->load_default_config(); 69 68 … … 73 72 { 74 73 $this->config = unserialize($conf_file); 75 $this->config['full_usersbranch'] = $this->config['usersbranch'].','.$this->config['basedn']; 76 $this->config['full_groupbranch'] = $this->config['groupbranch'].','.$this->config['basedn']; 77 } 78 } 79 80 function save_config() 81 { 74 // $this->config['full_usersbranch'] = $this->config['usersbranch'].','.$this->config['basedn']; 75 // $this->config['full_groupbranch'] = $this->config['groupbranch'].','.$this->config['basedn']; 76 // I don't place it in config['..'] because it will save it in the config file, and I don't want that ! 77 $this->full_usersbranch = $this->config['usersbranch'].','.$this->config['basedn']; 78 $this->full_groupbranch = $this->config['groupbranch'].','.$this->config['basedn']; 79 } 80 } 81 82 function save_config(){ 82 83 $file = fopen( LDAP_LOGIN_PATH.'/data.dat', 'w' ); 83 84 fwrite($file, serialize($this->config) ); … … 85 86 } 86 87 87 function ldap_admin_menu($menu) 88 { 88 function ldap_admin_menu($menu){ 89 89 array_push($menu, 90 90 array( … … 121 121 // then we authenticate if anonymous search is forbidden 122 122 if (!empty($obj->config['ld_binddn']) && !empty($obj->config['ld_bindpw'])){ 123 if (@ldap_bind($this->cnx,$this->config['ld_binddn'],$this->config['ld_bindpw'])){ 123 $password = strtr($obj->config['ld_bindpw'], array("\'"=>"'")); 124 125 if (@ldap_bind($this->cnx,$this->config['ld_binddn'],$password)){ 124 126 return true; 125 127 } … … 147 149 return $this->ldap_search_dn($name); 148 150 } 149 else { return $this->config['ld_attr'].'='.$name.','.$this-> config['full_usersbranch']; }151 else { return $this->config['ld_attr'].'='.$name.','.$this->full_usersbranch; } 150 152 } 151 153 … … 156 158 } 157 159 else { 158 $result[] = $this->config['ld_group'].'='.$groupname.','.$this-> config['full_groupbranch'];160 $result[] = $this->config['ld_group'].'='.$groupname.','.$this->full_groupbranch; 159 161 return $result; 160 162 } … … 163 165 // authentication 164 166 public function ldap_bind_as($user,$user_passwd){ 167 $user_passwd = strtr($user_passwd, array("\'"=>"'")); 168 165 169 if (@ldap_bind($this->cnx,$this->ldap_name($user),$user_passwd)){ 166 170 return true; … … 182 186 $ld_group = $this->config['ld_group']; 183 187 184 $sr=@ldap_search($this->cnx, $this-> config['full_groupbranch'], "($ld_group=$to_search)", array('dn'),0,0);188 $sr=@ldap_search($this->cnx, $this->full_groupbranch, "($ld_group=$to_search)", array('dn'),0,0); 185 189 $groups = @ldap_get_entries($this->cnx, $sr); 186 190 $result = array(); … … 191 195 } 192 196 197 /* $filter="(sAMAccountName=".$user.")"; 198 199 if(($results=ldap_search($this->cnx,$this->config['basedn'],$filter,array('dn',$this->config['ld_attr'])))!==false) 200 { $firstEntry=ldap_first_entry($this->cnx,$results); 201 202 if($firstEntry==null) 203 { return false; 204 } 205 else 206 { if(($userDn=ldap_get_dn($this->cnx,$firstEntry))!==false) 207 { if(($isBound=wpDirAuth_bindTest($this->cnx,$userDn,$user_passwd,$this->config['basedn']))===true) 208 { return true; 209 } 210 else 211 { return false; 212 } 213 } 214 } 215 } */ 216 217 218 193 219 public function ldap_search_dn($to_search){ 194 220 $ld_attr = $this->config['ld_attr']; 195 221 196 $sr=@ldap_search($this->cnx, $this->config['full_usersbranch'], "($ld_attr=$to_search)", array('dn','mail'),0,0); 197 $entry = @ldap_get_entries($this->cnx, $sr); 198 199 if (!empty($entry[0]['dn'])) { 200 return $entry[0]['dn']; 201 } 202 else { return False; } 222 if(($results=@ldap_search($this->cnx,$this->config['basedn'],"($ld_attr=$to_search)",array('dn','mail',$ld_attr)))!==false) 223 //$sr= @ldap_search($this->cnx, $this->full_usersbranch, "($ld_attr=$to_search)", array('dn','mail'),0,0); 224 $entry = @ldap_first_entry($this->cnx, $results); 225 226 if($entry==null) 227 { 228 return false; 229 } 230 231 else 232 { if(($userDn=ldap_get_dn($this->cnx,$entry))!==false) 233 { 234 return $userDN; 235 } 236 else 237 { 238 return null; 239 } 240 } 241 // if (!empty($entry[0]['dn'])) { 242 // return $entry[0]['dn']; 243 // } 244 // else { return False; } 203 245 } 204 246 -
extensions/Ldap_Login/language/fr_FR/plugin.lang.php
r28535 r29135 30 30 31 31 $lang['Ldap attributes'] = 'Attributs ldap'; 32 $lang['Base DN'] = 'Arbre ldap à explorer où rechercher les utilisateurs (ex : ou=users,dc=exemple,dc=com)';32 $lang['Base DN'] = 'Arbre ldap à explorer où rechercher les utilisateurs et les groupes (ex : dc=exemple,dc=com)'; 33 33 $lang['Attribute corresponding to the user name'] = 'Attribut correspondant au nom d\'utilisateur'; 34 34
Note: See TracChangeset
for help on using the changeset viewer.