2013-07-18 49 views
1

我试图自动登录到cPanel,然后将用户重定向到Awstats页面。 但我遇到了一些麻烦。 唯一的工作方法,我发现是这样的:外部cPanel登录并重定向

<form method="post" id="login-form" action="http://domain.com:2082/login"> 
    <input type="hidden" name="login_theme" id="login_theme" value="cpanel"> 
    <input type="hidden" name="goto_uri" id="goto_uri" value="awstats.pl?config=euqueroinvestir.com&lang=pt"> 
    <input type="hidden" name="user" id="user" value="myuser"> 
    <input type="hidden" name="pass" id="pass" value="mypass"> 
</form> 
<script>window.onload = function() { document.forms["login-form"].submit(); }</script> 

但是,正如你所看到的,如果用户查看源代码,密码会以纯文本明确。我不能那样做。所以我尝试了cUrl,但现在我遇到了标题,cookies等问题。

这是我最后一次尝试:

$url = "http://domain.com:2082/login"; 

$curl = curl_init(); 

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_VERBOSE, 1); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_POSTFIELDS, "user=myuser&pass=mypass"); 
$result = curl_exec($curl); 
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); 
$header = substr($result, 0, $header_size); 
$body = substr($result, $header_size); 
curl_close($curl); 

$header = str_replace("\r", '', $header); 
$header = explode("\n", $header); 

foreach ($header as $h) { 
    header ($h); 
} 
$parts = explode('URL=', $result); 
$session_parts = explode('/frontend/', $parts[1]); 
$token = $session_parts[0]; 

header('Location: http://domain.com:2082'.$token.'/awstats.pl?config=domain.com&ssl=&lang=pt'); 

有了这个,我可以得到一个安全令牌,并在foreach($标题为$ H)环是我试图建立来自卷边客户端头和饼干到用户浏览器。

每一个帮助将不胜感激。 是的,我通过谷歌搜索了很多。

回答

1

我知道这是一个老问题,但认为我会抛出一个答案,因为没有人回应。也许它会帮助其他人尝试这一点。

你不能得到这个工作的原因是因为cPanel验证用户的IP地址。您的cURL脚本使用其IP保存在您的服务器上,并且尝试登录的用户拥有自己的IP地址。

查看cPanel(x3)登录表单,甚至没有提交IP地址的表单字段,所以它只能在服务器端进行检索以防止欺骗。

<form id="login_form" action="/login/" method="post" target="_top"> 
    <div class="input-req-login"><label for="user">Username</label></div> 
    <div class="input-field-login icon username-container"> 
     <input name="user" id="user" autofocus="autofocus" value="" placeholder="Enter your username." class="std_textbox" type="text" tabindex="1" required> 
    </div> 
    <div style="margin-top:30px;" class="input-req-login"><label for="pass">Password</label></div> 
    <div class="input-field-login icon password-container"> 
     <input name="pass" id="pass" placeholder="Enter your account password." class="std_textbox" type="password" tabindex="2" required> 
    </div> 
    <div class="controls"> 
     <div class="login-btn"> 
      <button name="login" type="submit" id="login_submit" tabindex="3">Log in</button> 
     </div> 

            </div> 
    <div class="clear" id="push"></div> 
</form>