[php] problems with cURL login to cPanel

mathiflip

Registered
Mar 13, 2012
2
0
51
cPanel Access Level
Website Owner
Hi everyone,

I hope I post this question in the right section.

On my webhost mochahost i'm trying to login to my cpanel and redirect to the roundcube webmail.
Because I made a customized login form on my website for the webmail and I want to use that rather than the cpanel style.

I don't have much experience with cURL, but after some tries I got a 200 header.
Now I got the page after login, which is good, but with this host I have to chose between 3 mailapps (squirrel, horde and roundcube). And this is where I got stuck. I can't find out how to redirect to roundcube without losing the authentication.

Here is my code:
Code:
    $post = array();
    $post['user'] = 'myusername';
    $post['pass'] = 'mypassword';
    $post['goto_uri'] = '/';
    $post['login_theme'] = 'cpanel';
    $url = 'https://eleanor.mochahost.com:2096/login/';
   
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);   
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   
    // grab URL and pass it to the browser
    $response = curl_exec($ch);
    echo $response;
   
    // close cURL resource, and free up system resources
    curl_close($ch);
I want to get in to roundcube so I looked into the link with firebug and I tried to change the
Code:
$post['goto_uri'] = '/';
to
Code:
$post['goto_uri'] = '/3rdparty/roundcube/index.php';
which I tought should do the trick, but unfortunately it wasn't that easy.

Now i got an error:

CONFIGURATION ERROR

main.inc.php was not found.
db.inc.php was not found.
Please read the INSTALL instructions!
I also tried the sample php authentication script from the "Authenticating API Function Calls "-page.
But also no luck there.


Hope somebody can help me out, thanks in advance!
 

cPDan

cPanel Staff
Staff member
Mar 9, 2004
724
15
243
Hi everyone,
hello ;)

I want to get in to roundcube so I looked into the link with firebug and I tried to change the
Code:
$post['goto_uri'] = '/';
to
Code:
$post['goto_uri'] = '/3rdparty/roundcube/index.php';
Side note on that: you probably want to make it security token safe per Making your script work with security tokens in cPanel & WHM - cPanel Integration

Now i got an error:
Code:
CONFIGURATION ERROR

main.inc.php was not found.
db.inc.php was not found.
Please read the INSTALL instructions!
Do you get that error when you go to roundcube in a browser? (see Test it in the User Interface - cPanel Integration)
 

mathiflip

Registered
Mar 13, 2012
2
0
51
cPanel Access Level
Website Owner
Thanks cpdan for the reply!
Sorry for my late response.

I tried your link about "Making your script work with security tokens in cPanel & WHM"
which I couldn't get to work. My $_ENV variable in php was always empty.

I don't get that error when I go to roundcube in a browser, only when I try via cURL

Any more ideas?
 

cPDan

cPanel Staff
Staff member
Mar 9, 2004
724
15
243
My $_ENV variable in php was always empty.
The ENV variable that the URL mentions is only set when the PHP code is being executed through cpsrvd.

If you run it though the command line there is nothing to set it.
 
  • Like
Reactions: Tiberiu