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
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
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.
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?
Last edited by sshum; 09-04-2007 at 05:11 AM.
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.
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"a=$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); ?>
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.
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.
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.
Thanks for all the help,
I only have one server, and i installed curl which im using anyway.
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.
please show me how to use hode cpanel
so that i can use it now