dns zone configurator
v1.3.0: BH-15288. Update some dependencies for php 8.2 (#39)
Pustaka Php untuk mem-parsing dan mengedit file zona dns secara terprogram dengan abstraksi tingkat tinggi.
composer require ltd-beget/dns-zone-configurator
<?php
use LTDBeget dnsconfigurator Zone ;
require ' ./vendor/autoload.php ' ;
// get you zone file content
$ content = file_get_contents ( __DIR__ . " /dns/zones/zone.conf " );
// make zone object from plain content
$ zone = Zone :: fromString ( " voksiv.ru. " , $ content );
// iterate via nodes of zone, where Node is group of resource records with same name
foreach ( $ zone -> 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. " );
jika Anda hanya ingin tokenisasi file zona, Anda dapat menggunakan perpustakaan ini
$ ./vendor/bin/phpdox
$ php phpunit.phar --coverage-html coverage
dns-zone-configurator dirilis di bawah Lisensi MIT. Lihat file LISENSI yang dibundel untuk detailnya.