From 92e2b393c855684f90f8dab09054240e739eca77 Mon Sep 17 00:00:00 2001 From: fram3d Date: Tue, 20 Jun 2023 20:01:03 +0200 Subject: [PATCH] use new variables from expandbase in prepareldap function and rename it to prepare --- luser/models.py | 62 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/luser/models.py b/luser/models.py index ead7d4b..4134691 100644 --- a/luser/models.py +++ b/luser/models.py @@ -67,73 +67,21 @@ class LUSER(): if basealt == '': self.alt = False - def prepareluser(self): + def prepare(self): ''' Create base on LDAP host ''' + # Create dcObject on LDAP server and store boolean indicating it's success - # Split base string with commas to find values of organization and dc - baselist = self.base.split(",") - basealtlist = self.basealt.split(",") - - # Find ou in base and set it as organization variable - for i in baselist: - if i.split('=')[0] == 'ou': - organization = i.split('=')[1] - break - - for i in basealtlist: - if i.split('=')[0] == 'ou': - organizationalt = i.split('=')[1] - break - - # Find first dc and set it as dc variable - for i in baselist: - if i.split('=')[0] == 'dc': - dc = i.split('=')[1] - break - - for i in basealtlist: - if i.split('=')[0] == 'dc': - dcalt = i.split('=')[1] - break - - # Find full dc and set it as dcfull variable - dcfull = '' - for i in baselist: - if i.split('=')[0] == 'dc': - dcfull += ',dc=' + i.split('=')[1] - - for i in basealtlist: - if i.split('=')[0] == 'dc': - dcfullalt += ',dc=' + i.split('=')[1] - - # Remove first column character - dcfull = dcfull[1:] - dcfullalt = dcfull[1:] - - # Create organization on LDAP server and store boolean indicating it's success - - rcode1 = self.ldapconnection.add(f'dc={dcfull}', ['dcObject', 'organization'], {'o' : dc, 'dc' : dc}) - - if self.alt: - rcode2 = self.ldapconnection.add(f'dc={dcfullalt}', ['dcObject', 'organization'], {'o' : dcalt, 'dc' : dcalt}) - else: - rcode2 = True + rcode1 = self.ldapconnection.add(f'dc={self.dcfull}', ['dcObject', 'organization'], {'o' : self.dc, 'dc' : self.dc}) # Create organizational units on LDAP server and store boolean indicating it's success - rcode3 = self.ldapconnection.add(self.base, ['top', 'organizationalUnit'], {'ou' : organization}) - - if self.alt : - rcode4 = self.ldapconnection.add(self.basealt, ['top', 'organizationalUnit'], {'ou' : organizationalt}) - else: - rcode4 = True - + rcode2 = self.ldapconnection.add(self.base, ['top', 'organizationalUnit'], {'ou' : self.organization}) # Return True only if all return values are true - return rcode1 and rcode2 and rcode3 and rcode4 + return rcode1 and rcode2 def lastpwchangenow(self): '''