def addAtributeToObjectClass(self, object_class_name, attribute_name): if not type(attribute_name) == type([]): attribute_name = [attribute_name] objcl_s = self.getObjectClass(object_class_name) if objcl_s: self.conn.modify("cn=schema", {'objectClasses': [MODIFY_DELETE, objcl_s]}) if not self.conn.result['description']== 'success': return False, self.conn.result['description']+'({})'.format(self.conn.result['message']) else: objcl_s = "( 1.3.6.1.4.1.48710.1.4.200 NAME '{}' SUP top AUXILIARY )".format(object_class_name) obcl_obj = ObjectClass(objcl_s) may_list = list(obcl_obj.may) for attribute in attribute_name: if not attribute in may_list: may_list.append(attribute) obcl_obj.may = tuple(may_list) self.conn.modify("cn=schema", {'objectClasses': [MODIFY_ADD, str(obcl_obj)]}) if not self.conn.result['description']== 'success': return False, self.conn.result['description'] return True, 'success'
def parse_open_ldap_schema(fn): f = open(fn).readlines() entry_finished = True new_entry = [] new_object = [] attributes = [] objectclasses = [] for i, l in enumerate(f): if l.lower().startswith('attributetype') or l.lower().startswith( 'objectclass') or (i == len(f) - 1): entry_finished = False objs = ' '.join(new_entry) if objs.lower().startswith('attributetype'): attributes.append(AttributeType(objs[14:])) elif objs.lower().startswith('objectclass'): objectclasses.append(ObjectClass(objs[12:])) new_entry = [] if not entry_finished: if not l.startswith('#'): ls = l.strip() if ls: new_entry.append(ls) return {'attributes': attributes, 'objectclasses': objectclasses}
def home(): try: appconf = AppConfiguration.query.first() except: return render_template('index_nodb.html') if not appconf: return render_template('intro.html', setup='cluster') print appconf.object_class_base if not appconf.object_class_base: return redirect(url_for('attributes.object_class')) server = Server.query.filter_by(primary_server=True).first() ldp = getLdapConn(server.hostname, "cn=directory manager", server.ldap_password) attrib_list_in_class = [] objcl_s = ldp.getObjectClass(appconf.object_class_base) if objcl_s: objcl_obj = ObjectClass(objcl_s) attrib_list_in_class = list(objcl_obj.may) attrib_list = [] attrib_list_s = ldp.getCustomAttributes() attrib_list = [AttributeType(str(a)) for a in attrib_list_s] return render_template('attributes.html', attrib_list_in_class=attrib_list_in_class, attrib_list=attrib_list, ojectclass=appconf.object_class_base)
def removeAtributeFromObjectClass(self, object_class_name, attribute_name): objcl_s = self.getObjectClass(object_class_name) if objcl_s: obcl_obj = ObjectClass(objcl_s) may_list = list(obcl_obj.may) if attribute_name in may_list: self.conn.modify("cn=schema", {'objectClasses': [MODIFY_DELETE, objcl_s]}) if not self.conn.result['description']== 'success': return False, self.conn.result['description'] may_list.remove(attribute_name) obcl_obj.may = tuple(may_list) self.conn.modify("cn=schema", {'objectClasses': [MODIFY_ADD, str(obcl_obj)]}) if not self.conn.result['description']== 'success': return False, self.conn.result['description'] return True, 'success'
def handle(self, dn, entry): self.schema = { 'dn': dn, 'objectClass': entry['objectClass'], 'objectClasses': [], 'attributeTypes': [], 'ldapSyntaxes': entry.get('ldapSyntaxes', []), } for ocls in entry.get('objectClasses', []): o = ObjectClass(ocls) self.schema['objectClasses'].append(o) for name in o.names: self.class_names.append(name) for atyp in entry.get('attributeTypes', []): a = AttributeType(atyp) self.schema['attributeTypes'].append(a) for name in a.names: self.attribute_names.append(name)
f = open(fn).readlines() entry_finished = True new_entry= [] new_object = [] attributes = [] objectclasses = [] for i,l in enumerate(f): if l.lower().startswith('attributetype') or l.lower().startswith('objectclass') or (i==len(f)-1): entry_finished = False objs = ' '.join(new_entry) if objs.lower().startswith('attributetype'): attributes.append(AttributeType(objs[14:])) elif objs.lower().startswith('objectclass'): objectclasses.append(ObjectClass(objs[12:])) new_entry = [] if not entry_finished: if not l.startswith('#'): ls = l.strip() if ls: new_entry.append(ls) spath, sfile = os.path.split(fn) fname, fext = os.path.splitext(sfile) opendj_fn = 'opendj_schema/{}-{}.ldif'.format(c,fname) with open(opendj_fn, 'w') as f: f.write('dn: cn=schema\nobjectClass: top\nobjectClass: ldapSubentry\nobjectClass: subschema\n')
def add_classs(self, s): o = ObjectClass(s) self.schema['objectClasses'].append(o) for name in o.names: self.class_names.append(name)