как использовать единый вход для входа пользователя в cpanel?

Я пытаюсь реализовать эту функцию в моем веб-приложении, используемом WHM.
Пожалуйста, проверьте это изображение

Я читаю документация для единого входа API и придумал следующий код:

<?php

// This can also be the reseller who owns the cPanel user.
$whmusername = "resellerusername";
$whmpassword = "abctesting";// The user on whose behalf the API call runs.
$cpanel_user = "normaluser"; //under reseller

$query = "https://domainname.com:2087/json-api/create_user_session?api.version=1&user=$cpanel_user&service=cpaneld";

$curl = curl_init();                                     // Create Curl Object.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);       // Allow self-signed certificates...
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);       // and certificates that don't match the hostname.
curl_setopt($curl, CURLOPT_HEADER, false);               // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);        // Return contents of transfer on curl_exec.
$header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\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
}$decoded_response = json_decode( $result, true );
print_r($decoded_response);

$session_url = $decoded_response['data']['url'];
$cookie_jar = 'cookie.txt';

curl_setopt($curl, CURLOPT_HTTPHEADER, null);             // Unset the authentication header.
curl_setopt($curl, CURLOPT_COOKIESESSION, true);          // Initiate a new cookie session.
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);       // Set the cookie jar.
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);      // Set the cookie file.
curl_setopt($curl, CURLOPT_URL, $session_url);            // Set the query url to the session login url.

$result = curl_exec($curl);                               // Execute the session login call.
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
// Log an error if curl_exec fails.
}

$session_url = preg_replace( '{/login(?:/)??.*}', '', $session_url );  // make $session_url = https://10.0.0.1/$session_key

$query = "$session_url/execute/Ftp/list_ftp";

curl_setopt($curl, CURLOPT_URL, $query);  // Change the query url to use the UAPI call.
$result = curl_exec($curl);               // Execute the UAPI call.
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
// log error if curl exec fails
}

curl_close($curl);

print $result;

?>

Я получаю это в качестве вывода:

Array
(
[data] => Array
(
[url] => https://domainname.com:2083/cpsess5326278746/login/?session=normaluser%3azRtR0RzLZ5owYZin%3acreate_user_session%2c4597fa33ff7ce68f3fdab84d9f3a51a1
[session] => normaluser:zRtR0RzLZ5owYZin:create_user_session,4597fa33ff7ce68f3fdab84d9f3a51a1
[expires] => 1490532538
[cp_security_token] => /cpsess5326278746
[service] => cpaneld
)

[metadata] => Array
(
[result] => 1
[command] => create_user_session
[version] => 1
[reason] => Created session
)

)
<br />
<b>Warning</b>:  curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument in <b>C:\xampp\htdocs\cpanel-api\open-cpanel.php</b> on line <b>34</b><br />
{"messages":null,"data":[{"homedir":"/home/normaluser","type":"main","user":"normaluser"},{"type":"logaccess","homedir":"/usr/local/apache/domlogs/normaluser","user":"normaluser_logs"}],"errors":null,"status":1,"metadata":{"transformed":1}}

но когда я использую этот URL в браузере https://domainname.com:2083/cpsess5326278746/login/?session=normaluser%3azRtR0RzLZ5owYZin%3acreate_user_session%2c4597fa33ff7ce68f3fdab84d9f3a51a1,

это не войти меня в cPanel.

Я заметил, что страница перенаправления WHM имеет следующий HTML-код, который регистрирует пользователя:

<html slick-uniqueid="3"><head><meta http-equiv="refresh" content="2;URL=https://domainname.com:2083/cpsess7055670446/login/?session=normaluser:7PMD2WWAjnQc_cDL,e691a31623f55cf37ee32a63a390fb08"></head><body>
</body></html>

так как мне сгенерировать URL-адрес, аналогичный тому, который генерирует whm, и зарегистрировать пользователя в cPanel (т.е. открыть cpanel с вошедшим в него normaluser)?

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …