Cloudflare DNS Updater
This skill creates or updates a Cloudflare DNS 'A' record, pointing it to a specified IP address and ensuring it is proxied. It is a foundational tool for automating service deployment and DNS management.
Pre-requisites
This skill requires the CLOUDFLARE_API_TOKEN environment variable to be set with a valid Cloudflare API Token that has DNS edit permissions.
The model should verify this prerequisite before attempting to use the skill. If the variable is not set, it should inform the user and stop.
Core Action: scripts/update-record.py
The core logic is handled by the update-record.py script.
Inputs (Command-Line Arguments)
- -
--zone: (Required) The root domain name. Example: INLINECODE4 - INLINECODE5 : (Required) The name of the record (subdomain). Use
@ for the root domain itself. Example: INLINECODE7 - INLINECODE8 : (Required) The IPv4 address to point the record to.
- INLINECODE9 : (Optional) Boolean (
true or false) to set the Cloudflare proxy status. Defaults to true.
Output
The script will print its progress to stdout.
- - On success, it prints a confirmation message and a JSON object of the created/updated record.
- On failure, it prints a descriptive error message to stderr and exits with a non-zero status code.
Execution Workflow
To use this skill, follow these steps:
- 1. Verify Prerequisites: Check if the
CLOUDFLARE_API_TOKEN environment variable is set. If not, notify the user and abort. - Gather Inputs: From the user's request, identify the
zone, record name, and target ip. - Construct Command: Build the full shell command to execute the script.
- Execute Command: Run the command using the
exec tool. - Report Result:
- If the command succeeds, report the successful creation or update to the user.
- If the command fails, analyze the error message from stderr and report the issue to the user in a clear, understandable way.
Example Usage
User Request: "Point www.example.com to the server's public IP."
AI's Thought Process:
- 1. The user wants to update a DNS record on Cloudflare. The
cloudflare-dns-updater skill is perfect for this. - I will use the
update-record.py script. - I need the zone, record name, and IP.
- Zone:
example.com
- Record:
www
- IP: I need to find the server's public IP first. I can use
curl -s https://ipv4.icanhazip.com/.
- 4. I will first get the IP, then construct the final command.
- I will execute the command and report the outcome.
AI's Actions:
CODEBLOCK0
Failure Strategy
- - If
CLOUDFLARE_API_TOKEN is not set: Do not attempt to run the script. Inform the user that the required environment variable is missing and needs to be configured by the administrator. - If the script exits with an error: Read the error message from stderr. Common errors include invalid API token, incorrect zone name, or insufficient permissions. Report the specific error to the user.
Cloudflare DNS 更新器
该技能用于创建或更新 Cloudflare DNS 的 A 记录,将其指向指定的 IP 地址,并确保启用代理功能。它是自动化服务部署和 DNS 管理的基础工具。
前置条件
此技能需要设置 CLOUDFLAREAPITOKEN 环境变量,该变量需包含具有 DNS 编辑权限的有效 Cloudflare API 令牌。
模型在尝试使用此技能前应验证该前置条件。如果变量未设置,应告知用户并停止操作。
核心操作:scripts/update-record.py
核心逻辑由 update-record.py 脚本处理。
输入(命令行参数)
- - --zone:(必需)根域名。示例:example.com
- --record:(必需)记录名称(子域名)。使用 @ 表示根域名本身。示例:www
- --ip:(必需)记录指向的 IPv4 地址。
- --proxied:(可选)布尔值(true 或 false),用于设置 Cloudflare 代理状态。默认值为 true。
输出
脚本会将进度信息打印到标准输出。
- - 成功时,打印确认消息以及创建/更新记录的 JSON 对象。
- 失败时,将描述性错误消息打印到标准错误输出,并以非零状态码退出。
执行流程
使用此技能时,请遵循以下步骤:
- 1. 验证前置条件:检查 CLOUDFLAREAPITOKEN 环境变量是否已设置。如果未设置,通知用户并中止操作。
- 收集输入:根据用户的请求,确定 zone、record 名称和目标 ip。
- 构建命令:构建执行脚本的完整 shell 命令。
- 执行命令:使用 exec 工具运行命令。
- 报告结果:
- 如果命令成功,向用户报告成功创建或更新。
- 如果命令失败,分析标准错误输出中的错误消息,并以清晰易懂的方式向用户报告问题。
使用示例
用户请求: 将 www.example.com 指向服务器的公网 IP。
AI 的思考过程:
- 1. 用户想要更新 Cloudflare 上的 DNS 记录。cloudflare-dns-updater 技能非常适合此任务。
- 我将使用 update-record.py 脚本。
- 我需要区域、记录名称和 IP。
- 区域:example.com
- 记录:www
- IP:我需要先获取服务器的公网 IP。可以使用 curl -s https://ipv4.icanhazip.com/。
- 4. 我将先获取 IP,然后构建最终命令。
- 我将执行命令并报告结果。
AI 的操作:
bash
步骤 1:获取 IP
PUBLIC_IP=$(curl -s https://ipv4.icanhazip.com/)
步骤 2:运行技能脚本
python3 skills/cloudflare-dns-updater/scripts/update-record.py \
--zone example.com \
--record www \
--ip $PUBLIC_IP
失败处理策略
- - 如果 CLOUDFLAREAPITOKEN 未设置: 不要尝试运行脚本。告知用户缺少必需的环境变量,需要由管理员进行配置。
- 如果脚本因错误退出: 读取标准错误输出中的错误消息。常见错误包括 API 令牌无效、区域名称不正确或权限不足。向用户报告具体的错误信息。