#!/bin/bash
export LC_ALL=C
line() { printf '\n----- %s -----\n' "$1"; }

line "HTTP/HTTPS LISTEN"
ss -tlnp 2>/dev/null | grep -E ':(80|443)\s' | sed 's/  */ /g' | cut -c1-110

line "VHOST MAP"
apachectl -S 2>/dev/null | head -20

line "esaricity.conf (key lines)"
grep -nE 'ServerName|ServerAlias|DocumentRoot|SSLCertificate|Redirect|ProxyPass' /etc/apache2/sites-enabled/esaricity.conf 2>/dev/null | head -20

line "LOCAL HTTP CHECK"
curl -s -o /dev/null -w 'http://localhost/ -> %{http_code} in %{time_total}s\n' --max-time 10 http://localhost/ 2>&1
curl -sk -o /dev/null -w 'https://localhost/ -> %{http_code} in %{time_total}s\n' --max-time 10 https://localhost/ 2>&1

line "TLS CERTS (certbot)"
certbot certificates 2>/dev/null | grep -E 'Certificate Name|Domains|Expiry' | head -12 || echo "(certbot not available)"

line "DOCKER"
docker ps --format '{{.Names}} | {{.Image}} | {{.Status}}' 2>/dev/null | head -15
printf 'containers running: %s\n' "$(docker ps -q 2>/dev/null | wc -l)"
docker system df 2>/dev/null | head -5

line "DISK CONSUMERS (/)"
du -xhd1 / 2>/dev/null | sort -rh | head -10

line "DISK CONSUMERS (/var)"
du -xhd1 /var 2>/dev/null | sort -rh | head -8

line "INODES"
df -i / | sed -n '1,2p'

line "FAIL2BAN / SSH HARDENING"
fail2ban-client status 2>&1 | head -5
grep -iE '^\s*(PermitRootLogin|PasswordAuthentication|PubkeyAuthentication|Port)' /etc/ssh/sshd_config 2>/dev/null
printf 'sshd effective: %s\n' "$(sshd -T 2>/dev/null | grep -E '^(permitrootlogin|passwordauthentication)' | tr '\n' ' ')"

line "UFW DETAIL"
ufw status verbose 2>/dev/null | head -10

line "TOP ATTACK SOURCES (auth.log)"
grep 'Failed password' /var/log/auth.log 2>/dev/null | grep -oE 'from [0-9.]+' | awk '{print $2}' | sort | uniq -c | sort -rn | head -8

line "LOG SIZES"
du -sh /var/log/* 2>/dev/null | sort -rh | head -8

line "END"
