Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 24 of 24
  1. #16
    Member
    Join Date
    Sep 2001
    Posts
    315

    Default

    Quote Originally Posted by cpanelnick View Post
    The has will work as well.
    But how can I add the hash in the url? Can you make an example?

  2. #17
    cPanel Staff cpanelnick's Avatar
    Join Date
    Feb 2003
    Location
    Houston, TX
    Posts
    4,597

    Default

    Quote Originally Posted by CoolMike View Post
    But how can I add the hash in the url? Can you make an example?
    You have to sent into in the authentication header

  3. #18
    Member
    Join Date
    Sep 2001
    Posts
    315

    Default

    Quote Originally Posted by cpanelnick View Post
    You have to sent into in the authentication header
    Would it be possible to give us an example? I think a lot of people try to use the api at the moment. It works perfectly when i use the root login details in the url, but I think that's definitly the wrong and insecure way to do it. You would for sure help a lot of people with an example to write more secure scripts.

    Thanks
    Michael

  4. #19
    cPanel Staff cpanelnick's Avatar
    Join Date
    Feb 2003
    Location
    Houston, TX
    Posts
    4,597

    Default

    Quote Originally Posted by CoolMike View Post
    Would it be possible to give us an example? I think a lot of people try to use the api at the moment. It works perfectly when i use the root login details in the url, but I think that's definitly the wrong and insecure way to do it. You would for sure help a lot of people with an example to write more secure scripts.

    Thanks
    Michael
    ($page, $result, %headers)
    = Net::SSLeay::post_https('demo.cpanel.net', 2087, '/xml-api/listaccts',
    Net::SSLeay::make_headers('Authorization' => 'WHM ' . $authstr,'Connection' => 'close'),
    $formdata);

    where $authstr is the access hash

  5. #20
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    May 2003
    Location
    Ukraine
    Posts
    195
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Any php example?
    Regards, Alexey

  6. #21
    Member
    Join Date
    Oct 2005
    Posts
    73

    Default

    This is all very interesting. Where would I go to find more information about API used outside WHM. Like if I were to create a script for my hosting site to auto setup accounts. I'm no PHP guru but pointed in the right direction I might accomplish the task at hand. Are there tutorials, none encoded scripts I could learn from. Something?

  7. #22
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by Xiode View Post
    This is all very interesting. Where would I go to find more information about API used outside WHM. Like if I were to create a script for my hosting site to auto setup accounts. I'm no PHP guru but pointed in the right direction I might accomplish the task at hand. Are there tutorials, none encoded scripts I could learn from. Something?
    The XML API is designed for scripts operating outside WHM to interact with cPanel/WHM's accounting system.

    Documentation for the XML API is available at: http://www.cpanel.net/plugins/xmlapi/index.html

  8. #23
    Registered User
    Join Date
    Nov 2003
    Location
    Floripa - Brazil
    Posts
    69

    Default

    Hi,
    take the script from the cpanel documentation:

    function suspend ($host,$user,$accesshash,$usessl,$suspenduser) {
    $result = whmreq("/scripts/remote_suspend?user=${suspenduser}",$host,$user,$accesshash,$usessl);
    if ($cpanelaccterr != "") { return; }
    return $result;
    }


    How can I convert this to get results from XML-API?
    I use access hash and don't want to use password on my php script eighter

    I apreceate if you give me a tip on how to do that

  9. #24
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by deieno View Post
    Hi,
    take the script from the cpanel documentation:

    function suspend ($host,$user,$accesshash,$usessl,$suspenduser) {
    $result = whmreq("/scripts/remote_suspend?user=${suspenduser}",$host,$user,$accesshash,$usessl);
    if ($cpanelaccterr != "") { return; }
    return $result;
    }


    How can I convert this to get results from XML-API?
    I use access hash and don't want to use password on my php script eighter

    I apreceate if you give me a tip on how to do that
    Here's an example from the XML API documentation:

    /xml-api/suspendacct?user=bob&reason=no%20payment


    So all you need to do is have your PHP script coded to access this URL. You can authenticate using headers and hashes with header:

    Code:
    Authentication: WHM $hash
    Where $hash is your access hash.

    While I'm not authorized to give advice regarding coding, you may want to take the code that will actually make the calls to the API and place it in a function similarly abstracted to your whmreq() function.

    Here's some code I've been working on myself with regards to using the XML API with PHP (just a head's up that it's merely a work in progress since my test server is not liking me):

    PHP Code:
    // $hash = your hash
    // $theServer = your server's hostname or IP

    $apiPath "/xml-api/listaccts";

    // NOTE:
    //    THIS CODE WILL ONLY WORK IF YOU HAVE ENABLED
    //    OPENSSL IN PHP.  YOU CAN DO THIS BY GOING TO WHM
    //    AND IN THE SOFTWARE SECTION, CLICK ON APACHE UPDATE
    //    THEN LOAD PREVIOUS CONFIG AND THEN CHECK THE BOX
    //    NEXT TO OPENSSL TO ENABLE SSL SUPPORT
    //
    // Of course, you could always go with http:// and 2086, but why?

    # Open a socket for HTTPS
    $fp fsockopen("ssl://" $theServer2087$errno$errstr30);

    # Uncomment to use unsecure HTTP instead
    //$fp = fsockopen($theServer, 2086, $errno, $errstr, 30);

    # Die on error initializing socket
    if ($errno == && $fp == FALSE) {
     die(
    "Socket Error: Could not initialize socket.");
    } elseif (
    $fp == FALSE) {
     die(
    "Socket Error #" $errno ": " $errstr);
    }

    # Assemble the header to send
    $header "";
    $header .= "GET " $apiPath " HTTP/1.0\r\n";
    $header .= "Host: " $theServer "\r\n";
    $header .= "Authorization: WHM " $hash "\r\n";
    $header .= "Connection: close\r\n";
    $header .= "\r\n";

    # Send the Header
    fputs($fp$header);

    # Get the raw output from the server
    $rawResult "";
    while (!
    feof($fp)) {
     
    $rawResult .= @fgets($fp128); // Suppress errors with @
    }

    # Close the socket
    fclose($fp);

    # Ignore headers
    $rawResultParts explode("\r\n\r\n",$rawResult);
    $result $rawResultParts[1];

    # Output XML
    echo $result

Similar Threads & Tags
Similar threads

  1. XML API 2 help
    By Dragonxito in forum cPanel Developers
    Replies: 1
    Last Post: 05-13-2011, 04:23 PM
  2. xml-api/accountsummary
    By monaghan in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 06-25-2008, 03:57 PM
  3. XML-API is any of these possible?
    By neo4242002 in forum cPanel Developers
    Replies: 3
    Last Post: 03-17-2008, 01:46 PM
  4. XML API: always get login screen, not XML
    By sldff3ald in forum cPanel Developers
    Replies: 3
    Last Post: 09-19-2007, 09:29 AM
  5. How do I use the xml - api?
    By rhopperger in forum cPanel Developers
    Replies: 3
    Last Post: 05-19-2007, 08:07 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube