Help with cPanel API and DNS Zones
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.
-
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 ' 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 '
addit='.$addit;
0 -
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; [COLOR="silver">- - - 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 0 -
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? 0 -
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! 0 -
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. 0 -
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.
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.0 -
Could you verify if the "Advanced DNS Zone Editor" feature is enabled for the feature list associated with this account's package?
Yes, "Advanced DNS Zone Editor" is enabled.0 -
Note: I am using WHM's account credentials, not WHM's root credentials.
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.0 -
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.
I am using cPanel Account.0 -
I am using cPanel Account.
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.0
Please sign in to leave a comment.
Comments
11 comments