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.

Intergration via PHP with domain owner (not WHM)

Discussion in 'cPanel Developers' started by TruConcept, Dec 7, 2010.

  1. TruConcept

    TruConcept Registered

    Joined:
    Dec 7, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hello, i wish to make a "mini-control-panel" for my site due to my host putting unwanted/annoying advertisements on the cPanel so i have to use a basic theme that is hard to work with, also i can make users and only give them certain permissions etc.

    I want to get basic stats from my cPanel, and be able to list, add, remove, edit domains, emails, ftp accounts etc. and the other features. i'm not sure how to do this, i have a class that i used, but it doesn't work for all of it. especially getting the data, it is also a heavy class so it slows down the page load time by a lot.

    Any help would be appreciated.
    Thanks,
    Dan - TruConcept.Net
     
  2. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I guess the first question I would have for you, is: what class are you using?

    The xmlapi.php class we have is capable of performing any API1 or API2 call, which covers *everything* in the cPanel interface (with a couple of small exceptions). To see an example of this class please look:

    http://forums.cpanel.net/f42/xml-api-php-class-version-1-0-a-136449.html

    Now, this is not designed with UI-type environments, so there could possibly be issues.

    Now, when looking at automating specific tasks, you'll want to view the API1/API2 docs:

    WebHome < ApiDocs < TWiki

    These documents cover all of the API calls in cPanel and WHM. Generally, for what you are wanting to do, you should favor an API2 call over an API1 call as API2 will return datastructures.

    Please let me know if you need further detail.
     
  3. TruConcept

    TruConcept Registered

    Joined:
    Dec 7, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Well, its a custom class that logs in to cpanel, gets the html source and strips it down from that, but it doesn't to it good and is time consuming:
    PHP:
    <?php file_get_contents('http://'.$user.':'.$pass.'@'.$domain.':'.$port ?>
    etc...

    and is the API included on all cPanels or does it have to be manually installed by the hosts?
     
  4. TruConcept

    TruConcept Registered

    Joined:
    Dec 7, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Okay, i am using the XML API, but i keep getting the JSON Response (i want JSON):
    Code:
    {"data":{"reason":"Access denied","result":"0"},"type":"text"}
    How do i fix this? i changed the port in xmlapi to 2082 instead of 2087 (for cPanel instead of WHM) and the host is my servers IP address (i'm running the code of my pc / localhost (different from server) so would that be causing it?)
     
  5. TruConcept

    TruConcept Registered

    Joined:
    Dec 7, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    okay, got that working using:
    PHP:
    $xmlapi->set_port(2082);
    but, how do i get the stats displayed in the side-menu, such as. main-domain, disk space, bandwidth, amount of db's, amount of ftp accounts etc?
     
  6. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Dan,

    You'll want to use the StatsBar::stat API2 call. The documentation is here, ApiStatsBar < ApiDocs/Api2 < TWiki. Below is a code example.

    PHP:
    include("xmlapi.php");

    $ip "10.1.1.1";

    $acct['username'] = "you";
    $acct['password'] = "YourS3cret!";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($acct['username'], $acct['password']);
    $xmlapi->set_output('json');
    $xmlapi->set_port('2083');
    $xmlapi->set_debug(1);

    //There are many display items, this is just a few
    // Make sure is one long list, separated by the pipe character ("|")
    $args = array('display' => 'bandwidthusage|emailaccounts|sqldatabases|hostname');

    $result $xmlapi->api2_query($acct['username'], "StatsBar""stat"$args);
    Best Regards,
    -DavidN
     
Loading...

Share This Page