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.

WHM Account Creation API Issue

Discussion in 'cPanel Developers' started by webdes03, May 4, 2013.

  1. webdes03

    webdes03 Member

    Joined:
    Nov 24, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I've been pulling my hair out on this all day, and I'm wondering if there's any chance there's a bug in the API.

    We're on build 5 of WHM 11.36.1, and we're building our own management utility to handle back-end account creation, support, etc. We're using curl throughout our utility to surface account details and information from WHM and cPanel, with no issues at all, but we're seeing some very strange behavior when using the API to create accounts.

    We automatically generate random 8 character usernames, and random secure passwords, which are pushed to the curl url during execution. We're doing this all behind https, using the WHM accesshash for authentication (just like all of our other curl calls).

    PHP:
    $newAcct curl_init();
    curl_setopt($newAcctCURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($newAcctCURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($newAcctCURLOPT_RETURNTRANSFER,1);
    curl_setopt($newAcctCURLOPT_HEADER0);
    $newAcctHeader[0] = "Authorization: WHM root:".preg_replace("'(\r|\n)'","",$accesshash);
    curl_setopt($newAcctCURLOPT_HTTPHEADER,$newAcctHeader);
    curl_setopt($newAcctCURLOPT_URL,"https://".$host.":2087/json-api/createacct?username=".$username."&plan=".$package."&password=".$password."&domain=".$domain);
    $result curl_exec($newAcct);
    curl_close($newAcct);

    if (
    strpos($result"...Done") === false) {
        echo 
    alert_bar('Error creating hosting account ('.$username.'). ('.$result.')','red');
    }
    Every single time we execute this, it tells us the username is already being used (and errors), but creates the account anyway. As an example...

    The script generated a username of "ofme7bwe" and attempted to create an account for the domain "build.host.com". Neither the domain or user exists in the system. The script did create the account, but the output of the API shows it failed because of the user.

    Code:
    {"result":[{"options":null,"statusmsg":"Sorry, a group for that username already exists.","status":0,"rawout":null}]}
    We're relying on the WHM API output to either halt or continue the configuration of the account, so this "false positive" is holding up the entire script even though it seems to successfully build the account.

    Any thoughts?
     
    #1 webdes03, May 4, 2013
    Last edited: May 4, 2013
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Are you able to add the accounts via WHM UI? This API call is likely just a wrapper around that same account creation process.

    Are you sure that group doesn't actually exist? If you're using "random" names, you may have some collisions as there are only 8 characters.

    Code:
    cat /etc/group | grep "ofme7bwe"
    

    I ran some tests and have 0 issues creating accounts on 11.36.1.5.
     
Loading...

Share This Page