feat: add helper scripts for infrastructure management and troubleshooting

This commit is contained in:
2026-11-06 15:24:05 -05:00
parent aea8608f3d
commit 1965d37687
48 changed files with 1399 additions and 39 deletions

View File

@@ -1,31 +1,24 @@
import urllib.request
import urllib.parse
import http.cookiejar
import paramiko
import sys
def test_login(ip):
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
# 1. Fetch login page to get CSRF/session
login_url = f"http://{ip}/admin/login"
req = urllib.request.Request(login_url, headers={"User-Agent": "Mozilla/5.0"})
with opener.open(req) as resp:
html = resp.read().decode('utf-8')
# 2. Submit password
post_data = urllib.parse.urlencode({"pw": "snarfnetadmin", "login": "Log in (uses cookie)"}).encode('ascii')
req_post = urllib.request.Request(f"http://{ip}/admin/login", data=post_data, headers={"User-Agent": "Mozilla/5.0", "Referer": login_url})
try:
with opener.open(req_post) as resp:
content = resp.read().decode('utf-8')
if "Wrong password" in content:
print(f"Server {ip}: WRONG PASSWORD!")
else:
print(f"Server {ip}: LOGIN SUCCESSFUL! Redirected to {resp.geturl()}")
except Exception as e:
print(f"Server {ip}: Exception during login: {e}")
sys.stdout.reconfigure(encoding='utf-8')
key_path = r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet'
test_login("140.44.4.36")
test_login("140.44.4.65")
def test_login(ip, name):
print(f"\n--- Testing Pi-hole auth on {name} ({ip}) ---")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username='root', key_filename=key_path, timeout=10)
stdin, stdout, stderr = ssh.exec_command("k3s kubectl get pods -n dns -l app=pihole -o jsonpath='{.items[0].metadata.name}'")
pod = stdout.read().decode().strip()
# Test login via curl to Pi-hole API
cmd = f'k3s kubectl exec -n dns {pod} -- curl -s -X POST -H "Content-Type: application/json" -d \'{{"password":"snarfnetadmin"}}\' http://localhost/api/auth'
stdin, stdout, stderr = ssh.exec_command(cmd)
print("API Auth response:", stdout.read().decode())
ssh.close()
test_login('140.44.4.11', 'Aerodrome')
test_login('140.44.4.41', 'Spaceport')