Постановка проблемы
В настоящее время мы используем cPanel API и используем метод безопасного удаленного входа для аутентификации пользователя.https://documentation.cpanel.net/display/DD/Guide+to+API+Authentication https://documentation.cpanel.net/display/DD/Guide+to+API+Authentication+-+Secure+Remote+Logins
Мы используем этот класс cPanel LogMeIn - https://gist.github.com/kmark/4440574 (скрипт устарел)
Ошибка: даже на сайтах с cPanel и исправленаuser / password, плагин сообщает, что user / password неверен.
Я уже пытался установить curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false);как кто-то упоминал на Github, но он не работает.
class LogMeIn {
// The available services with their HTTPS ports
private static $servicePorts = array('cpanel' => 2083, 'whm' => 2087, 'webmail' => 2096);
public static function getLoggedInUrl($user, $pass, $hostname, $service, $goto = '/', $is_reset_host = false) {
// If no valid service has been given, default to cPanel
$port = isset(self::$servicePorts[$service]) ? self::$servicePorts[$service] : 2083;
$ch = curl_init();
$fields = array('user' => $user, 'pass' => $pass, 'goto_uri' => $goto);
// Sets the POST URL to something like: https://example.com:2083/login/
curl_setopt($ch, CURLOPT_URL, $hostname . ':' . $port . '/login/');
curl_setopt($ch, CURLOPT_POST, true);
// Turn our array of fields into a url encoded query string i.e.: ?user=foo&pass=bar
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
// RFC 2616 14.10 compliance
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection' => 'close'));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute POST query returning both the response headers and content into $page
$page = curl_exec($ch);
curl_close($ch);
if($is_reset_host === false && strpos($page,'301 Moved')){
$start = strpos($page,'https://');
$end = strpos($page,':2083');
$link = substr($page,$start,$end - $start);
return self::getLoggedInUrl($user,$pass,$link,$service,$goto,true);
}
$session = $token = array();
// Find the session cookie in the page headers
if(!preg_match('/session=([^\;]+)/', $page, $session)) {
// This will also fail if the login authentication failed. No need to explicitly check for it.
return false;
}
// Find the cPanel session token in the page content
if(!preg_match('|<META HTTP-EQUIV="refresh"[^>]+URL=/(cpsess\d+)/|i', $page, $token)) {
return false;
}
// Append the goto_uri to the query string if it's been manually set
$extra = $goto == '/' ? '' : '&goto_uri=' . urlencode($goto);
return 'https://' . $hostname . ':' . $port . '/' . $token[1] . '/login/?session=' . $session[1] . $extra;
}
public static function getCpanelHost($hostname, $is_reset_host = false) {
// If no valid service has been given, default to cPanel
$port = 2083;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $hostname . ':' . $port);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection' => 'close'));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
curl_close($ch);
if($is_reset_host === false && strpos($page,'301 Moved')){
$start = strpos($page,'https://')+8;
$end = strpos($page,':2083');
$link = substr($page,$start,$end - $start);
return self::getCpanelHost($link,true);
}
$hostname = str_replace('http://','',$hostname);
$hostname = str_replace('https://','',$hostname);
return $hostname;
}
}