Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Example perl code that uses AddonDomain or equilvanent

Discussion in 'cPanel Developers' started by esotericbyte, Nov 22, 2011.

  1. esotericbyte

    esotericbyte Registered

    Sep 24, 2010
    Likes Received:
    Trophy Points:
    Example code using AddonDomain perl package

    I am looking for examples that use the AddonDomain:: module.
    Preferably one that uses each function

    I am looking for a fully functional script that properly authenticates, demonstrates best practices and does reasonable housekeeping, lists domains, deletes a domain and ads a domain. I am very excited to learn the cpanel API, andthis is a good starting point.

    Other issues and questions:
    What other API functions are complementary to these?
    How do these calls affect the directory associated with adon domain if it already exists, if it does not exist?
    What specifically should be backed up and / or journaled by a script prior to these calls so that they are reversed?
    Is the Apache configuration regenerated after each call ? Does this disrupt or cause Apache to reset when these calls are made?

    I am writing a script that consolidates sites from several users into one user.
    I'd like to make it use an alternative subdomain to test a copy of the sites in the new location before removing the original site.
    I have a map between sites and users already in a python script that It can format and write to a file to pass off to the perl script code. The python code generates a bash script to create the new directories if needed and copy and synchronize them.

    I plan to use a subdomain as the top level of the new user and make a simple dummy site so the public_html directory just contains folders to the separate sites.

    John Hall
    Web Developer
    #1 esotericbyte, Nov 22, 2011
    Last edited: Nov 23, 2011
  2. cPanelDavidN

    cPanelDavidN Integration Developer

    Dec 17, 2009
    Likes Received:
    Trophy Points:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Just so you know, you don't have to use Perl!

    The API documentation for the API modules/functions might look Perl specific but that's because the API functions usually correlate to a specific subroutine in the depths of the cPanel architecture. If you intend to have you script work outside the cPanel runtime process (ie, a website of your cPanel account (served via Apache), a standalone script, or on a different box) then you will need to make you calls using the XML/JSON API. The XML/JSON will let you perform cPanel API1/2 calls. You can use whatever language you want to create, send, and handle this remote HTTP request.

    If the various APIs available on a cPanel & WHM system start to make you dizzy, checkout this Intro Blog Article.

    There are two different PHP client classes (a simple or intricate library) and a Perl client module & namespace, all of which were authored by inhouse staff. Each of these have various examples with them. The purpose of these clients is to do the heavy lifting (the URL argument structure and the authentication headers) and provide a simple interface for making these calls.

    Best Regards,
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice