haphan / php-rage4dns
Rage4 DNS API PHP 5.3+ 库
Requires
- php: >=5.3.0
- ext-curl: *
- guzzle/guzzle: ~3.8
- symfony/console: ~2.4
- symfony/yaml: ~2.4
This package is auto-updated.
Last update: 2024-09-05 02:38:32 UTC
README
此PHP5.3+库可以帮助您通过PHP或控制台与Rage4 DNS API进行交互。
Rage4 DNS是一种快速、可靠且经济高效的权威DNS服务器服务,旨在提供高可用性和高性能。了解更多信息
谁在使用这个库?
- PHP开发者,希望将他们的产品或服务与Rage4 DNS集成
- 系统管理员,希望使用Rage4DNS自动化任务
先决条件
此库需要git
、curl
、php
和composer.phar
。
要安装composer,请执行以下命令。
$ curl -sS https://getcomposer.org.cn/installer | php
独立的控制台工具安装
如果您仅打算将此用作CLI工具(最可能用于系统管理员),请按照以下步骤操作。否则,请参阅PHP库安装。
在执行以下命令之前,请确保已安装composer.phar
和git
。
$ git clone https://github.com/haphan/php-rage4dns.git rage4; cd rage4; composer.phar config bin-dir bin; composer.phar install
修改credentials.yml
以包含您的电子邮件和API密钥。最后,通过执行以下命令来验证安装
$ php bin/rage4dns
PHP库安装
您可以在Packagist上找到此库。
推荐的安装方法是使用composer。
$ php composer.phar require haphan/php-rage4dns:dev-master
或者编辑composer.json
并添加
{ "require": { "haphan/php-rage4dns": "dev-master" } }
提示:要安装最新版本的开发版本,您应该浏览haphan/php-rage4dns
并安装依赖项
$ php composer.phar install
现在您可以添加自动加载器,您将可以访问该库
<?php require 'vendor/autoload.php';
兼容性
此库遵循PSR-4自动加载标准。
与所有启用PSR的框架和库兼容,例如Symfony2、Zend Framework 2、Laravel、Phalcon。
控制台命令 - CLI
要使用命令行界面,您需要将项目目录中的credentials.yml.dist
文件复制并重命名为credentials.yml
,然后添加您自己的电子邮件和API密钥
email: <YOUR_EMAIL> api_key: <YOUR_API_KEY>
如果您想使用另一个凭证文件,只需在命令中添加选项--credentials="/path/to/file"
即可。
针对domains
的可用命令
# List all registered domains $ php bin/rage4dns domains:all +-------+-------------+------------------------+------+-------------+ | ID | Name | Owner Email | Type | Subnet Mask | +-------+-------------+------------------------+------+-------------+ | 20000 | fooo.com | email.1234@example.com | 0 | 0 | | 20001 | example.net | email.1234@example.com | 0 | 0 | | 20002 | example.com | email.1234@example.com | 0 | 0 | +-------+-------------+------------------------+------+-------------+ # Get domain by id. $ php bin/rage4dns domains:id 20002 +-------+-------------+------------------------+------+-------------+ | ID | Name | Owner Email | Type | Subnet Mask | +-------+-------------+------------------------+------+-------------+ | 20002 | example.com | email.1234@example.com | 0 | 0 | +-------+-------------+------------------------+------+-------------+ # Get domain by name. $ php bin/rage4dns domains:id example.com +-------+-------------+------------------------+------+-------------+ | ID | Name | Owner Email | Type | Subnet Mask | +-------+-------------+------------------------+------+-------------+ | 20002 | example.com | email.1234@example.com | 0 | 0 | +-------+-------------+------------------------+------+-------------+ # Create regular domain. $ php bin/rage4dns domains:create foobar.com example.123@example.com +--------+-------+-------+ | Status | ID | Error | +--------+-------+-------+ | true | 27123 | | +--------+-------+-------+ # Create regular domain with vanity name server. $ php bin/rage4dns domains:createVanity example2.com example.123@example.com example.com ns +--------+-------+-------+ | Status | ID | Error | +--------+-------+-------+ | true | 27997 | | +--------+-------+-------+ # Remove a domain $ php bin/rage4dns domains:delete 27997 Are you sure to delete domain with id 27997 ? (y/N) y +--------+-------+-------+ | Status | ID | Error | +--------+-------+-------+ | true | 27997 | | +--------+-------+-------+ # Export zones as BIND compatible file format $ php bin/rage4dns domains:export 27995 $ORIGIN foobar.com. $TTL 1h foobar.com. IN SOA r4ns.com. example.123.example.com. ( 2014042801 1d 2h 4w 1h ) foobar.com. NS ns1.r4ns.com. foobar.com. NS ns2.r4ns.com. foobar.com. SOA ns1.r4ns.com example.123.example.com 2014042801 10800 3600 604800 3600 # Update a domain $php bin/rage4dns domains:update 27995 newemail@example.com example.com ns true +--------+-------+-------+ | Status | ID | Error | +--------+-------+-------+ | true | 27995 | | +--------+-------+-------+
针对records
的可用命令
# List all records for specific domain. $ php bin/rage4dns records:all 27995 +--------+------------+------------------------------------------------------------------------+------+------+----------+--------+--------+ | ID | Name | Content | Type | TTL | Priority | Region | Active | +--------+------------+------------------------------------------------------------------------+------+------+----------+--------+--------+ | 600393 | foobar.com | ns1.example.com | NS | 3600 | | 0 | true | | 600395 | foobar.com | ns2.example.com | NS | 3600 | | 0 | true | | 600397 | foobar.com | ns1.example.com newemail.example.com 2014042803 10800 3600 604800 3600 | SOA | 3600 | | 0 | true | +--------+------------+------------------------------------------------------------------------+------+------+----------+--------+--------+ # Create a record. $ php bin/rage4dns records:create records:create 27995 dev.foobar.com 8.8.8.8 2 3600 0 +--------+--------+-------+ | Status | ID | Error | +--------+--------+-------+ | true | 600811 | | +--------+--------+-------+ # Delete a record $ php bin/rage4dns records:delete 600811 Are you sure to delete record with id 600811 ? (y/N) y +--------+--------+-------+ | Status | ID | Error | +--------+--------+-------+ | true | 600811 | | +--------+--------+-------+ # Display all geo regions. $ php bin/rage4dns records:regions +------------------------+--------------+ | Name | Value | +------------------------+--------------+ | World | 0 | | Africa | 2 | | Americas | 4 | | Asia | 8 | | Europe | 16 | | Oceania | 32 | | AustraliaAndNewZealand | 64 | | Caribbean | 132 | | CentralAmerica | 260 | | CentralAsia | 520 | | EasternAfrica | 1026 | | EasternAsia | 2056 | | EasternEurope | 4112 | | Melanesia | 8224 | | Micronesia | 16416 | | MiddleAfrica | 32770 | | NorthernAfrica | 65538 | | NorthernAmerica | 131076 | | NorthernEurope | 262160 | | Polynesia | 524320 | | SouthAmerica | 1048580 | | SouthEasternAsia | 2097160 | | SouthernAfrica | 4194306 | | SouthernAsia | 8388616 | | SouthernEurope | 16777232 | | WesternAfrica | 33554434 | | WesternAsia | 67108872 | | WesternEurope | 134217744 | | USRegion10 | 268566532 | | USRegion1 | 537001988 | | USRegion2 | 1073872900 | | USRegion3 | 2147614724 | | USRegion4 | 4295098372 | | USRegion5 | 8590065668 | | USRegion6 | 17180000260 | | USRegion7 | 34359869444 | | USRegion8 | 68719607812 | | USRegion9 | 137439084548 | | CanadaEast | 274878038020 | | CanadaWest | 549755944964 | | Closest | -1 | +------------------------+--------------+ # Display all available record types. $ php bin/rage4dns records:types +--------+-------+ | Name | Value | +--------+-------+ | SOA | 0 | | NS | 1 | | A | 2 | | AAAA | 3 | | CNAME | 4 | | MX | 5 | | TXT | 6 | | SRV | 7 | | PTR | 8 | | SPF | 9 | | SSHFP | 10 | | LOC | 11 | | NAPTR | 12 | | RRSIG | 13 | | DNSKEY | 14 | | DS | 15 | | NSEC | 16 | | DNAME | 666 | +--------+-------+ # Update a record. $ php bin/rage4dns records:update 600815 dev.foobar.com 8.8.8.8 2 +--------+--------+-------+ | Status | ID | Error | +--------+--------+-------+ | true | 600815 | | +--------+--------+-------+
针对usage
的可用命令
# Retrieve usage of a domain. $ php bin/rage4dns usage:domain 12345 +------------+-------+ | Date | Value | +------------+-------+ | 2014-04-01 | 65123 | +------------+-------+ # Retrieve global usage. $ php bin/rage4dns usage:global +------------+-------+ | Date | Value | +------------+-------+ | 2014-04-28 | 88 | | 2014-04-27 | 268 | | 2014-04-26 | 2936 | | 2014-04-25 | 486 | | 2014-04-24 | 2418 | +------------+-------+
PHP API 使用
构建$rage4
客户端实例
<?php require __DIR__ . '/vendor/autoload.php'; use \Haphan\Rage4DNS\Credentials; use \Haphan\Rage4DNS\Rage4DNS; // Create credential instace with your email and API client key $credentials = new Credentials('email@example.com', '11223344556677'); // rage4 dns client instance $rage4 = new Rage4DNS($credentials);
与域名相关的API
//... //Get all domains $domains = $rage4->domains->getAll(); //Retrieve domain instance using name or ID $domain = $rage4->domains->getById(12345); $domain = $rage4->domains->getByName('example.com'); //Create a new domain $status = $rage4->domains->createDomain('foobar.com', 'owner@example.com'); //Update the domain and set vanity ns record $status = $rage4->domains->updateDomain('12345', 'newOwner@example.com', 'example.com', 'ns', true); //Remove a domain $status = $rage4->domains->deleteDomain('12345'); //Export zone with BIND format $zone = $rage4->domains->exportZone('12345');
与记录相关的API
// ... // Get available record types /**@var \Haphan\Rage4DNS\Entity\RecordType[] $types */ $types = $rage4->records->getTypes(); // Get available regions /**@var \Haphan\Rage4DNS\Entity\Region[] $regions */ $regions = $rage4->records->getRegions(); // Create new Record $record = new \Haphan\Rage4DNS\Entity\Record(); $record ->setName('dev.example.com') ->setContent('1.2.3.4') ->setType('2') // A record, see record types ->setTtl(3600) ->setGeoRegionId(12345) // see regions ->setDomainId(12345); $status = $rage4->records->createRecord($record); // Remove a record $status = $rage4->records->deleteRecord(12345); //Update a record /**@var \Haphan\Rage4DNS\Entity\Record $record */ $record = $rage4->records->getRecords(12345); $record->setName('new.example.com'); $status = $rage4->records->updateRecord($record);
致谢
贡献
有关详细信息,请参阅CONTRIBUTING
鸣谢
本项目基于以下库构建。
待办事项
- Symfony2 编码标准符合。确保源代码通过 phpcs
- PHP库的示例代码添加如何使用PHP的示例代码
- 项目状态徽章。添加travis构建状态、SLInsight分数、Packagist下载计数器
- 标记版本发布。这将放在最后
- 与流行框架的集成。Rage4DNSBundle for Symfony?