vimalkumar_k

Member
Feb 24, 2007
18
0
151
Hi,

I am trying to write a php script which when executed from the browser, will redirect and login to the WHM and am looking forward to some help regarding the same.

I have read through a similar post (old, though).. http://forums.cpanel.net/f42/help-whm-login-script-php-161349.html

My scenario:
Trying using curl to execute json-api, like applist works:

PHP:
        $api = "applist";
        $query = "https://$ip:2087/json-api/$api";

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        $header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey); // remotekey stored in db as TEXT
        curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
        curl_setopt($curl, CURLOPT_URL, $query);
        $result = curl_exec($curl);
        curl_close($curl);
        if ($result == false) {
            return FALSE; // error
        }
        
        return json_decode($result, true);
But trying to get the same idea executed via php header() is failing for me:

PHP:
            $srv_info = array(
                "ip" => $row->s_ip,
                "username" => $row->user_name,
                "remotekey" => $row->remote_key
            );
            
            $ip = $srv_info["ip"];
            $whmusername = $srv_info["username"];
            $remotekey = $srv_info["remotekey"];
            
            header("Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey));
            header("Location: http://" . $ip . ":2086/");

            // Also tried:

            // header("Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey) . "\r\n");
            // header("Location: https://" . $ip . ":2087/");
Using the header() stuff, even json calls fail, say if I change to:

PHP:
            header("Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey));
            header("Location: http://" . $ip . ":2086/json-api/applist");
.. and when I load this php script, it redirects to ../applist with the following error:

Code:
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
I am sure the remotekey is corret, as curl api calls (first code block) function fine for me.

I played around with the code from http://forums.cpanel.net/f42/help-whm-login-script-php-161349.html but without success. I always end up with the WHM login screen, or its login prompt.

What to do? Help..!! :confused:
 
Last edited:

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
Is there any way of tweaking the logmein to post remotekey to <whm>/login/ url.. and then generate url with session id and redirect page, as done in logmein?
Sorry, but no. Authentication done with a remote accesshash key will not provide the server or client mechanics necessary for an interactive session, such as those required for a browser session. Remote accesshashes for programmatic API request actions.

Regards,
-DavidN