Skip to content

Commit

Permalink
ns-api: fix ns.dns from review
Browse files Browse the repository at this point in the history
  • Loading branch information
andre8244 committed Oct 13, 2023
1 parent 9e44cf4 commit ba70c1a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/ns-api/files/ns.dns
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def add_record(args):

def is_wildcard(u, ip, name):
try:
cur = u.get('dhcp', get_server(u), 'address', list=True)
cur = list(u.get('dhcp', get_server(u), 'address', list=True))
except:
return False

for addr in cur[0].split(","):
for addr in cur:
if f'/{name}/{ip}' == addr:
return True
return False
Expand All @@ -50,28 +50,26 @@ def remove_wildcard(u, ip, name):
server = get_server(u)
new = []
try:
cur = u.get('dhcp', server, 'address', list=True)
cur = list(u.get('dhcp', server, 'address', list=True))
except:
return
for addr in cur[0].split(","):
for addr in cur:
if f'/{name}/{ip}' == addr:
continue
new.append(addr)
u.set('dhcp', server, 'address', ",".join(new))
u.set('dhcp', server, 'address', new)
u.save('dhcp')

def add_wildcard(u, ip, name):
remove_wildcard(u, ip, name)
server = get_server(u)
address_list = []
try:
for addr in u.get("dhcp", server, "address", default=[], list=True):
address_list.append(addr)
addr = list(u.get('dhcp', server, 'address', list=True))
except:
pass
addr = []

address_list.append(f'/{name}/{ip}')
u.set('dhcp', server, 'address', ",".join(address_list))
addr.append(f'/{name}/{ip}')
u.set('dhcp', server, 'address', addr)
u.save('dhcp')

def edit_record(args):
Expand Down

0 comments on commit ba70c1a

Please sign in to comment.