feat: Add initial connect
This commit is contained in:
parent
9c280ee03d
commit
2db689fc9e
97
hnslinks.py
97
hnslinks.py
@ -192,6 +192,101 @@ def hnslinks(params, authentication):
|
||||
response = account.signMessage(authentication,domain,"hns-links")
|
||||
if "error" in response and response["error"]:
|
||||
return {"status": f"Error: {response['error']}"}
|
||||
return {"status": response}
|
||||
|
||||
if 'result' not in response:
|
||||
return {"status": "Error signing message"}
|
||||
signature = response["result"]
|
||||
|
||||
# Send request to hns-links
|
||||
data = {
|
||||
"domain": domain,
|
||||
"signature": signature,
|
||||
"data":{
|
||||
"title": domain,
|
||||
"description": "Connected via FireWallet",
|
||||
"address": [
|
||||
{
|
||||
"token": "hns",
|
||||
"address": address
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
response = requests.post("https://links.hns.au/api/v1/site", json=data)
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to hns-links"}
|
||||
response = response.json()
|
||||
if "error" in response and response["error"]:
|
||||
return {"status": f"Error: {response['error']}"}
|
||||
|
||||
ip = response["IP"]
|
||||
tlsa = response["TLSA"]
|
||||
|
||||
# Get zones from varo
|
||||
with open("user_data/varo.json", "r") as f:
|
||||
auth = json.load(f)
|
||||
if not auth:
|
||||
return {"status": "Missing Varo API or instance"}
|
||||
if 'api' not in auth or 'instance' not in auth:
|
||||
return {"status": "Missing Varo API or instance"}
|
||||
api = auth["api"]
|
||||
instance = auth["instance"]
|
||||
|
||||
response = requests.post(f"https://{instance}/api", json={"action":"getZones"}, headers={"Authorization": f"Bearer {api}"})
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if response.json()["success"] != True:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
zones = response.json()["data"]
|
||||
for zone in zones:
|
||||
if zone["name"] == domain:
|
||||
zoneID = zone["id"]
|
||||
break
|
||||
if zoneID == "":
|
||||
return {"status": "Error finding zone in Varo"}
|
||||
|
||||
response = requests.post(f"https://{instance}/api", json={"action":"getRecords","zone":zoneID},
|
||||
headers={"Authorization": f"Bearer {api}"})
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if response.json()["success"] != True:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if 'data' in response.json():
|
||||
records = response.json()["data"]
|
||||
else:
|
||||
records = []
|
||||
for record in records:
|
||||
if record["type"] == "A" and record["name"] == domain:
|
||||
response = requests.post(f"https://{instance}/api", json={"action":"deleteRecord","zone":zoneID,"record":record["uuid"]},
|
||||
headers={"Authorization": f"Bearer {api}"})
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if response.json()["success"] != True:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if record["type"] == "TLSA" and record["name"] == f"_443._tcp.{domain}":
|
||||
response = requests.post(f"https://{instance}/api", json={"action":"deleteRecord","zone":zoneID,"record":record["uuid"]},
|
||||
headers={"Authorization": f"Bearer {api}"})
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if response.json()["success"] != True:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
|
||||
response = requests.post(f"https://{instance}/api", json={"action":"addRecord","zone":zoneID,"name":"@","type":"A","content":ip},
|
||||
headers={"Authorization": f"Bearer {api}"})
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if response.json()["success"] != True:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
|
||||
if tlsa != "":
|
||||
response = requests.post(f"https://{instance}/api", json={"action":"addRecord","zone":zoneID,"name":f"_443._tcp","type":"TLSA","content":tlsa},
|
||||
headers={"Authorization": f"Bearer {api}"})
|
||||
if response.status_code != 200:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
if response.json()["success"] != True:
|
||||
return {"status": "Error connecting to Varo"}
|
||||
|
||||
|
||||
return {"status": "YAY!!! All done! Just wait a few minutes and proceed to the finalize TLSA!"}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user