|
@ -32,7 +32,7 @@ async def create_subdomain( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def set_subdomain_paid(payment_hash: str) -> Subdomains: |
|
|
async def set_subdomain_paid(payment_hash: str) -> Subdomains: |
|
|
row = await db.fetchone("SELECT * FROM subdomain WHERE id = ?", (payment_hash,)) |
|
|
row = await db.fetchone("SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?", (payment_hash,)) |
|
|
if row[8] == False: |
|
|
if row[8] == False: |
|
|
await db.execute( |
|
|
await db.execute( |
|
|
""" |
|
|
""" |
|
@ -57,28 +57,57 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains: |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
subdomain = await get_subdomain(payment_hash) |
|
|
subdomain = await get_subdomain(payment_hash) |
|
|
|
|
|
|
|
|
|
|
|
### SEND REQUEST TO CLOUDFLARE |
|
|
|
|
|
url="https://api.cloudflare.com/client/v4/zones/" + domaindata.cf_zone_id + "/dns_records" |
|
|
|
|
|
header= {'Authorization': 'Bearer ' + domaindata.cf_token, 'Content-Type': 'application/json'} |
|
|
|
|
|
aRecord=subdomain.subdomain + '.' + subdomain.domain_name |
|
|
|
|
|
cf_response = "" |
|
|
|
|
|
async with httpx.AsyncClient() as client: |
|
|
|
|
|
try: |
|
|
|
|
|
r = await client.post( |
|
|
|
|
|
url, |
|
|
|
|
|
headers=header, |
|
|
|
|
|
json={ |
|
|
|
|
|
"type": "A", |
|
|
|
|
|
"name": aRecord, |
|
|
|
|
|
"content": subdomain.ip, |
|
|
|
|
|
"ttl": 0, |
|
|
|
|
|
"proxed": False |
|
|
|
|
|
}, |
|
|
|
|
|
timeout=40, |
|
|
|
|
|
) |
|
|
|
|
|
cf_response = r.text |
|
|
|
|
|
except AssertionError: |
|
|
|
|
|
cf_response = "Error occured" |
|
|
|
|
|
|
|
|
|
|
|
### Use webhook to notify about cloudflare registration |
|
|
if domaindata.webhook: |
|
|
if domaindata.webhook: |
|
|
async with httpx.AsyncClient() as client: |
|
|
async with httpx.AsyncClient() as client: |
|
|
try: |
|
|
try: |
|
|
r = await client.post( |
|
|
r = await client.post( |
|
|
domaindata.webhook, |
|
|
domaindata.webhook, |
|
|
json={ |
|
|
json={ |
|
|
"domain": subdomain.domain, |
|
|
"domain": subdomain.domain_name, |
|
|
"subdomain": subdomain.subdomain, |
|
|
"subdomain": subdomain.subdomain, |
|
|
"email": subdomain.email, |
|
|
"email": subdomain.email, |
|
|
"ip": subdomain.ip |
|
|
"ip": subdomain.ip, |
|
|
|
|
|
"cost:": str(subdomain.sats) + " sats", |
|
|
|
|
|
"duration": str(subdomain.duration) + " days", |
|
|
|
|
|
"cf_response": cf_response |
|
|
}, |
|
|
}, |
|
|
timeout=40, |
|
|
timeout=40, |
|
|
) |
|
|
) |
|
|
except AssertionError: |
|
|
except AssertionError: |
|
|
webhook = None |
|
|
webhook = None |
|
|
return subdomain |
|
|
|
|
|
subdomain = await get_subdomain(payment_hash) |
|
|
subdomain = await get_subdomain(payment_hash) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_subdomain(subdomain_id: str) -> Optional[Subdomains]: |
|
|
async def get_subdomain(subdomain_id: str) -> Optional[Subdomains]: |
|
|
row = await db.fetchone("SELECT * FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?", (subdomain_id,)) |
|
|
row = await db.fetchone("SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?", (subdomain_id,)) |
|
|
|
|
|
print(row) |
|
|
return Subdomains(**row) if row else None |
|
|
return Subdomains(**row) if row else None |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -99,14 +128,14 @@ async def delete_subdomain(subdomain_id: str) -> None: |
|
|
# Domains |
|
|
# Domains |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def create_domain(*, wallet: str, domain: str, cfToken: str, cfZoneId: str, webhook: Optional[str] = None, description: str, cost: int) -> Domains: |
|
|
async def create_domain(*, wallet: str, domain: str, cf_token: str, cf_zone_id: str, webhook: Optional[str] = None, description: str, cost: int) -> Domains: |
|
|
domain_id = urlsafe_short_hash() |
|
|
domain_id = urlsafe_short_hash() |
|
|
await db.execute( |
|
|
await db.execute( |
|
|
""" |
|
|
""" |
|
|
INSERT INTO domain (id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, amountmade) |
|
|
INSERT INTO domain (id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, amountmade) |
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
""", |
|
|
""", |
|
|
(domain_id, wallet, domain, webhook, cfToken, cfZoneId, description, cost, 0), |
|
|
(domain_id, wallet, domain, webhook, cf_token, cf_zone_id, description, cost, 0), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
domain = await get_domain(domain_id) |
|
|
domain = await get_domain(domain_id) |
|
|