# shellcheck shell=bash # cmd_doctor — end-to-end health check of the running laboratory. _c_ok() { ok "$*"; } _c_warn() { warn "$*"; DOCTOR_WARNS=$(( DOCTOR_WARNS + 1 )); } _c_fail() { fail "$*"; DOCTOR_FAILS=$(( DOCTOR_FAILS + 1 )); } cmd_doctor() { DOCTOR_FAILS=0 DOCTOR_WARNS=0 local i name ip step "host" if ip link show "$BRIDGE" >/dev/null 2>&1; then _c_ok "bridge ${BRIDGE} present" else _c_fail "bridge ${BRIDGE} missing — run sudo ./scripts/setup-network.sh" fi step "machines" for i in "${!VM_NAMES[@]}"; do name=${VM_NAMES[$i]} ip=${VM_IPS[$i]} if ! backend_running "$name"; then _c_fail "$name is not running — ./lab.sh up" continue fi if tcp_open "$ip" 445; then _c_ok "$(printf '%-6s %-14s smb up' "$name" "$ip")" else _c_warn "$(printf '%-6s %-14s smb not answering' "$name" "$ip")" fi if [[ $name == dc01 || $name == ws01 || $name == fs01 ]]; then if tcp_open "$ip" 5985; then _c_ok "$(printf '%-6s %-14s winrm up' "$name" "$ip")" else _c_warn "$(printf '%-6s %-14s winrm not answering' "$name" "$ip")" fi fi done step "domain" if have_cmd dig; then local www www=$(dig +short +time=2 +tries=1 "@$LAB_DC_IP" www.norbourg.lab 2>/dev/null | head -1) if [[ $www == 10.10.10.20 ]]; then _c_ok "dns: www.norbourg.lab -> $www" else _c_fail "dns: www.norbourg.lab did not resolve via ${LAB_DC_IP} (got '${www:-nothing}')" fi local srv srv=$(dig +short +time=2 +tries=1 "@$LAB_DC_IP" SRV _ldap._tcp.dc._msdcs.norbourg.lab 2>/dev/null | head -1) if [[ -n $srv ]]; then _c_ok "dns: ldap SRV record present" else _c_fail "dns: ldap SRV record missing — AD discovery would fail" fi else _c_warn "dig not installed, DNS checks skipped" fi step "web" local code code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://10.10.10.20/" 2>/dev/null || true) if [[ $code == 200 ]]; then _c_ok "site answers on 10.10.10.20" else _c_fail "site not answering (${code:-timeout}) — ./lab.sh web --sync" fi code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://10.10.10.20/public/IT-inventaire.txt" 2>/dev/null || true) if [[ $code == 200 ]]; then _c_ok "entry point reachable: /public/IT-inventaire.txt" else _c_fail "entry point missing (${code:-timeout})" fi step "share" if have_cmd smbclient; then if smbclient //10.10.10.20/Public -U 'NORBOURG\helpdesk1%Welcome2024!' -c 'ls' 2>/dev/null | grep -q 'IT-inventaire'; then _c_ok "Public share reachable with the leaked credential" else _c_warn "Public share not readable as helpdesk1 (domain channel or DNS?)" fi else _c_warn "smbclient not installed, share check skipped" fi printf '\n' if (( DOCTOR_FAILS )); then fail "${DOCTOR_FAILS} problem(s), ${DOCTOR_WARNS} warning(s)" return 1 fi ok "laboratory healthy · ${DOCTOR_WARNS} warning(s)" }