58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
#! /usr/bin/env python
|
|
|
|
import optparse
|
|
import os
|
|
import ldap
|
|
import sys
|
|
|
|
|
|
parser = optparse.OptionParser()
|
|
parser.add_option('--template', dest='template_filename', default='ocrloader.ini')
|
|
parser.add_option('--output', dest='output_filename',
|
|
default='ocrloader-complete.ini')
|
|
parser.add_option('--ldap-uri', dest='ldap_uri', default='ldap://ldap.pcf.be')
|
|
parser.add_option('--binddn', dest='binddn',
|
|
default='cn=ldap,ou=ouAdmin,ou=ouUsers,dc=win,dc=info,dc=pcf')
|
|
parser.add_option('--bindpw', dest='bindpw')
|
|
(options, args) = parser.parse_args()
|
|
if not options.bindpw:
|
|
parser.error('Missing LDAP bind password')
|
|
|
|
ldap_conn = ldap.initialize(options.ldap_uri)
|
|
ldap_conn.simple_bind_s(options.binddn, options.bindpw)
|
|
|
|
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(options.output_filename, 'w')
|
|
print >> fd, file(options.template_filename).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()
|
|
|