仰望星辰工作室

miaopanel

miaopanel/ scripts/ssl-test.sh 2.2 KB · 53 行 原始文件
1#!/usr/bin/env bash
2# End-to-end Let's Encrypt test against a sslip.io hostname.
3# Usage: ssl-test.sh <entry> <domain> <staging:0|1>
4set -uo pipefail
5ENTRY="${1:-ipdduiyy}"
6DOMAIN="${2:-186-241-74-221.sslip.io}"
7STAGING="${3:-1}"
8BASE="http://127.0.0.1:8888/$ENTRY"
9PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
10ORIGIN="http://127.0.0.1:8888"
11
12curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \
13 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
14CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])")
15H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN")
16
17SID=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c "
18import json,sys
19rows=[s['id'] for s in json.load(sys.stdin)['data'] if '$DOMAIN' in s['domains']]
20print(rows[0] if rows else '')")
21
22if [ -z "$SID" ]; then
23 echo "== 创建测试站点 =="
24 curl -s "${H[@]}" -d "{\"kind\":\"static\",\"domains\":[\"$DOMAIN\"],\"options\":{\"waf\":true,\"security_headers\":true}}" \
25 "$BASE/api/v1/sites" > /tmp/ssl-site.json
26 SID=$(python3 -c "import json;print(json.load(open('/tmp/ssl-site.json'))['data']['id'])")
27 echo "site id=$SID"
28 sleep 1
29fi
30
31echo "== SSL 状态 =="
32curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/$SID/ssl"
33
34echo
35echo "== 申请证书 staging=$STAGING =="
36curl -s --max-time 240 -b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' \
37 -H "Origin: $ORIGIN" -d "{\"staging\":$([ "$STAGING" = "1" ] && echo true || echo false),\"auto_renew\":true}" \
38 "$BASE/api/v1/sites/$SID/ssl/issue" | tee /tmp/ssl-issue.json
39echo
40
41echo "== nginx 配置 =="
42nginx -t 2>&1 | tail -1
43ls -l /www/server/panel/vhost/cert/*/ 2>/dev/null | tail -4
44
45echo "== HTTPS 访问(本地解析) =="
46curl -sk --resolve "$DOMAIN:443:127.0.0.1" -o /dev/null -w "https local: %{http_code}\n" "https://$DOMAIN/"
47echo | openssl s_client -connect 127.0.0.1:443 -servername "$DOMAIN" 2>/dev/null |
48 openssl x509 -noout -subject -issuer -dates 2>/dev/null
49
50echo "== 公网 HTTPS =="
51curl -sk -o /dev/null -w "https public: %{http_code}\n" --max-time 8 "https://$DOMAIN/"
52
53echo "SID=$SID"