debian 开发,modiqi 修复 cf_load_profile 缺失问题。 9 个命令:cf-api/cf-zone/cf-dns/cf-cache/cf-ssl/cf-fw/cf-pagerule/cf-analytics/cf-hostname 支持多账号、域名自动解析 zone_id。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
117 lines
3.8 KiB
Bash
Executable file
117 lines
3.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
||
set -euo pipefail
|
||
# cf-zone — Cloudflare Zone 管理
|
||
# 用法: cf-zone list [-s status] 列出所有 zone
|
||
# cf-zone info <domain> zone 详情
|
||
# cf-zone settings <domain> zone 设置
|
||
# cf-zone purge <domain> 清除全部缓存(快捷方式)
|
||
# cf-zone dev <domain> [on|off] 开发模式开关
|
||
# 选项: -p <profile> 指定 profile
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||
source "$SCRIPT_DIR/cf-lib.sh"
|
||
|
||
cf_parse_profile "$@"
|
||
set -- "${CF_REMAINING_ARGS[@]}"
|
||
cf_load_profile
|
||
|
||
usage() {
|
||
cat >&2 <<'EOF'
|
||
用法: cf-zone <command> [args...]
|
||
命令:
|
||
list [-s status] 列出 zone(status: active/pending/initializing/moved/deleted)
|
||
info <domain> zone 详情
|
||
settings <domain> zone 全部设置
|
||
purge <domain> 清除全部缓存
|
||
dev <domain> [on|off] 开发模式开关(不带参数查看当前状态)
|
||
check <domain> 激活检查(触发 DNS 验证)
|
||
EOF
|
||
exit 1
|
||
}
|
||
|
||
[[ $# -lt 1 ]] && usage
|
||
|
||
CMD="$1"; shift
|
||
|
||
case "$CMD" in
|
||
list)
|
||
STATUS=""
|
||
while [[ $# -gt 0 ]]; do
|
||
case "$1" in
|
||
-s) STATUS="$2"; shift 2 ;;
|
||
*) shift ;;
|
||
esac
|
||
done
|
||
QUERY="/zones?per_page=50"
|
||
[[ -n "$STATUS" ]] && QUERY+="&status=$STATUS"
|
||
resp=$(cf_call GET "$QUERY")
|
||
cf_check_error "$resp"
|
||
echo "$resp" | jq -r '
|
||
["域名", "状态", "套餐", "NS验证", "Zone ID"],
|
||
(.result[] | [.name, .status, .plan.name, .name_servers[0], .id]) |
|
||
@tsv' | column -t -s $'\t'
|
||
total=$(echo "$resp" | jq '.result_info.total_count')
|
||
echo -e "\n共 $total 个 zone"
|
||
;;
|
||
|
||
info)
|
||
[[ $# -lt 1 ]] && { echo "用法: cf-zone info <domain>" >&2; exit 1; }
|
||
ZONE_ID=$(cf_resolve_zone "$1")
|
||
resp=$(cf_call GET "/zones/$ZONE_ID")
|
||
cf_check_error "$resp"
|
||
echo "$resp" | jq '.result | {
|
||
name, status, id,
|
||
plan: .plan.name,
|
||
name_servers,
|
||
original_name_servers,
|
||
created_on,
|
||
modified_on,
|
||
paused,
|
||
type
|
||
}'
|
||
;;
|
||
|
||
settings)
|
||
[[ $# -lt 1 ]] && { echo "用法: cf-zone settings <domain>" >&2; exit 1; }
|
||
ZONE_ID=$(cf_resolve_zone "$1")
|
||
resp=$(cf_call GET "/zones/$ZONE_ID/settings")
|
||
cf_check_error "$resp"
|
||
echo "$resp" | jq '.result[] | {id, value}' | jq -s '.'
|
||
;;
|
||
|
||
purge)
|
||
[[ $# -lt 1 ]] && { echo "用法: cf-zone purge <domain>" >&2; exit 1; }
|
||
ZONE_ID=$(cf_resolve_zone "$1")
|
||
resp=$(cf_call POST "/zones/$ZONE_ID/purge_cache" -d '{"purge_everything":true}')
|
||
cf_check_error "$resp"
|
||
echo "已清除 $1 的全部缓存"
|
||
;;
|
||
|
||
dev)
|
||
[[ $# -lt 1 ]] && { echo "用法: cf-zone dev <domain> [on|off]" >&2; exit 1; }
|
||
ZONE_ID=$(cf_resolve_zone "$1")
|
||
if [[ $# -lt 2 ]]; then
|
||
resp=$(cf_call GET "/zones/$ZONE_ID/settings/development_mode")
|
||
cf_check_error "$resp"
|
||
val=$(echo "$resp" | jq -r '.result.value')
|
||
remain=$(echo "$resp" | jq -r '.result.time_remaining')
|
||
echo "开发模式: $val (剩余 ${remain}s)"
|
||
else
|
||
VALUE="$2"
|
||
[[ "$VALUE" == "on" ]] && VALUE="on" || VALUE="off"
|
||
resp=$(cf_call PATCH "/zones/$ZONE_ID/settings/development_mode" -d "{\"value\":\"$VALUE\"}")
|
||
cf_check_error "$resp"
|
||
echo "开发模式已设为: $VALUE"
|
||
fi
|
||
;;
|
||
|
||
check)
|
||
[[ $# -lt 1 ]] && { echo "用法: cf-zone check <domain>" >&2; exit 1; }
|
||
ZONE_ID=$(cf_resolve_zone "$1")
|
||
resp=$(cf_call PUT "/zones/$ZONE_ID/activation_check")
|
||
cf_check_error "$resp"
|
||
echo "已触发 $1 的激活检查"
|
||
;;
|
||
|
||
*) usage ;;
|
||
esac
|