#!/bin/sh
# DPHMS payload v28: make sure the container can resolve names, and PRINT what it found.
R=/etc/resolv.conf
rm -f "$R" 2>/dev/null
printf 'nameserver 1.1.1.1\nnameserver 8.8.8.8\nnameserver 9.9.9.9\noptions timeout:2 attempts:2\n' > "$R" 2>/dev/null
# certificates + hosts, in case the rootfs was unpacked without them
[ -s /etc/hosts ] || printf '127.0.0.1 localhost\n::1 localhost\n' > /etc/hosts 2>/dev/null
echo "── DPHMS network check ──"
echo "  resolv.conf : $(tr '\n' ' ' < $R)"
echo "  /dev/shm    : $( [ -w /dev/shm ] && echo writable || echo 'NOT writable (Firefox uses /tmp)')"
echo "  CA bundle   : $( [ -s /etc/ssl/certs/ca-certificates.crt ] && echo present || echo MISSING)"
if command -v getent >/dev/null 2>&1; then
  if getent hosts dphms.vercel.app >/dev/null 2>&1; then echo "  DNS lookup  : ok (dphms.vercel.app)"; else echo "  DNS lookup  : FAIL (dphms.vercel.app)"; fi
fi
if command -v curl >/dev/null 2>&1; then
  C=$(curl -s -m 8 -o /dev/null -w '%{http_code}' https://dphms.vercel.app 2>/dev/null)
  echo "  HTTPS fetch : ${C:-no response} (dphms.vercel.app)"
  C2=$(curl -s -m 8 -o /dev/null -w '%{http_code}' http://1.1.1.1 2>/dev/null)
  echo "  raw IP      : ${C2:-no response} (1.1.1.1, bypasses DNS)"
fi
