add script to fill ocr config from LDAP (#3455)

This commit is contained in:
Frédéric Péters 2013-12-30 17:18:16 +01:00
parent ff596fc526
commit c9e1f58986
1 changed files with 43 additions and 0 deletions

43
generate-ldap-users.py Normal file
View File

@ -0,0 +1,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()