reolservices / cloudflare
一个用于与 CloudFlare API V1 通信并管理 DNS 记录的 Yii2 扩展
1.0.0
2015-09-03 14:46 UTC
Requires
- php: >=5.3.2
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-10-02 10:52:50 UTC
README
此扩展实现了 Cloudflare API v1 的一些功能。即使该 API 已被弃用,并且建议使用 API v4,它(和将来)仍然会得到支持,并且仅允许使用 GET 请求。此扩展的当前版本允许用户检索在 Cloudflare 账户上注册的特定域的主要信息,添加新域(或任何 DNS 记录),或删除子域(出于安全原因,除了主要域名之外的任何 DNS 记录)。
安装
使用 composer 的 Cloudflare 客户端非常简单。只需将以下内容添加到您的 composer.json 文件中
"require-dev": { ... "reolservices/cloudflare": "*", ... }
然后运行 composer update 以将扩展集成到您的应用程序中。
用法
只需将 reolservices/cloudflare 添加到您项目的需求中。您需要将 Cloudflare 凭据添加到您的配置中,如下所示
$config = [ ... 'params' => [ ... 'cloudflare' => [ "cloudflare_auth_email" => "email@domain.com", "cloudflare_auth_key" => "YOUR_AUTH_KEY_HERE", ], ... ], ... ];
然后可以使用如下代码
// Initialize the client $cfClient = new \Cloudflare\Client(); // Retrieve the lise of all DNS records for a given domain that is registered in your Cloudflare account $domains = $cfClient->getDNSRecords('example.com'); // Retrieve the list of 'A' records for a given subdomain $subDomains = $cfClient->getDNSRecords('sub.example.com', 'A'); // Add a new Subdomain (A record) to your Cloudflare DNS records $newDomain = $cfClient->addDNSRecord('new.sub.example.com', '1.2.3.4'); // Add a new CNAME / MX record to your Cloudflare DNS records $newCNAME = $cfClient->addDNSRecord('other.sub.example.com', 'new.sub.example.com', 'CNAME'); $newMX = $cfClient->addDNSRecord('new.sub.example.com', '1.2.3.4', 'MX'); // Remove an MX DNS record from your DNS records for a given (sub)domain $deleteMX = $cfClient->deleteDNSRecords('new.sub.example.com', 'MX'); // Remove all DNS records for a given (sub)domain // This is not allowed on top level domains for security reasons // if you want to do it anyway, please connect to your Cloudflare console $deleteDomain = $cfClient->deleteDNSRecords('sub.example.com');
修改库
这是一个许可为 LGPL v3 或更高版本的免费/开源库。您的 pull requests 和/或反馈非常欢迎!
贡献者
由 ReolServices Edge 团队,Renaud Tilte,Simith D'Oliveira 和贡献者创建。
我们期待您的贡献和 pull requests!
测试
即将推出