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.

How to make a simple Cron::listcron request using cURL in PHP ?

Discussion in 'cPanel Developers' started by stephane02, Dec 17, 2011.

  1. stephane02

    stephane02 Member

    Joined:
    Dec 14, 2011
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello,

    I'm using the following code to get cron list but it returns a blank page and when I change port 2087 to 2083 it returns {"data":{"reason":"Access denied","result":"0"},"type":"text"} with 403 HTTP status. Anyone to help me find the issue?


    PHP:
    $user $_ENV['REMOTE_USER'] ? $_ENV['REMOTE_USER'] : 'root';
                    
    $accessHash $this->getLocalAccessHash();
                    if(
    $accessHash === FALSE) return FALSE;
                    
                    
    $url "https://127.0.0.1:2087/json-api/cpanel?user=$user&cpanel_jsonapi_module=Cron&cpanel_jsonapi_func=listcron&cpanel_jsonapi_version=2";
                    
    $ch curl_init();
                    
    curl_setopt($chCURLOPT_VERBOSE1);
                    if(
    $fp fopen('curl_http.txt'"wa")) curl_setopt($chCURLOPT_STDERR$fp);
                    
    curl_setopt($chCURLOPT_URL$url);
                    
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
                    
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
                    
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
                    
    //curl_setopt($ch, CURLOPT_POST, 1);
                    
    curl_setopt($chCURLOPT_HTTPHEADER, array("Authorization: WHM $user:$accessHash"));
                    
    $cronlistJSON curl_exec($ch);
                    
    $ci curl_getinfo($ch);
                    
    curl_close($ch);
                    if(
    $fpfclose($fp);
                    
                    
    print_r($ci);
                    die(
    $cronlistJSON);
    Thx for helping,

    Stephane
     
Loading...
Similar Threads - simple Cron listcron
  1. mesut85u2
    Replies:
    14
    Views:
    1,320

Share This Page