From 5980edbf89a9d417b4f06445fca727a20d5246fe Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Tue, 12 Dec 2023 14:33:23 +1100 Subject: [PATCH] feat: Start clone to alts function --- varo.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/varo.py b/varo.py index 4b92798..98553d4 100644 --- a/varo.py +++ b/varo.py @@ -10,6 +10,13 @@ city_domain = os.getenv('CITY_DOMAIN') if city_domain == "localhost": city_domain = "exampledomainnathan1" +alt_domains = os.getenv('ALT_DOMAINS') + +if alt_domains == None: + alt_domains = [] +else: + alt_domains = alt_domains.split(",") + server_ip = os.getenv('CITY_IP') def update_auth(auth,domain): @@ -46,6 +53,8 @@ def update_auth(auth,domain): 'Content-Type': 'application/json' } r = requests.put(url, headers=headers, json=data) + + copy_to_alts(domain) return r.text @@ -184,6 +193,7 @@ def update_avatar(avatar,domain): "record": record_id } r = requests.post(url, headers=headers, json=data) + copy_to_alts(domain) return r.text def verify_ALIAS(domain): @@ -223,4 +233,53 @@ def verify_ALIAS(domain): "content": TLSA, } r = requests.post(url, headers=headers, json=data) - return r.text \ No newline at end of file + copy_to_alts(domain) + return r.text + +def copy_to_alts(domain): + # Get DNS from domain and copy to each alt + data = { + "action": "getRecords", + "zone": zone, + "name": domain+"."+city_domain, + "type": "", + "content": "" + } + url = "https://reg.woodburn.au/api" + headers = { + 'Authorization': 'Bearer '+REG_KEY, + 'Content-Type': 'application/json' + } + r = requests.post(url, headers=headers, json=data) + r = r.json() + if 'data' not in r: + return + + records = r['data'] + + for alt_domain in alt_domains: + # Get the zone for the alt + alt_zone = "" + data = { + "action": "getZones" + } + r = requests.post(url, headers=headers, json=data) + r = r.json() + for tmpzone in r['data']: + if tmpzone['name'] == alt_domain: + alt_zone = tmpzone['id'] + print(alt_zone) + if alt_zone == "": + continue + # Add each record to each alt + for record in records: + data = { + "action": "addRecord", + "zone": alt_zone, + "type": record['type'], + "name": record['name'].replace(domain,alt_domain), + "content": record['content'], + } + print(data) + r = requests.post(url, headers=headers, json=data) + print(r.text)