feat: add diagnostic and management scripts for DNS, NPM, and cluster infrastructure
This commit is contained in:
73
scripts/fix_technitium_web_ips.py
Normal file
73
scripts/fix_technitium_web_ips.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import ssl
|
||||
import json
|
||||
import http.client
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
|
||||
def do_req(ip, host_header, path):
|
||||
conn = http.client.HTTPSConnection(ip, 443, context=ctx, timeout=8)
|
||||
conn.request("GET", path, headers={"Host": host_header})
|
||||
resp = conn.getresponse()
|
||||
data = resp.read().decode('utf-8')
|
||||
conn.close()
|
||||
return json.loads(data)
|
||||
|
||||
def get_token(ip, host_header):
|
||||
path = "/api/user/login?user=admin&pass=snarfnetadmin&includeInfo=true"
|
||||
data = do_req(ip, host_header, path)
|
||||
return data['token']
|
||||
|
||||
def update_server(ip, host_header):
|
||||
print(f"\n=======================================================")
|
||||
print(f"Connecting to {host_header} via {ip}...")
|
||||
token = get_token(ip, host_header)
|
||||
print(f"Token acquired for {host_header}")
|
||||
|
||||
# Records to fix
|
||||
records = [
|
||||
("pihole1", "140.44.4.70"),
|
||||
("pihole2", "140.44.4.70"),
|
||||
("dns1", "140.44.4.70"),
|
||||
("dns2", "140.44.4.70"),
|
||||
("ns1", "140.44.4.36"),
|
||||
("ns2", "140.44.4.65"),
|
||||
]
|
||||
|
||||
for dom, target_ip in records:
|
||||
full_dom = f"{dom}.snarfnet.net"
|
||||
# 1. Delete old record
|
||||
del_p = urllib.parse.urlencode({"token": token, "domain": full_dom, "zone": "snarfnet.net", "type": "A"})
|
||||
try:
|
||||
do_req(ip, host_header, f"/api/zones/records/delete?{del_p}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. Add correct record
|
||||
use_ptr = "true" if dom.startswith("ns") else "false"
|
||||
add_p = urllib.parse.urlencode({
|
||||
"token": token,
|
||||
"domain": full_dom,
|
||||
"zone": "snarfnet.net",
|
||||
"type": "A",
|
||||
"ipAddress": target_ip,
|
||||
"ptr": use_ptr,
|
||||
"overwrite": "true",
|
||||
"ttl": 60
|
||||
})
|
||||
res = do_req(ip, host_header, f"/api/zones/records/add?{add_p}")
|
||||
print(f" ✓ {full_dom} -> {target_ip}: {res.get('status')}")
|
||||
|
||||
# Update Aerodrome Technitium via Traefik 140.44.4.34
|
||||
update_server("140.44.4.34", "dns1.snarfnet.net")
|
||||
|
||||
# Update Spaceport Technitium via Traefik 140.44.4.62
|
||||
update_server("140.44.4.62", "dns2.snarfnet.net")
|
||||
|
||||
print("\nSuccessfully updated DNS records on both Technitium servers!")
|
||||
Reference in New Issue
Block a user