Changeset 3664 for branches/2.2/setup


Ignore:
Timestamp:
01/07/11 08:04:33 (13 years ago)
Author:
rodsouza
Message:

Ticket #707 - Tratando usuarios de base LDAP existente.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/setup/ldapmodify.php

    r3607 r3664  
    9191        if ( array_key_exists( 'ldap_group_context', $phpgw_info[ 'server' ] ) && count( $phpgw_info['server']['global_denied_groups'] ) ) 
    9292        { 
    93                 $sr = ldap_search( $ldap, $config[ 'ldap_group_context' ], '(objectClass=posixGroup)', array( 'gidnumber', 'cn', 'memberuid' ) ); 
     93                $sr = ldap_search( $ldap, $config[ 'ldap_group_context' ], '(objectClass=posixGroup)', 
     94                        array( 'gidnumber', 'cn', 'memberuid', 'objectclass', 'phpgwaccountstatus', 'phpgwaccounttype', 'phpgwaccountexpires' ) 
     95                ); 
    9496                $info = ldap_get_entries( $ldap, $sr ); 
    9597                $tmp = ''; 
     
    121123        ); 
    122124 
    123         //error_log( print_r( $config, true ), 3, '/tmp/log' ); 
    124         //error_log( print_r( $group_info, true ), 3, '/tmp/log' ); 
    125  
    126125        if ( array_key_exists( 'submit', $_POST ) ) 
    127126        { 
     
    133132                        $groups = CreateObject( 'phpgwapi.accounts' ); 
    134133                        copyobj( $GLOBALS[ 'phpgw_setup' ] -> db, $groups -> db ); 
    135  
    136                         //error_log( print_r( $_POST[ 'ldapgroups' ], true ), 3, '/tmp/log' ); 
    137134 
    138135                        foreach ( $_POST[ 'ldapgroups' ] as $groupid ) 
     
    159156                                        $groups->account_id = ( int ) $thisacctid; 
    160157 
    161                                         $sr = ldap_search( $ldap, $config[ 'ldap_group_context' ], 'cn=' . $thisacctlid ); 
    162                                         $entry = ldap_get_entries( $ldap, $sr ); 
    163  
    164                         //              error_log( print_r( $entry, true ), 3, '/tmp/log' ); 
    165  
    166                                         reset( $entry[ 0 ][ 'objectclass' ] ); 
     158                                        reset( $group_info[ $groupid ][ 'objectclass' ] ); 
    167159 
    168160                                        $add = array( ); 
    169161 
    170                                         if ( ! in_array( 'phpgwAccount', $entry[ 0 ][ 'objectclass' ] ) ) 
     162                                        if ( ! in_array( 'phpgwAccount', $group_info[ $groupid ][ 'objectclass' ] ) ) 
    171163                                                $add[ 'objectclass'] = array( 'phpgwAccount' ); 
    172164 
    173                                         if ( ! array_key_exists( 'phpgwaccountstatus', $entry[ 0 ] ) ) 
     165                                        if ( ! array_key_exists( 'phpgwaccountstatus', $group_info[ $groupid ] ) ) 
    174166                                                $add[ 'phpgwaccountstatus'] = array( 'A' ); 
    175167 
    176                                         if ( ! array_key_exists( 'phpgwaccounttype', $entry[ 0 ] ) ) 
     168                                        if ( ! array_key_exists( 'phpgwaccounttype', $group_info[ $groupid ] ) ) 
    177169                                                $add[ 'phpgwaccounttype' ] = array( 'g' ); 
    178170 
    179                                         if ( ! array_key_exists( 'phpgwaccountexpires', $entry[ 0 ] ) ) 
     171                                        if ( ! array_key_exists( 'phpgwaccountexpires', $group_info[ $groupid ] ) ) 
    180172                                                $add[ 'phpgwaccountexpires' ] = array( -1 ); 
    181173 
    182                         //              error_log( print_r( $add, true ), 3, '/tmp/log' ); 
    183  
    184                                         //if ( count( $add ) ) 
    185                                         //      ldap_mod_add( $ldap, $thisdn, $add ); 
     174                                        if ( count( $add ) ) 
     175                                                ldap_mod_add( $ldap, $thisdn, $add ); 
    186176 
    187177                                        // Now make the members a member of this group in phpgw. 
     
    190180                                                if ( array_key_exists( 'count', $thismembers ) ) 
    191181                                                        unset( $thismembers[ 'count' ] ); 
    192  
    193                         //                      error_log( print_r( $thismembers, true ), 3, '/tmp/log' ); 
    194                         //                      error_log( print_r( $account_info, true ), 3, '/tmp/log' ); 
    195182 
    196183                                                foreach ( $thismembers as $key => $members ) 
     
    215202                                                                $acl -> account_id = ( int ) $tmpid; 
    216203                                                                $acl -> read_repository( ); 
    217          
     204 
    218205                                                                $acl -> delete( 'phpgw_group', $thisacctid, 1 ); 
    219206                                                                $acl -> add( 'phpgw_group', $thisacctid, 1 ); 
    220          
     207 
    221208                                                                // Now add the acl to let them change their password 
    222209                                                                $acl -> delete( 'preferences', 'changepassword', 1 ); 
    223210                                                                $acl -> add( 'preferences', 'changepassword', 1 ); 
    224          
     211 
    225212                                                                $acl -> save_repository( ); 
    226213                                                        } 
     
    247234                } 
    248235 
    249                 if ( array_key_exists( 'users', $_POST ) && is_array( $_POST[ 'users' ] ) ) 
     236                if ( ( array_key_exists( 'users', $_POST ) && is_array( $_POST[ 'users' ] ) ) || ( array_key_exists( 'admins', $_POST ) && is_array( $_POST[ 'admins' ] ) ) ) 
    250237                { 
    251238                        $accounts = CreateObject( 'phpgwapi.accounts' ); 
     
    258245                        //error_log( print_r( $config, true ), 3, '/tmp/log' ); 
    259246 
    260                         foreach ( $_POST[ 'users' ] as $user_id ) 
    261                         { 
    262                                 $id_exist = 0; 
    263                                 $thisacctid  = $account_info[ $user_id ][ 'uidnumber' ][ 0 ]; 
    264                                 $thisacctlid = $account_info[ $user_id ][ 'uid' ][ 0 ]; 
    265                                 $thisdn      = $account_info[ $user_id ][ 'dn']; 
    266  
    267                                 echo "{$thisdn}<br>\nUpdating USERID : {$thisacctlid}<br>\n"; 
    268                                  
    269                                 // Do some checks before we try to import the data. 
    270                                 if ( !empty($thisacctid) && !empty($thisacctlid)) 
     247                        foreach ( array( 'admins', 'users' ) as $type ) 
     248                                if ( array_key_exists( $type, $_POST ) ) 
    271249                                { 
    272                                         $users_process++; 
    273  
    274                                         //$res = ldap_search( $ldap, $config[ 'ldap_group_context' ], 'uid=' . $thisacctlid, array( 'uid', 'objectClass' ) ); 
    275                                         //$entry = ldap_get_entries( $ldap, $res ); 
    276  
    277                                         //error_log( print_r( $entry, true ), 3, '/tmp/log' ); 
    278  
    279                                         //for ( $entry = ldap_first_entry( $ldap, $res ); $entry !== false, $arr = ldap_get_attributes( $ldap, $entry ); $entry = ldap_next_entry( $ldap, $entry ) ) 
    280                                         //{ 
    281                                         //      error_log( print_r( $arr, true ), 3, '/tmp/log' ); 
    282                                         //} 
    283                                         //error_log( "---------------------------------------------------\n", 3, '/tmp/log' ); 
    284  
    285                                         //error_log( print_r( $account_info[ $user_id ], true ), 3, '/tmp/log' ); 
    286                                         //error_log( "---------------------------------------------------\n", 3, '/tmp/log' ); 
    287  
    288                                         $add = array( ); 
    289                                         $objectClass = array( ); 
    290  
    291                                         if ( ! in_array( 'qmailUser', $account_info[ $user_id ][ 'objectclass' ] ) ) 
    292                                                 $objectclass[ ] = 'qmailUser'; 
    293  
    294                                         if ( ! in_array( 'phpgwAccount', $account_info[ $user_id ][ 'objectclass' ] ) ) 
     250                                        if ( $type == 'admins' ) 
    295251                                        { 
    296                                                 $objectclass[ ] = 'phpgwAccount'; 
    297                                                 $add[ 'phpgwAccountExpires' ] = array( '-1' ); 
    298                                                 $add[ 'phpgwAccountStatus' ] = array( 'A' ); 
    299                                                 $add[ 'phpgwAccountType' ] = array( 'u' ); 
    300                                                 $add[ 'phpgwLastPasswdChange' ] = array( '1290632486' ); 
     252                                                // give admin access to all apps, to save us some support requests 
     253                                                $all_apps = array(); 
     254                                                $GLOBALS[ 'phpgw_setup' ] -> db -> query( 'SELECT app_name FROM phpgw_applications ORDER BY app_name' ); 
     255                                                while ( $GLOBALS[ 'phpgw_setup' ] -> db -> next_record( ) ) 
     256                                                        $all_apps[ ] = $GLOBALS[ 'phpgw_setup' ]  -> db -> f( 'app_name' ); 
    301257                                        } 
    302258 
    303                                         if ( count( $objectclass ) ) 
    304                                                 $add[ 'objectclass' ] = $objectclass; 
    305  
    306                                         if ( count( $add ) ) 
    307                                                 ldap_mod_add( $ldap, $thisdn, $add ); 
    308  
    309                                         $accounts -> account_id = ( int ) $thisacctid; 
    310                                          
    311                                         // Insert default acls for this user. 
    312                                         $acl -> account_id = ( int ) $thisacctid; 
    313                                         $acl -> read_repository( ); 
    314          
    315                                         // Now add the acl to let them change their password 
    316                                         $acl -> delete( 'preferences', 'changepassword', 1 ); 
    317                                         $acl -> add( 'preferences', 'changepassword', 1 ); 
    318  
    319                                         // Add user to a default group, previous created 
    320                                         $acl -> add( 'phpgw_group', '12007', 1 ); 
    321  
    322                                         echo "Adding in ACL BD: {$thisacctid}<br><br>\n"; 
    323  
    324                                         // Save these new acls. 
    325                                         $acl -> save_repository( ); 
    326                                                  
    327                                         $new_uidnumber++; 
     259                                        foreach ( $_POST[ $type ] as $user_id ) 
     260                                        { 
     261                                                $id_exist = 0; 
     262                                                $thisacctid  = $account_info[ $user_id ][ 'uidnumber' ][ 0 ]; 
     263                                                $thisacctlid = $account_info[ $user_id ][ 'uid' ][ 0 ]; 
     264                                                $thisdn      = $account_info[ $user_id ][ 'dn']; 
     265 
     266                                                echo "{$thisdn}<br>\nUpdating ({$type}) USERID : {$thisacctlid}<br>\n"; 
     267 
     268                                                // Do some checks before we try to import the data. 
     269                                                if ( !empty($thisacctid) && !empty($thisacctlid)) 
     270                                                { 
     271                                                        $users_process++; 
     272 
     273                                                        $add = array( ); 
     274                                                        $objectClass = array( ); 
     275 
     276                                                        if ( ! in_array( 'qmailUser', $account_info[ $user_id ][ 'objectclass' ] ) ) 
     277                                                                $objectclass[ ] = 'qmailUser'; 
     278 
     279                                                        if ( ! in_array( 'phpgwAccount', $account_info[ $user_id ][ 'objectclass' ] ) ) 
     280                                                        { 
     281                                                                $objectclass[ ] = 'phpgwAccount'; 
     282                                                                $add[ 'phpgwAccountExpires' ] = array( '-1' ); 
     283                                                                $add[ 'phpgwAccountStatus' ] = array( 'A' ); 
     284                                                                $add[ 'phpgwAccountType' ] = array( 'u' ); 
     285                                                                $add[ 'phpgwLastPasswdChange' ] = array( '1290632486' ); 
     286                                                        } 
     287 
     288                                                        if ( count( $objectclass ) ) 
     289                                                                $add[ 'objectclass' ] = $objectclass; 
     290 
     291                                                        if ( count( $add ) ) 
     292                                                                ldap_mod_add( $ldap, $thisdn, $add ); 
     293 
     294                                                        $accounts -> account_id = ( int ) $thisacctid; 
     295 
     296                                                        // Insert default acls for this user. 
     297                                                        $acl -> account_id = ( int ) $thisacctid; 
     298                                                        $acl -> read_repository( ); 
     299 
     300                                                        // Now add the acl to let them change their password 
     301                                                        $acl -> delete( 'preferences', 'changepassword', 1 ); 
     302                                                        $acl -> add( 'preferences', 'changepassword', 1 ); 
     303 
     304                                                        // Add user to a default group, previous created 
     305                                                        //$acl -> add( 'phpgw_group', '12007', 1 ); 
     306 
     307                                                        echo "Adding in ACL BD: {$thisacctid}<br><br>\n"; 
     308 
     309                                                        // Save these new acls. 
     310                                                        $acl -> save_repository( ); 
     311 
     312                                                        $new_uidnumber++; 
     313                                                } 
     314 
     315                                                if ( $type == 'admins' ) 
     316                                                { 
     317                                                        $GLOBALS[ 'phpgw_setup' ] -> add_acl(array( 'admin', 'expressoAdmin1_2' ), 'run', ( int ) $thisacctid ); 
     318                                                        $GLOBALS[ 'phpgw_setup' ] -> db -> query( "INSERT INTO phpgw_expressoadmin VALUES ( '{$thisacctlid}', '{$config[ 'ldap_context' ]}', 2199023253495 )" ); 
     319                                                        foreach ( $all_apps as $app ) 
     320                                                                $GLOBALS[ 'phpgw_setup' ] -> db -> query( "INSERT INTO phpgw_expressoadmin_apps VALUES ( '{$thisacctlid}', '{$config[ 'ldap_context' ]}', '{$app}' )" ); 
     321                                                } 
     322                                        } 
    328323                                } 
    329                         } 
    330324                } 
    331325 
Note: See TracChangeset for help on using the changeset viewer.