Changeset 1438


Ignore:
Timestamp:
09/21/09 15:56:22 (15 years ago)
Author:
alexandrecorreia
Message:

Ticket #649 - Correção para liberar organização ( sub-ous ) por grupo.

Location:
trunk/jabberit_messenger/inc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/jabberit_messenger/inc/class.contacts_im.inc.php

    r1160 r1438  
    1919        private $ldap; 
    2020        private $db; 
     21        private $dn_User; 
    2122        private $ou_User; 
    2223        private $serverJabber; 
     
    2728                $this->db = new db_im(); 
    2829 
     30                // (DN) User 
     31                $this->dn_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn']; 
     32 
    2933                // (OU) User 
    30                 $this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn']; 
     34                $this->ou_User = $this->dn_User; 
    3135                $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou=")); 
    3236                $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc="))); 
     
    131135                                { 
    132136                                        if( $tmp != "" ) 
    133                                                 $orgs[] = "OU=". $tmp;             
    134                                 } 
    135                                  
     137                                        { 
     138                                                if( strpos($tmp, "/") !== false ) 
     139                                                { 
     140                                                        $tt = explode("/", $tmp); 
     141                                                        $newOU = implode(",OU=",array_reverse($tt)); 
     142                                                        $orgs[] = "OU=". $newOU ; 
     143                                                } 
     144                                                else  
     145                                                        $orgs[] = "OU=". $tmp; 
     146                                        }             
     147                                } 
     148 
    136149                    $orgs = array_unique($orgs); 
    137  
     150         
    138151                                foreach( $orgs as $orgB )                                
    139152                                        $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB ); 
     
    170183        } 
    171184         
     185        private final function strallpos($haystack, $needle, $offset = 0) 
     186        { 
     187            $result = array(); 
     188            for($i = $offset; $i< strlen($haystack); $i++ ) 
     189            { 
     190                $pos = strpos($haystack,$needle,$i); 
     191                if($pos !== FALSE) 
     192                { 
     193                    $offset =  $pos; 
     194                    if($offset >= $i) 
     195                        $result[] = $i = $offset; 
     196                } 
     197            } 
     198         
     199        return $result; 
     200        }  
     201 
    172202        public final function verifyAddNewContact($pUid) 
    173203        { 
     
    175205                $gidNumbers = array(); 
    176206                $uid = $pUid['uid']; 
     207                $uid_User = substr($this->dn_User, 0, strpos($this->dn_User, ",")); 
     208                $uid_User = substr($uid_User, 4); 
    177209 
    178210                foreach($groupsLocked as $tmp) 
     
    186218                 
    187219                $result = $this->ldap->getGroupsMemberUid($filter_gid); 
    188  
     220                 
    189221                if( $result && is_array($result) ) 
    190222                { 
     
    205237                        $search = array(); 
    206238                        $search_Gid = array(); 
    207                          
     239 
    208240                        // Verifica Uid em Grupo Bloqueado 
    209241                        foreach($Groups as $value) 
     
    212244                                { 
    213245                                        $ou = substr($value['dn'],strpos($value['dn'], "ou=")); 
    214                                         $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc="))); 
    215                                         $search_Gid[] = $value['gidnumber']; 
    216                                 }        
    217                         } 
    218                 } 
    219  
     246                                        if( array_search($uid_User, $value['memberuid']) === false ) 
     247                                        { 
     248                                                $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc="))); 
     249                                                $search_Gid[] = $value['gidnumber']; 
     250                                        } 
     251                                } 
     252                        } 
     253                } 
     254                 
     255         
    220256                if( $this->groupsLocked() ) 
    221257                { 
     
    229265                                        { 
    230266                                                $ousTp = explode(",",$tpGroups[2]); 
    231                                                 $ou_User = substr($this->ou_User,3); 
     267                                                $ou_User = strtoupper(trim($this->dn_User)); 
    232268                                                 
     269                                                $posAll = $this->strallpos($ou_User, "OU=" ); 
     270                                                $orgs = array(); 
     271                                 
     272                                                for( $i = 0 ; $i < count($posAll); $i++ ) 
     273                                                { 
     274                                                        $pos = strpos($ou_User, ","); 
     275                                                        $tmpString = substr($ou_User, $posAll[$i] + 3); 
     276                                                        $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); 
     277                                                } 
     278                                 
     279                                                $ou_User = implode("/", array_reverse($orgs)); 
     280 
    233281                                                if( array_search( $ou_User, $ousTp) !== false ) 
    234282                                                        return "true"; 
     
    251299                                        {                                                        
    252300                                                $tpGroups = explode(":",$value); 
     301                                                 
    253302                                                if( $tpGroups[1] == $search_Gid[0] ) 
    254303                                                { 
    255304                                                        $ousTp = explode(",",$tpGroups[2]); 
    256                                                         $ou_User = substr($this->ou_User,3); 
    257                                                                  
     305                                                        $ou_User = strtoupper(trim($this->dn_User)); 
     306                                         
     307                                                        $posAll = $this->strallpos($ou_User, "OU=" ); 
     308                                                        $orgs = array(); 
     309                                         
     310                                                        for( $i = 0 ; $i < count($posAll); $i++ ) 
     311                                                        { 
     312                                                                $pos = strpos($ou_User, ","); 
     313                                                                $tmpString = substr($ou_User, $posAll[$i] + 3); 
     314                                                                $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); 
     315                                                        } 
     316                                         
     317                                                        $ou_User = implode("/", array_reverse($orgs)); 
     318                                                         
    258319                                                        if( array_search( $ou_User, $ousTp) !== false ) 
    259320                                                                return "true"; 
  • trunk/jabberit_messenger/inc/class.db_im.inc.php

    r988 r1438  
    426426        public final function setOuGroupsLocked($pGroup) 
    427427        { 
     428                 
     429                function strallpos($haystack, $needle, $offset = 0) 
     430                { 
     431                    $result = array(); 
     432                    for($i = $offset; $i< strlen($haystack); $i++ ) 
     433                    { 
     434                        $pos = strpos($haystack,$needle,$i); 
     435                        if($pos !== FALSE) 
     436                        { 
     437                            $offset =  $pos; 
     438                            if($offset >= $i) 
     439                                $result[] = $i = $offset; 
     440                        } 
     441                    } 
     442                 
     443                return $result; 
     444                }  
     445 
    428446                $group = $pGroup['group']; 
    429447                $gidnumber = $pGroup['gidnumber']; 
    430                 $organization = strtoupper($pGroup['ou']); 
     448                $organization = strtoupper(trim($pGroup['ou'])); 
     449 
     450                $posAll = strallpos($organization, "OU=" ); 
     451                $orgs = array(); 
     452 
     453                for( $i = 0 ; $i < count($posAll); $i++ ) 
     454                { 
     455                        $pos = strpos($organization, ","); 
     456                        $tmpString = substr($organization, $posAll[$i] + 3); 
     457                        $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); 
     458                } 
     459 
     460                $organization = implode("/", array_reverse($orgs)); 
    431461 
    432462                if( $this->db ) 
  • trunk/jabberit_messenger/inc/class.ldap_im.inc.php

    r1160 r1438  
    5151                 
    5252                $GLOBALS['phpgw_info']['server']['ldap_version3'] = true; 
    53  
    54                 $this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_user . "," . $this->ldap_context , $this->ldap_pass, false ); 
     53                 
     54                if( $this->ldap_user && $this->ldap_pass ) 
     55                        $this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_user . "," . $this->ldap_context , $this->ldap_pass, false ); 
     56                else 
     57                        $this->ldap = $this->common->ldapConnect( $this->ldap_host, $this->ldap_context , "", false ); 
    5558        } 
    5659         
    5760        private final function ldapRoot() 
    5861        { 
    59                 $this->ldap_host        = (isset($_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_host']; 
    60                 $this->ldap_context     = (isset($_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_context']; 
    61                 $this->ldap_user        = (isset($_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
    62                 $this->ldap_pass        = (isset($_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
     62                $this->ldap_host        = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']; 
     63                $this->ldap_context     = $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit']; 
     64                $this->ldap_user        = $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit']; 
     65                $this->ldap_pass        = $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit']; 
    6366 
    6467                $this->ldapConn(); 
     
    146149                if( $this->ldap ) 
    147150                { 
    148                         $filter="ou=*";          
    149                         $justthese = array("ou"); 
    150                         $search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese);                       
    151                         $entry = ldap_get_entries($this->ldap, $search); 
    152                 } 
    153  
    154                 foreach($entry as $tmp) 
    155                         if($tmp['ou'][0] != "") 
    156                                 $result_org[] = $tmp['ou'][0];   
    157  
    158                 return $result_org; 
    159         } 
    160  
     151                        $filter = "(ou=*)"; 
     152                        $justthese = array("dn"); 
     153                        $search = ldap_search($this->ldap, $this->ldap_context, $filter, $justthese); 
     154                        $info = ldap_get_entries($this->ldap, $search); 
     155                 
     156                        for ($i=0; $i<$info["count"]; $i++) 
     157                                $a_sectors[] = $info[$i]['dn'];  
     158                } 
     159 
     160                // Retiro o count do array info e inverto o array para ordenação. 
     161                foreach ($a_sectors as $context) 
     162                { 
     163                        $array_dn = ldap_explode_dn ( $context, 1 ); 
     164                        $array_dn_reverse  = array_reverse ( $array_dn, true ); 
     165                        array_pop ( $array_dn_reverse ); 
     166                        $inverted_dn[$context] = implode ( "#", $array_dn_reverse ); 
     167                } 
     168                 
     169                // Ordenação 
     170                natcasesort($inverted_dn); 
     171 
     172                foreach ( $inverted_dn as $dn=>$invert_ufn ) 
     173                { 
     174            $display = ''; 
     175 
     176            $array_dn_reverse = explode ( "#", $invert_ufn ); 
     177            $array_dn  = array_reverse ( $array_dn_reverse, true ); 
     178 
     179            $level = count( $array_dn ) - (int)(count(explode(",", $this->ldap_context)) + 1); 
     180 
     181            if ($level == 0) 
     182                    $display .= '+'; 
     183            else  
     184            { 
     185                                for( $i = 0; $i < $level; $i++) 
     186                                        $display .= '---'; 
     187            } 
     188 
     189            reset ( $array_dn ); 
     190            $display .= ' ' . (current ( $array_dn ) ); 
     191                         
     192                        $dn = trim(strtolower($dn)); 
     193                        $options[$dn] = $display; 
     194        } 
     195 
     196            return $options; 
     197 
     198        } 
    161199 
    162200        public final function getUsersLdapCatalog( $search ) 
  • trunk/jabberit_messenger/inc/class.uienabledgroups.inc.php

    r946 r1438  
    5858                        if( ($LdapOus = $ldap->getOrganizationsLdap()) ) 
    5959                        { 
    60                                 foreach($LdapOus as $tmp ) 
    61                                         $ous .= "<option value='".$tmp."'>".$tmp."</option>"; 
     60                                foreach($LdapOus as $key => $val ) 
     61                                        $ous .= "<option value='".$key."'>".$val."</option>"; 
    6262                        } 
    6363 
  • trunk/jabberit_messenger/inc/class.uigroupslocked.inc.php

    r946 r1438  
    7070                 
    7171                $ous = "<option value='-1'>-- ".lang('Select Organization')." --</option>";      
     72                 
    7273                if( ($LdapOus = $ldap->getOrganizationsLdap()) ) 
    7374                { 
    74                         foreach($LdapOus as $tmp ) 
    75                                 $ous .= "<option value='".$tmp."'>".$tmp."</option>"; 
     75                        foreach($LdapOus as $key=>$val ) 
     76                                $ous .= "<option value='".$val."'>".$val."</option>"; 
    7677                } 
    77                  
     78 
    7879                $groupsRestricts = ""; 
    7980 
     
    8283                        $glocked = explode(';',$GLOBALS['phpgw_info']['server']['groups_locked_jabberit']); 
    8384                        natcasesort($glocked); 
    84                          
     85         
    8586                        foreach( $glocked as $tmp ){ 
    8687                                $option = explode(":",$tmp); 
Note: See TracChangeset for help on using the changeset viewer.