Api2 delsubdomain does not remove DNS entries?
Hi. Newbie here.
I have some PHP code that will create as well as delete a SubDomain. The create seems to work properly, but I am finding that the delete subdomain does not remove the DNS A records (subdomain.example.com and www.subdomain.example.com).
The create code will properly create a subdomain that is viewable in cPanel via the SubDomains tool. After running the delete subdomain code, the subdomain is no longer shown in the SubDomains tool, but the DNS records still exist as viewed in the Simple (or Advanced) DNS Zone Editor. Any attempt to again create the subdomain (via cPanel GUI or code) results in error.
When deleting a SubDomain do I have to also delete the DNS records? (I find that strange).
Or is there something wrong with the my code (the API says it is successful)
Or is there something wrong with the server setup (probably harder to figure out)
Or is this a cPanel API bug?
Advice appreciated.
This is the php delete code:
[PHP]
$xmlapi = new xmlapi($host);
$xmlapi->set_port(2083);
$xmlapi->password_auth($user, $pwd);
$xmlapi->set_output('json');
//$xmlapi->set_debug(1);
$cpResponse = 1;
try {
$result = $xmlapi->api2_query($user,
"SubDomain", "delsubdomain",
array(
'domain' => "$subdomain.example.com"
)
);
} catch (Exception $e) {
$cpResponse = 0;
$errorMsg = $e->getMessage();
$msg[] = "ERROR - cPanel SubDomain Delete exception >$errorMsg<";
$error = true;
}
if ($cpResponse) {
$result = json_decode($result, true);
// result: boolean 1=success, 0=failed
// reason: string msg of success or reason for failure
//$msg[] = "delsubdomain Response:" . print_r($result, true) . "\n";
if ($result["cpanelresult">["data">[0]["result"> != 1) {
$reason = $result["cpanelresult">["data">[0]["reason">;
$msg[] = "ERROR - cPanel SubDomain Delete Failed >$reason<";
$error = true;
} else {
$msg[] = "cPanel SubDomain Deleted";
}
}
[/PHP]
Thanks.
ds00424
-
Hello, I'm able to successfully delete a subdomain using the SubDomain::delsubdomain cPanel API 2 function: # cpapi2 --user=cptest01 SubDomain delsubdomain domain=twothree.cptest01.com --- cpanelresult: apiversion: 2 data: - reason: "Bind reloading on release using rndc zone: [cptest01.com]\nThe subdomain "twothree.cptest01.com" has been removed." result: 1 event: result: 1 func: delsubdomain module: SubDomain
Have you tested this function using the command line instead of the script to verify if the issue is isolated to your custom PHP script? Thank you.0 -
Thanks for the reply. The API in the posted code returns successfully (result == 1). After it's execution, looking at the cPanel GUI Subdomains tool the subdomain is no longer listed. However, some (not all) of the subdomain's DNS records still exist as viewed Advanced DNS Zone Editor tool (IIRC, subdomain.example.com and www.subdomain.example.com are still listed). Without deleting these subdomain DNS entries, any attempt to again create the subdomain (via cPanel GUI or code) results in error. Steps to reproduce (apologies for not posting this initially): - ]
- Create a Subdomain (cPanel GUI or programmatic). See that several DNS records have been created (subdomain.example.com, www.subdomain.example.com, cpcalendars.subdomain.example.com, webdisk.subdomain.example.com, cpcontacts.subdomain.example.com)
- Delete the subdomain using the api2 interface (as shown in posted PHP code). See that the api result is all good.
- Via the cPanel GUI SubDomains tool, see that the subdomain is no longer listed
- Via the cPanel GUI Advanced DNS Zone Editor tool, see that subdomain.example.com and www.subdomain.example.com still exist
- Via the cPanel GUI Subdomains tools create subdomain.example.com - see that this action fails.
0 -
Sorry, been busy with a project. I see: "cPanel Version 56.0 (build 22)" as well as "cPanel Pro 1.0 (RC1)" Created foobar.example.com via cpanel GUI Deleted foobar subdomain via PHP Still see www.foobar.example.com and foobar.example.com in Advanced Zone editor error_log addition during the event: ======================= ==> cpsrvd 11.56.0.22 started ==> cpsrvd: loading security policy....Done ==> cpsrvd: Setting up native SSL support ... Done ==> cpsrvd: transferred port bindings ==> cpsrvd: bound to ports ======================= HTH Will try cli later or tomorrow. For now my code will not only delete the subdomain but then delete the zones that remain. I don't like the zone delete, as it is by line and must be requeried after each delete. Plus this is not threadsafe (or multiprocess safe) due to need to query/delete. I respectfully request the ZoneEdit:remove_zone_record api be by Name and not line number. That would make things more straight forward and safe. Thanks for looking into this. Much appreciated. 0 -
Deleting via CLI give same result as posted cpapi2 --user=cpuser SubDomain delsubdomain domain=foobar.example.com
Give successful result:cpanelresult: apiversion: 2 data: - reason: The subdomain "foobar.mydbcx.net" result: 1 event: result: 1 func: delsubdomain module: SubDomain
Via Subdomains tool, foobar.example.com is not shown However, via Advanced Zone Editor, foobar.example.com and www.foobar.example.com remain Now here is a thought. (This may be a red herring) When this VPS was originally set up, the hosting provider set the account and cpanel user to (something like) "businessna6". For various reasons I won't get into, I asked them to change it to "businessname". Instead they led me thru steps creating another cpanel account named "businessname" that can control the system and along the way set a temp domain name (I think for busnessna6 - but it was over a year ago). All of my cpanel actions have been using cpuser "businessname" So I tried: Via the cpanel "businessname" account, created foobar.example.com via CLI with cpuser "businessna6" delete subdomain I get lots of error output and an api return of:cpanelresult: apiversion: 2 data: - reason: subdomain 'foobar.example.com.example-temp.com' does not exist for user 'businessna6' result: 0 error: subdomain 'foobar.example.com.example-temp.com' does not exist for user 'businessna6' event: result: 1 func: delsubdomain module: SubDomain
Again, I do not know if this is relevant to the issue at hand, but thought I would mention it as it is probably different than the norm. Thanks.0 -
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 -
Hello @ds00424, I've not seen any additional feedback to this thread. I'm marking this thread as resolved, however feel free to let us know if you require additional assistance, or to let us know the ticket number of the ticket you opened. Thank you. 0
Please sign in to leave a comment.
Comments
7 comments