feat: Add varo connections
This commit is contained in:
parent
e30aceb0a9
commit
41cbe258c0
91
hnslinks.py
91
hnslinks.py
@ -1,12 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
import account
|
import account
|
||||||
import requests
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
# Plugin Data
|
# Plugin Data
|
||||||
info = {
|
info = {
|
||||||
"name": "HNS Links",
|
"name": "HNS Links",
|
||||||
"description": "This is a plugin to quickly setup a HNS Links site",
|
"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",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"author": "Nathan.Woodburn/"
|
"author": "Nathan.Woodburn/"
|
||||||
}
|
}
|
||||||
@ -20,7 +21,7 @@ functions = {
|
|||||||
"description": "You need to connect to a varo instance to setup the dns for domains",
|
"description": "You need to connect to a varo instance to setup the dns for domains",
|
||||||
"params": {
|
"params": {
|
||||||
"instance": {
|
"instance": {
|
||||||
"name":"Varo Instance",
|
"name":"Varo Instance (eg. domains.hns.au)",
|
||||||
"type":"text"
|
"type":"text"
|
||||||
},
|
},
|
||||||
"key": {
|
"key": {
|
||||||
@ -36,10 +37,10 @@ functions = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dns":{
|
"addDomain":{
|
||||||
"name": "Set Onchain DNS for Domains",
|
"name": "Add domain to varo",
|
||||||
"type": "default",
|
"type": "default",
|
||||||
"description": "Set onchain DNS for domains before HNS Links can work",
|
"description": "Add a domain to Varo",
|
||||||
"params": {
|
"params": {
|
||||||
"domain": {
|
"domain": {
|
||||||
"name":"Domain",
|
"name":"Domain",
|
||||||
@ -47,11 +48,13 @@ functions = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"returns": {
|
"returns": {
|
||||||
"hash": {
|
"status":
|
||||||
"name": "Hash of the transaction",
|
{
|
||||||
"type": "tx"
|
"name": "Status of the function",
|
||||||
|
"type": "text"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +84,72 @@ def login(params, authentication):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dns(params,authentication):
|
def addDomain(params, authentication):
|
||||||
dns = params["dns"]
|
# Add a domain to Varo
|
||||||
return {"hash":"f921ffe1bb01884bf515a8079073ee9381cb93a56b486694eda2cce0719f27c0"}
|
domain = params["domain"]
|
||||||
|
|
||||||
|
if not os.path.exists("user_data/hnslinks.json"):
|
||||||
|
return {"status": "Missing Varo API or instance"}
|
||||||
|
|
||||||
|
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"]
|
||||||
|
|
||||||
|
headers = {"Authorization": f"Bearer {api}"}
|
||||||
|
data = {
|
||||||
|
"action": "getZones"
|
||||||
|
}
|
||||||
|
zones = requests.post(f"https://{instance}/api", json=data, headers=headers)
|
||||||
|
if zones.status_code != 200:
|
||||||
|
return {"status": "Error connecting to Varo"}
|
||||||
|
if zones.json()["success"] != True:
|
||||||
|
return {"status": "Error connecting to Varo"}
|
||||||
|
|
||||||
|
zones = zones.json()["data"]
|
||||||
|
for zone in zones:
|
||||||
|
if zone["name"] == domain:
|
||||||
|
return {"status": "Domain already exists"}
|
||||||
|
|
||||||
|
# Check domain is owned by user
|
||||||
|
wallet = authentication.split(":")[0]
|
||||||
|
owned = account.getDomains(wallet)
|
||||||
|
# Only keep owned domains ["name"]
|
||||||
|
ownedNames = [domain["name"] for domain in owned]
|
||||||
|
if domain not in ownedNames:
|
||||||
|
return {"status": "Domain not owned by user"}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"action": "createZone",
|
||||||
|
"domain": domain
|
||||||
|
}
|
||||||
|
response = requests.post(f"https://{instance}/api", json=data, headers=headers)
|
||||||
|
if response.status_code != 200:
|
||||||
|
return {"status": "Error connecting to Varo"}
|
||||||
|
if response.json()["success"] != True:
|
||||||
|
return {"status": "Error connecting to Varo"}
|
||||||
|
zoneID = response.json()["data"]["zone"]
|
||||||
|
data = {
|
||||||
|
"action": "showZone",
|
||||||
|
"zone": zoneID
|
||||||
|
}
|
||||||
|
response = requests.post(f"https://{instance}/api", json=data, headers=headers)
|
||||||
|
if response.status_code != 200:
|
||||||
|
return {"status": "Error connecting to Varo"}
|
||||||
|
if response.json()["success"] != True:
|
||||||
|
return {"status": "Error connecting to Varo"}
|
||||||
|
zone = response.json()["data"]
|
||||||
|
|
||||||
|
dns = []
|
||||||
|
for ns in zone['NS']:
|
||||||
|
dns.append({'type': 'NS', 'value': ns})
|
||||||
|
ds = zone['DS']
|
||||||
|
ds = ds.split(' ')
|
||||||
|
dns.append({'type': 'DS', 'keyTag': int(ds[0]), 'algorithm': int(ds[1]), 'digestType': int(ds[2]), 'digest': ds[3]})
|
||||||
|
dns = json.dumps(dns)
|
||||||
|
response = account.setDNS(authentication,domain,dns)
|
||||||
|
return {"status": "Success"}
|
Loading…
Reference in New Issue
Block a user