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!

problem authenticating in php

Discussion in 'cPanel Developers' started by davidvanrensbur, May 30, 2010.

  1. davidvanrensbur

    Joined:
    May 26, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    51
    hi im having problems authenticating in php
    this is the error im getting when i run my php script
    Not Found

    The requested URL /cpanel/scripts/command was not found on this server.

    This is my php code.


    <?php
    $whmusername = "davidv1";
    $whmpassword = "secret";

    $query = "https://cpanel.pcnetwork.co.za:2087/";

    $curl = curl_init();
    # Create Curl Object
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    # Allow self-signed certs
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
    # Allow certs that do not match the hostname
    curl_setopt($curl, CURLOPT_HEADER,0);
    # Do not include header in output
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
    # Return contents of transfer on curl_exec
    $header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    # set the username and password
    curl_setopt($curl, CURLOPT_URL, $query);
    # execute the query
    $result = curl_exec($curl);
    if ($result == false) {
    error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
    # log error if curl exec fails
    }
    curl_close($curl);

    print $result;

    ?>
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    3
    Trophy Points:
    68
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi davidvanrensbur,

    Are you sure it's an authentication error? Looks more like a 404 error, i.e. the page doesn't exist or isn't been served.

    Also, did you know that there's an XMLAPI PHP client class?
    DevDownloads < AllDocumentation/AutomationIntegration < TWiki

    You can inherit the class and make you own query method modeled on the parent class's. That is, if you need to. You can use the class's authentication mechanisms; ensures authentication is correct. The class can use either cURL or fopen for connections...just a thought :)

    Anyway, a cursory glance at your code looks fine. Try authenticating into WHM and then manually requesting the URL that you PHP code is trying to get all in the browse...just to double check ;)

    Regards,
    -DavidN
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. davidvanrensbur

    Joined:
    May 26, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    51
    hi thanks but,

    If i change the password to something incorrect in my php then it loads up a Login Attempt Failed! cpanel inc etc.

    With that code - it loads up the cpanel type of frames (one along the left, thin one at top, then big in centre) so it looks like its kindof working.
    BUT... in each frame it says Not Found

    The requested URL /cpanel/scripts/command was not found on this server.

    If i then put - http://cpanel.secret.co.za:2086/xml-api/listaccts?searchtype=domain&search=aquarellamining.co.za
    into the address bar it says access is denied (in xml format)

    then if i connect to http://cpanel.secret.co.za:2086/ and login then paste then paste the above address into the address bar it comes back with the correct XML.

    ?? does anyone have any ideas?
    as soon as i can get this to work i should be able to use simple xml and do some nice interface for my supoport staff.
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    3
    Trophy Points:
    68
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    If you're changing the password and you're getting a different notice, then it's obvious that you're authenicating properly.

    Why are you trying to fetch /cpanel/scripts/command? The WHM interface was not designed to be fetched or used programmatically. I'm afraid if you continue doing that you'll probably find several quirks, as you already mentioned. Programmatically interfacing with WHM will undoubtably by unreliable, laborious at best.

    The XMLAPI binary is designed specifically to give you the core functionality of WHM along with access to cPanel (via API1/API2 module/function calls).

    Yes, if in your browser you manually authenticate and then type in an xml-api binary path, it will render in the browser, just as if you had scripted it with PHP or Perl, or whatever.

    Regards,
    -DavidN
     
    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