The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with cPanel API and DNS Zones

Discussion in 'cPanel Developers' started by mwachtmann, Feb 22, 2014.

  1. mwachtmann

    mwachtmann Registered

    Joined:
    Feb 22, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I'm trying to find an example script "end to end" in php that will use the cpanel API to add/modify/delete DNS zone records.

    I think I've found all the "pieces" but I can't get an end to end script running that works.

    I know it can be done with perl/cgi script, but prefer PHP.

    Can anybody point me in the right direction where I might find a working example in PHP.

    Thanks.
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. mwachtmann

    mwachtmann Registered

    Joined:
    Feb 22, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    This was very helpful. Thank you. I was able to get a listing out of all of the zone files with your assist. Next I was trying to add a new subdomain to an existing zone file. I used the following code. I don't get any error messages of any kind (blank page), but it doesn't create the subdomain A record. Thought I might get an assist on what I'm doing wrong.

    Tried it this way:

    include '../phpinclude/xmlapi.php';

    $ip = '192.168.1.1';
    $domain = "somedomain.com";
    $name = "subdomain";
    $type = "A";
    $address = "192.168.1.1:2174";
    $ttl = 60;

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root","rootpassword");
    $xmlapi->set_http_client('curl');
    $xmlapi->set_port(2086);
    $xmlapi->set_debug(1);

    $addit = $xmlapi->adddns($domain, $name, $type, $adddress );
    print '<p>addit='.$addit;



    And as the github example shows:

    include '../phpinclude/xmlapi.php';

    $ip = '192.168.1.1';
    $domain = "somedomain.com";
    $name = "subdomain";
    $type = "A";
    $address = "192.168.1.1:2174";
    $ttl = 60;

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root","rootpassword");
    $xmlapi->set_http_client('curl');
    $xmlapi->set_port(2086);
    $xmlapi->set_debug(1);

    $addit = $xmlapi->adddns($domain, $ip );
    print '<p>addit='.$addit;
     
  4. mwachtmann

    mwachtmann Registered

    Joined:
    Feb 22, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    OK. Continuing to make progress but stuck

    When I execute the code below:

    $xmlapi = new xmlapi($ip);
    $xmlapi->set_host("192.158.1.1");
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_debug(1);
    $xmlapi->set_output('json');


    echo $xmlapi->api2_query($account, "ZoneEdit", "add_zone_record" , array($domain, $subdomain, $type, $ipaddr, $ttl));

    If I set $account = "root", I throw the exception:

    "SSL read: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac, errno 0"


    If I set $account = "domain.com" of the zone file I'm trying to add the record to: receive:

    You do not have permission to read the zone for :


    So it appears that root is the way to go. But can't find anything that helps me with the error code. Followed the api2 example for adding a pop email account so pretty sure the array submitted with the request is correct. Here are those variable assignments:

    $account = "root";
    $domain = 'domain.com';
    $subdomain = 'subdomain.';
    $type = 'A';
    $ipaddr = '192.158.1.1';
    $ttl = 60;

    - - - Updated - - -

    Correction. I'm setting $account = "cpuser" to the userid of the cpanel account that owns the zone file, not what is below.

    If I set $account = "domain.com" of the zone file
     
  5. mwachtmann

    mwachtmann Registered

    Joined:
    Feb 22, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Turning into a saga here. Looks like you can't use the root user. It can't get the proper hash.

    So when using the cPanel id, for the zone I'm working on (the cPanel ID is the owner of the zone). I can do the following commands w/o issue:

    fetch_cpanel_generated_domains
    fetchzones

    As soon as I try any command that needs to do something differently like:

    resetzone
    add_zone_record

    Get the error: statusmsg: "You do not have permission to read the zone for : "

    Receive this error with doing it through a PHP script, or when using the cPanel API shell from within cPanel so it is some configuration issue. All the research I did shows there was a problem a couple years back. Have tried changing several things such as making sure the account was a "reseller".

    Anybody point me at what is wrong with the settings on the cPanel account that will resolve this error?
     
  6. Aaqib Khan

    Aaqib Khan Registered

    Joined:
    Jan 6, 2016
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Pakistan
    cPanel Access Level:
    Root Administrator
    I am also receiving error "You do not have permission to read the zone for" when I use function remove_zone_record of cPanel API 2.
    However, add_zone_record function for ZoneEdit module is working fine.

    Note: I am using WHM's account credentials, not WHM's root credentials.

    Can someone help me out??? I am unable to find any solution. :(

    Thank you!
     
  7. jaysonng

    jaysonng Registered

    Joined:
    Jan 18, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Philippines
    cPanel Access Level:
    Reseller Owner
    did you find out the error on this one? all i can think off is that you're on a shared hosting provider and somehow don't have access to do those.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Could you verify if the "Advanced DNS Zone Editor" feature is enabled for the feature list associated with this account's package? It's configured via:

    "WHM Home » Packages » Feature Manager » Edit Feature List"

    It's required if you authenticate as the cPanel user when using this API function.

    Thank you.
     
  9. Aaqib Khan

    Aaqib Khan Registered

    Joined:
    Jan 6, 2016
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Pakistan
    cPanel Access Level:
    Root Administrator
    Yes, "Advanced DNS Zone Editor" is enabled.
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Is the zone owned by this account username? Try authenticating as the cPanel account username the zone is added under to see if the issue persists.

    Thank you.
     
  11. Aaqib Khan

    Aaqib Khan Registered

    Joined:
    Jan 6, 2016
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Pakistan
    cPanel Access Level:
    Root Administrator
    I am using cPanel Account.
     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    I'm unable to reproduce this issue. Could you open a support ticket using the link in my signature so we can take a closer look? You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
Loading...

Share This Page