Files
SnarfCode/scripts/check_pihole_pw.py

31 lines
1.2 KiB
Python

import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
key_path = r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet'
def check_cluster(ip, name):
print(f"\n--- Checking Pi-hole 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)
# Check Pi-hole pod name
stdin, stdout, stderr = ssh.exec_command("k3s kubectl get pods -n dns -l app=pihole -o jsonpath='{.items[0].metadata.name}'")
pod_name = stdout.read().decode().strip()
print(f"Pod name: {pod_name}")
# Check password in setupVars or FTL
stdin, stdout, stderr = ssh.exec_command(f"k3s kubectl exec -n dns {pod_name} -- grep -i pwhash /etc/pihole/pihole-FTL.conf /etc/pihole/setupVars.conf")
print("Password hash check:\n", stdout.read().decode())
# Test curl to localhost:80/admin/
stdin, stdout, stderr = ssh.exec_command(f"k3s kubectl exec -n dns {pod_name} -- curl -s -I http://localhost/admin/")
print("Local admin response:\n", stdout.read().decode())
ssh.close()
check_cluster('140.44.4.11', 'Aerodrome')
check_cluster('140.44.4.41', 'Spaceport')