2023-11-16 14:12:24 +11:00
|
|
|
import requests
|
|
|
|
import os
|
|
|
|
import dotenv
|
|
|
|
|
|
|
|
dotenv.load_dotenv()
|
|
|
|
zone = ""
|
2023-11-16 14:55:38 +11:00
|
|
|
TLSA = ""
|
2023-11-16 14:12:24 +11:00
|
|
|
varo_api = os.getenv('VARO')
|
|
|
|
city_domain = os.getenv('CITY_DOMAIN')
|
2023-11-16 14:55:38 +11:00
|
|
|
if city_domain == "localhost":
|
|
|
|
city_domain = "exampledomainnathan1"
|
2023-11-16 14:12:24 +11:00
|
|
|
|
2023-11-16 14:55:38 +11:00
|
|
|
server_alias = os.getenv('CITY_ALIAS')
|
2023-11-16 14:12:24 +11:00
|
|
|
|
|
|
|
def update_auth(auth,domain):
|
2023-11-16 14:55:38 +11:00
|
|
|
verify_ALIAS(domain)
|
2023-11-16 14:12:24 +11:00
|
|
|
record = get_auth_id(domain)
|
|
|
|
if record == "":
|
|
|
|
data = {
|
|
|
|
"action": "addRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"type": "TXT",
|
|
|
|
"name": domain,
|
|
|
|
"content": auth,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
data = {
|
|
|
|
"action": "updateRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"record": record,
|
|
|
|
"column": "content",
|
|
|
|
"value": auth
|
|
|
|
}
|
|
|
|
if auth == "" and record == "":
|
|
|
|
return
|
|
|
|
if auth == "" and record != "":
|
|
|
|
data = {
|
|
|
|
"action": "deleteRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"record": record
|
|
|
|
}
|
|
|
|
# Update TXT record
|
|
|
|
url = "https://reg.woodburn.au/api"
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Bearer '+varo_api,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
r = requests.put(url, headers=headers, json=data)
|
|
|
|
return r.text
|
|
|
|
|
|
|
|
|
|
|
|
def get_auth_id(domain):
|
|
|
|
if zone == "":
|
|
|
|
get_zone()
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"action": "getRecords",
|
|
|
|
"zone": zone,
|
2023-11-16 14:55:38 +11:00
|
|
|
"name": domain + "." + city_domain,
|
2023-11-16 14:12:24 +11:00
|
|
|
"type": "TXT",
|
|
|
|
"content": ""
|
|
|
|
}
|
|
|
|
url = "https://reg.woodburn.au/api"
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Bearer '+varo_api,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
r = r.json()
|
2023-11-16 15:11:54 +11:00
|
|
|
if 'data' not in r:
|
|
|
|
return ""
|
2023-11-16 14:12:24 +11:00
|
|
|
for record in r['data']:
|
2023-11-16 15:11:54 +11:00
|
|
|
if 'profile avatar=' not in record['content']:
|
|
|
|
return record['uuid']
|
2023-11-16 14:12:24 +11:00
|
|
|
return ""
|
|
|
|
|
|
|
|
def get_auth(domain):
|
|
|
|
if zone == "":
|
|
|
|
get_zone()
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"action": "getRecords",
|
|
|
|
"zone": zone,
|
2023-11-16 14:55:38 +11:00
|
|
|
"name": domain + "." + city_domain,
|
2023-11-16 14:12:24 +11:00
|
|
|
"type": "TXT",
|
|
|
|
"content": ""
|
|
|
|
}
|
|
|
|
url = "https://reg.woodburn.au/api"
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Bearer '+varo_api,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
r = r.json()
|
2023-11-16 15:11:54 +11:00
|
|
|
if 'data' not in r:
|
|
|
|
return ""
|
|
|
|
|
2023-11-16 14:12:24 +11:00
|
|
|
for record in r['data']:
|
2023-11-16 15:11:54 +11:00
|
|
|
if 'profile avatar=' not in record['content']:
|
|
|
|
return record['content']
|
2023-11-16 14:12:24 +11:00
|
|
|
return ""
|
|
|
|
|
|
|
|
def get_zone():
|
|
|
|
global zone
|
2023-11-16 14:55:38 +11:00
|
|
|
global TLSA
|
2023-11-16 14:12:24 +11:00
|
|
|
url = "https://reg.woodburn.au/api"
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Bearer '+varo_api,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
data = {
|
|
|
|
"action": "getZones"
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
r = r.json()
|
|
|
|
for domain in r['data']:
|
|
|
|
if domain['name'] == city_domain:
|
|
|
|
zone = domain['id']
|
2023-11-16 14:55:38 +11:00
|
|
|
|
|
|
|
data = {
|
|
|
|
"action": "getRecords",
|
|
|
|
"zone": zone,
|
|
|
|
"name": "*."+city_domain,
|
|
|
|
"type": "TLSA",
|
|
|
|
"content": ""
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
print(r.text)
|
|
|
|
r = r.json()
|
|
|
|
for record in r['data']:
|
|
|
|
TLSA = record['content']
|
|
|
|
return zone
|
|
|
|
|
2023-11-16 14:12:24 +11:00
|
|
|
|
|
|
|
def update_avatar(avatar,domain):
|
2023-11-16 14:55:38 +11:00
|
|
|
verify_ALIAS(domain)
|
2023-11-16 14:12:24 +11:00
|
|
|
if zone == "":
|
|
|
|
get_zone()
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"action": "getRecords",
|
|
|
|
"zone": zone,
|
2023-11-16 14:55:38 +11:00
|
|
|
"name": domain + "." + city_domain,
|
2023-11-16 14:12:24 +11:00
|
|
|
"type": "TXT",
|
|
|
|
"content": ""
|
|
|
|
}
|
|
|
|
url = "https://reg.woodburn.au/api"
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Bearer '+varo_api,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
r = r.json()
|
|
|
|
record_id = ""
|
2023-11-16 15:11:54 +11:00
|
|
|
if 'data' in r:
|
|
|
|
for record in r['data']:
|
|
|
|
if record['name'] == domain + "." + city_domain:
|
|
|
|
if 'profile avatar=' in record['content']:
|
|
|
|
if record['content'].split("profile avatar=")[1] == avatar:
|
|
|
|
print("Avatar already set", flush=True)
|
|
|
|
return "Avatar already set"
|
|
|
|
record_id = record['uuid']
|
2023-11-16 14:12:24 +11:00
|
|
|
|
|
|
|
if record_id == "":
|
|
|
|
data = {
|
|
|
|
"action": "addRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"type": "TXT",
|
|
|
|
"name": domain,
|
|
|
|
"content": "profile avatar=" + avatar,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
data = {
|
|
|
|
"action": "updateRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"record": record,
|
|
|
|
"column": "content",
|
|
|
|
"value": "profile avatar=" + avatar
|
|
|
|
}
|
|
|
|
if avatar == "" and record_id == "":
|
|
|
|
return
|
|
|
|
if avatar == "" and record_id != "":
|
|
|
|
data = {
|
|
|
|
"action": "deleteRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"record": record_id
|
|
|
|
}
|
|
|
|
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
return r.text
|
2023-11-16 14:55:38 +11:00
|
|
|
|
|
|
|
def verify_ALIAS(domain):
|
|
|
|
if zone == "":
|
|
|
|
get_zone()
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"action": "getRecords",
|
|
|
|
"zone": zone,
|
|
|
|
"name": domain+"."+city_domain,
|
|
|
|
"type": "ALIAS",
|
|
|
|
"content": ""
|
|
|
|
}
|
|
|
|
url = "https://reg.woodburn.au/api"
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'Bearer '+varo_api,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
r = r.json()
|
|
|
|
if 'data' in r:
|
|
|
|
return
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"action": "addRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"type": "ALIAS",
|
|
|
|
"name": domain,
|
|
|
|
"content": server_alias,
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
data = {
|
|
|
|
"action": "addRecord",
|
|
|
|
"zone": zone,
|
|
|
|
"type": "TLSA",
|
|
|
|
"name": "_443._tcp."+domain+"."+city_domain,
|
|
|
|
"content": TLSA,
|
|
|
|
}
|
|
|
|
r = requests.post(url, headers=headers, json=data)
|
|
|
|
print(r.text)
|
|
|
|
return r.text
|