Plugin Directory

Changeset 674096


Ignore:
Timestamp:
02/27/2013 03:14:14 PM (13 years ago)
Author:
glatze
Message:

Added ldap paging for bulk import
[Issue 0058] http://bt.steindorff.de/view.php?id=0058

Location:
active-directory-integration/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • active-directory-integration/trunk/ad-integration.php

    r670744 r674096  
    656656                                 '------------------------------------------');
    657657       
     658        if (function_exists('ldap_control_paged_result')) {
     659            $this->_log(ADI_LOG_INFO, 'LDAP paging: enabled');
     660        } else {
     661            $this->_log(ADI_LOG_INFO, 'LDAP paging: not available');
     662        }
     663       
    658664        // IMPORTANT!
    659665        $this->_authenticated = false;
    660666        $user_id = NULL;
    661         $username = strtolower($username);
     667        $username = strtolower($username); 
    662668        $password = stripslashes($password);
    663669
     
    22542260                update_site_option('AD_Integration_auto_update_user', (bool)$arrPost['AD_Integration_auto_update_user']);
    22552261           
    2256                 if ( !empty( $arrPost['AD_Integration_auto_update_description'] ) )
     2262            if ( !empty( $arrPost['AD_Integration_network_timeout'] ) )
     2263                update_site_option('AD_Integration_network_timeout', (int)$arrPost['AD_Integration_network_timeout']);
     2264           
     2265            if ( !empty( $arrPost['AD_Integration_auto_update_description'] ) )
    22572266                update_site_option('AD_Integration_auto_update_description', (bool)$arrPost['AD_Integration_auto_update_description']);
    22582267             
  • active-directory-integration/trunk/ad_ldap/adLDAP.php

    r371867 r674096  
    1616 * to benefit the entire community :)
    1717 *
    18  * EXTENDED with the ability to change the port and recursive_groups bug fix
    19  *  by Christoph Steindorff, ECW GmbH
    20  *   email: cst@ecw.de
    21  *   http://www.ecw.de
     18 * EXTENDED with the ability to change the port, recursive_groups bug fix
     19 * and paging support by
     20 *   Christoph Steindorff
     21 *   email: christoph@steindorff.de
     22 *   http://www.steindorff.de
    2223 *
    2324 * This library is free software; you can redistribute it and/or
     
    3738 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPLv2.1
    3839 * @revision $Revision: 91 $
    39  * @version 3.3.2 EXTENDED (201102221155)
     40 * @version 3.3.2 EXTENDED (201302271401)
    4041 * @link http://adldap.sourceforge.net/
    4142 */
     
    157158     * @var unknown_type
    158159     */
    159     const VERSION = '3.3.2 Extended (201104081456)';
     160    const VERSION = '3.3.2 EXTENDED (201302271401)';
    160161   
    161162   
     
    746747     * @param array $fields
    747748     */
    748     public function group_members_by_primarygroupid($pgid= NULL, $fields = NULL)
     749    public function group_members_by_primarygroupid($pgid= NULL, $fields = NULL, $recursive = false)
    749750    {
    750751        if (!$this->_bind){ return (false); }
    751752       
    752753        if ($pgid===NULL){ return (false); }
    753        
    754        
    755         $filter="(&(objectCategory=user)(primarygroupid=".$pgid."))";
    756         $sr=ldap_search($this->_conn,$this->_base_dn,$filter,array('dn'));
    757         $users = ldap_get_entries($this->_conn, $sr);
     754       
     755        $filter="(&(objectCategory=user)(primarygroupid=".$pgid."))";
     756       
     757        // Let's use paging if available
     758        if (function_exists('ldap_control_paged_result')) {
     759           
     760            $pageSize = 500;
     761            $cookie = '';
     762            $users =  array();
     763            $users_page = array();
     764           
     765            do {
     766                ldap_control_paged_result($this->_conn, $pageSize, true, $cookie);
     767           
     768                $sr = ldap_search($this->_conn, $this->_base_dn, $filter, array('dn'));
     769                $users_page = ldap_get_entries($this->_conn, $sr);
     770               
     771                if (!is_array($users_page)) {
     772                    return false;
     773                }
     774               
     775                $users = array_merge($users, $users_page);
     776                ldap_control_paged_result_response($this->_conn, $sr, $cookie);
     777                 
     778            } while($cookie !== null && $cookie != '');
     779           
     780            $users['count'] = count($users) -1; // Set a new count value !important!
     781           
     782            ldap_control_paged_result($this->_conn, $pageSize, true, $cookie); // RESET is important
     783           
     784        } else {
     785           
     786            // Non-Paged version
     787            $sr = ldap_search($this->_conn, $this->_base_dn, $filter, array('dn'));
     788            $users = ldap_get_entries($this->_conn, $sr);
     789        }
    758790       
    759791        if (!is_array($users)) {
    760792            return (false);   
    761793        }
    762        
     794       
    763795        $user_array=array();
    764796
    765797        for ($i=0; $i<$users["count"]; $i++){
    766798             $filter="(&(objectCategory=person)(distinguishedName=".$this->ldap_slashes($users[$i]['dn'])."))";
     799             
    767800             $fields = array("samaccountname", "distinguishedname", "objectClass");
    768              $sr=ldap_search($this->_conn,$this->_base_dn,$filter,$fields);
     801             $sr = ldap_search($this->_conn, $this->_base_dn, $filter, $fields);
    769802             $entries = ldap_get_entries($this->_conn, $sr);
    770803
     
    796829        return ($user_array);
    797830    }
    798                
     831
    799832       
    800833   
     
    810843       
    811844        if ($recursive===NULL){ $recursive=$this->_recursive_groups; } // Use the default option if they haven't set it
     845
    812846        // Search the directory for the members of a group
    813847        $info=$this->group_info($group,array("member","cn"));
     
    820854            return (false);   
    821855        }
     856       
    822857 
    823858        $user_array=array();
     
    856891    }
    857892   
     893   
    858894    /**
    859895    * Group Information.  Returns an array of information about a group.
     
    875911        //echo ($filter."!!!<br>");
    876912        if ($fields===NULL){ $fields=array("member","memberof","cn","description","distinguishedname","objectcategory","samaccountname"); }
    877         $sr=ldap_search($this->_conn,$this->_base_dn,$filter,$fields);
    878         $entries = ldap_get_entries($this->_conn, $sr);
     913       
     914        // Let's use paging if available
     915        if (function_exists('ldap_control_paged_result')) {
     916       
     917            $pageSize = 500;
     918            $cookie = '';
     919            $entries =  array();
     920            $entries_page = array();
     921       
     922            do {
     923                ldap_control_paged_result($this->_conn, $pageSize, true, $cookie);
     924       
     925                $sr=ldap_search($this->_conn,$this->_base_dn,$filter,$fields);
     926                $entries_page = ldap_get_entries($this->_conn, $sr);
     927       
     928                if (!is_array($entries_page)) {
     929                    return (false);
     930                }
     931       
     932                $entries = array_merge($entries, $entries_page);
     933                ldap_control_paged_result_response($this->_conn, $sr, $cookie);
     934       
     935            } while($cookie !== null && $cookie != '');
     936           
     937            $entries['count'] = count($entries) - 1; // Set a new count value !important!
     938           
     939            ldap_control_paged_result($this->_conn, $pageSize, true, $cookie); // RESET is important
     940       
     941        } else {
     942       
     943            // Non-Paged version
     944            $sr=ldap_search($this->_conn,$this->_base_dn,$filter,$fields);
     945            $entries = ldap_get_entries($this->_conn, $sr);
     946        }
     947       
    879948        //print_r($entries);
    880949        return ($entries);
  • active-directory-integration/trunk/bulkimport.php

    r670753 r674096  
    254254        foreach ($all_users AS $username) {
    255255           
    256             $ad_username = $username;
     256            $ad_username = $username; // Issue #0077
    257257           
    258258            // getting user data
    259             //$user = get_userdatabylogin($username); // deprecated
    260259            $user = get_user_by('login', $username);
     260            //$ad_username = get_user_meta($user->ID, 'adi_samaccountname', true); // Issue #0077
    261261           
    262262            // role
  • active-directory-integration/trunk/readme.txt

    r670753 r674096  
    3636* Using LDAP_OPT_NETWORK_TIMEOUT (default 5 seconds) to fall back to local authorization when your Active Directory Server is unreachable.
    3737* Bulk SyncBack to manually write all "Additional User Attributes" back to Active Directory.
    38 * **NEW** Disable user accounts in WordPress if they are disabled in Active Directory.
    39 * **NEW** Option to disable fallback to local (WordPress) authentication.
     38* Disable user accounts in WordPress if they are disabled in Active Directory.
     39* Option to disable fallback to local (WordPress) authentication.
     40* **NEW** Support for large groups (>1000 user) in Bulk Import with PHP 5.4.0 and above.
    4041
    4142The latest major release 1.1 was sponsored by [VARA](http://vara.nl). Many thanks to Bas Ruijters.
     
    9899= Why will no users be imported if I'm using "Domain Users" as security group for Bulk Import? =
    99100Here we have a special problem with the builtin security group "Domain Users". In detail: the security group "Domain Users" is usually the primary group of all users. In this case the members of this security group are not listed in the members attribute of the group. To import all users of the security group "Domain Users" you must set the option "Import members of security groups" to "**Domain Users;id:513**". The part "id:513" means "Import all users whos primaryGroupID is 513." And as you might have guessed, 513 is the ID of the security group "Domain Users".
     101
     102= I have problems with accounts that have special characters in the username. What can I do? =
     103It is never a good idea to allow special characters in usernames! For ADI it won't be a problem, but in Wordpress only lowercase letters (a-z) and numbers are allowed. The only option is to change the usernames in AD. Hey! Stop! Don't shoot the messenger.   
    100104
    101105= I'm interested in the further development of ADI. How to keep up to date? =
     
    128132== Changelog ==
    129133
    130 = 1.1.4 =
    131 * Fix: Bulk Import didn't work correctly if account suffix is appended to username. (Bug report by Stephen. Issue #0076.)
    132 * Change: Moved class BulkSyncBackADIntegrationPlugin() from syncback.php to BulkSyncBackADIntegrationPlugin.class.php (Recommendation by nic0tin. Issue #0075.)
     134= 1.1.5 =
     135* ADD: LDAP paging support for Bulk Import on PHP 5.4.0 so more than 1000 users per group can be imported. (Issue #0058. Thanks to billrod for the bug report.)
     136* Fix: Added network_timeout setting to wpmu settings.
     137* Fix: Bulk Import didn't work correctly if account suffix is appended to username. (Issue #0076. Thanks to Stephen Rice for the bug report.)
     138* Change: Moved class BulkSyncBackADIntegrationPlugin() from syncback.php to BulkSyncBackADIntegrationPlugin.class.php (Recommendation by nic0tin. Issue #0075.)
     139 
    133140
    134141= 1.1.4 =
Note: See TracChangeset for help on using the changeset viewer.