nom=$people['nom']; $this->prenom=$people['prenom']; $this->mail=$people['mail']; $this->naissance=$people['naissance']; $this->uid=$people['uid']; $this->ine=$people['ine']; if (isset($people['userpw'])) $this->pwdhash=$people['userpw']; } else{ $this->read_from_ldap(func_get_arg(0)); } } } /** * Mapping des paramètres LDAP / Objet * */ function assign_attrib_from_ldap($ldap_entry,$ldap_attrib,$attrib) { if (is_array($ldap_entry[$ldap_attrib])) { $this->$attrib=$ldap_entry[$ldap_attrib]['0']; } } function map_to_ldap(&$ldap_entry,$attrib,$ldap_attrib) { if ($this->$attrib !='') { $ldap_admin[$ldap_entry]=$this->$attrib; } } /** * Génération aléatoire de mot de passe */ function random_password() { $this->userpw=substr(`openssl rand -base64 12 | tr -d '/'`,0,8); $this->set_password($this->userpw); } /** * Fixer les mots de passe dans le LDAP */ function set_password() { if ($this->uid_is_in_ldap()) { $password=$userpassword = "{SHA}" . base64_encode( pack('H*', sha1( $this->userpw))); $ntpassword=`mkntpwd -N $this->userpw`; $lmpassword=`mkntpwd -L $this->userpw`; $attribut['userPassword']=$password; $attributlm['sambaLMPassword']=$lmpassword; $attributnt['sambaNTPassword']=$ntpassword; $search_dn=$c2i_ldap['people_dn']; $filter="(uid=".$this->uid.")"; $dn="uid=".$this->uid.",".$c2i_ldap['people_dn']; $ldap_search_result=ldap_search($ldap_res,$search_dn,$filter); $info=ldap_get_entries($ldap_res,$ldap_search_result); if (isset($info['0']['userpassword'])) { //password exists ldap_mod_replace($ldap_res,$dn,$attribut); } else { ldap_mod_add($ldap_res,$dn,$attribut); } if (isset($info['0']['sambaNTPassword'])) { //password exists ldap_mod_replace($ldap_res,$dn,$attributnt); } else { ldap_mod_add($ldap_res,$dn,$attributnt); } if (isset($info['0']['sambaLMPassword'])) { //password exists ldap_mod_replace($ldap_res,$dn,$attributlm); } else { ldap_mod_add($ldap_res,$dn,$attributlm); } } // TODO : * regrouper en un seul appel // * si on a amdin, modifier le htpassword aussi pour setup } function add_to_group($group) { global $Se3Ldap; if (!$this->is_member($group)) { $ldap_dn="cn=$group,".$Se3Ldap->dn['groups']; $ldap_people['memberUid']=$this->uid; ldap_mod_add($Se3Ldap->res,$ldap_dn,$ldap_people); } } function del_from_group($group) { global $Se3Ldap; if ($this->is_member($group)) { $ldap_dn="cn=$group,".$Se3Ldap->dn['groups']; $ldap_people['memberUid']=$this->uid; ldap_mod_del($Se3Ldap->res,$ldap_dn,$ldap_people); } } function uid_is_in_ldap() { global $Se3Ldap; if (!isset($this->uid)) return FALSE; $search_dn=$Se3Ldap->dn['people']; $filter="(uid=".$this->uid.")"; $ldap_search_result=ldap_search($Se3Ldap->res,$search_dn,$filter); $info=ldap_get_entries($Se3Ldap->res,$ldap_search_result); if ($info['count']>0) { return TRUE; } else { return FALSE; } } function is_member($group) { global $Se3Ldap; $search_dn=$Se3Ldap->dn['groups']; $filter="(&(cn=$group)(memberUid=".$this->uid."))"; $ldap_search_result=ldap_search($Se3Ldap->res,$search_dn,$filter); $info=ldap_get_entries($Se3Ldap->res,$ldap_search_result); if ($info['count']>0) { return true; } else { return false; } } function get_groups($type='') { global $Se3Ldap; $groups=array(); $search_dn=$Se3Ldap->dn['groups']; $filter="(memberUid=".$this->uid.")"; if ($type != '') $filter="(&(cn=".$type."*)".$filter.")"; $ldap_search_result=ldap_search($Se3Ldap->res,$search_dn,$filter); $info=ldap_get_entries($Se3Ldap->res,$ldap_search_result); $number_groups=$info['count']; for ($i=0;$i<$number_groups;$i++) { $groups[$info[$i]['cn']['0']]=$info[$i]['description']['0']; } return $groups; } function get_equipes() { return $this->get_groups("Equipe_"); } function get_matieres() { return $this->get_groups("Matiere_"); } function read_from_ldap ($uid) { // le uid peut être donné isolément ou sous la forme de dn LDAP global $Se3Ldap; $search_dn=$Se3Ldap->dn['people']; $uid=trim($uid); $exploded=explode(',',$uid); $uid=$exploded['0']; $exploded=explode('=',$uid); if (isset($exploded['1'])) { $uid=$exploded['1']; } else { $uid=$exploded['0']; } $filter="(uid=$uid)"; $ldap_search_result=ldap_list($Se3Ldap->res,$search_dn,$filter); $peoples=ldap_get_entries($Se3Ldap->res,$ldap_search_result); $people=$peoples['0']; $this->uid=$people['uid']['0']; $this->name=$people['sn']['0']; $this->assign_attrib_from_ldap($people,'givenname','firstname'); $this->assign_attrib_from_ldap($people,'mail','mail'); $this->assign_attrib_from_ldap($people,'telephonenumber','phone'); $this->assign_attrib_from_ldap($people,'title','title'); $this->assign_attrib_from_ldap($people,'carlicense','birth'); $this->assign_attrib_from_ldap($people,'departmentnumber','section'); $this->assign_attrib_from_ldap($people,'userpassword','pwdhash'); $this->assign_attrib_from_ldap($people,'ou','rne'); $this->assign_attrib_from_ldap($people,'jpegphoto','photo'); $this->assign_attrib_from_ldap($people,'employeetype','type'); $this->assign_attrib_from_ldap($people,'employeenumber','ine'); $this->assign_attrib_from_ldap($people,'cn','cn'); $this->assign_attrib_from_ldap($people,'l','localisation'); } function modify_into_ldap() { global $c2i_ldap; global $ldap_res; global $current_year; $ldap_dn="uid=".$this->uid.",".$c2i_ldap['people_dn']; $ldap_entry['objectClass']="inetOrgPerson"; $ldap_entry['uid']=$this->uid; $this->map_to_ldap($ldap_entry,'name','sn'); $this->map_to_ldap($ldap_entry,'firstname','givenName'); $this->cn=$this->firstname." ".$this->name; $this->map_to_ldap($ldap_entry,'cn','cn'); $this->map_to_ldap($ldap_entry,'title','title'); $this->map_to_ldap($ldap_entry,'rne','ou'); $this->map_to_ldap($ldap_entry,'mail','mail'); $this->map_to_ldap($ldap_entry,'phone','telephoneNumber'); if ($this->type=="pupil") { $this->map_to_ldap($ldap_entry,'section','departmentNumber'); $this->map_to_ldap($ldap_entry,'birth','carLicense'); $this->map_to_ldap($ldap_entry,'localisation','l'); break; } ldap_modify($ldap_res,$ldap_dn,$ldap_entry); if (isset($this->pwdclear)) { $this->set_password($this->pwdclear); } } function destroy(){ global $c2i_ldap; global $ldap_res; global $current_year; if ($this->is_in_ldap()) { switch ($this->type) { case 'sadmin': $this->del_from_group('sadmins'); break; case 'admin': if ($this->is_member('admins')) $this->del_from_group('admins'); $this->delete_from_SQL(); break; case 'teacher': if ($this->is_member('teacher')) $this->del_from_group('teachers'); $this->delete_from_SQL(); break; case 'pupil': $group = $current_year."_".$this->rne."_".$this->section; if ($this->is_member($group)) $this->del_from_group($group); if ($this->is_member('pupils')) $this->del_from_group('pupils'); if ($this->is_member('trash')) $this->del_from_group('trash'); break; } $ldap_dn="uid=".$this->uid.",".$c2i_ldap['people_dn']; ldap_delete($ldap_res,$ldap_dn); } } } ?>