Jump to content

setting default DNS for each registrar


dewdropz

Recommended Posts

Heya dewdropz,

You could use the PreDomainRegister hook to change the nameservers associated with the domain based on an array before its registered e.g.

$registrars = [
	'ResellerClub' => [
		'ns1' => 'ns1.domain.tld',
		'ns2' => 'ns2.domain.tld',
		'ns3' => 'ns3.domain.tld',
		'ns4' => 'ns4.domain.tld'
	]
];

If you need me to write a hook, just let me know what Registrars and nameservers you need, can PM me in private if you wish.

Link to comment
Share on other sites

  • 2 weeks later...

Hi dewdropz,

So I don't have the modules for Epik or ConnectReseller, however you just need to amend the values in the arrays below.

Create a file in your /includes/hooks/ folder and paste the following code:

<?php

use WHMCS\Database\Capsule;

if (!defined('WHMCS')) {
    die('You cannot access this file directly.');
}


function pre_register_nameservers($vars) {
   
    $registrars = [

        'resellerclub' => [
            'ns1' => 'ns1.test.com',
            'ns2' => 'ns2.test.com',
            'ns3' => '',
            'ns4' => '',
        ],

        'connectreseller' => [
            'ns1' => 'ns3.test.com',
            'ns2' => 'ns4.test.com',
        ],

        'epik' => [
            'ns1' => 'ns5.test.com',
            'ns2' => 'ns6.test.com',
            'ns3' => 'ns7.test.com',
        ],

    ];

    /* ------------------------------------------------- */
    /*        ONLY EDIT VARIABLES ABOVE THIS LINE        */
    /* ------------------------------------------------- */

    $domain = $vars['params']['domain'];
    
    $domainDetails = Capsule::table('tbldomains')->where('domain', $domain)->first();

    foreach ($registrars as $registrar => $nameservers) {
        
        if ($domainDetails->registrar != $registrar) {
            continue;
        }

        if (empty($nameservers)) {
            continue;
        }

        $nameservers = array_reverse($nameservers);

        $nameservers['domainid'] = $domainDetails->id;

        $command = localAPI('DomainUpdateNameservers', array_reverse($nameservers));

        if ($command['result'] == 'error') {
            logActivity("Automatic nameserver assignment failed for {$domain} with error: {$command['error']}", $domainDetails->userid);
        }

    }

}

add_hook('AfterRegistrarRegistration', 1, 'pre_register_nameservers');

Edit the nameserver arrays as required, you don't need to include all nameservers, just the ones you wish to update. (Though I'd suggest defining them all and leaving the ones that are not needed blank)

I've left in resellerclub as an example, you will need to update the names for epik and connectreseller if they are not correct. I don't have the modules so am unsure what they are called. However if you look up the tbldomains database table, the correct names will be listed under the registrar column.

You will obviously need to update the nameservers also, I've just left them in as an example.

Edited by leemahoney3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated