Skip to content

Commit 62ff5f1

Browse files
committed
Adjustments
added extra comments, renamed class file and added new example file for the Mysql module.
1 parent 0bf3b2b commit 62ff5f1

File tree

3 files changed

+62
-9
lines changed

3 files changed

+62
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See the example files, but typical useage takes the form of:
88

99
```
1010
//load class
11-
$cpuapi = new cpaneluapi('user', 'password', 'cpanel.example.com');
11+
$cpuapi = new cpanelUAPI('user', 'password', 'cpanel.example.com');
1212
1313
//Set the scope to the module we want to use. in this case, Mysql
1414
$cpuapi->scope = 'Mysql';

cpaneluapi.class renamed to cpaneluapi.class.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<?php
22

3+
/**
4+
* PHP class to handle connections with cPanel's UAPI as seamlessly and simply as possible.
5+
*
6+
* For documentation on cPanel's UAPI:
7+
* @see https://documentation.cpanel.net/display/SDK/UAPI+Functions
8+
*
9+
* @author N1ghteyes - www.source-control.co.uk
10+
* @copyright 2014 N1ghteyes
11+
* @license license.txt The MIT License (MIT)
12+
* @link https://github.com/N1ghteyes/cpanel-UAPI-php-class
13+
*/
14+
315
/**
416
* Class cpanelUAPI
517
*/
@@ -82,7 +94,7 @@ protected function curl_request($url)
8294
curl_setopt($ch, CURLOPT_URL, $url);
8395
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic " . $this->auth));
8496
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
85-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
97+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
8698

8799
$content = $this->curl_exec_follow($ch);
88100
$err = curl_errno($ch);
@@ -118,22 +130,22 @@ protected function curl_exec_follow($ch, &$maxredirect = null)
118130

119131
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
120132
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
121-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
122-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
133+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
134+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
123135

124136
} else {
125137

126-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
138+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
127139

128140
if ($mr > 0) {
129141
$original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
130142
$newurl = $original_url;
131143

132144
$rch = curl_copy_handle($ch);
133145

134-
curl_setopt($rch, CURLOPT_HEADER, true);
135-
curl_setopt($rch, CURLOPT_NOBODY, true);
136-
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
146+
curl_setopt($rch, CURLOPT_HEADER, TRUE);
147+
curl_setopt($rch, CURLOPT_NOBODY, TRUE);
148+
curl_setopt($rch, CURLOPT_FORBID_REUSE, FALSE);
137149
do {
138150
curl_setopt($rch, CURLOPT_URL, $newurl);
139151
$header = curl_exec($rch);
@@ -164,7 +176,7 @@ protected function curl_exec_follow($ch, &$maxredirect = null)
164176
else
165177
$maxredirect = 0;
166178

167-
return false;
179+
return FALSE;
168180
}
169181
curl_setopt($ch, CURLOPT_URL, $newurl);
170182
}

examples/mysql.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* For documentation on cPanel's UAPI:
5+
* @see https://documentation.cpanel.net/display/SDK/UAPI+Functions
6+
*
7+
* @author N1ghteyes - www.source-control.co.uk
8+
* @copyright 2014 N1ghteyes
9+
* @license license.txt The MIT License (MIT)
10+
* @link https://github.com/N1ghteyes/cpanel-UAPI-php-class
11+
*/
12+
13+
include "../cpaneluapi.class.php"; //include the class file
14+
$uapi = new cpanelUAPI('cPuser', 'cPpass', 'cPanel.example.com'); //instantiate the object
15+
16+
$database = 'database';
17+
$databaseuser = 'databaseuser';
18+
$databasepass = 'databasepass';
19+
20+
/**
21+
* Mysql - Create a database and user, then assign the user to that database.
22+
* For a full list of functions available for the Mysql module, see: https://documentation.cpanel.net/display/SDK/Mysql
23+
* Mysql requires cPanel 11.44 +
24+
*/
25+
26+
$uapi->scope = 'Mysql'; // set the scope to the module we want to use. NOTE: this IS case sensitive.
27+
28+
//If database prefixing is enabled, this parameter must include the database prefix for the account.
29+
//This is normally the account username, followed by an underscore. e.g. cPuser_database.
30+
// ----
31+
//Arguments are passed by an array, where a url parameter of ?name=database is needed, it is passed with
32+
//the array key as the parameter e.g. array('name' => 'database').
33+
34+
$uapi->create_database(array('name' => $database)); //Create the database
35+
$uapi->create_user(array('name' => $databaseuser, 'password' => $databasepass)); //create a user for the new database
36+
37+
38+
//After you create the user, you must use the set_privileges_on_database function call to grant access to the
39+
//user for a database.
40+
//add the user, set all privileges - add specific privileges by comma separation. e.g. 'DELETE,UPDATE,CREATE,ALTER'
41+
$uapi->set_privileges_on_database(array('user' => $databaseuser, 'database' => $database, 'privileges' => 'ALL'));

0 commit comments

Comments
 (0)