Skip to content

Commit be5d7c6

Browse files
author
Matthew Dees
committed
Initial checkin of the xml-api PHP class
1 parent 05475b1 commit be5d7c6

14 files changed

+2660
-0
lines changed

CHANGELOG.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
CHANGELOG.txt for xmlapi.php
2+
3+
1.0.7:
4+
- Corrected typo for setrellerlimits where xml_query incorrectly called xml-api's setresellerips
5+
6+
1.0.6:
7+
- Changed 'user' URL parameter for API1/2 calls to 'cpanel_xmlapi_user'/'cpanel_jsonapi_user' to
8+
resolve conflicts with API2 functions that use 'user' as a parameter
9+
- Relocated exmaple script to Example subdirectory
10+
- Modified example scripts to take remote server IP and root password from environment variables
11+
REMOTE_HOST and REMOTE_PASSWORD, respectively
12+
- Created subdirectory Tests for PHPUnit tests
13+
- Add PHPUnit test BasicParseTest.php
14+
15+
1.0.5:
16+
- fix bug where api1_query and api2_query would not return JSON data
17+
18+
1.0.4:
19+
- set_port will now convert non-int values to ints
20+
21+
1.0.3:
22+
- Fixed issue with set_auth_type using incorrect logic for determining acceptable auth types
23+
- Suppress non-UTF8 encoding when using curl
24+
25+
1.0.2:
26+
- Increased curl buffer size to 128kb from 16kb
27+
- Fix double encoding issue in terminateresellers()
28+
29+
1.0.1:
30+
- Fixed use of wrong variable name in curl error checking
31+
- adjust park() to use api2 rather than API1
32+
33+
1.0
34+
- Added in 11.25 functions
35+
- Changed the constructor to allow for either the "DEFINE" config setting method or using parameters
36+
- Removed used of the gui setting
37+
- Added fopen support
38+
- Added auto detection for fopen or curl (uses curl by default)
39+
- Added ability to return in multiple formats: associative array, simplexml, xml, json
40+
- Added PHP Documentor documentation for all necessary functions
41+
- Changed submission from GET to POST

Examples/adddns_example.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
include("../xmlapi.php");
25+
26+
$ip = getenv('REMOTE_HOST');
27+
$root_pass = getenv('REMOTE_PASSWORD');
28+
29+
$domain = "somedns.com";
30+
31+
$xmlapi = new xmlapi($ip);
32+
$xmlapi->password_auth("root",$root_pass);
33+
$xmlapi->set_http_client('curl');
34+
$xmlapi->set_port(2086);
35+
$xmlapi->set_debug(1);
36+
37+
print $xmlapi->adddns($domain,$ip);
38+
39+
?>

Examples/addip_example.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
include("../xmlapi.php");
25+
26+
$ip = getenv('REMOTE_HOST');
27+
$root_pass = getenv('REMOTE_PASSWORD');
28+
29+
$xmlapi = new xmlapi($ip);
30+
$xmlapi->password_auth("root",$root_pass);
31+
32+
$xmlapi->set_debug(1);
33+
34+
print $xmlapi->addip("127.0.0.3","255.255.255.0");
35+
36+
?>

Examples/api1_example.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
include("../xmlapi.php");
25+
26+
$ip = getenv('REMOTE_HOST');
27+
$root_pass = getenv('REMOTE_PASSWORD');
28+
29+
$account = "cptest";
30+
$email_user = "somerandomuser";
31+
$email_password = "adfm90f1m3f0m0adf";
32+
$email_domain = "somedomain.com";
33+
$email_query = '10';
34+
35+
$xmlapi = new xmlapi($ip);
36+
$xmlapi->password_auth("root",$root_pass);
37+
$xmlapi->set_output('json');
38+
39+
$xmlapi->set_debug(1);
40+
print $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
41+
42+
43+
?>

Examples/api2_example.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
include("../xmlapi.php");
25+
26+
$ip = getenv('REMOTE_HOST');
27+
$root_pass = getenv('REMOTE_PASSWORD');
28+
29+
30+
$account = "cptest";
31+
32+
$xmlapi = new xmlapi($ip);
33+
$xmlapi->password_auth("root",$root_pass);
34+
$xmlapi->set_output("json");
35+
36+
$xmlapi->set_debug(1);
37+
print $xmlapi->api2_query($account, "Email", "listpopswithdisk" );
38+
39+
40+
?>

Examples/api2_example_withargs.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
include("../xmlapi.php");
25+
26+
$ip = getenv('REMOTE_HOST');
27+
$root_pass = getenv('REMOTE_PASSWORD');
28+
29+
$account = "someuser";
30+
$email_account = "randomemail";
31+
$email_domain = "somedomain.com";
32+
33+
$xmlapi = new xmlapi($ip);
34+
$xmlapi->password_auth("root",$root_pass);
35+
36+
$xmlapi->set_debug(1);
37+
print $xmlapi->api2_query($account, "Email", "getdiskusage", array(domain=>$email_domain, login=>$email_account) );
38+
39+
40+
?>

Examples/createacct_example.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
include_once "../xmlapi.php" ;
24+
25+
$ip = getenv('REMOTE_HOST');
26+
$root_pass = getenv('REMOTE_PASSWORD');
27+
28+
$xmlapi = new xmlapi($ip);
29+
$xmlapi->password_auth("root",$root_pass);
30+
31+
$xmlapi->set_debug(1);
32+
33+
$acct = array( username => "someuser", password => "pass123", domain => "thisdomain.com");
34+
print $xmlapi->createacct($acct);
35+
36+
?>

Examples/hashauth_example.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
25+
include("../xmlapi.php");
26+
27+
$ip = getenv('REMOTE_HOST');
28+
29+
# The access has can be found on your server under WHM's "Setup remote access hash" section or at /root/.accesshash
30+
$root_hash = '__ROOT_HASH_GOES_HERE__';
31+
32+
$xmlapi = new xmlapi($ip);
33+
$xmlapi->hash_auth("root",$root_hash);
34+
$xmlapi->return_xml(1);
35+
$xmlapi->set_debug(1);
36+
37+
print $xmlapi->listaccts();
38+
39+
?>

Examples/killdns_example.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
# Copyright (c) 2009, cPanel, Inc.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided
6+
# that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9+
# following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
# following disclaimer in the documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
13+
# products derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
24+
include("../xmlapi.php");
25+
26+
$ip = getenv('REMOTE_HOST');
27+
$root_pass = getenv('REMOTE_PASSWORD');
28+
29+
$domain = "somedns.com";
30+
31+
$xmlapi = new xmlapi($ip);
32+
$xmlapi->password_auth("root",$root_pass);
33+
34+
$xmlapi->set_debug(1);
35+
36+
print $xmlapi->killdns($domain);
37+
38+
?>

0 commit comments

Comments
 (0)