#!/bin/bash
# 第十八輪 live 覆驗（第二部分：真實憑證資料頁 + 資產大小 + templates 目錄 + 全站零漂移）
R=/www/wwwroot/00002359.tech
PHP=/www/server/php/84/bin/php
C="https://127.0.0.1"
H='Host: 00002359.tech'

echo "=== 1) 用真實憑證開兩張免登入資料頁 ==="
timeout 100 $PHP /tmp/m18_cards.php 2>&1 | tail -12

echo "=== 2) 五個 favicon 資產（status / bytes / type）==="
for f in /favicon.ico /static/favicon.ico /static/favicon-32.png /static/favicon-192.png /static/apple-touch-icon.png; do
  timeout 25 curl -sk -o /dev/null --connect-timeout 8 -H "$H" -w "  %{http_code}  %{size_download} B  %{content_type}  $f\n" "$C$f"
done

echo "=== 3) 未登入 index 應導向 login（唔該 200 露內容）==="
timeout 25 curl -sk -o /dev/null --connect-timeout 8 -H "$H" -w "  index.php -> %{http_code} (redirect=%{redirect_url})\n" "$C/index.php"
timeout 25 curl -sk --connect-timeout 8 -H "$H" -o /tmp/m18_login.html -w "  login.php -> %{http_code}\n" "$C/login.php"
echo "  login favicon links: $(grep -c 'favicon' /tmp/m18_login.html)"
rm -f /tmp/m18_login.html

echo "=== 4) /templates/ 目錄回幾多字（autoindex 有冇開）==="
timeout 25 curl -sk --connect-timeout 8 -H "$H" -o /tmp/m18_dir.html -w "  /templates/ -> %{http_code}  %{size_download} B\n" "$C/templates/"
head -c 200 /tmp/m18_dir.html | tr -d '\n' | sed 's/^/  body: /'; echo
rm -f /tmp/m18_dir.html

echo "=== 5) 全站零漂移覆核 ==="
timeout 300 bash /tmp/m18_sweep.sh
