Compare commits

...

9 Commits

Author SHA1 Message Date
malle-pietje
665fed93e2 shortened several property names 2021-03-22 11:58:20 +01:00
malle-pietje
36c0fecaff minor improvements 2021-03-22 11:52:44 +01:00
malle-pietje
474578a9d5 removed non-compliant header suffix 2021-03-21 16:08:55 +01:00
malle-pietje
5281db56de API client class v1.1.69
- added list_device_states() function/method, as suggested by @hoerter
- implemented fix to prevent cURL from sending an `Expect: 100-continue` header with each POST request
- implemented a callback function with the CURLOPT_HEADERFUNCTION option to process the response headers after each request and extract the Cookie contents
- general cleanup
2021-03-21 16:03:05 +01:00
malle-pietje
021d01ba86 API client class v1.1.68
- fixed a bug that was introduced with 1.1.67 and would only occur in certain corner cases
2021-01-24 18:09:38 +01:00
malle-pietje
caf838abb9 API client class v1.1.67
- fixed a bug where the request headers for subsequent function calls within the same Client instance would not always be cleared
2021-01-24 17:58:23 +01:00
malle-pietje
aa778c9b7b API client class v1.1.66
- simplified code based on Scrutinizer reports
2021-01-24 14:21:26 +01:00
malle-pietje
0e9ee66cef updated README to include new functions/methods 2021-01-23 11:44:12 +01:00
malle-pietje
721ba7d084 API client class v1.1.65
- applied minor improvements based on Scrutinizer reports
- applied minor changes to `authorize_guest()` to further improve handling of 0/null/empty values passed
- restricted protocols to be used by cURL to only allow http and https for improved security
- added methods/functions `list_device_name_mappings()` and `stat_full_status()`
2021-01-23 11:41:52 +01:00
2 changed files with 322 additions and 235 deletions

View File

@@ -4,6 +4,7 @@ A PHP class that provides access to Ubiquiti's [**UniFi Network Controller**](ht
The package can be installed manually or by using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects. The package can be installed manually or by using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
## Requirements ## Requirements
- a server with PHP, version 5.5.0 or higher, and the PHP cURL module 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) - a server with PHP, version 5.5.0 or higher, and the PHP cURL module 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)
@@ -17,10 +18,12 @@ Support for UniFi OS-based controllers (UniFi Dream Machine Pro or Cloud Key Gen
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 UniFi OS devices in a production environment.
## Installation ## Installation
Use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the API client class. Use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the API client class.
### Composer ### Composer
The preferred installation method is through [composer](https://getcomposer.org). Follow these [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed. The preferred installation method is through [composer](https://getcomposer.org). Follow these [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.
@@ -47,6 +50,7 @@ Finally, be sure to include the autoloader in your code:
require_once 'vendor/autoload.php'; require_once 'vendor/autoload.php';
``` ```
### Git ### Git
Execute the following `git` command from the shell in your project directory: Execute the following `git` command from the shell in your project directory:
@@ -61,6 +65,7 @@ When git is done cloning, include the file containing the class like so in your
require_once 'path/to/src/Client.php'; require_once 'path/to/src/Client.php';
``` ```
### Download the Release ### Download the Release
If you prefer not to use composer or git, 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: If you prefer not to use composer or git, 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:
@@ -69,6 +74,7 @@ If you prefer not to use composer or git, simply [download the package](https://
require_once 'path/to/src/Client.php'; require_once 'path/to/src/Client.php';
``` ```
## Example usage ## Example usage
A basic example how to use the class: A basic example how to use the class:
@@ -90,6 +96,7 @@ $results = $unifi_connection->list_alarms(); // returns a PHP array con
Please refer to the `examples/` directory for some more detailed examples which can be used as a starting point for your own PHP code. Please refer to the `examples/` directory for some more detailed examples which can be used as a starting point for your own PHP code.
#### IMPORTANT NOTES: #### IMPORTANT NOTES:
1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when managing the site in the UniFi Network Controller. For example with this URL: 1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when managing the site in the UniFi Network Controller. For example with this URL:
@@ -98,7 +105,8 @@ Please refer to the `examples/` directory for some more detailed examples which
`jl3z2shm` is the short site "name" and the value to assign to $site_id. `jl3z2shm` is the short site "name" and the value to assign to $site_id.
2. 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 that is associated with the FQDN in the `controller_url` parameter. This option was added with API client version 1.1.16. 2. 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 that is associated with the FQDN in the `controller_url` parameter. This option was added with API client version 1.1.16.
## Functions/methods supported ## Functions/methods supported
@@ -156,6 +164,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- list_current_channels() - list_current_channels()
- list_dashboard() - list_dashboard()
- list_devices() - list_devices()
- list_device_name_mappings()
- list_dpi_stats() - list_dpi_stats()
- list_dynamicdns() - list_dynamicdns()
- list_events() - list_events()
@@ -247,6 +256,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- stat_speedtest_results() - stat_speedtest_results()
- stat_sta_sessions_latest() - stat_sta_sessions_latest()
- stat_status() - stat_status()
- stat_full_status()
- stat_sysinfo() - stat_sysinfo()
- stat_voucher() - stat_voucher()
- stat_monthly_aps() - stat_monthly_aps()
@@ -287,10 +297,12 @@ Other functions, getters/setters:
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. 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.
## Contribute ## Contribute
If you would like to contribute code (improvements), please open an issue and include your code there or else create a pull request. If you would like to contribute code (improvements), please open an issue and include your code there or else create a pull request.
## Credits ## Credits
This class is based on the initial work by the following developers: This class is based on the initial work by the following developers:
@@ -302,6 +314,7 @@ and the API as published by Ubiquiti:
- https://dl.ui.com/unifi/6.0.41/unifi_sh_api - https://dl.ui.com/unifi/6.0.41/unifi_sh_api
## Important Disclaimer ## Important Disclaimer
Many of the functions in this API client class are not officially supported by UBNT and as such, may not be supported in future versions of the UniFi Controller API. Many of the functions in this API client class are not officially supported by UBNT and as such, may not be supported in future versions of the UniFi Controller API.

File diff suppressed because it is too large Load Diff