I've spent the past few weeks working on re-writing the XML-API PHP class, this is done taking lessons learned from the original one to write it in a much easier to use, fully-documented format. Within the new class, we have quite a few new features (and full backwards-compatibility with the old version.
I have also incorporated some of the features from the versions posted to the previous thread on the XML-API PHP Class. Thanks to all of y'all that have given feedback on this class/providing patches/etc it really is appreciated as it helps speed up development. Also I owe thanks to xenomedia and klaude from softlayer for helping with the development of this class.
New Features:
Added in 11.25 functions
Changed the constructor to allow for either the "DEFINE" config setting method or using parameters
Removed used of the gui setting
Added fopen support
Added auto detection for fopen or curl (uses curl by default)
Added ability to return in multiple formats: associative array, simplexml, xml, json
Added PHP Documentor documentation for all necessary functions
Changed submission from GET to POST
Change api1 and api2 query to use XML-API fast mode
added authentication failure detection for 11.24
add array checking where array parameters are taken in
This has been under internal review for a few days now and I feel that it is fleshed out to a point where it is ready for release. Another thing that we are working on is fully testing this class along with our product testing so that we can ensure that this works properly
URL is at the bottom of this post.
it should also be noted that there is full documentation on this class, look at the docs/ directory in the tarball (it's also pretty well documented in the code)
Original post (stealing for the sake of documentation):
A basic explanation of how to use this should be obvious from the example scripts attached, however I will go over what this is capable of:
All xml-api functions are implemented in this, provided with an easy interface:
f.ex:
Some functions are called with normal arguments:Code:$xmlapi->listaccts() can be used to list accounts
f.ex:
On top of this, some functions require associative arrays (hashes) to be passed to them:Code:$xmlapi->addip($ip,$netmask)
Code:$acct = array( username => "someuser", password => "pass123", domain => "thisdomain.com"); $xmlapi->createacct($acct);
When instantiating this class it needs to call both the constructor and an authenticator function. This class support both password authentication and hash authentication, called via password_auth(user,pass) and hash_auth(user,authhash) respectively.
f.ex with hash auth.
f.ex. with password auth.Code:$xmlapi = new xmlapi($ip); $xmlapi->hash_auth("root",$root_hash);
Another feature is that this object can generate the API1 and API2 code automatically:Code:$xmlapi = new xmlapi($ip); $xmlapi->password_auth("root",$root_pass);
f.ex.
Along with this, some debugging functions are provided with a simple boolean interface.Code:print $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_domain) );
The first of these is set_debug which will show all URLs generated, API1/API2 XML and responses in XML and SimpleXML formats:
f.ex. call
will result in an output similar to:Code:$xmlapi->set_debug(1); $xmlapi->listips();
There is also a return_xml object that will just return the XML as a string rather than a SimpleXML object.Code:QUERY: https://127.0.0.1:2087/xml-api/listips? RAW XML: <listips> <result> <active>1</active> <if>eth1</if> <ip>127.0.0.1</ip> <mainaddr>1</mainaddr> <removable>0</removable> <used>1</used> </result> <result> <active>1</active> <if>eth1:1</if> <ip>127.0.0.2</ip> <mainaddr>0</mainaddr> <removable>0</removable> <used>1</used> </result> <result> <active>1</active> <if>eth1:3</if> <ip>127.0.0.3</ip> <mainaddr>0</mainaddr> <removable>1</removable> <used>0</used> </result> <result> <active>1</active> <if>eth1:4</if> <ip>127.0.0.4</ip> <mainaddr>0</mainaddr> <removable>1</removable> <used>0</used> </result> </listips> <!-- Web Host Manager (c) cPanel, Inc. 2008 http://cpanel.net/ Unauthorized copying is prohibited. --> object(SimpleXMLElement)#2 (1) { ["result"]=> array(4) { [0]=> object(SimpleXMLElement)#3 (6) { ["active"]=> string(1) "1" ["if"]=> string(4) "eth1" ["ip"]=> string(14) "127.0.0.1" ["mainaddr"]=> string(1) "1" ["removable"]=> string(1) "0" ["used"]=> string(1) "1" } [1]=> object(SimpleXMLElement)#4 (6) { ["active"]=> string(1) "1" ["if"]=> string(6) "eth1:1" ["ip"]=> string(14) "127.0.0.2" ["mainaddr"]=> string(1) "0" ["removable"]=> string(1) "0" ["used"]=> string(1) "1" } [2]=> object(SimpleXMLElement)#5 (6) { ["active"]=> string(1) "1" ["if"]=> string(6) "eth1:3" ["ip"]=> string(14) "127.0.0.3" ["mainaddr"]=> string(1) "0" ["removable"]=> string(1) "1" ["used"]=> string(1) "0" } [3]=> object(SimpleXMLElement)#6 (6) { ["active"]=> string(1) "1" ["if"]=> string(6) "eth1:4" ["ip"]=> string(14) "127.0.0.4" ["mainaddr"]=> string(1) "0" ["removable"]=> string(1) "1" ["used"]=> string(1) "0" } } }
EDIT:
Patched for version 1.0.5.
There are a couple of fixes.
http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.7.tar.gz
Changelog:
* 1.0.6:
* Changed 'user' URL parameter for API1/2 calls to 'cpanel_xmlapi_user'/'cpanel_jsonapi_user' to resolve conflicts with API2 functions that use 'user' as a parameter
* Relocated exmaple script to Example subdirectory
* Modified example scripts to take remote server IP and root password from environment variables REMOTE_HOST and REMOTE_PASSWORD, respectively
* Created subdirectory Tests for PHPUnit tests
* Add PHPUnit test BasicParseTest.php
*
* 1.0.5:
* fix bug where api1_query and api2_query would not return JSON data
*
* 1.0.4:
* set_port will now convert non-int values to ints
*
* 1.0.3:
* Fixed issue with set_auth_type using incorrect logic for determining acceptable auth types
* Suppress non-UTF8 encoding when using curl
*
* 1.0.2:
* Increased curl buffer size to 128kb from 16kb
* Fix double encoding issue in terminateresellers()
*
* 1.0.1:
* Fixed use of wrong variable name in curl error checking
* adjust park() to use api2 rather than API1



