add a configuration file to generate-ldap-users
This commit is contained in:
parent
510eda7895
commit
a56fda0858
|
@ -1,5 +1,6 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import ConfigParser
|
||||
import optparse
|
||||
import os
|
||||
import ldap
|
||||
|
@ -7,19 +8,19 @@ import sys
|
|||
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--template', dest='template_filename', default='ocrloader.ini')
|
||||
parser.add_option('--config', dest='config', default='ldap.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)
|
||||
cfg = ConfigParser.ConfigParser()
|
||||
cfg.read(options.config)
|
||||
|
||||
ldap_conn = ldap.initialize(cfg.get('general', 'ldap_uri'))
|
||||
ldap_conn.simple_bind_s(cfg.get('general', 'bind_dn'), options.bindpw)
|
||||
|
||||
usernames = []
|
||||
|
||||
|
@ -36,9 +37,11 @@ for entry in ldap_conn.search_s("dc=win,dc=info,dc=pcf", ldap.SCOPE_SUBTREE, "ob
|
|||
usernames.append(username)
|
||||
|
||||
fd = file(options.output_filename, 'w')
|
||||
print >> fd, file(options.template_filename).read()
|
||||
print >> fd, file(cfg.get('general', 'template')).read()
|
||||
|
||||
for username in usernames:
|
||||
vars = {'username': username, 'username_lower': username.lower()}
|
||||
vars.update(dict(cfg.items('variables')))
|
||||
print username
|
||||
print >> fd, '''[ged-%(username_lower)s@pfwb.be]
|
||||
default_type = dmsdocument
|
||||
|
@ -48,7 +51,13 @@ user = %(username)s
|
|||
[ged-file-%(username)s@pfwb.be]
|
||||
store_path = /srv/ocr/%(username)s
|
||||
|
||||
''' % {'username': username, 'username_lower': username.lower()}
|
||||
[ged-test-%(username_lower)s@pfwb.be]
|
||||
ged_base_url = %(test_server_url)s
|
||||
default_type = dmsdocument
|
||||
default_directory = Members/%(username)s
|
||||
user = %(username)s
|
||||
|
||||
''' % vars
|
||||
|
||||
if not os.path.exists('/srv/ocr/%s' % username):
|
||||
os.mkdir('/srv/ocr/%s' % username)
|
||||
|
|
Reference in New Issue