Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    3

    Default AddonDomain Help with Curl

    Hi there,

    This was working a while ago but I think a Cpanel Update has stopped it from working since that is the only thing that has changed since. Could anyone just check through the following code to make sure that there isnt anything obvious I have checked the docs a few times over but cant seem to see anything there.

    PHP Code:
    function addDomainToCpanel($url,$cpanelusername,$cpanelpassword)
    {
    $pass "******";
    $queryold "$url:2083/xml-api/cpanel?user=$cpanelusername&xmlin=<cpanelaction><module>AddonDomain</module><func>addaddondomain</func><args><dir>public_html/domains/domains/$url</dir><newdomain>$url</newdomain><subdomain>$url</subdomain><pass>$pass</pass></args></cpanelaction>
    "
    ;
    $query "$url:2083/json-api/cpanel?user=$cpanelusername &cpanel_xmlapi_module=AddonDomain&cpanel_xmlapi_func=addaddondomain &cpanel_xmlapi_version=2&dir=public_html/domain/domains/$url&newdomain=$url&subdomain=$url&pass=$pass";

    $curl curl_init();        
    # Create Curl Object
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER,0);    
    # Allow self-signed certs
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST,0);     
    # Allow certs that do not match the hostname
    curl_setopt($curlCURLOPT_HEADER,0);            
    # Do not include header in output
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);    
    # Return contents of transfer on curl_exec
    $header[0] = "Authorization: Basic " base64_encode($cpanelusername.":".$cpanelpassword) . "\n\r";
    curl_setopt($curlCURLOPT_HTTPHEADER$header);  
    # set the username and password
    curl_setopt($curlCURLOPT_URL$query);            
    # execute the query
    $result curl_exec($curl);
    if (
    $result == false) {
        
    error_log("curl_exec threw error \"" curl_error($curl) . "\" for $query");
        echo 
    curl_error($curl);
        echo 
    $query;
        return 
    0;    
    # log error if curl exec fails
    }
    else
    {
        echo 
    curl_error($curl);
        echo
    "<br><br>";
        echo 
    $query;
        echo
    "<br><br>";
        return 
    1;
    }

    curl_close($curl); 
    If I echo the result of the curl it seems to just take me to the cpanel page.

    Thanks

    Regards

    Chris

  2. #2
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default

    Hi Chris,

    I think your problem is that in variable $query, you're cPanel URL is pointed to the JSON API (json-api) yet your parameter keys are for the XML API.
    Code:
    //direct transcription of your $query string for a proper json-api query
    $query = "$url:2083/json-api/cpanel?"
                   ."user=$cpanelusername"
                   ."&cpanel_jsonapi_module=AddonDomain"
                   ."&cpanel_jsonapi_func=addaddondomain"
                   ."&cpanel_jsonapi_version=2"
                   ."&dir=public_html/domain/domains/$url"
                   ."&newdomain=$url"
                   ."&subdomain=$url"
                   ."&pass=$pass";
    If you just wanted XML results, then just leave the parameters as 'cpanel_xmlapi_X" and change the first part of the URL back to :2083/xml-api/cpanel?

    It that doesn't work, post your $result and well get it figured out.
    -David

    PS. I find it unusual that the base URL of $query, $url, is also the same as what you provide for the new addon domain's 'newdomain' string. I guess I'm missing something.

    PSS. You may want to consider adding some logic similar to the code block below so that you can POST
    Code:
    // Assumes CURLOPT_URL is something like https://$domain:2083/xml-api/cpanel
    //$postdata is a regular query string made with http_build_query()
    //$authstr is your base64_encode with \r\n
    
    $header[0] = $authstr .
    	"Content-Type: application/x-www-form-urlencoded\r\n" .
    	"Content-Length: " . strlen($postdata) . "\r\n" . "\r\n" . $postdata;
    		
    	curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    	curl_setopt($curl, CURLOPT_POST, 1);
    Have you checked out our XMLAPI.php client class? I can make this sort of thing a breeze. http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.5.tar.gz
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

Similar Threads & Tags
Similar threads

  1. PHP compiled with curl, but cannot find curl.so
    By racerx8413 in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 07-15-2011, 06:08 PM
  2. Problem when adding an addondomain
    By max2009 in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 06-18-2009, 11:30 AM
  3. curl-7.9.5-2.2.legacy conflicts with file from package curl-ssl-7.10.3-1'
    By jackie46 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 09-09-2005, 09:03 PM
  4. Replies: 4
    Last Post: 09-09-2005, 09:01 PM
  5. CURL problem, Curl is taking the server load to 40+ Help Please!
    By badawi in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 05-18-2005, 08:28 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube