Skip to content

Commit

Permalink
UniFi API browser 2.0.9
Browse files Browse the repository at this point in the history
- executed composer update to update packages
- upgraded PHP API client to version 1.1.52
- minor changes
- added max. tx/rx-rates attributes to fetch for the gateway stats
  • Loading branch information
malle-pietje committed Apr 14, 2020
1 parent bb6fa34 commit fbade73
Show file tree
Hide file tree
Showing 40 changed files with 327 additions and 270 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ You will find examples and detailed instructions there.
Please keep the following in mind:

- the API browser tool doesn't support all available data collections/API endpoints, see the list below of those that are currently supported
- currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.12.35 has been confirmed to work) as well as UniFi OS-based controllers (version 5.12.59 has been confirmed to work)
- when accessing UniFi OS-based controllers (e.g. UDM PRO) through this tool, please read the remarks below regarding UniFi OS support
- currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.12.66 has been confirmed to work) as well as UbiOS-based controllers (version 5.12.59 has been confirmed to work)
- when accessing UbiOS-based controllers (e.g. UDM PRO) through this tool, please read the remarks below regarding UbiOS support
- there is still work to be done to add/improve functionality and usability of this tool so suggestions/comments are welcome. Please use the GitHub [issue](https://github.com/Art-of-WiFi/UniFi-API-browser/issues) list or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/m-p/1392651) to share your ideas/questions.
- please read the Security Notice below before installing this tool!

Expand Down Expand Up @@ -130,9 +130,9 @@ Alternatively you may choose to download the zip file and unzip it in your direc
- after following these steps, you can open the tool in your browser (assuming you installed it in the root folder of your web server as suggested above) by going to this url: `http(s)://<server IP address>/UniFi-API-browser/`


### UniFi OS support
### UbiOS support

Support for UniFi OS-based controllers (UniFi Dream Machine Pro) has been added with version 2.0.7. When adding the details for a UniFi OS device to the `config/config.php` file, please make sure not to add a port suffix or trailing slashes to the URL.
Support for UbiOS-based controllers (UniFi Dream Machine Pro) has been added with version 2.0.7. When adding the details for a UbiOS device to the `config/config.php` file, please make sure not to add a port suffix or trailing slashes to the URL.


### Extending the dropdown menu
Expand All @@ -148,7 +148,7 @@ $collections = array_merge($collections, [
'options' => [
[
'type' => 'collection', // either collection or divider
'label' => 'hourly site stats past 24 hours', // string that is dosplayed in the dropdown menu
'label' => 'hourly site stats past 24 hours', // string that is displayed in the dropdown menu
'method' => 'stat_hourly_site', // the method/function in the API client class that is called
'params' => [(time() - (24 * 60 *60)) * 1000, time() * 1000], // an array containing the parameters that are passed to the method/function
'key' => 'custom_0' // unique key for this menu option, may be required for future versions
Expand Down
2 changes: 1 addition & 1 deletion ajax/fetch_about_modal_metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
* output the results with correct JSON formatting
*/
header('Content-Type: application/json; charset=utf-8');
echo (json_encode($results));
echo (json_encode($results));
6 changes: 4 additions & 2 deletions ajax/fetch_collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
'lan-tx_dropped',
'wan-tx_bytes',
'wan-rx_bytes',
'max_rx_bytes-r',
'max_tx_bytes-r',
'wan2-tx_bytes',
'wan2-rx_bytes',
'latency_min',
Expand Down Expand Up @@ -196,8 +198,8 @@
$load_perc = (($time_after_load - $time_after_login) / $time_total) * 100;
$remain_perc = 100 - $login_perc - $load_perc;

$results['timings']['login'] = $time_after_login;
$results['timings']['load'] = $time_after_load;
$results['timings']['login'] = $time_after_login;
$results['timings']['load'] = $time_after_load;
$results['timings']['login_perc'] = $login_perc;
$results['timings']['load_perc'] = $load_perc;
}
Expand Down
2 changes: 1 addition & 1 deletion ajax/fetch_sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@
header('Content-Type: application/json; charset=utf-8');
echo (json_encode($results));

$_SESSION['memory_used'] = round(memory_get_peak_usage(false) / 1024 / 1024, 2) . 'M';
$_SESSION['memory_used'] = round(memory_get_peak_usage(false) / 1024 / 1024, 2) . 'M';
2 changes: 1 addition & 1 deletion ajax/show_api_debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@
}
} else {
echo 'ignore';
}
}
2 changes: 1 addition & 1 deletion ajax/update_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
* output the results with correct JSON formatting
*/
header('Content-Type: application/json; charset=utf-8');
echo (json_encode($results));
echo (json_encode($results));
2 changes: 1 addition & 1 deletion ajax/update_theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
* output the results with correct JSON formatting
*/
header('Content-Type: application/json; charset=utf-8');
echo (json_encode($results));
echo (json_encode($results));
2 changes: 1 addition & 1 deletion collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,4 @@
],
],
],
];
];
2 changes: 1 addition & 1 deletion common.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* with this package in the file LICENSE.md
*
*/
define('TOOL_VERSION', '2.0.8');
define('TOOL_VERSION', '2.0.9');

/**
* gather some basic information for the About modal
Expand Down
36 changes: 17 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/config-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
// primary, secondary, success, danger, warning, info, light, dark, white, transparent

$debug = false; // set to true (without quotes) to enable debug output to the browser and the PHP error log
// when fetching the sites collection after selecting a controller
// when fetching the sites collection after selecting a controller
2 changes: 1 addition & 1 deletion config/users-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
'user_name' => '', // string, the user name
'password' => '', // string, the SHA512 hash of the password
],
];
];
4 changes: 2 additions & 2 deletions js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ function fetchCollection() {
'Total time: ' + (json.timings.load + json.timings.login) + ' seconds' +
'<div class="progress">' +
'<div class="progress-bar bg-warning" role="progressbar" style="width: ' + json.timings.login_perc +
'%" aria-valuenow="' + json.timings.login_perc + ' aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="API login took ' + json.timings.login + ' seconds">API login time</div>' +
'%" aria-valuenow="' + json.timings.login_perc + ' aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="API login and connect took ' + json.timings.login + ' seconds">API login</div>' +
'<div class="progress-bar bg-success" role="progressbar" style="width: ' + json.timings.load_perc +
'%" aria-valuenow="' + json.timings.load_perc + '" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="Data loading took ' + json.timings.load + ' seconds">data load time</div>' +
'%" aria-valuenow="' + json.timings.load_perc + '" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="Data transfer took ' + json.timings.load + ' seconds">data transfer</div>' +
'</div>'
)

Expand Down
2 changes: 1 addition & 1 deletion templates/components/about_modal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="modal-body">
<div class="row">
<div class="col-sm-8 offset-sm-2">
A tool for browsing the data collections which are exposed through Ubiquiti's UniFi Controller API, created by <a href="http://www.dereferer.org/?https://artofwifi.net/portfolio/unifi-api-browser/" target="_blank">Art of WiFi</a>.
A tool for browsing the data collections that are exposed through Ubiquiti's UniFi Controller API, created by <a href="http://www.dereferer.org/?https://artofwifi.net/portfolio/unifi-api-browser/" target="_blank">Art of WiFi</a>.
</div>
</div>
<br>
Expand Down
27 changes: 20 additions & 7 deletions vendor/art-of-wifi/unifi-api-client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## UniFi Controller API client class

A PHP class that provides access to Ubiquiti's [**UniFi SDN Controller**](https://unifi-sdn.ui.com/) API, versions 4.X.X and 5.X.X of the UniFi SDN Controller software are supported (version 5.12.35 has been confirmed to work) as well as UniFi OS-based controllers (version 5.12.59 has been confirmed to work). This class is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
A PHP class that provides access to Ubiquiti's [**UniFi SDN Controller**](https://unifi-sdn.ui.com/) API, versions 4.X.X and 5.X.X of the UniFi SDN Controller software are supported (version 5.12.66 has been confirmed to work) as well as UbiOS-based controllers (version 5.12.59 has been confirmed to work). This class is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).

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

Expand All @@ -9,11 +9,11 @@ The package can be installed manually or using composer/[packagist](https://pack
- a web server with PHP and cURL modules installed (tested on Apache 2.4 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.2.24 and cURL 7.58.0)
- network connectivity between this web server and the server and port (normally TCP port 8443) where the UniFi Controller is running

## UniFi OS Support
## UbiOS Support

Support for UniFi OS-based controllers (UniFi Dream Machine Pro) has been added as of version 1.1.47. The class automatically detects UniFi OS devices and adjusts URLs and several functions/methods accordingly. If your own code applies strict validation of the URL that is passed to the constructor, please adapt your logic to allow URLs without a port suffix when dealing with a UniFi OS-based controller.
Support for UbiOS-based controllers (UniFi Dream Machine Pro) has been added as of version 1.1.47. The class automatically detects UbiOS devices and adjusts URLs and several functions/methods accordingly. If your own code applies strict validation of the URL that is passed to the constructor, please adapt your logic to allow URLs without a port suffix when dealing with a UbiOS-based controller.

Please test all methods you plan on using thoroughly before using the API Client with UniFi OS devices in a production environment.
Please test all methods you plan on using thoroughly before using the API Client with UbiOS devices in a production environment.

## Installation

Expand Down Expand Up @@ -100,7 +100,7 @@ Please refer to the `examples/` directory for some more detailed examples which

## Functions/methods supported

The class currently supports the following functions/methods to GET/POST/PUT/DELETE data through the UniFi Controller API. Please refer to the source code for more details on the functions/methods and their respective parameters.
The class currently supports the following functions/methods to GET/POST/PUT/DELETE data through the UniFi Controller API. Please refer to the comments in the source code for more details on the functions/methods and their respective parameters.

- login()
- logout()
Expand Down Expand Up @@ -242,15 +242,28 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- cancel_rolling_upgrade()
- cmd_stat()

Internal functions, getters/setters:
Other functions, getters/setters:

- set_debug()
- get_debug()
- set_site()
- get_site()
- get_cookie() (renamed from getcookie())
- set_cookies()
- get_cookies()
- get_cookie() (renamed from getcookie(), deprecated but still available, use get_cookies() instead)
- get_last_results_raw()
- get_last_error_message()
- set_request_type()
- get_request_type()
- set_ssl_verify_peer()
- get_ssl_verify_peer()
- set_ssl_verify_host()
- get_ssl_verify_host()
- set_connection_timeout()
- get_connection_timeout()
- set_is_unifi_os()
- get_is_unifi_os()


## Need help or have suggestions?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
$set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login(); // always true regardless of site id

foreach ($macs_to_block as &$mac) {
foreach ($macs_to_block as $mac) {
// block_result is always true even if mac address does not exist :(
$block_result = $unifi_connection->block_sta($mac);

Expand Down
Loading

0 comments on commit fbade73

Please sign in to comment.