From 1d4dfb594bf80892897aeafde4c0f4130dbe87ab Mon Sep 17 00:00:00 2001 From: Snarf Date: Sat, 7 Nov 2026 18:21:46 -0500 Subject: [PATCH] feat(dns): point snarfhome.snarfnet.net to 14.4.4.20 and remove Nabu Casa redirection --- scripts/fix_snarfhome_redirection.py | 68 ++++++++++++++++++++++++++++ scripts/get_technitium_snarfhome.py | 22 +++++++++ 2 files changed, 90 insertions(+) create mode 100644 scripts/fix_snarfhome_redirection.py create mode 100644 scripts/get_technitium_snarfhome.py diff --git a/scripts/fix_snarfhome_redirection.py b/scripts/fix_snarfhome_redirection.py new file mode 100644 index 0000000..fbc77ac --- /dev/null +++ b/scripts/fix_snarfhome_redirection.py @@ -0,0 +1,68 @@ +import urllib.request +import urllib.parse +import ssl +import json +import paramiko + +ctx = ssl.create_default_context() +ctx.check_hostname = False +ctx.verify_mode = ssl.CERT_NONE + +# 1. Add DNS A records for snarfhome.snarfnet.net -> 14.4.4.20 on Technitium DNS +for dns_host in ["dns1.snarfnet.net", "dns2.snarfnet.net"]: + try: + login_url = f"https://{dns_host}/api/user/login?user=admin&pass=snarfnetadmin&includeInfo=true" + with urllib.request.urlopen(urllib.request.Request(login_url), context=ctx, timeout=8) as resp: + token = json.loads(resp.read().decode())['token'] + + for name in ["snarfhome", "homeassistant"]: + params = { + "token": token, + "domain": f"{name}.snarfnet.net", + "zone": "snarfnet.net", + "type": "A", + "ipAddress": "14.4.4.20", + "ptr": "true", + "overwrite": "true", + "ttl": 3600 + } + add_url = f"https://{dns_host}/api/zones/records/add?{urllib.parse.urlencode(params)}" + with urllib.request.urlopen(urllib.request.Request(add_url), context=ctx, timeout=8) as resp: + result = json.loads(resp.read().decode()) + print(f"[{dns_host}] Added {name}.snarfnet.net -> 14.4.4.20: {result.get('status')}") + except Exception as e: + print(f"[{dns_host}] Error: {e}") + +# 2. Disable Redirection Host 1 in NPM DB and remove 1.conf +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +client.connect("140.44.4.71", username="root", key_filename=r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet", timeout=10) + +npm_cleanup = """python3 - << 'EOF' +import sqlite3, os +db = '/var/lib/docker/volumes/nginx-proxy-manager_nginx-data/_data/database.sqlite' +conn = sqlite3.connect(db) +conn.execute("UPDATE redirection_host SET enabled = 0, is_deleted = 1 WHERE id = 1") +conn.commit() +print("Updated database: redirection_host id 1 disabled and marked deleted") + +conf_file = '/var/lib/docker/volumes/nginx-proxy-manager_nginx-data/_data/nginx/redirection_host/1.conf' +if os.path.exists(conf_file): + os.remove(conf_file) + print("Removed 1.conf") +EOF +""" +stdin, stdout, stderr = client.exec_command(npm_cleanup) +print(stdout.read().decode()) +print(stderr.read().decode()) + +# 3. Reload nginx on both Swarm NPM nodes +client.exec_command("for id in $(docker ps -q -f name=nginx-proxy-manager_app); do docker exec $id nginx -s reload; done") +client.close() + +client2 = paramiko.SSHClient() +client2.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +client2.connect("140.44.4.72", username="root", key_filename=r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet", timeout=10) +client2.exec_command("for id in $(docker ps -q -f name=nginx-proxy-manager_app); do docker exec $id nginx -s reload; done") +client2.close() +print("Reloaded Nginx across NPM swarm replicas") diff --git a/scripts/get_technitium_snarfhome.py b/scripts/get_technitium_snarfhome.py new file mode 100644 index 0000000..10a1632 --- /dev/null +++ b/scripts/get_technitium_snarfhome.py @@ -0,0 +1,22 @@ +import paramiko +import json + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +client.connect("140.44.4.11", username="root", key_filename=r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet", timeout=10) + +cmd = """python3 -c ' +import urllib.request, json +login_data = json.loads(urllib.request.urlopen("http://10.43.117.221:5380/api/user/login?user=admin&pass=snarfnetadmin").read().decode()) +token = login_data["token"] +rec_url = f"http://10.43.117.221:5380/api/zones/records/get?token={token}&domain=snarfnet.net&zone=snarfnet.net&listZone=true" +records = json.loads(urllib.request.urlopen(rec_url).read().decode()) +for r in records.get("response", {}).get("records", []): + if "home" in r.get("name", "") or "snarf" in r.get("name", ""): + print(r) +'""" + +stdin, stdout, stderr = client.exec_command(cmd) +print(stdout.read().decode()) +print(stderr.read().decode()) +client.close()