Files
SnarfCode/scripts/check_pihole_toml.py

26 lines
1.2 KiB
Python

import paramiko
def check_pihole_toml(host, name):
print(f"=== {name} ({host}) ===")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
stdin, stdout, stderr = ssh.exec_command('k3s kubectl exec -n dns deployment/pihole -- grep -A 10 "\[webserver" /etc/pihole/pihole.toml 2>/dev/null || true')
print("webserver section in pihole.toml:")
print(stdout.read().decode('utf-8', errors='ignore'))
stdin, stdout, stderr = ssh.exec_command('k3s kubectl exec -n dns deployment/pihole -- grep -rn "pwhash" /etc/pihole/ 2>/dev/null || true')
print("pwhash matches:")
print(stdout.read().decode('utf-8', errors='ignore'))
# Let's test logging into pihole API with curl using password "snarfnetadmin"
stdin, stdout, stderr = ssh.exec_command('k3s kubectl exec -n dns deployment/pihole -- curl -s -X POST "http://localhost/api/auth" -H "Content-Type: application/json" -d \'{"password":"snarfnetadmin"}\'')
print("API auth test:")
print(stdout.read().decode('utf-8', errors='ignore'))
ssh.close()
check_pihole_toml('140.44.4.11', 'Aerodrome')
check_pihole_toml('140.44.4.41', 'Spaceport')