#!/usr/bin/env bash # End-to-end Let's Encrypt test against a sslip.io hostname. # Usage: ssl-test.sh set -uo pipefail ENTRY="${1:-ipdduiyy}" DOMAIN="${2:-186-241-74-221.sslip.io}" STAGING="${3:-1}" BASE="http://127.0.0.1:8888/$ENTRY" PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt) ORIGIN="http://127.0.0.1:8888" curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \ -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])") H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN") SID=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c " import json,sys rows=[s['id'] for s in json.load(sys.stdin)['data'] if '$DOMAIN' in s['domains']] print(rows[0] if rows else '')") if [ -z "$SID" ]; then echo "== 创建测试站点 ==" curl -s "${H[@]}" -d "{\"kind\":\"static\",\"domains\":[\"$DOMAIN\"],\"options\":{\"waf\":true,\"security_headers\":true}}" \ "$BASE/api/v1/sites" > /tmp/ssl-site.json SID=$(python3 -c "import json;print(json.load(open('/tmp/ssl-site.json'))['data']['id'])") echo "site id=$SID" sleep 1 fi echo "== SSL 状态 ==" curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/$SID/ssl" echo echo "== 申请证书 staging=$STAGING ==" curl -s --max-time 240 -b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' \ -H "Origin: $ORIGIN" -d "{\"staging\":$([ "$STAGING" = "1" ] && echo true || echo false),\"auto_renew\":true}" \ "$BASE/api/v1/sites/$SID/ssl/issue" | tee /tmp/ssl-issue.json echo echo "== nginx 配置 ==" nginx -t 2>&1 | tail -1 ls -l /www/server/panel/vhost/cert/*/ 2>/dev/null | tail -4 echo "== HTTPS 访问(本地解析) ==" curl -sk --resolve "$DOMAIN:443:127.0.0.1" -o /dev/null -w "https local: %{http_code}\n" "https://$DOMAIN/" echo | openssl s_client -connect 127.0.0.1:443 -servername "$DOMAIN" 2>/dev/null | openssl x509 -noout -subject -issuer -dates 2>/dev/null echo "== 公网 HTTPS ==" curl -sk -o /dev/null -w "https public: %{http_code}\n" --max-time 8 "https://$DOMAIN/" echo "SID=$SID"