feat(dns): point snarfhome.snarfnet.net to 14.4.4.20 and remove Nabu Casa redirection

This commit is contained in:
2026-11-07 18:21:46 -05:00
parent 42bfb43b65
commit 1d4dfb594b
2 changed files with 90 additions and 0 deletions

View File

@@ -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")

View File

@@ -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()