I have tried doing it this way:

def showthemall():
    # LDAP connection settings
    LDAP_SERVER = "ldap://ad.superhost";
    BIND_DN = "superuser@ad.superhost"
    BIND_PASS = "mysupersecretpassword"
    # Connect to LDAP
    con = ldap.initialize(LDAP_SERVER)
    # Authenticate in LDAP
    con.simple_bind_s(BIND_DN, BIND_PASS)
    # We don't want disabled users, so we use some magic LDAP-Active
Directory filers for it
    ldapfilter =
'(&(&(objectclass=person)(
objectcategory=person))(!(userAccountControl:1.2.840.113556.1.4.803:=2)))'
    # What user attributes do we want list in link:
    # 
http://www.manageengine.com/products/ad-manager/help/csv-import-management/active-directory-ldap-attributes.html
    attrs = ['displayName', 'givenName', 'sn', 'mail', 'mailNickname',
'department']
    # Get all users from ldap
    base_dn = 'ou=<OU>,dc=<DC>,dc=<DC>'
    ad_users = con.search_s( base_dn, ldap.SCOPE_SUBTREE, ldapfilter, attrs 
)

    for user in ad_users:
        # get 2nd value separated by comma
        ouvar=user[0].split(',')[1]
        # if ouvar valude is not Generic
        if ouvar != 'OU=Generic':
            # add user to the auth_user table
            required_fields = set([ 'sn', 'givenName', 'mail',
'department', 'mailNickname' ])
            if required_fields.issubset(set(user[1])):
                db.auth_user.insert(first_name=user[1]['givenName'],
                                    last_name=user[1]['sn'],
                                    email=user[1]['mail'],
                                    username=user[1]['mailNickname'],
                                    password=None,
                                    registration_id=user[1]['mailNickname'])



It is importing contact as (I mean every value in the DB is enveloped in 
vertical bar):

|Grzegorz||Dzien||gdzien@domai...|gdzien|None|gdzien|


By the way - is there a way to re-use web2py's AD connector's connection?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to