summaryrefslogtreecommitdiffstats
path: root/generate-ldap-users.py
blob: 4f70f67325f91a8046e410067b1f05e05050c95c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env python

import os
import ldap
import sys

ldap_conn = ldap.initialize('ldap://ldap.pcf.be')
ldap_conn.simple_bind_s('cn=ldap,ou=ouAdmin,ou=ouUsers,dc=win,dc=info,dc=pcf', sys.argv[1])

usernames = []

for entry in ldap_conn.search_s("dc=win,dc=info,dc=pcf", ldap.SCOPE_SUBTREE, "objectclass=user"):
    if not entry[0]:
        continue
    if not entry[1].get('profilePath'):
        continue

    try:
        username = entry[1]['sAMAccountName'][0]
    except KeyError:
        continue
    usernames.append(username)

fd = file('ocrloader-complete.ini', 'w')
print >> fd, file('ocrloader.ini').read()

for username in usernames:
    print username
    print >> fd, '''[ged-%(username_lower)s@pfwb.be]
default_type = dmsdocument
default_directory = Members/%(username)s
user = %(username)s

[ged-file-%(username)s@pfwb.be]
store_path = /srv/ocr/%(username)s

''' % {'username': username, 'username_lower': username.lower()}

    if not os.path.exists('/srv/ocr/%s' % username):
        os.mkdir('/srv/ocr/%s' % username)

fd.close()