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.

Creating Sub Domains With External Scripts?

Discussion in 'cPanel Developers' started by Patrick_M, Mar 31, 2008.

  1. Patrick_M

    Patrick_M Registered

    Joined:
    May 9, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    Ever since my host has upgraded our cpanel version to the latest
    build, my sub-domain creation php script no longer works!

    I've been reading the docs here and on these forums for hours
    now, but cannot find anything specifically on this subject.

    Here's an example of the old code that used to work for me:

    PHP:
    $request "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
    $result subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
    There were other ways that use to work as well such as the way
    "WHMSUBS" original script use to handle creating sub domains.

    Non of these old ways are working any more, what gives?

    Please give example of the current working way to do this using
    a php script, please.

    Any help would be very much appreciated, I'm at a loss, and going
    crazy looking for the answer.

    Thanks,
    Patrick
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I recommend using our APIs instead of trying to do stuff through the themes as theme code can, and does, change.

    The X3 theme is build upon API1 and API2. If you have root access, you can check out the source for X3 at /usr/local/cpanel/base/frontend/x3
     
  3. Patrick_M

    Patrick_M Registered

    Joined:
    May 9, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hi David,

    Well thanks, but I'm only a reseller, and I do not have root access. We don't even have
    an "X3" theme available to us.

    I spent somewhere around 5 hours last night reading through all of the documentation,
    but couldn't find anything on adding sub-domains, the only thing I found, and have no
    idea how to use
    , is the "SubDomain::delsubdomain" function located here:

    http://www.cpanel.net/plugins/api2/Cpanel::SubDomain::delsubdomain.pod.html

    I give away small free sub-domain accounts on my system, so all I need is something
    very simple and to the point, that can be run from an php script in my main domain
    directory or a folder on the main domain that will host the sub-domain accounts.

    Does anyone have any tips, hints, or maybe even an tutorial?

    Thanks again for any help,
    Patrick
     
    #3 Patrick_M, Mar 31, 2008
    Last edited: Mar 31, 2008
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You would call the API2 function from the XML-API. It can be a bit overwhelming to mesh all the syntax together. The XML-API is what bridges your external (PHP) script with the internal APIs of cPanel.

    Starting at Slide 21 of last year's Customizing cPanel presentation at the cPanel Conference is a quick introduction to API2. There's also a presentation on the XML-API available at: http://www.cpanel.net/docs/seminar07/XML_API.pdf

    I recommend trying to understand them independently of one another before trying to use API2 from the XML-API.

    For adding a subdomain, here is the API1 code that the x3 theme calls:

    Code:
    <cpanel SubDomain="addsubdomain($FORM{'domain'},$FORM{'rootdomain'},0,0,$FORM{'dir'})">
    API1 is a bit older than API2, so the syntax is slightly different. However, there is documentation on how to use API1 with the XML-API on our website at:

    http://www.cpanel.net/plugins/xmlapi/cpanel.html

    As you can see, our API documentation continues to be a work in progress.

    By the way, I know one of the forum members has created a PHP Class that wraps the XML-API. Just thought you may be interested in that.
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The XML API isn't a full-on RPC, it's merely based off calling specific URLs so the learning curve isn't terribly hard. I recommend using PHP 5 as a basis for any PHP code that is parsing XML for the simple fact that it's much easier/consistent in PHP 5 than it was in 4.
     
  6. Patrick_M

    Patrick_M Registered

    Joined:
    May 9, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hi David,

    Hey, thanks a lot for all of your effort here.

    I'm feeling a bit like a fish out of water with this XML stuff, I knew the day would come
    when I would have to add it into my hobbyists programmers toolbox, I guess this is
    where it's going to start. ;)

    >By the way, I know one of the forum members has created a PHP Class that wraps the
    >XML-API. Just thought you may be interested in that.

    Yes, that would be very cool indeed. I will do a search for it and see if I can find it.

    OK, I will take the info you've given me here and see if I can figure out how to create
    a working php script to handle my sub-domain creations and deletions.

    Thanks again for your help and insight,
    Patrick
     
Loading...

Share This Page