#!/bin/sh
# Collect diagnostic logs from the router and save to ./router-logs.txt
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 22 root@192.168.1.1 "
echo '=== SYSLOG ==='
logread
echo '=== DMESG ==='
dmesg
echo '=== PROCESSES ==='
ps
echo '=== NETWORK ==='
netstat -tulnp 2>/dev/null
echo '=== UCI ==='
uci show
echo '=== NFTABLES ==='
nft list ruleset
echo '=== DNSMASQ CONFIG (runtime) ==='
cat /var/etc/dnsmasq.conf 2>/dev/null
echo '=== DNSMASQ CONFIG (main) ==='
cat /etc/dnsmasq.conf 2>/dev/null
echo '=== DNSMASQ DROP-INS (/etc/dnsmasq.d/) ==='
for f in /etc/dnsmasq.d/*; do echo \"--- \$f ---\"; cat \"\$f\" 2>/dev/null; done
echo '=== DNSMASQ DROP-INS (/tmp/dnsmasq.d/) ==='
for f in /tmp/dnsmasq.d/*; do echo \"--- \$f ---\"; cat \"\$f\" 2>/dev/null; done
echo '=== DNSMASQ CACHE STATS ==='
kill -USR1 \$(pidof dnsmasq) 2>/dev/null && sleep 1 && logread | grep -E 'cache|DNSMASQ' | tail -20
echo '=== DNSMASQ CONFIG TEST ==='
dnsmasq --test 2>&1
echo '=== DNSMASQ SYSLOG ==='
logread | grep dnsmasq
echo '=== FAMILY-SAFE DNS GUARD LOG (/tmp/family-safe-dns-guard.log) ==='
cat /tmp/family-safe-dns-guard.log 2>/dev/null
cat /tmp/family-safe-dns-guard.log.1 2>/dev/null
echo '=== FAMILY-SAFE DNS HEALTH LOG (/tmp/family-safe-dns-health.log) ==='
cat /tmp/family-safe-dns-health.log 2>/dev/null
cat /tmp/family-safe-dns-health.log.1 2>/dev/null
echo '=== FAMILY-SAFE DNS HEALTH STATUS (heartbeat) ==='
cat /tmp/family-safe-dns-health.status 2>/dev/null
" > ./router-logs.txt
