Free PHP interface for cPanel API

Patiek

Active Member
May 23, 2003
36
0
156
I wrote this script one day for fun a few months ago and I decided to share it since I really haven't used it and I release most of my scripts under gnu gpl anyway ;)

I honestly do not know the state of this script as I wrote / tested it to some degree a few months ago. Therefore I do not know what still works or never worked. I do know that I originally tested a bunch of the functionality. However, I do not think I tested subdomains extensively (as I found a bug or two related to subs when documenting it just now) and that makes me think other parts *may* not be tested. Remember, the script was written a few months ago so html for some parts could possibly have changed (requiring regex change) and if so just tell me.

Originally the script was designed to be run as root so I have no idea if URLs that it access are valid for resellers as well (I would guess they are). Never tested for reseller account though (only as root). The original file is PHP 5, so I have produced both PHP 5 and PHP 4 versions, with PHP 4 version completely untested (simply has PHP 5 specific tags stripped out).

The primary functions are as follows:
createAccount()
changeOwner()
addReseller()
setResellerLimits()
suspendAccount()
enableAccount()
deleteAccount()
getAccountList()
getPackageList()
getError()
isReseller()
isUser()
isDomain()
getUser()
getPackage()
getDomain()
getAllDomains()
isSubdomain()
getSubdomains()
getAllSubdomains()

Most of those functions accept various arguments and I just now went through and tried to document the large majority of it. The methods are fairly well commented but I haven't gone through the code to comment any of it yet as I usually do. Again, this was original intended for private use exclusively so I didn't count on others seeing this... so feel free to point out errors. The main goal of the script was to add reseller functionality.

If for nothing else, this script would certainly be a good start on a more developed interface to cPanel API for various people who make such requests. I attached a version / identification to it in the event I decide to develop it.

You can find download attached. Use _PHP4 version of file if you have PHP 4.x (not tested).
 

Attachments

Last edited:

Patiek

Active Member
May 23, 2003
36
0
156
I have updated it again (actually, this is my third time).

Fixed a few bugs:
PHP 4 version's constructor had a typo. Reseller usernames' included html underline and subdomains were not being correctly handled in some cases.

I also updated the examples to be a bit better looking. If anyone encounters any errors in new version, please post them.
 

-jdk-

Well-Known Member
Aug 28, 2005
63
0
156
How about a request: Multi add addon domains :) That would be a nice feature.
 

Patiek

Active Member
May 23, 2003
36
0
156
-jdk- said:
How about a request: Multi add addon domains :) That would be a nice feature.
The ability to park a domain (functionality of /scripts/prepark in WHM)?
 

arshem

Member
Jul 16, 2006
9
0
151
Warning: Invalid argument supplied for foreach() in /home/*/public_html/order/EP_Dev_cPanel_API_PHP4.php on line 497
Packages:

Any way to fix that...?
 

Patiek

Active Member
May 23, 2003
36
0
156
arshem said:
Warning: Invalid argument supplied for foreach() in /home/*/public_html/order/EP_Dev_cPanel_API_PHP4.php on line 497
Packages:

Any way to fix that...?
Make sure you are using the latest version (the BETA 3 zip file) that I updated yesterday. There were some bugs with my first two releases simply because I didn't do much testing before hand and the script was a few months old.

I tested the beta 3 version using root on two separate servers using default WHM skin. The specific error you posted is the result of one or more of the following:
a) Constructor not being called (fixed in beta 3).
b) Command to API failing.
c) regex not working when parsing accounts (non-standard or non-default WHM html perhaps).

In other words, it is the result of fetchAccountList() failing. You should make sure commands in general are working.
 
Last edited:

arshem

Member
Jul 16, 2006
9
0
151
Patiek said:
I tested the beta 3 version using root on two separate servers using default WHM skin. The specific error you posted is the result of one or more of the following:
a) Constructor not being called (fixed in beta 3).
b) Command to API failing.
c) regex not working when parsing accounts (non-standard or non-default WHM html perhaps).

In other words, it is the result of fetchAccountList() failing. You should make sure commands in general are working.
I am usin the latest one(downlaoded just not 5 mintues ago) and it's showing a Webhost Login page...am supose to addon on to cpanel(my host for some reason disabled the addons for cpanel)
 

Patiek

Active Member
May 23, 2003
36
0
156
This script will only work with root access at the moment (because of /scripts/reslist). I will see if I can implement a secondary account parsing function. Of course reseller creation capability is not possible without root access or third party hacks / add-ons to cPanel.
 

arshem

Member
Jul 16, 2006
9
0
151
I can create accounts manually through WHM but for some reason they have disabled add-ons
 

Patiek

Active Member
May 23, 2003
36
0
156
I think I posted this in the wrong forum and you are confused because of it.

This is not an add-on. As stated in the title, it is a PHP interface for cPanel API.
 

arshem

Member
Jul 16, 2006
9
0
151
Okay i was JUST making srue, and could i use the script if i can access WHM?i can add users and stuff so i didnt know...it does shwo all the packages but that thats all the ones on the entire server..which i would like to narrow down to just mine any suggestiosn?
 

Patiek

Active Member
May 23, 2003
36
0
156
arshem said:
Okay i was JUST making srue, and could i use the script if i can access WHM?i can add users and stuff so i didnt know...it does shwo all the packages but that thats all the ones on the entire server..which i would like to narrow down to just mine any suggestiosn?
I already answered that question:

Patiek said:
This script will only work with root access at the moment (because of /scripts/reslist).
 

B12Org

Well-Known Member
Jul 15, 2003
691
1
168
Seattle Washington
cPanel Access Level
Root Administrator
Hi guys,

I was wondering, how would I call these scripts from a remote machine, sort of as a publicly available web service/api.

The reason I ask is becuase i want to use one api to connect to and manage the account through this api - one that would reside on multiple servers, and the main api would connect to the machine's whm/cpanel api accordingly.