def execute(self): if self.args['dns']: d_dns = sort.list_dns() if d_dns['status']: d_dns = d_dns['data'] dat = list() for row in d_dns: tmp = sort.get_data('zone',key=None,tags='nm_zone',value=row)['data'][0] dat.append(tmp) d_unsync = list() d_id = list() for row in dat: if row['state'] == 0: d_unsync.append(row) d_id.append(row['id_zone']) if d_unsync: print("\n============================ Unsynchronized DNS ============================\n") d_unsync = util.convert(d_unsync) d_unsync = util.table_cleanup(d_unsync) print(tabulate(d_unsync,headers='keys',showindex='always',tablefmt="rst")) index = input(""" Type the index of the zone (0~{}), if you want to remove multiple record separate the index using comma (,) """.format(len(d_id)-1)) index = index.split(',') index = util.check_availability(index,(len(d_id)-1)) for idx in index: d_sync = { "sync" : "dns", "data" : {"id_zone" : d_id[int(idx)] } } res=app.syncdat(d_sync) else : print("All dns is already synchronized with knot server") elif self.args['record']: zone = sort.list_dns() zone = zone['data'] show = sort.list_record(zone) show = show['data'] d_record = list() id_record = list() for row in show: if row['state'] == 0: id_record.append(row['id_record']) d_record.append(row) if len(d_record)<=0 : print("All record is already synchronized with Knot server") return 0 else : d_record = util.table_cleanup(d_record) print(tabulate(d_record,headers="keys",showindex="always",tablefmt="rst")) index = input(""" Type the index of the record (0~{}), if you want to remove multiple record separate the index using comma (,) """.format(len(d_record)-1)) index = index.split(',') index = util.check_availability(index,(len(show)-1)) for idx in index: d_sync = {"sync" : "record", "data" : {"id_record" : id_record[int(idx)]}} res=app.syncdat(d_sync) if not res["status"]: sys.stderr.write("Failure on index {}".format(idx))
def execute(self): if self.args['dns']: zone = [self.args['--nm']] try : listdns = ls.list_record(zone) if 'data' in listdns: listdns = listdns['data'] listdns = util.table_cleanup(listdns) util.log_warning('The following record will also be deleted\n') print(tabulate(listdns,headers="keys",tablefmt="rst")) except TypeError : print("DNS don't have record") if util.assurance() and check_password(): delete.remove_zone(zone[0]) else: exit() elif self.args['record']: if self.args['--nm-zone']: id_record = list() zone = [self.args['--nm-zone']] tags = self.args show = list() show = ls.list_record(zone,tags) try : show = show['data'] except Exception as e: sys.stderr.write("Data doesn't exist") sys.stderr.write(str(e)) exit() else: zone = ls.list_dns() zone = zone['data'] show = ls.list_record(zone) show = show['data'] show = util.convert(show) id_record = list() for row in show: row = util.convert(row) id_record.append(row['id_record']) if(len(show)>0): show = util.table_cleanup(show) print(tabulate(show, headers="keys" ,showindex="always",tablefmt="rst")) index = input(""" Type the index of the record (0~{}), if you want to remove multiple record separate the index using comma (,) """.format(len(show)-1)) index = index.split(',') index = util.check_availability(index,(len(show)-1)) sendid = list() for i in index: sendid.append(id_record[int(i)]) util.log_warning('Removing record is irreversible, are you sure ?\n') if util.assurance() and check_password(): res = delete.remove_record(sendid) else: exit()
def test_create_record(self): mock_zone = ['testclis2.com', 'testclis.com'] mock_type = ['tipe', 'CNAME'] mock_ttl = ['2200', '7200'] mock_data = list() passed = list() for zone in mock_zone: for tipe in mock_type: for ttl in mock_ttl: mock_data.append({ '--nm-zn': zone, '--type': tipe, '--ttl': ttl, '--nm': 'test', '--nm-con': 'alias', '--nm-con-ser': None }) mock_data.append({ '--nm-zn': mock_zone[1], '--type': 'SRV', '--ttl': mock_ttl[1], '--nm': 'test', '--nm-con': 'alias', '--nm-con-ser': '80 80 80 80' }) mock_data.append({ '--nm-zn': mock_zone[1], '--type': 'MX', '--ttl': mock_ttl[1], '--nm': 'test', '--nm-con': 'alias', '--nm-con-ser': 'serialcontenttestdata' }) for i in mock_data: if util.check_existence('zone', i['--nm-zn']): if (util.check_existence('type', i['--type']) and util.check_existence('ttl', i['--ttl'])): passed.append(i) #print(i) for i in passed: i['--date'] = util.get_time() app.setRecord(i) record_list = ls.list_record([mock_zone[1]]) record_list = util.convert(record_list['data']) clean = util.table_cleanup(record_list) check = True for i in record_list: for j in passed: if j['--type'] == i['nm_type']: check = bool(check and bool(j['--nm-zn'] and i['nm_zone'])) check = bool(check and bool(j['--nm'] and i['nm_record'])) check = bool(check and bool(j['--ttl'] and i['nm_ttl'])) check = bool(check and bool(j['--nm-con'] and i['nm_content'])) assert check == True
def execute(self): if self.args['ttl']: vallist = sort.listing_endpoint('ttl') print('Available TTL values are : ') print(vallist) elif self.args['type']: vallist = sort.listing_endpoint('type') print('Available Types are : ') print(vallist) elif self.args['dns']: vallist = sort.list_dns() if vallist['status'] == False: print(vallist['message']) exit() util.convert(vallist) vallist = vallist['data'] d_dns = list() for row in vallist: state = sort.get_data("zone", "state", "nm_zone", row) state = state["data"][0] d_dns.append({"nm_zone": row, "state": state}) print('Your Domains List Are : ') print( tabulate(d_dns, headers='keys', showindex='always', tablefmt="rst")) elif self.args['record']: if self.args['--nm-zone']: zone = [self.args['--nm-zone']] tags = self.args vallist = ls.list_record(zone, tags) else: zone = sort.list_dns() try: zone = zone['data'] vallist = sort.list_record(zone) except Exception: sys.stderr.write(zone['message'] + '\n') exit() if vallist['status'] and 'data' in vallist: vallist = util.table_cleanup(vallist['data']) print( tabulate(vallist, headers="keys", showindex="always", tablefmt="rst")) else: print("You have no record yet.")
def execute(self): if self.args['ttl']: vallist = sort.listing_endpoint('ttl') print('Available TTL values are : ') print(vallist) elif self.args['type']: vallist = sort.listing_endpoint('type') print('Available Types are : ') print(vallist) elif self.args['dns']: vallist = sort.list_dns() if vallist['status'] == False: print(vallist['message']) exit() util.convert(vallist) vallist = vallist['data'] show = list() for i in vallist: var = {"DNS NAME": i} show.append(var) print('Your Domains List Are : ') print( tabulate(show, headers='keys', showindex='always', tablefmt="rst")) elif self.args['record']: if self.args['--nm-zone']: id_record = list() zone = [self.args['--nm-zone']] tags = self.args vallist = ls.list_record(zone, tags) else: zone = sort.list_dns() try: zone = zone['data'] vallist = sort.list_record(zone) except Exception: print(zone['message']) exit() if vallist['status']: vallist = util.table_cleanup(vallist['data']) print( tabulate(vallist, headers="keys", showindex="always", tablefmt="rst")) else: print(vallist['message']) print("You have no record yet!")