Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Jan 2010
    Posts
    5

    Default api file_get_contents() error

    Hello, I'm trying to use json Fast Mode api from within a whm module and I keep getting this error:

    Warning: file_get_contents(http://host_here:2086/json-api/cpane..._func=listcron) [function.file-get-contents]: failed to open stream: Redirection limit reached, aborting in /usr/local/cpanel/whostmgr/docroot/module/gui/whm/main.php on line 48

    A POC of my code would be:

    PHP Code:
    cpanelSendQuery("cpanel?cpanel_jsonapi_module=Cron&cpanel_jsonapi_func=listcron");
       
        function 
    cpanelSendQuery($query) {
            
    $ip 'ip here';
            
    $hash 'hash key here';

            
    $query "http://".$ip.":2086/json-api/".$query;

            
    $context stream_context_create(
                            array(
                                    
    'http' => array(
                                            
    'allow_self_signed' => true,
                                            
    'method' => 'POST',
                                            
    'header' => "Authorization: WHM ".$_ENV['REMOTE_USER'].":".preg_replace("'(\r|\n)'","",$hash)."\r\n"
                                    
    )
                            )
                    );

            
    $result file_get_contents($queryfalse$context);

            return 
    $result;

        } 
    if I use api1 and api2 calls like /json-api/listips it works.

    Another problem is that I cannot use https. If I change the protocol to https and port to 2087 I always get a "No such file or directory" on any query, fast mode or not.

    This would be a lot easier with curl I guess but the WHM's php doesn't have curl installed and I can't figure it out how to install it.

    Thank you for any assistance you can provide.

  2. #2
    cPanel Staff cPanelCraig's Avatar
    Join Date
    Apr 2010
    Posts
    6

    Default

    Hello Danny,

    If you haven't already, please try taking advantage of the PHP XML-API class that is available:

    http://forums.cpanel.net/f42/xml-api...-a-136449.html

    It greatly simplifies calling into the XML-API.

    The server that you are trying to contact, are you able to login normally using the secure WHM port?
    For hands-on assistance please reference our support information center: Where should I go for support?
    -- cPanelCraig - Craig Morrison, Technical Analyst, cPanel Technical Support

  3. #3
    Member
    Join Date
    Jan 2010
    Posts
    5

    Default

    I've tried the script on 2 production servers and on my dev server. The script didn't work on either server.

    I've tried XML API PHP but I have pretty much the same issues:

    With:

    PHP Code:
    include("xmlapi.php");
    $account 'root';
    $ip "__IP HERE__";
    $root_pass "__PASS HERE__";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_output('array');
    $xmlapi->set_debug(1);

    print_r($xmlapi->api2_query($account"Cron""listcron" )); 
    I get:

    Warning: file_get_contents(https://.....:2087/xml-api/cpanel) [function.file-get-contents]: failed to open stream: No such file or directory in /usr/local/cpanel/whostmgr/docroot/module/xmlapi.php on line 724


    And with:
    PHP Code:
    define('XMLAPI_USER_SSL''1');
    define('XMLAPI_USE_SSL''0');

    include(
    "xmlapi.php");
    $account 'root';
    $ip "__IP HERE___";
    $root_pass "__PASS HERE__";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_port(2086);
    $xmlapi->set_output('array');
    $xmlapi->set_debug(1);

    print_r($xmlapi->api2_query($account"Cron""listcron" )); 
    I get:
    Warning: file_get_contents(http://....:2086/xml-api/cpanel) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /usr/local/cpanel/whostmgr/docroot/module/xmlapi.php on line 724

    but if instead of print_r($xmlapi->api2_query($account, "Cron", "listcron" )); i use something like print_r($xmlapi->listips()); it works. This is exactly what works in my version of the script. Non fast mode, non https query.

  4. #4
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    Quote Originally Posted by danny0n View Post
    but if instead of print_r($xmlapi->api2_query($account, "Cron", "listcron" )); i use something like print_r($xmlapi->listips()); it works. This is exactly what works in my version of the script. Non fast mode, non https query.
    That's very special.

    Have tried the steps in: Troubleshooting the XML-API - cPanel Integration ?

    If you have and still can't see the source of the problem please open a ticket a tickets.cpanel.net/submit/ with the subject "ATTN: Matt D" and include access to source, etc so that I can look into this issue more thoroughly.
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  5. #5
    Member
    Join Date
    Jan 2010
    Posts
    5

    Default

    It seems I get a lot of this in error log.

    Code:
    [2010-07-13 21:51:06 +0400] info [cpanel] api/cpanel call failed. Module name is required.
    [2010-07-13 21:51:06 +0400] warn [cpanel] User file '/var/cpanel/users/root' is empty or non-existent. at /usr/local/cpanel/Cpanel/Config/LoadCpUserFile.pm line 35
            Cpanel::Config::LoadCpUserFile::load('root') called at /usr/local/cpanel/Cpanel/Config/LoadCpUserFile.pm line 158
            Cpanel::Config::LoadCpUserFile::loadcpuserfile('root') called at /usr/local/cpanel/Cpanel.pm line 96
            Cpanel::initcp(Cpanel=HASH(0x9e62a00)) called at cpanel line 269

  6. #6
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    That makes it alot more clear, could you send me the specific URL you are sending via the class?
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

Similar Threads & Tags
Similar threads

  1. cpanel api error please help
    By andylee in forum cPanel Developers
    Replies: 5
    Last Post: 10-14-2011, 01:57 AM
  2. file_get_contents - need help
    By sam0t in forum New User Questions
    Replies: 1
    Last Post: 03-03-2010, 02:31 PM
  3. File_get_contents Couldn't resolve host name
    By furtif in forum New User Questions
    Replies: 4
    Last Post: 06-02-2009, 04:22 PM
  4. SOAP or file_get_contents of https page fails
    By jvanv8 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-15-2007, 01:49 PM
  5. file_get_contents error
    By upsforum in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-14-2007, 11:04 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube