Skip to content

Commit a145cbf

Browse files
committed
code cleanup based on analysis by [Scrutinizer](https://scrutinizer-ci.com/)
included PHP API client class v1.1.38 minor UX tweaks applied to alerts and the login form
1 parent 4f29f96 commit a145cbf

File tree

7 files changed

+166
-120
lines changed

7 files changed

+166
-120
lines changed

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
>**NOTICE**
2-
>
3-
>The repository has been transferred to this new GitHub organisation account, the project maintainer will remain the same and will continue to actively maintain it.
4-
> If you have previously installed the API browser tool using `git clone`, you may consider pointing the clone to the new repository URL. You can do this with the following command from within the directory of your clone:
5-
>
6-
>```bash
7-
>$ git remote set-url origin https://github.com/Art-of-WiFi/UniFi-API-browser.git
8-
>```
9-
101
## UniFi API browser
112

123
This tool is for browsing data that is exposed through Ubiquiti's UniFi Controller API, written in PHP, JavaScript and the [Bootstrap](http://getbootstrap.com/) CSS framework.
@@ -163,7 +154,7 @@ Showing the online device data collection using the default Bootstrap theme:
163154

164155
With one of the Bootswatch themes selected:
165156

166-
![Dark theme selected](https://user-images.githubusercontent.com/12016131/48832369-463c9000-ed79-11e8-841b-07e7842a23a5.png "Dark theme selected")
157+
![Slate theme selected](https://user-images.githubusercontent.com/12016131/48832369-463c9000-ed79-11e8-841b-07e7842a23a5.png "Slate theme selected")
167158

168159
The "About" modal:
169160

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* with this package in the file LICENSE.md
1818
*
1919
*/
20-
define('API_BROWSER_VERSION', '1.0.34');
20+
define('API_BROWSER_VERSION', '1.0.35');
2121
define('API_CLASS_VERSION', get_client_version());
2222

2323
/**
@@ -1053,6 +1053,7 @@ function get_client_version()
10531053
<div class="panel-body">
10541054
<h3 align="center">UniFi Controller login</h3>
10551055
<br>
1056+
<div id="login_alert_placeholder" style="display: none"></div>
10561057
<form method="post">
10571058
<?php if (empty($controller['user'])) : ?>
10581059
<div class="form-group">
@@ -1267,14 +1268,17 @@ function switchCSS(new_theme) {
12671268
* if needed we display the login form
12681269
*/
12691270
if (show_login == 1 || show_login == 'true') {
1270-
$('#login_form').show();
1271+
$('#login_alert_placeholder').html(alert_message);
1272+
$('#login_alert_placeholder').show();
1273+
$('#login_form').fadeIn(500);
1274+
} else {
1275+
$('#alert_placeholder').html(alert_message);
1276+
$('#alert_placeholder').fadeIn(500);
12711277
}
12721278

12731279
/**
12741280
* update dynamic elements in the DOM using some of the above variables
12751281
*/
1276-
$('#alert_placeholder').html(alert_message);
1277-
$('#alert_placeholder').fadeIn(1000);
12781282
$('#span_site_id').html(site_id);
12791283
$('#span_site_name').html(site_name);
12801284
$('#span_output_format').html(output_format);
@@ -1424,7 +1428,7 @@ function hideTooltip(btn) {
14241428
setTimeout(function () {
14251429
$(btn).tooltip('hide')
14261430
.attr('data-original-title', 'Copy to clipboard');
1427-
}, 1000);
1431+
}, 500);
14281432
}
14291433

14301434
/**

vendor/art-of-wifi/unifi-api-client/README.md

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,97 @@
11
## UniFi Controller API client class
22

3-
A PHP class which provides access to Ubiquiti's **UniFi Controller API**, versions 4.X.X and 5.X.X of the UniFi Controller software are supported (version 5.8.24 has been confirmed to work). It's a standalone version of the class which is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
3+
A PHP class which provides access to Ubiquiti's **UniFi Controller API**, versions 4.X.X and 5.X.X of the UniFi Controller software are supported (version 5.9.29 has been confirmed to work). It's a standalone version of the class which is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
44

55
This class can be installed manually or using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
66

7+
## Requirements
8+
9+
- a web server with PHP and cURL modules installed (tested on apache2 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.0.7 and cURL 7.37.0)
10+
- network connectivity between this web server and the server and port (normally TCP port 8443) where the UniFi Controller is running
11+
12+
## Installation ##
13+
14+
You can use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the API client class.
15+
16+
### Composer
17+
18+
The preferred method is via [composer](https://getcomposer.org). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.
19+
20+
Once composer is installed, simply execute this command from the shell in your project directory:
21+
22+
```sh
23+
composer require art-of-wifi/unifi-api-client
24+
```
25+
26+
Or you can manually add the package to your composer.json file:
27+
28+
```javascript
29+
{
30+
"require": {
31+
"art-of-wifi/unifi-api-client": "^1.1"
32+
}
33+
}
34+
```
35+
36+
Finally, be sure to include the autoloader in your code:
37+
38+
```php
39+
require_once('vendor/autoload.php');
40+
```
41+
42+
### Git
43+
44+
Execute the following `git` command from the shell in your project directory:
45+
46+
```sh
47+
git clone https://github.com/Art-of-WiFi/UniFi-API-client.git
48+
```
49+
50+
When git is done cloning, include the file containing the class like so in your code:
51+
52+
```php
53+
require_once('path/to/src/Client.php');
54+
```
55+
56+
### Download the Release
57+
58+
If you prefer not to use composer or git, you can simply [download the package](https://github.com/Art-of-WiFi/UniFi-API-client/archive/master.zip), uncompress the zip file, then include the file containing the class in your code like so:
59+
60+
```php
61+
require_once('path/to/src/Client.php');
62+
```
63+
64+
## Example usage
65+
66+
A basic example how to use the class:
67+
68+
```php
69+
/**
70+
* load the class using the composer autoloader
71+
*/
72+
require_once('vendor/autoload.php');
73+
74+
/**
75+
* initialize the Unifi API connection class, log in to the controller and request the alarms collection
76+
* (this example assumes you have already assigned the correct values to the variables used)
77+
*/
78+
$unifi_connection = new UniFi_API\Client($controller_user, $controller_password, $controller_url, $site_id, $controller_version, true);
79+
$login = $unifi_connection->login();
80+
$results = $unifi_connection->list_alarms(); // returns a PHP array containing alarm objects
81+
```
82+
83+
Please refer to the `examples/` directory for some more detailed examples which you can use as a starting point for your own PHP code.
84+
85+
#### IMPORTANT NOTES:
86+
87+
1. The last optional parameter that is passed to the constructor in the above example (`true`), enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is highly recommended to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller, and which is associated with the FQDN of the server as used in the `controller_url` parameter. This option was added with API client version 1.1.16.
88+
89+
2. In the example above, `$site_id` is the 8 character short site "name" which is visible in the URL when managing the site in the UniFi Controller:
90+
91+
`https://<controller IP address or FQDN>:8443/manage/site/jl3z2shm/dashboard`
92+
93+
In this case, `jl3z2shm` is the value required for $site_id.
94+
795
## Methods and functions supported
896

997
The class currently supports the following functions/methods to get/post/put/delete data through the UniFi Controller API:
@@ -139,6 +227,7 @@ The class currently supports the following functions/methods to get/post/put/del
139227
- upgrade_device_external()
140228
- start_rolling_upgrade()
141229
- cancel_rolling_upgrade()
230+
- cmd_stat()
142231

143232
Internal functions, getters/setters:
144233

@@ -152,94 +241,6 @@ Internal functions, getters/setters:
152241

153242
Please refer to the source code for more details on the functions/methods and their parameters.
154243

155-
## Requirements
156-
157-
- a web server with PHP and cURL modules installed (tested on apache2 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.0.7 and cURL 7.37.0)
158-
- network connectivity between this web server and the server and port (normally TCP port 8443) where the UniFi Controller is running
159-
160-
## Installation ##
161-
162-
You can use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the API client class.
163-
164-
### Composer
165-
166-
The preferred method is via [composer](https://getcomposer.org). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.
167-
168-
Once composer is installed, simply execute this command from the shell in your project directory:
169-
170-
```sh
171-
composer require art-of-wifi/unifi-api-client
172-
```
173-
174-
Or you can manually add the package to your composer.json file:
175-
176-
```javascript
177-
{
178-
"require": {
179-
"art-of-wifi/unifi-api-client": "^1.1"
180-
}
181-
}
182-
```
183-
184-
Finally, be sure to include the autoloader in your code:
185-
186-
```php
187-
require_once('vendor/autoload.php');
188-
```
189-
190-
### Git
191-
192-
Execute the following `git` command from the shell in your project directory:
193-
194-
```sh
195-
git clone https://github.com/Art-of-WiFi/UniFi-API-client.git
196-
```
197-
198-
When git is done cloning, include the file containing the class like so in your code:
199-
200-
```php
201-
require_once('path/to/src/Client.php');
202-
```
203-
204-
### Download the Release
205-
206-
If you prefer not to use composer or git, you can simply [download the package](https://github.com/Art-of-WiFi/UniFi-API-client/archive/master.zip), uncompress the zip file, then include the file containing the class in your code like so:
207-
208-
```php
209-
require_once('path/to/src/Client.php');
210-
```
211-
212-
## Example usage
213-
214-
A basic example how to use the class:
215-
216-
```php
217-
/**
218-
* load the class using the composer autoloader
219-
*/
220-
require_once('vendor/autoload.php');
221-
222-
/**
223-
* initialize the Unifi API connection class, log in to the controller and request the alarms collection
224-
* (this example assumes you have already assigned the correct values to the variables used)
225-
*/
226-
$unifi_connection = new UniFi_API\Client($controller_user, $controller_password, $controller_url, $site_id, $controller_version, true);
227-
$login = $unifi_connection->login();
228-
$results = $unifi_connection->list_alarms(); // returns a PHP array containing alarm objects
229-
```
230-
231-
Please refer to the `examples/` directory for some more detailed examples which you can use as a starting point for your own PHP code.
232-
233-
#### IMPORTANT NOTES:
234-
235-
1. The last optional parameter that is passed to the constructor in the above example (`true`), enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is highly recommended to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller, and which is associated with the FQDN of the server as used in the `controller_url` parameter. This option was added with API client version 1.1.16.
236-
237-
2. In the example above, `$site_id` is the 8 character short site "name" which is visible in the URL when managing the site in the UniFi Controller:
238-
239-
`https://<controller IP address or FQDN>:8443/manage/site/jl3z2shm/dashboard`
240-
241-
In this case, `jl3z2shm` is the value required for $site_id.
242-
243244
## Need help or have suggestions?
244245

245246
There is still work to be done to add functionality and further improve the usability of this class, so all suggestions/comments are welcome. Please use the GitHub [issue list](https://github.com/Art-of-WiFi/UniFi-API-client/issues) or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/PHP-class-to-access-the-UniFi-controller-API-updates-and/td-p/1512870) to share your suggestions and questions.

vendor/art-of-wifi/unifi-api-client/examples/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ Then update the contents of your new config.php with your controller details and
99

1010
Also make sure to update the path for the composer autoloader file (`vendor/autoload.php`) or the file containing the Class itself (`src/Client.php`) in your `require_once()` statement as required.
1111

12+
#### Executing scripts from the CLI
13+
14+
Most of the included example scripts can be run from the CLI or shell as follows after the necessary credentials and parameters have been added or updated:
15+
16+
17+
```sh
18+
$ php list_site_health.php
19+
```
20+
21+
NOTE: this does require the `php-cli` module to be installed
22+
1223
### Contribute
1324

1425
If you would like to share your own example file(s), please open an issue and include your code there or else create a pull request.

0 commit comments

Comments
 (0)