2012-12-03 1 views
1

와 보안의 cPanel 로그인에,의 cPanel는에 기록하는 방식을 변경했습니다스크립트 최근부터 PHP

로그인하기 전에 URL은 다음과 같습니다. https : //로 AccessURL을 : 2083/

로그인 후 : https : //로 AccessURL을 : 2083/cpsessXXXX/프론트 엔드/X3/index.html을 post_login = 89711792346495

당신은 URL에 포함 된 cpsessXXXX를주의 할 것이다?.

그리고 AWSTATS에 액세스 할 수있는 페이지입니다 : https : //로 AccessURL을 : 2083/cpsessXXXX/awstats.pl 설정 = 도메인 _ & SSL = & LANG = 나는 다음과 같은 PHP 코드

시도

엔 내가 코드를 단계별로 때

$username = 'xxx'; 
$password = 'xxx'; 
$loginUrl = 'https://<accessurl>'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $loginUrl); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_PORT,2083); 
$store = curl_exec($ch); 
curl_close($ch); 

$ 저장소의 값은 로그인 프로세스가 실패했음을 의미 FALSE입니다.

웹에서 비슷한 문제를 발견 한 참고 자료는 3 월 28 일 , http://blog.mcfang.com/입니다.

쿠키 파일에 cpsessXXXX 정보가 있지만 파일이 생성되지 않기를 바랬습니다. 어떤 도움

답변

4

에 대한

덕분에 당신은 받아 들여지기 스크립트의 순서를 토큰 다시의 cPanel에 보안을 참조 할 필요가있다. cPanel documentation for Security tokens

의 문서를 통해 당으로하면 다음의 예를 보자

function createSession() { // Example details 
$ip = "127.0.0.1"; 
$cp_user = "username"; 
$cp_pwd = "password"; 
$url = "http://$ip:2082/login"; 
$cookies = "/path/to/storage/for/cookies.txt"; 

// Create new curl handle 
$ch=curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); // Save cookies to 
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd"); 
curl_setopt($ch, CURLOPT_TIMEOUT, 100020); 

// Execute the curl handle and fetch info then close streams. 
$f = curl_exec($ch); 
$h = curl_getinfo($ch); 
curl_close($ch); 

// If we had no issues then try to fetch the cpsess 
if ($f == true and strpos($h['url'],"cpsess")) 
{ 
    // Get the cpsess part of the url 
    $pattern="/.*?(\/cpsess.*?)\/.*?/is"; 
    $preg_res=preg_match($pattern,$h['url'],$cpsess); 
} 

// If we have a session then return it otherwise return empty string 
return (isset($cpsess[1])) ? $cpsess[1] : ""; 
} 

cpsess은의 cPanel 다시 예상하는 URL을에게 올바른 토큰을 추가하는 데 사용됩니다.

+0

화려한 대답. 감사. 2083 포트를 변경하고 로그인 세부 정보를 변경하면 완벽하게 작동합니다. – user643862

+0

이 모든 목적은 AWSTATS의 검색을 자동화하는 것입니다. 반환 된 HTML은 기본적으로 "AWStats UseFramesWhenCGI 매개 변수를 으로 설정하여 보고서를 확인해야합니다."라는 점을 제외하면 모든 것이 올바르게 작동합니다. 공유 서버이므로 UseFramesWhenCGI = 0에 대한 AWSTATS conf 파일을 변경할 수 없습니다. PHP 컬을 사용하여이를 설정하는 방법이 있습니까? 또는 컬을 사용하여 프레임 세트 페이지를 계속 수신하려면 어떻게해야합니까? – user643862

+0

대답은 ** awstats.pl 인 관련 프레임을 보는 것입니다 (나를 위해 :-))?month = 11 & year = 2012 & config = $ domain & lang = ko && update = 1 & framename = 메인 라이트 ** – user643862

1

당신은이 간단한 행을 추가 헤더하여 "인증"행을 보낼 수 있습니다

$header[0] = "Authorization: Basic " . base64_encode($cp_user.":".$cp_pwd) . "\n\r"; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 

그래서 당신은 쿠키와 아무것도하지 않고, 자원 $의에서는 MyResource에 직접 요청을 보낼 수 있습니다. 는 간단히 :

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $myResource); 
$header[0] = "Authorization: Basic " . base64_encode($cp_user.":".$cp_pwd) . "\n\r"; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_PORT,2083); 
$store = curl_exec($ch); 
curl_close($ch); 

당신은 XML API of CPanel를 사용하는 것이 좋습니다. Github에서 xmlapi-php class을 찾을 수 있습니다.이 코드는 훌륭하게 작동하며 코드를 간단하고 쉽게 업데이트 할 수있게 도와줍니다.