miaopanel
1#!/usr/bin/env bash
2# Verify ownership handoff and full deletion (config + document root).
3set -uo pipefail
4ENTRY="${1:?usage: verify-delete.sh <entry>}"
5BASE="http://127.0.0.1:8888/$ENTRY"
6PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
7
8curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \
9 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/tmp/login.out
10CSRF=$(python3 -c "import json;print(json.load(open('/tmp/login.out'))['data']['csrf'])")
11
12echo "=== 创建临时站点 tmpdemo ==="
13curl -s -b /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \
14 -H "X-CSRF-Token: $CSRF" \
15 -d '{"name":"tmpdemo","kind":"static","domains":["tmp.demo"],"options":{"waf":true,"security_headers":true}}' \
16 "$BASE/api/v1/sites" >/tmp/tmp.json
17ID=$(python3 -c "import json;print(json.load(open('/tmp/tmp.json'))['data']['id'])")
18echo "id=$ID owner=$(stat -c '%U:%G' /www/wwwroot/tmpdemo)"
19ls -1 /www/server/panel/vhost/nginx/extension/tmpdemo/
20
21echo "=== 删除(含目录) ==="
22curl -s -b /tmp/ck.txt -H 'X-CSRF-Token: '"$CSRF" -X DELETE \
23 "$BASE/api/v1/sites/$ID?remove_files=1"; echo
24if [ -e /www/wwwroot/tmpdemo ]; then echo "目录仍存在"; else echo "目录已删除"; fi
25if [ -e /www/server/panel/vhost/nginx/tmpdemo.conf ]; then echo "vhost 仍存在"; else echo "vhost 已删除"; fi
26nginx -t 2>&1 | tail -1
27
28echo "=== 指标接口 ==="
29curl -s -b /tmp/ck.txt "$BASE/api/v1/system/info" | python3 -c "
30import json,sys
31d=json.load(sys.stdin)['data']
32print('host:', d['hostname'], d['distro']['pretty_name'])
33print('cpu: %.1f%% cores=%d load=%.2f' % (d['cpu_usage'], d['cpu_cores'], d['load1']))
34print('mem: %.1f%% of %d MB' % (100*d['memory']['used']/d['memory']['total'], d['memory']['total']//1048576))
35print('disk: %.1f%% of %d GB' % (100*d['disk']['used']/d['disk']['total'], d['disk']['total']//1073741824))
36print('uptime:', d['uptime'], 's')
37"