GithubHelp home page GithubHelp logo

Comments (10)

arislanhaikal avatar arislanhaikal commented on July 18, 2024 1

Yeah, this is the sample that I want. I understand now.

Thank you for creating this amazing package 💯

from powerdns-php.

trizz avatar trizz commented on July 18, 2024 1

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.

trizz avatar trizz commented on July 18, 2024

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.

arislanhaikal avatar arislanhaikal commented on July 18, 2024

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.

trizz avatar trizz commented on July 18, 2024

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.

arislanhaikal avatar arislanhaikal commented on July 18, 2024

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.
mail 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.

trizz avatar trizz commented on July 18, 2024

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.

arislanhaikal avatar arislanhaikal commented on July 18, 2024

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.

trizz avatar trizz commented on July 18, 2024

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.

arislanhaikal avatar arislanhaikal commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.