Elements required to make this functionality are –
Server/WHM Username
Cpanel account Username
Server login URL
Server accesshash key
And for Accesshash key , New or already generated Access key can get from here:-
WHM > Remote Access Key area and the Access Key located there.
or it should be at this path “/usr/local/cpanel/bin/realmkaccesshash
Once you get all these details , you can follow the code steps as:-
$query = "https://$server_login_link:2087/json-api/create_user_session?api.version=1&user=$cpanel_user&service=cpaneld";
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$hash);
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if ($result == false) {
// your error log
}
if($result){
$decoded_response = json_decode( $result, true );
if(isset($decoded_response['data']) && !empty($decoded_response['data'])){
$url = $decoded_response['data']['url'];
return $url;
}
}
once you get this URL, you can directly open this in a new tab or same tab and you must get logged in.
It generates the similar session as cpanel login and provides you all that specific cpanel privileges.
Remeber that it only logs you in with given specific account, not for all cpanel accounts access within a server.