feat: Add initial connect

feat: Add better description

fix: Remove unused test
This commit is contained in:
Nathan Woodburn 2025-03-07 14:47:10 +11:00
parent 9c280ee03d
commit 90ba69491e
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -7,7 +7,7 @@ import os
# Plugin Data
info = {
"name": "HNS Links",
"description": "This is a plugin to quickly setup a HNS Links site<br>First you need to setup the varo instance and api key<br>Then add the domain to varo, then add it to hns-links",
"description": "This is a plugin to quickly setup a HNS Links site<br>First you need to setup the varo instance and api key<br>2. Add domain to varo<br> 3. Add it to hns-links<br>4. Wait a few minutes and add it to HNS Links to ensure the TLSA is correct<br>5. Wait for the DNS update to propogate (up to 7 hrs)",
"version": "1.0",
"author": "Nathan.Woodburn/"
}
@ -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 for HNS Links to fully initialize the site."}