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

stephane02

Member
Dec 14, 2011
13
0
51
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($ch, CURLOPT_VERBOSE, 1);
                if($fp = fopen('curl_http.txt', "wa")) curl_setopt($ch, CURLOPT_STDERR, $fp);
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                //curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: WHM $user:$accessHash"));
                $cronlistJSON = curl_exec($ch);
                $ci = curl_getinfo($ch);
                curl_close($ch);
                if($fp) fclose($fp);
                
                print_r($ci);
                die($cronlistJSON);
Thx for helping,

Stephane