1

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

<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,但现在我遇到了标题、cookie 等问题。

这是我最后一次尝试:

 $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($header as $h) 循环是我试图将标头和 cookie 从 cUrl 客户端设置到用户浏览器。

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

4

1 回答 1

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>
于 2014-07-09T00:03:36.387 回答