From be14dc2b3004716190dfa7ca2d775aae976dc375 Mon Sep 17 00:00:00 2001 From: chayleaf Date: Sun, 2 Jul 2023 16:56:17 +0700 Subject: [PATCH] router/unbound: allow temporary dynamic query modification --- system/hosts/router/avahi-resolver-v2.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/system/hosts/router/avahi-resolver-v2.py b/system/hosts/router/avahi-resolver-v2.py index 8958e1b..9b6aa7b 100644 --- a/system/hosts/router/avahi-resolver-v2.py +++ b/system/hosts/router/avahi-resolver-v2.py @@ -638,11 +638,11 @@ def operate(id, event, qstate, qdata): n2 = name.rstrip('.') - if NFT_TOKEN and n2.endswith(f'.{NFT_TOKEN}'): - n3 = n2.removesuffix(f'.{NFT_TOKEN}') - for k, v in NFT_QUERIES.items(): - if v['dynamic']: - if n3.endswith(f'.{k}'): + if NFT_TOKEN and n2.endswith(f'{NFT_TOKEN}'): + if n2.endswith(f'.{NFT_TOKEN}'): + n3 = n2.removesuffix(f'.{NFT_TOKEN}') + for k, v in NFT_QUERIES.items(): + if v['dynamic'] and n3.endswith(f'.{k}'): n3 = n3.removesuffix(f'.{k}') qdomains = v['domains'] if not lookup_domain(qdomains, n3): @@ -655,6 +655,15 @@ def operate(id, event, qstate, qdata): old.append('*.' + n3) with open(f'/var/lib/unbound/{k}_domains.json', 'wt') as f: json.dump(old, f) + elif n2.endswith(f'.tmp{NFT_TOKEN}'): + n3 = n2.removesuffix(f'.tmp{NFT_TOKEN}') + for k, v in NFT_QUERIES.items(): + if v['dynamic'] and n3.endswith(f'.{k}'): + n3 = n3.removesuffix(f'.{k}') + qdomains = v['domains'] + if not lookup_domain(qdomains, n3): + add_split_domain(qdomains, ['*'] + n3.split('.')) + return True qnames = [] for k, v in NFT_QUERIES.items(): if lookup_domain(v['domains'], n2):