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.

bulk addon domain removal

Discussion in 'cPanel Developers' started by eville84, Jul 12, 2010.

  1. eville84

    eville84 Member

    Joined:
    Jul 20, 2005
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Does anyone know of an easy method to remove multiple addon domains in bulk? I have over 5000 domains added to an account and need to remove them.

    I have looked at the API and even downloaded, XML API PHP Class. After reviewing these, i still can not figure it out. (i looked at xmlapi.php and unfortunately a bulk addon domain function was not there)

    Because of all the connecting parts involved with addon domains, I do not want to bother using a hacked together method.

    Does anyone know of some api code that makes this easy?
     
  2. eville84

    eville84 Member

    Joined:
    Jul 20, 2005
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    bump --> anyone at cpanel staff know???
     
  3. Miraenda

    Miraenda Well-Known Member

    Joined:
    Jul 28, 2004
    Messages:
    242
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Coralville, Iowa USA
    I don't know in the API, but I can give you the steps to do it manually on the backend.

    Code:
    cd /var/cpanel/users
    cp username username.bak
    vi username
    In that file, remove the DNS lines for the addon and sub domains. If you are using vi, you can do 1000dd and remove 1000 lines at a time. Having made a backup of the file before editing it ensures that, if you make a mistake, everything will be restorable.

    After you've removed the domains you want out of the file, you can reload the userdomains to wipe out those domains:

    Code:
    /scripts/updateuserdomains
    Next, you need to remove the entries for Apache in the /var/cpanel/userdata/username folder:

    Code:
    cd /var/cpanel/userdata/username
    cp main main.bak
    vi main
    In that file, you can remove all of the addon and subdomains you want to be gone, then save the file. Again, there's a backup being made if there were any issues.

    You'd also want to move the subdomain.domain.com files out of that folder. It is probably easiest to just make a copy of the folder and copy the main file and the main domain and any other domains you still want into the new folder, then make that new folder the one you are using.

    After you've made those changes, you'd simply need to rebuild Apache:

    Code:
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak100713
    /scripts/rebuildhttpdconf
    /etc/init.d/httpd restart
    While the above might seem complicated, it's a lot faster than removing each of those addons one by one in cPanel for that many domains.

    One more area you might want to remove are the DNS zones. Those are in /var/named/ location with addondomain.com.db as the name for each addon domain name. Those are a lot more difficult to remove. If you aren't wanting to re-add these domains anywhere, you could just leave the DNS zones there. Otherwise, I really don't suggest removing zones manually. You'd want to go into the WHM interface and delete the domains in Delete DNS Zone area (you can delete multiple zones at once there by selecting all the domains to remove by highlighting each one).

    I apologize that I don't know a way in the API to do this for you. I considered answering this yesterday, but I wasn't sure if you'd want this type of method to do it. If not, that's understandable of course. I only am replying so you get some sort of response on at least one other way to do it other than using cPanel.
     
    #3 Miraenda, Jul 13, 2010
    Last edited: Jul 13, 2010
  4. cPanelCraig

    cPanelCraig Member
    Staff Member

    Joined:
    Apr 29, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    You will need to use two API calls:

    AddonDomain::listaddondomains
    AddonDomain::deladdondomain

    You can then use a loop like the following:

    Code:
    // get addon domain list
    $addons = $xmlapi->listaddondomains($cpuser);
    
    // walk the list of addons
    foreach ($addons->data as $addon) {
      // we need the domain and subdomain for deladdondomain
      $domain = (string) $addon->domain;
      $subdomain = (string) $addon->subdomain;
      // call AddonDomain::deladdondomain using an API2 entry
      $result = $xmlapi->api2_query($cpuser, "AddonDomain", "deladdondomain", array("domain" => $domain, "subdomain" => $subdomain));
      print "$domain => $subdomain: " . $result->data->reason . "\n";
    }
    
    You will need to authenticate in the script before this code. What the loop above does is iterate through all the addon domains for the $cpuser account. Gets the required information that needs to be passed to deladdondomain and then calls into the API to remove the addon.

    As always, make sure you have good backups before you do this.

    The usual disclaimers about data loss, corruption and damages apply here. If you use this code you acknowledge that you are assuming all liability.
     
  5. stevenbennett

    stevenbennett Registered

    Joined:
    Jul 28, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I'm in the process of doing something similar here, more for adding domains in bulk than removing them, although we'd like to be able to do both.

    The APIs you list here are useful to the purpose, and we'll be using them for now, but it would be *really* nice to have something which can do multiple domains in a single call (in both directions) for the future. Right now it takes a very long time for each individual domain to be added or deleted (on the order of a couple of seconds each -- when we're talking *lots* of domain names, that really adds up...). Consider this a request...

    The other thing I'd like to do is some bulk editing of addon domains, changing the home directory each one points to. I don't see any way of doing that currently short of deleting the addon and re-adding it back again with the changed setting. Is that correct?
     
  6. eville84

    eville84 Member

    Joined:
    Jul 20, 2005
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    i added all the domains using imacros. a pain, but it did automate things.
     
Loading...

Share This Page