Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

cPanel Login Fails

Discussion in 'cPanel Developers' started by ManXP, May 1, 2009.

  1. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    156
    I knwo it's impossible to add cronjobs using cPanel API, so I'm using curl to do it.

    The problem is, that I can't get cPanel login system working promptly. I can login to cPanel main page, but as soon as I request other cPanel pages (like cronjobs page), I'm logged out. It works *SOMETIMES*, so I believe it's something related to cPanel itself. I'm using same code for hundreds of other sites and it works perfectly. Here is the code I use:

    PHP:
    $cookie="cpanel_cookie.txt";


    //login to cPanel
    $ch=curl_init();
    curl_setopt($chCURLOPT_URL"http://domain.com:2082/login/?user=$cpanel_username&pass=$cpanel_password");
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
    curl_setopt($chCURLOPT_COOKIEJAR$cookie);
    curl_setopt($chCURLOPT_COOKIEFILE$cookie);
    $post=curl_exec($ch);
    curl_close($ch);

    //echo $post; //if I echo this, everything works PERFECTLY - I'm logged in!




    //add cronjob(s)

    //parse existing cronjobs first
    $ch=curl_init();
    curl_setopt($chCURLOPT_URL"http://domain.com:2082/frontend/x3/cron/advcron.html");
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
    curl_setopt($chCURLOPT_COOKIEFILE$cookie);
    $post=curl_exec($ch);
    curl_close($ch);

    //echo $post; //if I echo this, I'm NOT logged in anymore! But *SOMETIMES* it works...
    Any ideas?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,216
    Likes Received:
    10
    Trophy Points:
    313
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Do you have XSRF protection(s) enabled? You can check in WHM -> Server Configuration -> Tweak Settings -> Security.

    While it's not a good idea to disable these protections, that's something that could be interfering with the functionality of your script.
     
  3. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    156
    It's disabled. The most interesting part is that SOMETIMES it works correctly, and sometimes does not.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice