Skip to content

Commit 958483c

Browse files
authored
Merge pull request #8 from Deltik/master
Improved README.md
2 parents b456119 + 83b12b4 commit 958483c

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

README.md

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,79 @@
1-
## cPanel UAPI and API2 PHP class
1+
cPanel UAPI and API2 PHP class
2+
===
3+
[![GitHub release](https://img.shields.io/github/release/N1ghteyes/cpanel-UAPI-php-class.svg?style=flat-square)](https://github.com/N1ghteyes/cpanel-UAPI-php-class/releases)
24

3-
PHP class to provide an easy to use interface with cPanels UAPI and API2.
4-
Uses php magic functions to provide a simple and powerful interface.
5+
PHP class to provide an easy-to-use interface with cPanel's UAPI and API2.
6+
Uses PHP magic functions to provide a simple and powerful interface.
57

6-
v2.0 is not backwards compatible, and will likley under go a few more changes, see the changelog for details.
7-
The class has been renamed to cpanelAPI.
8+
v2.0 is not backwards compatible with v1.x, and will likley undergo a few more changes. See the [changelog](changelog.txt) for details.
9+
The class has been renamed to `cpanelAPI`.
810
Some more testing is required.
911

1012
## Usage
1113

12-
See the example files, but typical useage takes the form of:
14+
See the example files, but typical usage takes the form of:
1315

1416
### Instantiate the class
15-
```
16-
$capi = new cpanelAPI('user', 'password', 'cpanel.example.com');
17+
```php
18+
$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com');
1719
```
1820
The API we want to use and the Module (also called Scope) are now protected and are set by `__get()`.
19-
The request layout looks like this: `$capi->api->Module->request(args[])`
2021

21-
For example. We want to use the UAPI to call the Mysql get_restrictions function.
22-
```
23-
$response = $capi->uapi->Mysql->get_restrictions();
24-
print_r($response);
25-
```
22+
The request layout looks like this: `$cPanel->api->method->Module->request(args[])`
23+
24+
The `->method` part should be replaced with `->get` for GET requests and `->post` for POST requests, or omitted to default to GET requests.
2625

27-
Now that we have set both the api AND the Module, we can call other functions within this api and scope without specifying them again
28-
We have database prefixing enabled so we have to pass the usename into this function
29-
see https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Mysql%3A%3Acreate_database
26+
As an example, suppose we want to use the UAPI to call the [Mysql::get_server_information](https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Mysql%3A%3Aget_server_information) function:
27+
28+
```php
29+
$response = $cPanel->uapi->Mysql->get_server_information();
30+
var_dump($response);
3031
```
31-
$response = $capi->create_database(['name' => $capi->user.'_MyDatabase']);
32-
print_r($response);
32+
33+
Now that we have set both the API *and* the Module, we can call other functions within this API and Module without specifying them again:
34+
35+
```php
36+
$response = $cPanel->create_database(['name' => $cPanel->user.'_MyDatabase']);
37+
var_dump($response);
3338
```
3439

35-
we can also change the scope without respecifying the api, note that the Module call is case-sensitive.
40+
We can also change the Module scope without respecifying the API. Note that the Module call is case-sensitive.
41+
42+
```php
43+
$response = $cPanel->SSL->list_certs();
3644
```
37-
$response = $capi->SSL->list_certs();
45+
46+
#### File upload example
47+
48+
```php
49+
$cPanel = new cpanelAPI($username, $password, $hostname);
50+
$cPanel->uapi->post->Fileman
51+
->upload_files(['dir' => REMOTE_PATH_RELATIVE_TO_HOME,
52+
'file-1' => new CURLFile(LOCAL_PATH_TO_FILE)
53+
]);
3854
```
3955

4056
### API2
4157

4258
API2 is used in exactly the same way as the UAPI
43-
```
44-
$cpapi2 = new cpanelAPI('user', 'password', 'cpanel.example.com');
45-
```
4659

47-
For example. We want to use the API2 to add a subdomain
48-
```
49-
$response = $capi->api2->SubDomain->addsubdomain(['rootdomain' => 'domain.com', 'domain' => 'sub']);
50-
print_r($response);
60+
```php
61+
$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com');
5162
```
5263

53-
### 2 Factor Authentication
64+
For example, suppose we want to use the API2 to add a subdomain:
5465

55-
To use this class on a cPanel instance with 2 Factor authentication, you need to pass the secret into the class constructor.
66+
```php
67+
$response = $cPanel->api2->SubDomain->addsubdomain(['rootdomain' => 'domain.com', 'domain' => 'sub']);
68+
var_dump($response);
5669
```
57-
$capi = new cpanelAPI('user', 'password', 'cpanel.example.com', 'secret');
70+
71+
### Two-Factor Authentication
72+
73+
To use this class on a cPanel instance with two-factor authentication (2FA), you need to pass the secret into the class constructor:
74+
75+
```php
76+
$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com', 'secret');
5877
```
5978

60-
The secret can be found on the 2fa setup page. See: https://documentation.cpanel.net/display/ALD/Two-Factor+Authentication+for+cPanel#Two-FactorAuthenticationforcPanel-Configure2FA
79+
The secret can be found on the 2FA setup page. See [Two-Factor Authentication for cPanel – Configure two-factor authentication](https://documentation.cpanel.net/display/ALD/Two-Factor+Authentication+for+cPanel#Two-FactorAuthenticationforcPanel-Configure2FA) for details.

0 commit comments

Comments
 (0)