110 lines
3.5 KiB
Python
110 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Emergency DNS fix: revert GoDaddy NS + point records at tunnel."""
|
|
import json
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
import paramiko
|
|
|
|
GODADDY_KEY = "2wYVpc3VT4_Gi9AsNqzJ6BtSfNz6nLDuo"
|
|
GODADDY_SECRET = "NvC3qexGAU7Rd5QExUTH6z"
|
|
DOMAIN = "exposedgays.com"
|
|
TUNNEL_CNAME = "03079a26-f14c-4622-b463-ba54a24f7472.cfargotunnel.com"
|
|
GD_NS = ["ns71.domaincontrol.com", "ns72.domaincontrol.com"]
|
|
GD = "https://api.godaddy.com/v1"
|
|
PASS = "Bbt9115xty9176!"
|
|
|
|
|
|
def gd(path, method="GET", body=None):
|
|
req = urllib.request.Request(
|
|
GD + path,
|
|
data=json.dumps(body).encode() if body is not None else None,
|
|
method=method,
|
|
headers={
|
|
"Authorization": f"sso-key {GODADDY_KEY}:{GODADDY_SECRET}",
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
},
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=45) as r:
|
|
raw = r.read().decode()
|
|
return r.status, json.loads(raw) if raw else {}
|
|
except urllib.error.HTTPError as e:
|
|
raw = e.read().decode()
|
|
try:
|
|
return e.code, json.loads(raw)
|
|
except Exception:
|
|
return e.code, {"raw": raw[:800]}
|
|
|
|
|
|
def main():
|
|
code, before = gd(f"/domains/{DOMAIN}")
|
|
print("Before NS:", before.get("nameServers") if code == 200 else before)
|
|
|
|
print("\n=== Revert registrar NS to GoDaddy ===")
|
|
code, res = gd(f"/domains/{DOMAIN}", "PATCH", {"nameServers": GD_NS})
|
|
print(f"PATCH NS HTTP {code}: {res}")
|
|
|
|
code, mid = gd(f"/domains/{DOMAIN}")
|
|
print("After NS revert:", mid.get("nameServers") if code == 200 else mid)
|
|
|
|
print("\n=== Set tunnel CNAME for www ===")
|
|
code, res = gd(
|
|
f"/domains/{DOMAIN}/records/CNAME/www",
|
|
"PUT",
|
|
[{"data": TUNNEL_CNAME, "ttl": 600}],
|
|
)
|
|
print(f"PUT www CNAME HTTP {code}: {res}")
|
|
|
|
print("\n=== Try apex CNAME (GoDaddy may reject) ===")
|
|
code, res = gd(
|
|
f"/domains/{DOMAIN}/records/CNAME/@",
|
|
"PUT",
|
|
[{"data": TUNNEL_CNAME, "ttl": 600}],
|
|
)
|
|
print(f"PUT @ CNAME HTTP {code}: {res}")
|
|
|
|
if code not in (200, 204):
|
|
print("\n=== Apex CNAME failed — enable domain forward @ -> www ===")
|
|
code, res = gd(
|
|
f"/domains/{DOMAIN}/forwarding",
|
|
"PATCH",
|
|
{
|
|
"forwarding": {
|
|
"type": "PERMANENT",
|
|
"url": f"https://www.{DOMAIN}",
|
|
"mask": False,
|
|
}
|
|
},
|
|
)
|
|
print(f"PATCH forwarding HTTP {code}: {res}")
|
|
|
|
print("\n=== Current GoDaddy records ===")
|
|
code, records = gd(f"/domains/{DOMAIN}/records")
|
|
for r in records if isinstance(records, list) else []:
|
|
print(f" {r['type']:5} {r['name']:20} -> {r.get('data')}")
|
|
|
|
print("\nWaiting 20s for propagation...")
|
|
time.sleep(20)
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("10.10.0.10", username="localadministrator", password=PASS, timeout=30)
|
|
for cmd in [
|
|
f"dig @1.1.1.1 {DOMAIN} NS +short",
|
|
f"dig @1.1.1.1 {DOMAIN} A +short",
|
|
f"dig @1.1.1.1 www.{DOMAIN} CNAME +short",
|
|
f"curl -sSI https://www.{DOMAIN}/ | head -12",
|
|
f"curl -sSL https://www.{DOMAIN}/ | head -c 300",
|
|
f"curl -sSI https://{DOMAIN}/ | head -12",
|
|
]:
|
|
print(f"\n$ {cmd}")
|
|
_, o, e = c.exec_command(cmd, timeout=30)
|
|
o.channel.recv_exit_status()
|
|
print((o.read() + e.read()).decode(errors="replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |