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.

API Access on Different Server crashing

Discussion in 'cPanel Developers' started by websitedesigner, Jul 15, 2010.

  1. websitedesigner

    Joined:
    Jul 15, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Hi guys,

    I have had a programmer write me a script that should retrieve an account's disk space and bandwidth and display it in a table. This works fine as long as the cPanel account is hosted on the same server as our script. However as soon as we query another server (we have tried 2) the script just times out and crashes.

    I'm not a programmer which makes this difficult but I am hoping either (a) someone will know of some requirements that have to be met to use the api to retrieve data from an external server or (b) someone will be able to help put some code into what we are doing to at least retrieve the reason why it can't connect instead of just crashing.

    This is the code they have given me as an example of how they are trying to connect. Both servers are running cPanel 11.25. Domain1.com is on the same server as the script and it works fine. Domain2.com is on a different server.

    I have enabled access to the domain2 server from the domain 1 server's IP address as I thought this could be the problem but this didn't work.


    $domain = "domain1.com.au";
    $user = "*******";
    $password = "*******";

    $domain = "domain2.com.au";
    $user = "*******";
    $password = "*******";

    $query = "https://".$domain.":2083/json-api/cpanel?user=".$user."&cpanel_jsonapi_module=StatsBar&cpanel_jsonapi_func=stat&display=diskusage&domain=".$domain;

    $curl = curl_init();
    # Create Curl Object
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    # Allow self-signed certs
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
    # Allow certs that do not match the hostname
    curl_setopt($curl, CURLOPT_HEADER,0);
    # Do not include header in output
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);

    curl_setopt($curl, CURLOPT_TIMEOUT, 300);
    # Return contents of transfer on curl_exec
    $header[0] = "Authorization: Basic " . base64_encode($user.":".$password) . "\n\r";
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    # set the username and password
    curl_setopt($curl, CURLOPT_URL, $query);
    # execute the query
    $result = curl_exec($curl);
    if ($result == false) {
    error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
    # log error if curl exec fails
    }

    curl_close($curl);

    print_r($result);
     
  2. lexand

    lexand Member

    Joined:
    Mar 18, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    Have the same problem

    Hi

    I have the same problem

    i can freely connect to remote host from local virtual - virtual to domain1 and virtual to domain3 .

    but i can't make connection from one remote host to another, let say
    domain1 to domain3 or domain3 to domain1 - failed on timeout
    I tried various ways (curl) but they always failed.

    Does someone have some thoughts why does this happen?

    virtual
    PHP Version 5.3.2-1ubuntu4.2 x64
    curl version 7.19.7

    remote
    PHP Version 5.2.8
    curl version 7.19.4

    mmmm... maybe I should use fopen method instead of curl

    fopen doen't work (virtual tp remote)
    for port 2082 I get error
    xmlapi.php (724): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
    code: xmlapi::fopen_query: return file_get_contents($url, false, $context);

    for port 2083
    xmlapi.php (724): SSL: Connection reset by peer

    both ports (remote to remote)
    xmlapi.php (724): failed to open stream: Connection timed out
     
    #2 lexand, Jul 16, 2010
    Last edited: Jul 16, 2010
  3. lexand

    lexand Member

    Joined:
    Mar 18, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
  4. lexand

    lexand Member

    Joined:
    Mar 18, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    Seems like these ports (2082, 2083) are closed for outgoing connections.
    I must ask my hosters about this supposition
     
  5. websitedesigner

    Joined:
    Jul 15, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Cool ok I'll have a look into this blocking thing to see if this is the problem.

    Thanks for posting back.
     
    #5 websitedesigner, Jul 16, 2010
    Last edited: Jul 16, 2010
  6. lexand

    lexand Member

    Joined:
    Mar 18, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    answer from one of my hosters

    but I don't understand this
    I open connection from 2082 like it would be opened in browser (this just a client).
    This is not the same like open port for listening. Listening of ports that is the feature of servers, but not clients.....

    .....further discussion will be with my hoster only.....
     
    #6 lexand, Jul 16, 2010
    Last edited: Jul 16, 2010
  7. websitedesigner

    Joined:
    Jul 15, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Yah its working!

    Hey mate I spoke with my host and they said:

    Everything is closed in CSF be default, we must explicitly open ports to allow traffic. I have opened ports 2082 and 2083 for outgoing traffic, please let me know if this helps.


    and this worked!!!!!

    Very happy.
     
  8. websitedesigner

    Joined:
    Jul 15, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
  9. websitedesigner

    Joined:
    Jul 15, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    My issue above turned out to be me being blocked due to excessive incorrect logins. cPanel support cleared the cPHulkD database and it fixed the issue.
     
Loading...

Share This Page