def show_rights(uname): fn = 'show_rights' networks = [] zones = [] gebn_ent = api.get_entity_by_name(config.RootId, uname, 'User') user_id = gebn_ent['id'] user_rights = api.get_access_rights_for_user(user_id, 0, 15) if config.Debug: Logger.debug('Get Ent By Name for {}: {}'.format(uname, gebn_ent)) Logger.debug('User name: {} User Id: {}'.format(uname, user_id)) for right in user_rights: if config.Debug: Logger.debug('Right: {}'.format(right)) ent_id = right['entityId'] par_ent = api.get_parent(ent_id) par_id = par_ent['id'] for typ in ['IP4Network', 'Zone']: ents = api.get_entities(par_id, typ, 0, 10) for e in ents: pairs = e['properties'].split('|') pairs.remove('') for pair in pairs: (name, val) = pair.split('=') if name == 'CIDR': if val not in networks: networks.append(val) elif name == 'absoluteName': if val not in zones: zones.append(val) print('CIDR blocks:') for net in networks: print(' {}'.format(net)) print('Domains:') for zone in zones: print(' {}'.format(zone))
def get_info_by_name(fqdn): fn = 'get_info_by_name' obj_id = config.ViewId names = fqdn.split('.') lg = len(names) for name in names[::-1]: ent = api.get_entity_by_name(obj_id, name, 'Entity') if config.Debug: Logger.debug('{} name: {} entity: {}'.format(fn, name, ent)) pid = obj_id obj_id = ent['id'] ent['pid'] = pid if ent['type'] == 'Zone': pid = ent['id'] name = '' else: pid = ent['pid'] name = fqdn.split('.')[0] for obj_type in config.RRObjectTypes: if config.Debug: Logger.debug('{} RR type: {}'.format(fn, obj_type)) ents = api.get_entities(pid, obj_type, 0, 50) if config.Debug: if type(ents) is str: Logger.debug('{} Type: {} Ent: {}'.format(fn, obj_type, ents)) else: for e in ents: if e['name'] == name: Logger.debug('{} Type: {} Ent: {}'.format( fn, obj_type, e)) if config.Debug: print() return ent
def object_find(fqdn, rr_type, value): fn = object_find id = 0 if rr_type == 'MX': (value, priority) = mx_parse(value) obj_type = config.RRTypeMap[rr_type]['obj_type'] prop_key = config.RRTypeMap[rr_type]['prop_key'] names = fqdn.split('.') tld = names.pop() tld_ent = api.get_entity_by_name(config.ViewId, tld, 'Zone') pid = tld_ent['id'] pname = tld while (len(names)): name = names.pop() ent = api.get_entity_by_name(pid, name, 'Entity') obj_id = ent['id'] obj_ent = api.get_entity_by_id(obj_id) if config.Debug: Logger.debug('{} name: {} id: {} ent: {}'.format( fn, name, obj_id, ent)) if len(names) == 0 and obj_id: obj_type = obj_ent['type'] if obj_type == 'Zone': pid = obj_id else: ents = api.get_entities(pid, obj_type, 0, 100) if len(ents): for ent in ents: if 'properties' in ent and ent[ 'properties'] is not None: d = props2dict(ent['properties']) if d['absoluteName'] == fqdn: if 'addresses' in d: obj_id = ent['id'] elif value == d[prop_key]: obj_id = ent['id'] pname = name pid = obj_id return obj_id
def get_external_hosts(): exhosts = [] ents = api.get_entities(config.ViewId, 'ExternalHostRecord', 0, 250) for ent in ents: exhosts.append(ent['name']) return exhosts
def find_rr(fqdn, *argv): """Given a fqdn and an RR type and optionally a value return a list of entity IDs which match the given input """ fn = 'find_rr' rr_type = value = obj_rr_key = None trailing_dot = False obj_types = config.RRObjectTypes if config.Debug: Logger.debug('{}: fqdn: {} argv: {}'.format(fn, fqdn, argv)) arglen = len(argv) if arglen > 0: rr_type = argv[0] obj_types = [config.RRTypeMap[rr_type]['obj_type']] if arglen > 1: value = argv[1] obj_rr_key = config.RRTypeMap[rr_type]['prop_key'] if fqdn[-1] == '.': trailing_dot = True fqdn = fqdn[:-1] if config.Debug: Logger.debug('{}: rr_type: {}, rr_value: {}, obj_rr_key: {}'.format( fn, rr_type, value, obj_rr_key)) names = fqdn.split('.') tld = names.pop() if tld not in config.LegalTLDs: Logger.debug('{}: Top level domain name must be one of: {}'.format( fn, config.LegalTLDs)) tld_ent = api.get_entity_by_name(config.ViewId, tld, 'Entity') par_id = tld_ent['id'] if config.Debug: Logger.debug('{}: TLD entity: {}'.format(fn, tld_ent)) for name in names[::-1]: ent = api.get_entity_by_name(par_id, name, 'Entity') ent['pid'] = par_id par_id = ent['id'] if config.Debug: Logger.debug('{}: entity: {}'.format(fn, ent)) obj_id = ent['id'] par_id = ent['pid'] rr_ents = [] if ent['type'] == 'Zone': par_id = obj_id name = '' for obj_type in obj_types: ents = api.get_entities(par_id, obj_type, 0, 100) if config.Debug: if len(ents): Logger.debug('{}: RR type: {} Entities:'.format( fn, obj_type)) for ent in ents: Logger.debug(' {}'.format(ent)) if len(ents): if trailing_dot: rr_ents += ents else: for ent in ents: if ent['name'] == name: rr_ents.append(ent) else: for obj_type in obj_types: ents = api.get_entities_by_name(par_id, name, obj_type, 0, 10) if len(ents): rr_ents += ents if arglen == 2 and rr_type != 'CNAME': found = False if rr_type == 'A' or rr_type == 'TXT' or rr_type == 'MX': for ent in rr_ents: d = props2dict(ent['properties']) values = d[obj_rr_key] if rr_type == 'A': current_ips = values.split(',') if value in current_ips: found = True rr_ents = [ent] break elif rr_type == 'MX': (mx_host, priority) = mx_parse(value) if d['priority'] == priority and mx_host == values: found = True rr_ents = [ent] break elif value == values: found = True rr_ents = [ent] break if not found: rr_ents = [] ids = [] for rr_ent in rr_ents: if rr_ent['name'] == '': ids.append(rr_ent['id']) for rr_ent in rr_ents: if rr_ent['name'] != '': ids.append(rr_ent['id']) if config.Debug: print() return ids
def view_info_by_name(fqdn, *argv): fn = 'view_info_by_name' is_Zone = False ll = len(argv) if config.Debug: Logger.debug('{} fqdn: {}'.format(fn, fqdn)) for arg in argv: Logger.debug('arg: {}'.format(arg)) if ll > 0: rr_type = argv[0] obj_rr_type = config.RRTypeMap[rr_type]['obj_type'] if ll > 1: obj_rr_key = config.RRTypeMap[rr_type]['prop_key'] value = argv[1] else: obj_rr_type = 'Entity' obj_id = config.ViewId names = fqdn.split('.') for name in names[::-1]: ent = api.get_entity_by_name(obj_id, name, 'Entity') if config.Debug: Logger.debug('{} name: {} entity: {}'.format(fn, name, ent)) pid = obj_id obj_id = ent['id'] ent['pid'] = pid if ent['type'] == 'Zone': is_Zone = True pid = ent['id'] name = '' else: name = names[0] if config.Debug: Logger.debug() if ll == 0: ids = [] for obj_type in config.RRObjectTypes: ents = api.get_entities(pid, obj_type, 0, 50) for e in ents: if e['name'] == name: ids.append(e['id']) bind_print(ids) if is_Zone: rrs = {} for obj_type in config.RRObjectTypes: ents = api.get_entities(pid, obj_type, 0, 50) if len(ents): for e in ents: name = e['name'] if len(name): if name in rrs: lst = rrs[name] lst.append(e) rrs[name] = lst else: rrs[name] = [e] ids = [] for fqdn in sorted(rrs): for e in rrs[fqdn]: ids.append(e['id']) bind_print(ids) elif ll > 0: ents = api.get_entities(pid, obj_rr_type, 0, 50) ids = [] for e in ents: if e['name'] == name: if ll == 1: ids.append(e['id']) else: d = props2dict(e['properties']) if value in d[obj_rr_key]: ids.append(e['id']) return ent