add expand function
This commit is contained in:
parent
35abb85365
commit
533a9885d4
@ -12,14 +12,51 @@ class LUSER():
|
|||||||
basealt := string base in LDAP system where users are made with password hashes generated for openalt
|
basealt := string base in LDAP system where users are made with password hashes generated for openalt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, ldap_host, admin_user, admin_pass, base, basealt=''):
|
|
||||||
|
def expandbase(self):
|
||||||
|
'''
|
||||||
|
Extract orgnaization, name of dc object and full domain part with all dc values from base
|
||||||
|
'''
|
||||||
|
# Split base string with commas to find values of organization and dc
|
||||||
|
baselist = self.base.split(",")
|
||||||
|
|
||||||
|
organization = ''
|
||||||
|
dc = ''
|
||||||
|
dcfull = ''
|
||||||
|
|
||||||
|
# Find ou in base and set it as organization variable
|
||||||
|
for i in baselist:
|
||||||
|
if i.split('=')[0] == 'ou':
|
||||||
|
organization = i.split('=')[1]
|
||||||
|
|
||||||
|
# Find first dc and set it as dc variable
|
||||||
|
for i in baselist:
|
||||||
|
if i.split('=')[0] == 'dc':
|
||||||
|
dc = i.split('=')[1]
|
||||||
|
break
|
||||||
|
|
||||||
|
# Find full dc and set it as dcfull variable
|
||||||
|
for i in baselist:
|
||||||
|
if i.split('=')[0] == 'dc':
|
||||||
|
# if first dc, add it from dc variable
|
||||||
|
if dcfull == '':
|
||||||
|
dcfull = f'dc={dc}'
|
||||||
|
else:
|
||||||
|
dcfull += ',dc=' + i.split('=')[1]
|
||||||
|
|
||||||
|
return organization, dc, dcfull
|
||||||
|
|
||||||
|
def __init__(self, ldap_host, admin_user, admin_pass, base, basealt='', autoconnect=True):
|
||||||
self.ldap_host = ldap_host
|
self.ldap_host = ldap_host
|
||||||
self.admin_user = admin_user
|
self.admin_user = admin_user
|
||||||
self.admin_pass = admin_pass
|
self.admin_pass = admin_pass
|
||||||
self.base = base
|
self.base = base
|
||||||
|
self.organization, self.dc, self.dcfull = self.expandbase()
|
||||||
self.basealt = basealt
|
self.basealt = basealt
|
||||||
self.alt = True
|
self.alt = True
|
||||||
|
self.autoconnect = autoconnect
|
||||||
ldapserver = Server(ldap_host, use_ssl=True)
|
ldapserver = Server(ldap_host, use_ssl=True)
|
||||||
|
if self.autoconnect:
|
||||||
self.ldapconnection = Connection(ldapserver, admin_user, admin_pass, auto_bind=True)
|
self.ldapconnection = Connection(ldapserver, admin_user, admin_pass, auto_bind=True)
|
||||||
|
|
||||||
# uid and gid of most recently registered users
|
# uid and gid of most recently registered users
|
||||||
@ -62,6 +99,7 @@ class LUSER():
|
|||||||
break
|
break
|
||||||
|
|
||||||
# Find full dc and set it as dcfull variable
|
# Find full dc and set it as dcfull variable
|
||||||
|
dcfull = ''
|
||||||
for i in baselist:
|
for i in baselist:
|
||||||
if i.split('=')[0] == 'dc':
|
if i.split('=')[0] == 'dc':
|
||||||
dcfull += ',dc=' + i.split('=')[1]
|
dcfull += ',dc=' + i.split('=')[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user