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.

Creating Reseller Accounts using PHP?

Discussion in 'cPanel Developers' started by sshum, Sep 1, 2007.

  1. sshum

    sshum Registered

    Joined:
    Aug 31, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I have cPanel server, and I am making a simple script to create accounts in PHP.

    I can make accounts no problem, but I dont know how to make reseller accounts.

    Can anyone point me in the right direction :)

    Thanks,
    -Stu
     
  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
    With the XML API (http://www.cpanel.net/plugins/xmlapi/index.html) you can add Reseller Privileges to an existing user.

    You would use setupreseller (http://www.cpanel.net/plugins/xmlapi/setupreseller.html) to grant Reseller Privileges then use setacls (http://www.cpanel.net/plugins/xmlapi/setacls.html) to specify which privileges they should have.
     
  3. sshum

    sshum Registered

    Joined:
    Aug 31, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Thanks, I got it working.

    How do I set Disk and Bandwidth limits for a reseller? do i do it while adding the ACL?


    ---

    Also i got another question,

    Is it better to use the xml api to create a normal account? or should i use the accounting modual thingy?

    Also, which versions of cpanel does the xml api work on? I got cPanel 11, does it also work on 10?
     
    #3 sshum, Sep 4, 2007
    Last edited: Sep 4, 2007
  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
    I believe there was recently a feature request for setting reseller Disk and Bandwidth limits on the XML API mailing list. However, I do not have an ETA on when such functionality will be added to the API.

    Both methods will work equally well for now. However, you will find that the XML API as a whole is much more flexible.

    The XML API was not available in cPanel 10. However, with cPanel 11 being released into STABLE it is only a matter of time before the vast majority of those running cPanel are running version 11.
     
  5. wsenter

    wsenter Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    88
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Texas
    You could always just use PHP curl. I have put together a big page of examples for you...

    Code:
    <?php 
    // start the session and pass the Session parameter
    session_start(); 
    header("Cache-control: private"); //IE 6 Fix
    
    ######### Set up basic variables #########
    $serverIPaddress="192.168.1.1:2087";
    $whmusername="root";
    $whmpassword="123456";
    $server="https://$whmusername:$whmpassword@$serverIPaddress";
    
    //set the username of the account you are working with
    $user = "bobby12";
    $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
    
    
    
    ######### Here are few example of many of the items that you could do with curl.  It will not execute until the very bottom #########
    
    //change user's password
    $url="$server/scripts/passwd?password=$passwd&domain=$user&user=$user";
    
    //enable shell access		
    $url="$server/scripts2/domanageshells?user=$user&shell=Enable+Jailed+Shell&user=$user";
    
    //bandlimit increase		
    $url="$server/scripts2/dolimitbw?user=$user&bwlimit=$bndwidth";
    		
    //suspend an account
    $url="$server/scripts2/suspendacct?domain=$user&user=$user&suspend-domain=Suspend&reason=";
    
    //UN-suspend an account
    $url="$server/scripts2/suspendacct?domain=$user&user=$user&unsuspend-domain=UnSuspend&reason=";
    
    //add front page extensions
    $url="$server/scripts/installfp?domain=$user&user=$user&submit-domain=Install";
    
    //remove front page extensions
    $url="$server/scripts/uninstallfp?domain=$user&user=$user&submit-domain=UnInstall";
    
    //modify the quota on the account		
    $url="$server/scripts/editquota?user=$user&quota=$quota";
    
    //add a domain pointer
    $url="$server/scripts/park?txtdomain=&domain=$domain&ndomain=$NewDomain";
    		
    //modify the account
    $url="$server/scripts/saveedituser?user=$user&BWLIMIT";
    $url.="=$BWLIMIT&FEATURELIST=$FEATURELIST&IP=$IP&OWNER";
    $url.="=$OWNER&PLAN=$PLAN&STARTDATE=$STARTDATE&DNS=$domain";
    $url.="&RS=$RS&LANG=english&newuser=$user&seeshell=$shell&MAXPOP";
    $url.="=$MAXPOP&MAXFTP=$MAXFTP&MAXLST=$MAXLST&MAXSUB=$MAXSUB&MAXSQL";
    $url.="=$MAXSQL&MAXPARK=$MAXPARK&MAXADDON=$MAXADDON";
    
    //generate a csr
     //need to replace spaces in all of the variables with the '+' sign
    $host = str_replace(" ","+",$host);
    $country = str_replace(" ","+",$country);
    $state = str_replace(" ","+",$state);
    $city = str_replace(" ","+",$city);
    $cod = str_replace(" ","+",$cod);
    $co = str_replace(" ","+",$co);
    $email = str_replace(" ","+",$email);
    $pass = str_replace(" ","+",$pass);
    $url="$server/scripts/gencrt?xemail=$xemail&host=$host&country";
    $url.="=$country&state=$state&city=$city&co=$co&cod=$cod&email=$email&pass=$pass";
    		
    ######### execute curl #########
    
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    $buffer = curl_exec($ch);
    curl_close($ch);
    
    ?>
     
  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
    Note, not all servers have PHP Curl enabled so using it may be of limited use to those using the API for distributed billing applications for example.
     
  7. wsenter

    wsenter Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    88
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Texas
    This is correct that not all cPanel servers have curl enabled. However this would not prevent the code that I wrote from working. I'm assuming 1 of 2 possible scenarios with "sshum's" webhosting business.

    1. He only has 1 server total. In this case they would only have to install curl on this ONE server (but most likely it is already there anyway for other applications).

    2. He has multiple servers. 1 of the servers host's his web hosting company's website. (I'll refer to this as his "main" server.) He would only need to have curl installed on the main server as that would be remotely calling the other servers to set up accounts. In fact these other servers would not even need to have curl on them as they would be doing nothing more than responding to simply http requests. For the code I provided he would just change this line...

    $serverIPaddress="192.168.1.1:2087";

    He could even have an array of IP addresses from all of his servers and modify the script to pick one at random to create a new account on a randomly chosen server. I have this very script working perfectly in a live environment.

    As an interesting side note this page here....

    http://www.cpanel.net/support/docs/remoteaccess-php.htm

    It states that in order for cPanel's accounting software to work properly "You must have the curl+SSL module installed for this to work." So basically in order for any form of cpanel accounting scripts to work you need to have curl already enabled.
     
  8. 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
    Nifty, never gave much thought to that myself :).

    Note that cPanel::Accounting (also known as the WHM API, and is what that page references) is completely separate from the XML API. Therefore, what is required by the WHM API is not necessarily required by the XML API.

    However, I will note that the SSL module for PHP will need to be compiled into PHP if you do use https:// rather than http://. Then again if you're going through the inconvenience of enabling that, you can just as easily enable Curl on the same EA3/EA screen.

    Point taken :).
     
  9. sshum

    sshum Registered

    Joined:
    Aug 31, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for all the help,

    I only have one server, and i installed curl which im using anyway.
     
  10. wsenter

    wsenter Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    88
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Texas
    Try the script out.... modify accordingly and then post the script here so that others can benefit from it as well. Let me know how this works in a live environment for ya.
     
  11. info@cbnbank.or

    info@cbnbank.or Registered

    Joined:
    Sep 14, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    reply any one is free to answer me

    please show me how to use hode cpanel
    so that i can use it now
     
  12. wsenter

    wsenter Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    88
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Texas
    I don't understand your question. Please write back on here with a much more indepth explanation.
     
Loading...

Share This Page