{"record":{"id":"23adda4424898476","repo":"XIU2/CloudflareSpeedTest","slug":"key","errorCode":null,"errorMessage":"[错误] 缺少配置项 [KEY] !","messagePattern":"\\[错误\\] 缺少配置项 \\[KEY\\] !","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"script/cfst_ddns.sh","lineNumber":21,"sourceCode":"export PATH\n# --------------------------------------------------------------\n#\t项目: CloudflareSpeedTest 自动更新域名解析记录\n#\t版本: 1.0.5\n#\t作者: XIU2\n#\t项目: https://github.com/XIU2/CloudflareSpeedTest\n# --------------------------------------------------------------\n\n_READ() {\n\t[[ ! -e \"cfst_ddns.conf\" ]] && echo -e \"[错误] 配置文件不存在 [cfst_ddns.conf] !\" && exit 1\n\tCONFIG=$(cat \"cfst_ddns.conf\")\n\tFOLDER=$(echo \"${CONFIG}\"|grep 'FOLDER='|awk -F '=' '{print $NF}')\n\t[[ -z \"${FOLDER}\" ]] && echo -e \"[错误] 缺少配置项 [FOLDER] !\" && exit 1\n\tZONE_ID=$(echo \"${CONFIG}\"|grep 'ZONE_ID='|awk -F '=' '{print $NF}')\n\t[[ -z \"${ZONE_ID}\" ]] && echo -e \"[错误] 缺少配置项 [ZONE_ID] !\" && exit 1\n\tDNS_RECORDS_ID=$(echo \"${CONFIG}\"|grep 'DNS_RECORDS_ID='|awk -F '=' '{print $NF}')\n\t[[ -z \"${DNS_RECORDS_ID}\" ]] && echo -e \"[错误] 缺少配置项 [DNS_RECORDS_ID] !\" && exit 1\n\tKEY=$(echo \"${CONFIG}\"|grep 'KEY='|awk -F '=' '{print $NF}')\n\t[[ -z \"${KEY}\" ]] && echo -e \"[错误] 缺少配置项 [KEY] !\" && exit 1\n\tEMAIL=$(echo \"${CONFIG}\"|grep 'EMAIL='|awk -F '=' '{print $NF}')\n\t[[ -z \"${EMAIL}\" ]] && echo -e \"[信息] 缺少配置项 [EMAIL]，由 [API 密钥] 方式转为 [API 令牌] 方式!\"\n\tTYPE=$(echo \"${CONFIG}\"|grep 'TYPE='|awk -F '=' '{print $NF}')\n\t[[ -z \"${TYPE}\" ]] && echo -e \"[错误] 缺少配置项 [TYPE] !\" && exit 1\n\tNAME=$(echo \"${CONFIG}\"|grep 'NAME='|awk -F '=' '{print $NF}')\n\t[[ -z \"${NAME}\" ]] && echo -e \"[错误] 缺少配置项 [NAME] !\" && exit 1\n\tTTL=$(echo \"${CONFIG}\"|grep 'TTL='|awk -F '=' '{print $NF}')\n\t[[ -z \"${TTL}\" ]] && echo -e \"[错误] 缺少配置项 [TTL] !\" && exit 1\n\tPROXIED=$(echo \"${CONFIG}\"|grep 'PROXIED='|awk -F '=' '{print $NF}')\n\t[[ -z \"${PROXIED}\" ]] && echo -e \"[错误] 缺少配置项 [PROXIED] !\" && exit 1\n}\n\n_UPDATE() {\n\t# 这里可以自己添加、修改 CFST 的运行参数\n\t./cfst -o \"result_ddns.txt\"\n\n\t# 判断结果文件是否存在，如果不存在说明结果为 0\n\t[[ ! -e \"result_ddns.txt\" ]] && echo \"CFST 测速结果 IP 数量为 0，跳过下面步骤...\" && exit 0","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/XIU2/CloudflareSpeedTest/blob/1da0c025d7b6f9bf0b2b0cf47a547f65430deab2/script/cfst_ddns.sh#L3-L39","documentation":"_READ() extracts KEY from cfst_ddns.conf (grep 'KEY=' | awk -F '=' '{print $NF}') and exits 1 at script/cfst_ddns.sh:21 when empty. KEY is the Cloudflare credential: either the Global API Key (sent as X-Auth-Key together with EMAIL, line 51) or an API Token (sent as Authorization: Bearer, line 57). Without a credential no update is possible, so the script aborts early.","triggerScenarios":"cfst_ddns.conf has a missing, commented, or valueless 'KEY=' line. The grep takes the text after the last '=' on the line, so trailing whitespace or a partial paste can also corrupt the value even when non-empty.","commonSituations":"User removed the key because the conf is in a repo; key pasted with stray whitespace or a truncated token after Windows editor round-trips; user filled EMAIL but forgot KEY (or vice versa) and misreads which one is missing.","solutions":["Set KEY in cfst_ddns.conf to a Cloudflare API Token (works with the empty-EMAIL Bearer path) that has Zone -> DNS -> Edit permission on the zone, or to the Global API Key if EMAIL is also set","Confirm no leading '#' and no spaces around '='; tokens are opaque strings, paste them whole","Keep cfst_ddns.conf out of version control since it now holds a secret (chmod 600)","Re-run bash cfst_ddns.sh and check the remaining _READ checks pass"],"exampleFix":"# cfst_ddns.conf (before)\nKEY=\n# (after)\nKEY=v1.0-24c5d1ef9b4e0f2a... (API Token)","handlingStrategy":"validation","validationCode":"key=$(grep '^KEY=' cfst_ddns.conf | head -1 | cut -d= -f2-)\n[ -n \"$key\" ] || { echo 'KEY empty' >&2; exit 1; }\ncurl -s -o /dev/null -w '%{http_code}' -H \"Authorization: Bearer $key\" https://api.cloudflare.com/client/v4/user/tokens/verify | grep -q 200 || echo 'token verify failed' >&2","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the token once with /user/tokens/verify before scheduling the script","chmod 600 cfst_ddns.conf and exclude it from git so key blanks are noticed, not leaked","Decide the auth mode first (token vs global key) and fill KEY+EMAIL as a pair"],"tags":["shell","bash","cloudflare","ddns","configuration","secrets"],"backgroundTag":null,"analyzedSha":"1da0c025d7b6f9bf0b2b0cf47a547f65430deab2","analyzedAt":"2026-08-15T22:22:10.737Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}