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.

createacct xml-api always returns username taken

Discussion in 'cPanel Developers' started by unihost.pl, Mar 1, 2009.

  1. unihost.pl

    unihost.pl Registered

    Joined:
    Jan 29, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hello,
    I'm working on cPanel 11.24.4-R33609 - WHM 11.24.2 - X 3.9 and using php to call xml-api functions. Everything works perfect: listpkgs, listaccts, accountsummary etc but createacct always returns status=0 statusmsg=Sorry that username (any_username) is taken. Check /etc/passwd :(
    It creates an account but i can't check the result if it was successful or not.

    My function is identical to http://forums.cpanel.net/showpost.php?p=456989&postcount=6 just $apiPath changed to
    Code:
    "/xml-api/createacct?username=$username&plan=$plan&ip=0&cpmod=x3&password=$password&contactemail=$contactemail&domain=$domain&useregns=0&reseller=0"
    Could you give me some suggestions how to get it to work?
    Thanks
     
  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
    A good debugging technique for the XML API is to have the your script output the exact URL it is calling (with the variable values etc.) then attempt to visit that URL manually in your web browser.
     
  3. unihost.pl

    unihost.pl Registered

    Joined:
    Jan 29, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Ok I've checked the url from my script and when I visited it in browser response was good. So to be sure there is no doubt about script i created simple index.php without any database connections etc.
    PHP:
    <?php 
    // VARIABLES:
    //   $hash = your hash (not needed if using password authentication)
    //   $user = username for the reseller accompanying that hash
    //   $pass = password for that reseller (not needed if using hash authentication)
    //   $theServer = your server's hostname or IP
    $hash "long_hash_value";

    $user 'my_username';
    $theServer 'unihost.pl';

    # What is the path to the API function you wish to use?
    $apiPath '/xml-api/createacct?username=xxx&plan=Premium&ip=0&cpmod=x3&password=hardPassword&contactemail=some_mail@mail.eu&domain=xxx.unihost.pl&useregns=0&reseller=0';

    // NOTE:
    //    THIS CODE WILL ONLY WORK IF YOU HAVE ENABLED
    //    OPENSSL IN PHP.  YOU CAN DO THIS BY GOING TO WHM
    //    AND IN THE SOFTWARE SECTION, CLICK ON APACHE UPDATE
    //    THEN LOAD PREVIOUS CONFIG AND THEN CHECK THE BOX
    //    NEXT TO OPENSSL TO ENABLE SSL SUPPORT
    //
    // Of course, you could always go with http:// and 2086, but why?

    # Make hash into one long string, in case it isn't already
    $hash str_replace("\n",'',$hash); // Note \r is not part of the newline indicator on *nix systems.

    # Open a socket for HTTPS
    $fp fsockopen('ssl://' $theServer2087$errno$errstr30);

    # Uncomment to use unsecure HTTP instead
    //$fp = fsockopen($theServer, 2086, $errno, $errstr, 30);

    # Die on error initializing socket
    if ($errno == && $fp == FALSE) {
     die(
    'Socket Error: Could not initialize socket.');
    } elseif (
    $fp == FALSE) {
     die(
    'Socket Error #' $errno ': ' $errstr);
    }

    # Assemble the header to send
    $header '';
    $header .= 'GET ' $apiPath " HTTP/1.0\r\n";
    $header .= 'Host: ' $theServer "\r\n";
    $header .= "Connection: Close\r\n";
    $header .= 'Authorization: WHM ' $user ':' $hash "\r\n";
    # Comment above line and uncomment below line to use password authentication in place of hash authentication
    //$header .= 'Authorization: Basic ' . base64_encode($user . ':' . $pass) . "\r\n";
    $header .= "\r\n";

    # Send the Header
    fputs($fp$header);

    # Get the raw output from the server
    $rawResult '';
    while (!
    feof($fp)) {
     
    $rawResult .= @fgets($fp128); // Suppress errors with @
    }

    # Close the socket
    fclose($fp);

    # Ignore headers
    $rawResultParts explode("\r\n\r\n",$rawResult);
    $result $rawResultParts[1];

    # Output XML
    echo $result;  
    $apiPath is written without any variables.

    And again if I go to index.php it echoes:
    Code:
    0  Sorry that username (xxx) is taken. Check /etc/passwd
    
    but account for user xxx is created.

    if I log in to whm, terminate xxx account and go to
    Code:
    https://unihost.pl:2087/xml-api/createacct?username=xxx&plan=Premium&ip=0&cpmod=x3&password=hardPassword&contactemail=some_mail@mail.eu&domain=xxx.unihost.pl&useregns=0&reseller=0
    everything works fine and i get xml document with good response.

    I don't get it:(
     
  4. 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
    Keep in mind, with PHP, variables are only parsed in strings if the string is encapsulated within "" (double quotes). For example:

    PHP:
    echo "Happy Birthday, $name";
    If the string has single quotes, it is not parsed for variables. Single quotes should only be used for static strings. Any "variable" placed within a single-quote string is treated as a string literal.

    Meaning, in this example:
    PHP:
    echo 'Happy Birthday, $name';
    Literally prints: Happy Birthday, $name
     
  5. unihost.pl

    unihost.pl Registered

    Joined:
    Jan 29, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Yes I know that but as you can see in above script I've just written $apiPath by hand without any variables comming from php so username is just xxx domain is xxx.unihost.pl and so on
     
  6. 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
    And you are certain you are deleting that account before every time you run that hard-coded script?
     
  7. unihost.pl

    unihost.pl Registered

    Joined:
    Jan 29, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Sorry I had no time to visit this board.

    Yes i always delete an account before trying to create it. As i said everything works fine when i put command into address bar in browser co command seems to be correct.
    Now i work on 2 projects so i have no time for finding solution to this problem but it's not closed

    br
     
  8. britsenigma

    britsenigma Well-Known Member

    Joined:
    Dec 14, 2008
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    6
    That link is a virus, don't click it.
     
  9. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
  10. 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
    I first recommend updating to the latest cPanel/WHM. After doing so, let me know if createacct still always tells you the username is taken. If this problem remains, please provide a code sample (or sample URL etc.) we can attempt to use to replicate this issue.
     
Loading...

Share This Page