Page 1 of 4 123 ... LastLast
Results 1 to 20 of 63

Thread: Connect DirectAdmin server to cPanel DNS cluster servers

  1. #1
    Join Date
    Feb 2007
    Posts
    44

    Connect DirectAdmin server to cPanel DNS cluster servers

    If you're not keen on just rsyncing whole zone files or running other daemons etc, here's a script I wrote to connect a DA server to an existing cPanel DNS cluster. It still needs further work for things in the TODO list but it is functional.

    In case there's some people that want to at least know this is easily possible if running mixed cPanel/DA servers and a cPanel cluster, it is.

    Config file is separate for easier updating.

    Code:
    cd /usr/local/directadmin/scripts/custom
    wget -O /usr/local/directadmin/scripts/custom/dns_write_post.sh https://files.netnerd.com/directadmin/dns_write_post.sh
    wget -O /usr/local/directadmin/scripts/custom/dns_write_post_config.php https://files.netnerd.com/directadmin/dns_write_post_config.php.txt
    chown diradmin:diradmin dns_write_post.sh && chown diradmin:diradmin dns_write_post_config.php
    chmod 700 dns_write_post.sh && chmod 600 dns_write_post_config.php
    Then edit dns_write_post_config.php to put in your cPanel server details, you can add as many as you like, but the checks only connect to the first one (to see if a domain exists, and get existing records, it's assumed that the DNS cluster records all match). Now creating or editing a dns zone in DA will push it to the cPanel cluster servers you defined.

    Update: V2 ready, to update just run:

    Code:
    wget -O /usr/local/directadmin/scripts/custom/dns_write_post.sh https://files.netnerd.com/directadmin/dns_write_post.sh
    The main change in v2 is that it now compares the zones first, and only deletes/adds new/changed records, which makes it a lot faster.

    TODO:
    - SOA record handling
    - TTL's
    Last edited by nick-a; 07-02-2019 at 03:11 AM. Reason: Update for v2

  2. #2
    Join Date
    Jul 2019
    Posts
    4
    Quote Originally Posted by nick-a View Post
    If you're not keen on just rsyncing whole zone files or running other daemons etc, here's a script I wrote to connect a DA server to an existing cPanel DNS cluster. It still needs further work for things in the TODO list but it is functional.

    In case there's some people that want to at least know this is easily possible if running mixed cPanel/DA servers and a cPanel cluster, it is.

    Config file is separate for easier updating.

    Code:
    cd /usr/local/directadmin/scripts/custom
    wget -O /usr/local/directadmin/scripts/custom/dns_write_post.sh https://files.netnerd.com/directadmin/dns_write_post.sh
    wget -O /usr/local/directadmin/scripts/custom/dns_write_post_config.php https://files.netnerd.com/directadmin/dns_write_post_config.php.txt
    chown diradmin:diradmin dns_write_post.sh && chown diradmin:diradmin dns_write_post_config.php
    chmod 700 dns_write_post.sh && chmod 600 dns_write_post_config.php
    Then edit dns_write_post_config.php to put in your cPanel server details, you can add as many as you like, but the checks only connect to the first one (to see if a domain exists, and get existing records, it's assumed that the DNS cluster records all match). Now creating or editing a dns zone in DA will push it to the cPanel cluster servers you defined.

    Update: V2 ready, to update just run:

    Code:
    wget -O /usr/local/directadmin/scripts/custom/dns_write_post.sh https://files.netnerd.com/directadmin/dns_write_post.sh
    The main change in v2 is that it now compares the zones first, and only deletes/adds new/changed records, which makes it a lot faster.

    TODO:
    - SOA record handling
    - TTL's
    H Nick,

    Thank you for the great work.

    I can not connect to my cpanel dns only

    Please help me with this information.

    $ns["ns1"] = array( "host" => "ns1.domain.com",'rootpw' => "rootpasswordhere");
    $ns["ns2"] = array( "host" => "ns2.domain.com",'rootpw' => "rootpasswordhere");
    ["ns1"] = I did not change

    "host" = I tested putting only domain, ip, dns primary

    "ns1.domain.com" = I put my dns from the cluster

    'rootpw' = I did not change

    "rootpasswordhere" = Root password

    I run .sh file I receive error message:

    ./dns_write_post.sh
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 39
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 40
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 56
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 57
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 73
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 74
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 86
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 87
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 88
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 98
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 99
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 109
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 110
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 121
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 123
    PHP Notice: Undefined offset: 2 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 123
    PHP Notice: Undefined offset: 3 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 123
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 242
    PHP Notice: Array to string conversion in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 134
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 276
    PHP Warning: array_reverse() expects parameter 1 to be array, null given in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 385
    PHP Warning: Invalid argument supplied for foreach() in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 387
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    PHP Notice: Undefined index: host in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 210
    thank you if you can help me

  3. #3
    Join Date
    Jun 2019
    Posts
    34
    Thank You.

    Will this work on a standalone DNS only server already running as NS2 for one of our servers?

    also do we run the script on the dnsadmin server?

  4. #4
    Join Date
    Feb 2007
    Posts
    44
    Quote Originally Posted by experttechit View Post
    Thank You.

    Will this work on a standalone DNS only server already running as NS2 for one of our servers?

    also do we run the script on the dnsadmin server?
    I've got it connected to 2x cPanel DNS only servers as we speak. Yes it runs on the DA server, using this DA functionality:

    https://www.directadmin.com/features.php?id=450

  5. #5
    Join Date
    Jun 2019
    Posts
    34
    Hi Nick,

    Sorry, I am struggeling to get it to work....

    we just want it for ns2 only, so I filled in the ns2 details, but it doesn't seem to work?

    [root@cloud01 custom]# ./dns_write_post.sh
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 39
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 40
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 56
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 57
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 73
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 74
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 86
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 87
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 88
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 98
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 99
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 109
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 110
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 121
    PHP Notice: Undefined offset: 1 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 123
    PHP Notice: Undefined offset: 2 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 123
    PHP Notice: Undefined offset: 3 in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 123
    PHP Notice: Array to string conversion in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 134
    PHP Warning: array_reverse() expects parameter 1 to be array, null given in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 385
    PHP Warning: Invalid argument supplied for foreach() in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 387

    Thanks in advance

  6. #6
    Join Date
    Jul 2019
    Posts
    1
    Hi,

    First of all thanks for the great work!

    Quote Originally Posted by experttechit View Post
    PHP Notice: Array to string conversion in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 134
    PHP Warning: array_reverse() expects parameter 1 to be array, null given in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 385
    PHP Warning: Invalid argument supplied for foreach() in /usr/local/directadmin/scripts/custom/dns_write_post.sh on line 387
    same error here. It seems that the script isn't connecting to the cPanel API, and that's why the array is empty. However the log does not seem to contain any info.

  7. #7
    Join Date
    Feb 2007
    Posts
    44
    Ok 2 things:

    - If using only 1 nameserver, put it in the ns0 details, as the checks only use ns0.

    - It sounds like you're also seeing a problem someone else had, in that directadmin isn't setting the environment variables as per

    https://www.directadmin.com/features.php?id=450

    Can you modify dns_write_post.sh so it just contains:

    printenv >> envlog.txt

    Then create a test A record, and post the contents of

    cat /usr/local/directadmin/envlog.txt

  8. #8
    Join Date
    Jun 2019
    Posts
    34
    Hi Nick,

    thanks for your help....

    - If using only 1 nameserver, put it in the ns0 details, as the checks only use ns0??

    I can't see an ns0?, do we remove ns1,ns2 and just add ns0 ?

    - It sounds like you're also seeing a problem someone else had, in that directadmin isn't setting the environment variables as per

    https://www.directadmin.com/features.php?id=450

    Can you modify dns_write_post.sh so it just contains:

    printenv >> envlog.txt

    Do we need to remove everything in this file and just add the line

    printenv >> envlog.txt ?

    Thanks again

  9. #9
    Join Date
    Jun 2019
    Posts
    8
    Hello

    I changed all this functions " $url = "

    $url = "https://yourdnsonlyhostname:2087/json-api/".$command;

    Now working well

    Quote Originally Posted by experttechit View Post
    Hi Nick,

    thanks for your help....

    - If using only 1 nameserver, put it in the ns0 details, as the checks only use ns0??

    I can't see an ns0?, do we remove ns1,ns2 and just add ns0 ?

    - It sounds like you're also seeing a problem someone else had, in that directadmin isn't setting the environment variables as per

    https://www.directadmin.com/features.php?id=450

    Can you modify dns_write_post.sh so it just contains:

    printenv >> envlog.txt

    Do we need to remove everything in this file and just add the line

    printenv >> envlog.txt ?

    Thanks again

  10. #10
    Join Date
    Jun 2019
    Posts
    8
    But doesnt create dns zone.
    Only update when we created dns zone manually.

    Quote Originally Posted by hostixo View Post
    Hello

    I changed all this functions " $url = "

    $url = "https://yourdnsonlyhostname:2087/json-api/".$command;

    Now working well

  11. #11
    Join Date
    Feb 2007
    Posts
    44
    Sorry if just using 1 nameserver, then you probably want to switch it to single curl, and delete ns2 line in config file.

  12. #12
    Join Date
    Feb 2007
    Posts
    44
    Quote Originally Posted by hostixo View Post
    But doesnt create dns zone.
    Only update when we created dns zone manually.
    This is the bit of code that should create the zone if it doesn't exist on the first nameserver, it's designed for that scenario:

    Code:
    // If zone doesn't exist, then create the default cpanel zone on cluster
    if($zone_exists == false){
      $command = "adddns?domain=".$recs_domain."&ip=".$recs_domip;
      send_to_ns($command);
    }

  13. #13
    Without going into too much debugging of the 3rd party script, the dns_write_post.sh isn't a script you just "call" from ssh.
    It must be called by DA when you do some action. Only then would all required ENV variables get filled.

    Eg:
    Admin Level -> DNS Administration -> domain.com -> add record / delete record, etc.

    Hope that helps solves some confusion. Checking a sample box, there are lines like this:
    //file_put_contents("/usr/local/directadmin/scripts/custom/cpdnslog.txt", "A records from DA: ".var_export($recs_a,true)."\n", FILE_APPEND);

    which can be un-commented (remove the // characters from the far left side, and save the file), which then gives you more logging info about what the script is getting, inside the cpdnslog.txt.


    John

  14. #14
    Join Date
    Jun 2019
    Posts
    2

    MX entry error

    Hi,

    Firstly thank you for making this script, apart from the MX record everything is working perfectly. It does error sometimes when updating but I that just seems more of a GUI timeout issue as everything still completes correctly, bar the MX record.

    MX records are being updated to just 'mail.' not 'mail.domain.com.'

    To fix update line 88
    FROM:
    $da_clean_arr[] = array('type' => 'MX', 'name' => $rec_arr[0], 'preference' => $rec2[0], 'exchange' => $rec2[1]);
    TO:
    $da_clean_arr[] = array('type' => 'MX', 'name' => $rec_arr[0], 'preference' => $rec2[0], 'exchange' => $rec2[1] . '.' . $recs_domain);

    Thanks,
    Daniel.
    https://webhostingnz.com

  15. #15
    Join Date
    Jun 2019
    Posts
    2
    Quote Originally Posted by nick-a View Post
    This is the bit of code that should create the zone if it doesn't exist on the first nameserver, it's designed for that scenario:

    Code:
    // If zone doesn't exist, then create the default cpanel zone on cluster
    if($zone_exists == false){
      $command = "adddns?domain=".$recs_domain."&ip=".$recs_domip;
      send_to_ns($command);
    }
    I can confirm that it is not adding the zone file to the cpanel DNSONLY server. To test this I created an account on the Directadmin machine and checked for the file in /var/named on the DNSONLY, it was not present. I tried to reset the zonefile in DA to force it to copy to DNSONLY, it did not.

    I have not had time to debug that bit of the code but I will in the next few days if a fix isn't posted for it.

    Kind Regards,
    Daniel.
    https://webhostingnz.com

  16. #16
    Join Date
    Mar 2017
    Posts
    18
    Quote Originally Posted by Viperdh View Post
    I can confirm that it is not adding the zone file to the cpanel DNSONLY server. To test this I created an account on the Directadmin machine and checked for the file in /var/named on the DNSONLY, it was not present. I tried to reset the zonefile in DA to force it to copy to DNSONLY, it did not.

    I have not had time to debug that bit of the code but I will in the next few days if a fix isn't posted for it.

    Kind Regards,
    Daniel.
    https://webhostingnz.com
    yes, right. I am trying to make changes in dns_write_post_config.php it same can't write to DNS only cpanel

  17. #17
    Join Date
    Feb 2007
    Posts
    44
    Quote Originally Posted by Viperdh View Post
    I can confirm that it is not adding the zone file to the cpanel DNSONLY server. To test this I created an account on the Directadmin machine and checked for the file in /var/named on the DNSONLY, it was not present. I tried to reset the zonefile in DA to force it to copy to DNSONLY, it did not.

    I have not had time to debug that bit of the code but I will in the next few days if a fix isn't posted for it.

    Kind Regards,
    Daniel.
    https://webhostingnz.com
    Hmm I've tested that functionality numerous times and it does work on my test setup, along with the MX records you mentioned earlier. What version are your DNSonly servers? I'm wondering if there's something going on with the API calls that's behaving differently, you can see for yourself that the call is correct:

    https://documentation.cpanel.net/dis...tions+-+adddns

  18. #18
    Join Date
    Jun 2019
    Posts
    34
    Hi Nick,

    we have the lastest version of cpaneldns only...

    would it be better to create an api with password, rather than the server root password?

  19. #19
    Join Date
    Feb 2007
    Posts
    44
    Rootpw vs api call doesn't make any difference, it's only the authentication method.

    V3 will be out tonight with some improvements, checks all NS instead of just first once etc, and resets zones if existing ones don't match, and SOA record update.

    I'm thinking for V4 it might be better to just parse the zone file directly, that way the script can support a CLI mode too without many alterations.

  20. #20
    Join Date
    Jul 2019
    Posts
    4

    Problems DKIM e MX

    Hello, how are you?

    I installed the script and it worked fine, but I noticed some problems.

    The MX input is not actually sent automatically. If I enter DirectAdmin and only write the MX entry, it sends it correctly, but restoring a backup for example, it is not created.

    I also noticed another problem in the DKIM key, it was created correctly in WHM DNS Only but with incorrect characters at the beginning, it looks like this:

    "("v=DKIM1;
    k=rsa;
    p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvLcJZ+gMqecHCcoxr7RTfHO9gRNCghXbX7n8m6s2yAGiMM+gojO31zWEmD5RpLD4SYIt+jN/r8cdmDgL+WExFNw"\010\009\009\009\009\009"M/2KrlYfV8bgevv5HuBHxE8QFgWHqcb8THtrlrSjEWsWW0qs/tVivAXwTAy7GBZSSkgi/0Hfei4c/y867TQSltPzVRBZav5KTBNHk14TI6ZOAbcJ5SBqeSFtWxGP+Pc9hPXacqCx/W2AaufSHwMRIZ"\010\009\009\009\009\009"uZBJiKdD1i1HlaUWKp3luGO5ce/Gj6vEUHOM4QgF3CdpZQkZrmR1ZWAp4pKtGevua+lx+Wdn2RZ1hc2/Dcd63yqSlZexhQDoma34OuK7wIDAQAB")"

    The correct one should be:

    "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvLcJZ+gMqecHCcoxr7RTfHO9gRNCghXbX7n8m6s2yAGiMM+gojO31zWEmD5RpLD4SYIt+jN/r8cdmDgL+WExFNwM/2KrlYfV8bgevv5HuBHxE8QFgWHqcb8THtrlrSjEWsWW0qs/tVivAXwTAy7GBZSSkgi/0Hfei4c/y867TQSltPzVRBZav5KTBNHk14TI6ZOAbcJ5SBqeSFtWxGP+Pc9hPXacqCx/W2AaufSHwMRIZuZBJiKdD1i1HlaUWKp3luGO5ce/Gj6vEUHOM4QgF3CdpZQkZrmR1ZWAp4pKtGevua+lx+Wdn2RZ1hc2/Dcd63yqSlZexhQDoma34OuK7wIDAQAB"

    Am I doing something wrong?

    Thanks!

Page 1 of 4 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •