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.

Api2 delsubdomain does not remove DNS entries?

Discussion in 'cPanel Developers' started by ds00424, Jun 1, 2016.

Tags:
  1. ds00424

    ds00424 Member

    Joined:
    Apr 10, 2015
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Internet
    cPanel Access Level:
    Root Administrator
    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($resulttrue);
                    
    // 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";
                    }
                }
    Thanks.
    ds00424
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

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

    I'm able to successfully delete a subdomain using the SubDomain::delsubdomain cPanel API 2 function:

    Code:
    # 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.
     
  3. ds00424

    ds00424 Member

    Joined:
    Apr 10, 2015
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Internet
    cPanel Access Level:
    Root Administrator
    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):
    1. 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)
    2. Delete the subdomain using the api2 interface (as shown in posted PHP code). See that the api result is all good.
    3. Via the cPanel GUI SubDomains tool, see that the subdomain is no longer listed
    4. Via the cPanel GUI Advanced DNS Zone Editor tool, see that subdomain.example.com and www.subdomain.example.com still exist
    5. Via the cPanel GUI Subdomains tools create subdomain.example.com - see that this action fails.
    (If you like, I can go thru the above steps and post results/data/images.)


    If the subdomain delete is executed from the cPanel GUI Subdomains tool, all is good.

    I am not familiar with the command line. Will it use the api2 interface?

    BTW, The posted php is pretty vanilla, follows the docs (AFAICT), and returns a successful result.

    Thanks.
    ds00424
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Yes, the command line method uses the same function. It's documented at:

    https://documentation.cpanel.net/display/SDK/cPanel+API+2+Functions+-+SubDomain::delsubdomain

    I've been unable to reproduce this issue on cPanel 56 or cPanel 58 using the steps you provided. Could you let us know which version of cPanel is installed on this system? Also, do you notice any output to /usr/local/cpanel/logs/error_log when removing the subdomain?

    Thank you.
     
  5. ds00424

    ds00424 Member

    Joined:
    Apr 10, 2015
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Internet
    cPanel Access Level:
    Root Administrator
    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.
     
  6. ds00424

    ds00424 Member

    Joined:
    Apr 10, 2015
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Internet
    cPanel Access Level:
    Root Administrator
    Deleting via CLI give same result as posted
    Code:
    cpapi2 --user=cpuser SubDomain delsubdomain domain=foobar.example.com
    Give successful result:
    Code:
    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:
    Code:
    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.
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page