The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[php] problems with cURL login to cPanel

Discussion in 'cPanel Developers' started by mathiflip, Mar 13, 2012.

  1. mathiflip

    mathiflip Registered

    Joined:
    Mar 13, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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:

    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!
     
  2. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    3
    Trophy Points:
    18
    hello ;)

    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

    Do you get that error when you go to roundcube in a browser? (see Test it in the User Interface - cPanel Integration)
     
  3. mathiflip

    mathiflip Registered

    Joined:
    Mar 13, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  4. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    3
    Trophy Points:
    18
    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.
     
Loading...
Similar Threads - [php] problems cURL
  1. htmldesign
    Replies:
    4
    Views:
    497

Share This Page