Changeset 3664
- Timestamp:
- 01/07/11 08:04:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/setup/ldapmodify.php
r3607 r3664 91 91 if ( array_key_exists( 'ldap_group_context', $phpgw_info[ 'server' ] ) && count( $phpgw_info['server']['global_denied_groups'] ) ) 92 92 { 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 ); 94 96 $info = ldap_get_entries( $ldap, $sr ); 95 97 $tmp = ''; … … 121 123 ); 122 124 123 //error_log( print_r( $config, true ), 3, '/tmp/log' );124 //error_log( print_r( $group_info, true ), 3, '/tmp/log' );125 126 125 if ( array_key_exists( 'submit', $_POST ) ) 127 126 { … … 133 132 $groups = CreateObject( 'phpgwapi.accounts' ); 134 133 copyobj( $GLOBALS[ 'phpgw_setup' ] -> db, $groups -> db ); 135 136 //error_log( print_r( $_POST[ 'ldapgroups' ], true ), 3, '/tmp/log' );137 134 138 135 foreach ( $_POST[ 'ldapgroups' ] as $groupid ) … … 159 156 $groups->account_id = ( int ) $thisacctid; 160 157 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' ] ); 167 159 168 160 $add = array( ); 169 161 170 if ( ! in_array( 'phpgwAccount', $ entry[ 0][ 'objectclass' ] ) )162 if ( ! in_array( 'phpgwAccount', $group_info[ $groupid ][ 'objectclass' ] ) ) 171 163 $add[ 'objectclass'] = array( 'phpgwAccount' ); 172 164 173 if ( ! array_key_exists( 'phpgwaccountstatus', $ entry[ 0] ) )165 if ( ! array_key_exists( 'phpgwaccountstatus', $group_info[ $groupid ] ) ) 174 166 $add[ 'phpgwaccountstatus'] = array( 'A' ); 175 167 176 if ( ! array_key_exists( 'phpgwaccounttype', $ entry[ 0] ) )168 if ( ! array_key_exists( 'phpgwaccounttype', $group_info[ $groupid ] ) ) 177 169 $add[ 'phpgwaccounttype' ] = array( 'g' ); 178 170 179 if ( ! array_key_exists( 'phpgwaccountexpires', $ entry[ 0] ) )171 if ( ! array_key_exists( 'phpgwaccountexpires', $group_info[ $groupid ] ) ) 180 172 $add[ 'phpgwaccountexpires' ] = array( -1 ); 181 173 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 ); 186 176 187 177 // Now make the members a member of this group in phpgw. … … 190 180 if ( array_key_exists( 'count', $thismembers ) ) 191 181 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' );195 182 196 183 foreach ( $thismembers as $key => $members ) … … 215 202 $acl -> account_id = ( int ) $tmpid; 216 203 $acl -> read_repository( ); 217 204 218 205 $acl -> delete( 'phpgw_group', $thisacctid, 1 ); 219 206 $acl -> add( 'phpgw_group', $thisacctid, 1 ); 220 207 221 208 // Now add the acl to let them change their password 222 209 $acl -> delete( 'preferences', 'changepassword', 1 ); 223 210 $acl -> add( 'preferences', 'changepassword', 1 ); 224 211 225 212 $acl -> save_repository( ); 226 213 } … … 247 234 } 248 235 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' ] ) ) ) 250 237 { 251 238 $accounts = CreateObject( 'phpgwapi.accounts' ); … … 258 245 //error_log( print_r( $config, true ), 3, '/tmp/log' ); 259 246 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 ) ) 271 249 { 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' ) 295 251 { 296 $objectclass[ ] = 'phpgwAccount';297 $a dd[ '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' ); 301 257 } 302 258 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 } 328 323 } 329 }330 324 } 331 325
Note: See TracChangeset
for help on using the changeset viewer.