Comments (10)
Yeah, this is the sample that I want. I understand now.
Thank you for creating this amazing package 💯
from powerdns-php.
where there are content, priority, port and weight?
You can pass them as content, separated with a space in the same way as with MX records:
$zone->create('some-record', RecordType::SRV, '100 1 443 example.com.', 3600);
from powerdns-php.
Hi @arislanhaikal,
Unfortunately, it is not possible to add an NS record without sending the existing ones also. The reason for this is that the NS records in fact is just one 'record' ('resource set') with multiple values as content and not three (or two) separate records.
For more information you can look at #44 and #37. Please let me know if you still have questions about this, and I'll look if I can give you some examples.
from powerdns-php.
Ahh i see. I understand now, if the NS records in fact is just one record.
How about delete one record? like the sample above, suppose I want to delete ns3.example.com
.
I have to send 2 ns (ns1, ns2) to save only, or can I use unset record?
I saw the post on #43 . But but I still don't understand how to delete unwanted arrays. Can you provide an example of how to delete it?
Sorry my question is too stupid, i am a newbie :)
Thank for your answer @trizz
from powerdns-php.
Sorry my question is too stupid, i am a newbie :)
No worries, we've all been there.
How about delete one record? like the sample above, suppose I want to delete ns3.example.com.
I have to send 2 ns (ns1, ns2) to save only, or can I use unset record?
Yes, you need to update with ns1/ns2 as value. Below you'll find three examples: first create a new zone with ns1/ns2, next add another value for ns3 and after that remove ns2. As you can see it is a matter of updating an array with the data you want.
If things are still unclear, just let me know!
use Exonet\Powerdns\Powerdns;
use Exonet\Powerdns\RecordType;
use Exonet\Powerdns\Resources\Record;
use Exonet\Powerdns\Resources\ResourceRecord;
use Exonet\Powerdns\Resources\ResourceSet;
$domain = 'ns-example.id';
// Update the key to the real PowerDNS API Key.
$powerdns = new Powerdns('127.0.0.1', 'very_secret_secret');
// Uncomment this line if you want to run this example multiple times.
// $powerdns->deleteZone($domain);
/***************************************************************
* Create a new zone with the defined records and name servers.
*/
$zone = $powerdns->createZone($domain, ['ns1.example.com.', 'ns2.example.eu.']);
displayNsContents($zone->get(RecordType::NS));
/***************************************
* Add an extra item to the NS records.
*/
$resourceSets = $zone->get(RecordType::NS);
foreach ($resourceSets as $resourceSet) {
$records = $resourceSet->getRecords();
// $records is a plain array consisting of Record classes for each record.
// You can do with this array whatever you want. Add items, remove items, update items, etc.
$records[] = (new Record())->setContent('ns3.example.io.');
// After you've changed the array to your liking, you need to replace the existing ones:
$resourceSet->setRecords($records);
// And save the resource set:
$resourceSet->save();
}
displayNsContents($zone->get(RecordType::NS));
/**************
* Remove ns2
*/
$resourceSets = $zone->get(RecordType::NS);
foreach ($resourceSets as $resourceSet) {
$records = $resourceSet->getRecords();
foreach ($records as $index => $record) {
if ($record->getContent() === 'ns2.example.eu.') {
unset($records[$index]);
}
}
$resourceSet->setRecords($records);
$resourceSet->save();
}
displayNsContents($zone->get(RecordType::NS));
/**
* Little helper function to display the data.
*/
function displayNsContents(ResourceSet $nsResourceSet)
{
/** @var ResourceRecord $nsResource */
foreach ($nsResourceSet as $nsResource) {
echo "\n".$nsResource->getName();
foreach ($nsResource->getRecords() as $record) {
echo "\n ".$record->getContent();
}
}
echo "\n\n";
}
The expected output of this script:
ns-example.id.
ns1.example.com.
ns2.example.eu.
ns-example.id.
ns1.example.com.
ns2.example.eu.
ns3.example.io.
ns-example.id.
ns1.example.com.
ns3.example.io.
from powerdns-php.
Hi @trizz
May I ask again?
How do I remove a different name, while the type and content are the same.
Ex.
Name | Type | Status | TTL | Data |
---|---|---|---|---|
ftp | CNAME | Active | 3600 | example.com. |
www | CNAME | Active | 3600 | example.com. |
CNAME | Active | 3600 | example.com. |
I want remove mail. Can i use unset as you demonstrated?
And how to add an extra item to the CNAME records, with some content but different name?
Its make me confused.
Sorry I ask many questions.
from powerdns-php.
No, in this case it works differently. An important thing to remember is that, for PowerDNS, the "unique" is the combination of name and type. In case of the NS records, the name and type are the same, so the content is in a single resource set. In the case of this CNAMEs, the combination mail
and CNAME
is unique, so you can remove it like this:
$zone->find('mail', RecordType::CNAME)->delete();
Creating a new CNAME with the same content, but another name is the same as adding a new record, because the name/type combination does not exist yet:
$zone->create('some-record', RecordType::CNAME, 'example.com.', 3600);
$zone->create('another-record', RecordType::CNAME, 'example.com.', 3600);
from powerdns-php.
Oh i sorry about that, so other than NS what is in the content is in a single resource set? MX?
What it all depends on the conditions. And I have to manually check with find
whether it already exists or not, if it already exists, it means using single resource set, if there does not exist, with create
method. Its that true?
from powerdns-php.
so other than NS what is in the content is in a single resource set? MX?
In theory, it can be for every record, for example an A record with two different IPs. But that isn't used much, so usually NS and MX records.
What it all depends on the conditions. And I have to manually check with find whether it already exists or not, if it already exists, it means using single resource set, if there does not exist, with create method. Its that true?
I'm not sure that I understand what you mean. But yes, it depends on the conditions. You need to check if the name/type combination is unique, otherwise you'll overwrite existing data.
from powerdns-php.
Thank you very much for your explanation. I'm actually learning about the DNS system.
One more thing, can you give a sample how to create an SRV record type, where there are content, priority, port and weight?
Hopefully in the future I can learn a lot from you. Don't get bored if I often ask LOL.
Thanks again 🙏🏻
from powerdns-php.
Related Issues (20)
- Problem adding TXT record. HOT 2
- Can't add two Records with same name
- Compatibility with psr/log 3.0 HOT 2
- How to create additional records for the same subdomain
- How to delete one specific record
- cannot delete an MX record
- No SOA found for domain
- Accept zone name in `find`
- Delete metadata SOA-EDIT HOT 1
- listZones() parameter $omitDnssecAndEditedSerialFields is inverted
- Support all "Unknown" DNS Resource Record (RR) Types HOT 1
- Second (optional) argument of an Exception is its code, not debug variables HOT 1
- On another note: I don't think it's very friendly to have the syntax for the `Zone->create` method in mind (with the comments double array and stuff. If it's ok I would like to introduce the alternative of passing in the Objects (e.g. a ResourceRecord-Instance and an array of Comment-Instances). Let me know if that's something that would be approved
- SearchResult fails on zone and comment results HOT 1
- Bulk zone create HOT 1
- Question: `put` a full array of rrset changes to zone HOT 3
- Hardcoded PDNS port HOT 2
- More human readable output HOT 5
- cURL error 28: Failed to connect to xxx.xxxxx.xxx port 8081: Connection timed out HOT 1
- Manipulation of records for the zone HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powerdns-php.