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.

listaccts api problem

Discussion in 'cPanel Developers' started by apogee, Dec 1, 2010.

  1. apogee

    apogee Well-Known Member

    Joined:
    Nov 8, 2004
    Messages:
    107
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Europe
    cPanel Access Level:
    DataCenter Provider
    Hello

    I'm developing some new features for my own management suite, also an option to import all accounts on a cpanel server into my app.

    I used over 20 api calls in my app with no problem but with listaccts I've a lot of problems, tried over a day to find our whats wrong with it.

    here my code:
    PHP:
            $host_data get_host_data($host);

            
    $xmlapi = new xmlapi($host_data[ip]);
            
    $xmlapi->hash_auth($host_data[user],$host_data[hash]);
            
    $xmlapi->set_output('array');


            
    $apires4            $xmlapi->listaccts();
            
    $api_res_acct        $apires4[acct];

            
    print_r($apires4);
            
    print_r($api_res_acct);
    this displays nothing, but in my logs i found:
    PHP:
    [Wed Dec 01 21:42:06 2010] [error] [client 192.168.1.196Some error message hererefererhttp://192.168.1.2/buha/index.php?cmd=updateaccount-hostserver
    [Wed Dec 01 21:42:23 2010] [error] [client 192.168.1.196Some error message hererefererhttp://192.168.1.2/buha/index.php?cmd=updateaccount-hostserver
    comming from xmlapi.php (V. 1.0.7):
    PHP:
            // perform simplexml transformation (array relies on this)
            
    if ( ($this->output == 'simplexml') || $this->output == 'array') {
                
    $response simplexml_load_string($responsenullLIBXML_NOERROR LIBXML_NOWARNING);
                if (!
    $response){
                        
    error_log("Some error message here");
                        return;
                }
                if ( 
    $this->debug ) {
                    
    error_log("SimpleXML var_dump:\n" print_r($responsetrue));
                }
            }
    so my question, whats wrong? I also tried xml, json and simplexml, always the same result....

    other functions works like e.g.:
    PHP:
            $host_data get_host_data($host);

            
    $xmlapi = new xmlapi($host_data[ip]);
            
    $xmlapi->hash_auth($host_data[user],$host_data[hash]);
            
    $xmlapi->set_output('array');

            
    // cpanel version 
            
    $apires2            $xmlapi->version();
            
    $api_res_version    $apires2[version];
            echo 
    "<font color=\"green\"> OK!</b></font>Version $api_res_version<br>\n";
    all works proper except the listaccts function.... I tried it on 9 servers (with 11.28.51), always the same result

    any idea?

    BTW: if i use this:
    PHP:
    $xmlapi->set_debug(1); 

    $results $xmlapi->listaccts();
    var_dump($results);
    I just get "NULL"

    if I enter "https://xyz.xyz.com:2087/cpsess531454257388/xml-api/listaccts" in my browser I get the xml list

    thanks!
     
    #1 apogee, Dec 1, 2010
    Last edited: Dec 1, 2010
  2. 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
    I imagine it's something in the return data. I tried the following and it worked for me.
    PHP:
    <?php
    include("xmlapi.php");

    $ip "10.1.1.1";

    $xmlapi = new xmlapi($ip);
    $xmlapi->set_debug(1);
    $xmlapi->set_output('array');

    $hash "c7e048f2b4 -- SNIP -- 531b0b074ec";
    $hash str_replace(array("\n","\r"),'',$hash);
    $xmlapi->hash_auth('root',$hash);

    $accounts $xmlapi->listaccts();
    var_dump($accounts);
    I got good, clear results with no error on my 11.28.51 box.

    After you set
    PHP:
    $xmlapi->set_debug(1);
    you ran the code and checked your error log, right? At minimum, you should have "RESPONSE:" in the error log, which is a raw dump of the response string(XML/JSON).

    Is listaccts just now failing, or is this the first time you've used that method?

    In your code, you've got
    PHP:
    $xmlapi->hash_auth($host_data[user],$host_data[hash]);
    I presume that $host_data[user] is root, right? Hash access should be limited to only the root user (both as a policy and technically in the WHM/cPanel authentication code).

    Let me know what you find in your error log with the debug on, and we'll go from there.

    -DavidN

    PS. I HIGHLY recommend quoting your associative array keys in PHP. Technically, it's not an error to have them bare, but it's very possible that they might (at some point in your code's life cycle) be parsed by the PHP engine as constants or barewords/keywords.:)
     
Loading...

Share This Page