#!/usr/bin/env bash # File manager smoke test executed on the target host. set -uo pipefail ENTRY="${1:?usage: smoke-files.sh }" BASE="http://127.0.0.1:8888/$ENTRY" PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt) curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \ -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/tmp/login.out CSRF=$(python3 -c "import json;print(json.load(open('/tmp/login.out'))['data']['csrf'])") H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888') echo "=== 1. 列目录 ===" curl -s -b /tmp/ck.txt "$BASE/api/v1/files?path=/" | python3 -c "import json,sys;d=json.load(sys.stdin)['data'];print('root:',d['root']);print('entries:',[e['name'] for e in d['entries']])" echo "=== 2. 新建目录 + 写入 + 读取 ===" curl -s "${H[@]}" -d '{"path":"/_mptest"}' "$BASE/api/v1/files/mkdir"; echo curl -s "${H[@]}" -X PUT -d '{"path":"/_mptest/a.txt","content":"hello-miaopanel"}' "$BASE/api/v1/files/write"; echo curl -s -b /tmp/ck.txt "$BASE/api/v1/files/read?path=/_mptest/a.txt"; echo echo "=== 3. 上传 / 下载 ===" printf 'uploaded-by-smoke' > /tmp/up.txt curl -s -b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Origin: http://127.0.0.1:8888' \ -F "file=@/tmp/up.txt" "$BASE/api/v1/files/upload?dir=/_mptest"; echo curl -s -b /tmp/ck.txt -o /tmp/down.txt -w 'download http=%{http_code} ' "$BASE/api/v1/files/download?path=/_mptest/up.txt" echo "content=$(cat /tmp/down.txt) owner=$(stat -c '%U:%G' /www/wwwroot/_mptest/a.txt)" echo "=== 4. 压缩 / 解压 ===" curl -s "${H[@]}" -d '{"path":"/_mptest","format":"zip"}' "$BASE/api/v1/files/compress"; echo curl -s "${H[@]}" -d '{"path":"/_mptest.zip","dest":"/_mpout"}' "$BASE/api/v1/files/extract"; echo curl -s -b /tmp/ck.txt "$BASE/api/v1/files/read?path=/_mpout/_mptest/a.txt"; echo echo "=== 5. 回收站:删除 / 列表 / 恢复 ===" DEL=$(curl -s "${H[@]}" -X DELETE "$BASE/api/v1/files?path=/_mpout") echo "$DEL" ID=$(echo "$DEL" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['id'])") curl -s -b /tmp/ck.txt "$BASE/api/v1/files/trash" | head -c 200; echo curl -s "${H[@]}" -d "{\"id\":\"$ID\"}" "$BASE/api/v1/files/trash/restore"; echo curl -s -b /tmp/ck.txt -o /dev/null -w 'restored read http=%{http_code}\n' "$BASE/api/v1/files/read?path=/_mpout/_mptest/a.txt" echo "=== 6. 路径穿越(应全部拒绝) ===" for p in '%2F..%2F..%2Fetc%2Fpasswd' '%2F.%2E%2Fetc%2Fpasswd' '%2F_mptest%2F..%2F..%2Fetc'; do printf '%-32s -> %s\n' "$p" "$(curl -s -o /dev/null -w '%{http_code}' -b /tmp/ck.txt "$BASE/api/v1/files/read?path=$p")" done echo "=== 7. 清理 ===" for p in /_mptest /_mptest.zip /_mpout; do curl -s -o /dev/null "${H[@]}" -X DELETE "$BASE/api/v1/files?path=$p" done curl -s -o /dev/null "${H[@]}" -X DELETE "$BASE/api/v1/files/trash" ls /www/wwwroot/ | paste -sd' '