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/cpanel?cpanel_jsonapi_module=Cron&cpanel_jsonapi_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:
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.
Warning: file_get_contents(http://host_here:2086/json-api/cpanel?cpanel_jsonapi_module=Cron&cpanel_jsonapi_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:
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($query, false, $context);
return $result;
}
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.