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.

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:
    6
    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?
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    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:
    6
    It's disabled. The most interesting part is that SOMETIMES it works correctly, and sometimes does not.
     
Loading...

Share This Page