#!/usr/bin/env bash
set -euo pipefail

echo "Audit port aktif server."
read -rp "Tampilkan detail process listening juga? [Y/n]: " SHOW_PROCESS
SHOW_PROCESS="${SHOW_PROCESS:-Y}"

echo "Port listening:"
ss -tulpn
echo
echo "UFW:"
ufw status verbose || true
echo
echo "Nginx/Caddy/Apache:"
systemctl status nginx caddy apache2 --no-pager || true

if [[ "$SHOW_PROCESS" =~ ^[Yy]$ ]]; then
  echo
  echo "Process listening:"
  lsof -i -P -n | grep LISTEN || true
fi
