metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
214 stars 159 forks source link

Change Nameservers #221

Closed swartjie closed 4 years ago

swartjie commented 4 years ago

Hey Guys,

Ok so I'm adding a few functions to simply add, update & remove private nameservers with IP's... Can you please advise how to address it properly?

I have the below code for adding the NS record with the IP address... But I am completely unsure of how to update the NS to remove the old NS IP record and add the new one on change... Can you please advise?

function AddPrivateNameserver($domainname, $nameserver, $ipaddress) {
        $response = null;
        try {
            $domain = new eppDomain($domainname);

            $add = new eppDomain($domainname);
            $add->addHost(new eppHost($nameserver, $ipaddress));

            $update = new eppUpdateDomainRequest($domain, $add, null, null, true);

            if ($response = $this->conn->request($update)) {
                return true;
            }
        } catch (eppException $e) {
            throw new \Exception($e->getMessage());
            if ($response instanceof eppUpdateDomainResponse) {
                throw new \Exception($response->textContent);
            }
        }
    }
metaregistrar commented 4 years ago

With a nameserver change, you also have to remove the old ones.

So first do a domain:info, get the old nameservers, check if they are not the same as the new ones, and then remove the old ones and add the new ones.

Example code can be found here: https://github.com/metaregistrar/php-epp-client/blob/master/Examples/modifydomain.php

swartjie commented 4 years ago

Hey Bud,

if I add the code below to my function (it's from your example), I still get the error message that the glue records cannot be modified since the domain being updated don't own the glue records...

it seems as though the command tries to update the glue for some reason?

if (is_array($nameservers)) { / @var Metaregistrar\EPP\eppInfoDomainResponse $response / $oldns = $response->getDomainNameservers(); if (is_array($oldns)) { if (!$del) { $del = new eppDomain($domainname); } foreach ($oldns as $ns) { $del->addHost($ns); } } }

Error message: Error 2303: No glue can be associated with delegated host 'ns1.mynameserver.tld'

swartjie commented 4 years ago

Ok so what I noticed was... If the ns has glue on them, as all nameservers would, and it returns the record with an IP address as part of the ns record, The update fails and gives the above error...

What I did see was if I change the function to the one below, it does succeed. Please let me know if this is recommended or not.

One big issue I have though, What if the domain has glue on it? If the ns records is created it will then wipe the glue? Is there a better way of doing it?

// If new nameservers are given, get the old ones to remove them
                if (is_array($nameservers)) {
                    /* @var Metaregistrar\EPP\eppInfoDomainResponse $response */
                    $oldns = $response->getDomainNameservers();
                    if (is_array($oldns)) {
                        if (!$del) {
                            $del = new eppDomain($domainname);
                        }
                        foreach ($oldns as $ns) {
                            $del->addHost(new eppHost($ns->getHostname()));
                        }
                    }
                }
metaregistrar commented 4 years ago

Your change makes sense - the additional eppHost information (ip addresses and such) should not be part of the addHost command. I have amended the code in the repository.

When a domain name has glue records on them, it is always a big issue - you cannot delete these nameservers until all the domain names that use the nameservers have been updated not to use the nameservers any more. And you cannot delete the domain name before all the glue records have been deleted.

I have had this issue with Verisign last month, and they gave me a good solution: change the glue records nameserver names to another domain name (one you are not going to update/delete). Then you are able to remove nameservers and update or remove the domain name.