https://github.com/ltd-beget/dns-zone-configurator
Php library for parsing and editing dns zones files programmatically with high level abstraction.
https://github.com/ltd-beget/dns-zone-configurator
api
Last synced: about 1 year ago
JSON representation
Php library for parsing and editing dns zones files programmatically with high level abstraction.
- Host: GitHub
- URL: https://github.com/ltd-beget/dns-zone-configurator
- Owner: LTD-Beget
- License: mit
- Created: 2016-04-04T20:53:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-12-04T14:35:40.000Z (over 1 year ago)
- Last Synced: 2025-06-22T18:08:09.371Z (about 1 year ago)
- Topics: api
- Language: PHP
- Size: 256 KB
- Stars: 22
- Watchers: 19
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dns-zone-configurator
[](https://packagist.org/packages/ltd-beget/dns-zone-configurator)
[](https://packagist.org/packages/ltd-beget/dns-zone-configurator)
[](https://scrutinizer-ci.com/g/LTD-Beget/dns-zone-configurator/?branch=master)
[](https://scrutinizer-ci.com/g/LTD-Beget/dns-zone-configurator/?branch=master)
[](https://scrutinizer-ci.com/g/LTD-Beget/dns-zone-configurator/build-status/master)
[](http://ltd-beget.github.io/dns-zone-configurator/documentation/html/index.html)
[](http://ltd-beget.github.io/dns-zone-configurator/coverage/)
[](https://github.com/LTD-Beget/dns-zone-configurator/blob/master/LICENSE)
Php library for parsing and editing dns zones files programmatically with high level abstraction.
## Installation
```shell
composer require ltd-beget/dns-zone-configurator
```
## Usage
```php
iterateNodes() as $node) {
$node->getName();
$node->getZone();
}
// or get concrete node
if($zone->isNodeExist("node.name")) {
$node = $zone->getNode("node.name");
$node->getName();
$node->getZone();
}
// also you can iterate via resource records in zone
foreach ($zone->iterateRecords() as $record) {
$record->getType();
$record->getTtl();
$record->getNode();
}
// or iterate in node
if($zone->isNodeExist("node.name")) {
$node = $zone->getNode("node.name");
foreach ($node->iterateRecords() as $record) {
$record->getType();
$record->getTtl();
$record->getNode();
}
}
// or iterate only concrete records in zone or node
foreach ($zone->iterateA() as $record) {
$record->getAddress();
$record->getType();
$record->getTtl();
$record->getNode();
}
// all records can be modified
foreach ($zone->iterateNs() as $record) {
$record->setNsdName("new.nsd.name.");
}
// or they can be deleted
foreach ($zone->iterateMx() as $record) {
$record->remove();
}
// zone can be validate
if(! $zone->validate()) {
// and if any errors, you can see them as array
$zone->getErrorsStore()->toArray();
// or can iterate via all, and remove invalid records for example
foreach ($zone->getErrorsStore()->iterate() as $error) {
if($error->isHasRecord()) {
$error->getRecord()->remove();
}
}
}
// You can print zone as string, to put in in real zone file
$content = (string) $zone;
file_put_contents(__DIR__."/dns/zones/zone.conf", $content);
// Or you can store it in array format
$array_content = $zone->toArray();
// and make zone again from array format
Zone::fromArray("voksiv.ru.", $array_content);
// also you can make zone programmatically
$zone = new Zone("voksiv.ru.");
$node = $zone->getNode("@");
$node->getRecordAppender()->appendARecord("127.0.0.1");
$node->getRecordAppender()->appendNsRecord("google.com.");
```
### Dns zone file tokenize only
if you want only tokenize zone file you can use this [library](https://github.com/LTD-Beget/dns-zone-parser)
### Developers
## Regenerate documentation
```shell
$ ./vendor/bin/phpdox
```
### Run tests
```shell
$ php phpunit.phar --coverage-html coverage
```
## License
dns-zone-configurator is released under the MIT License.
See the [bundled LICENSE file](LICENSE) for details.