Compare commits

...

6 Commits

Author SHA1 Message Date
malle-pietje
0d99d4a776 API client class v1.1.56
- switched to use of curl_setopt_array instead of curl_setopt which should slightly reduce the overall PHP execution time (https://gist.github.com/masakielastic/3330620)
- several minor code improvements
2020-06-13 12:28:43 +02:00
malle-pietje
89ce2fd8dd - general code clean up
- removed repetitive code (checks using $this->is_loggedin())
- updated the main README to include the latest added functions/methods
2020-06-08 12:52:32 +02:00
malle-pietje
c77913fded API client class v1.1.54
- fixed list_alarms() method/function
2020-06-07 14:23:44 +02:00
malle-pietje
329ad595c9 API client class v1.1.53
- added list_routing() method/function, contributed by @VWT-Dan
- added list_firmware() method/function
- added get_class_version() method/function, returns the (semantic) version number of the Class
- cleaned up the class to remove repetitive code
- changed names of several protected functions for improved consistency
- general code clean up
- minor additions to the main README file
2020-06-07 14:11:52 +02:00
malle-pietje
badb615627 API client class v1.1.52
- fixed exec_curl() for cases where the cookie has expired and we need to re-login
- removed obsolete functions/methods
2020-04-14 14:59:00 +02:00
malle-pietje
49d0986bd7 API client class v1.1.51
- updated README with all getter and setter methods/functions
- updated get_cookies() and get_cookie() for consistency
- get_cookie() remains for backward compatibility only, should not be used in new code
- fix rare cases where the client would end up in a loop, e.g. issuing a request for a site the cached credentials have no
access to
2020-03-19 16:07:31 +01:00
3 changed files with 523 additions and 1153 deletions

View File

@@ -1,19 +1,21 @@
## UniFi Controller API client class ## 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. 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.
## Requirements ## Requirements
- 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) - a 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 - network connectivity between this server and the host and port (normally TCP port 8443) where the UniFi Controller is running
- you must use **local accounts**, not UniFi Cloud accounts, to access the UniFi Controller API through this class
## UniFi OS 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. ## UbiOS Support
Please test all methods you plan on using thoroughly before using the API Client with UniFi OS devices in a production environment. 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 UbiOS devices in a production environment.
## Installation ## Installation
@@ -100,7 +102,7 @@ Please refer to the `examples/` directory for some more detailed examples which
## Functions/methods supported ## 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() - login()
- logout() - logout()
@@ -151,6 +153,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- list_events() - list_events()
- list_extension() - list_extension()
- list_firewallgroups() - list_firewallgroups()
- list_firmware()
- list_guests() - list_guests()
- list_health() - list_health()
- list_hotspotop() - list_hotspotop()
@@ -162,6 +165,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- list_radius_accounts() (supported on controller version 5.5.19 and higher) - list_radius_accounts() (supported on controller version 5.5.19 and higher)
- list_radius_profiles() - list_radius_profiles()
- list_rogueaps() - list_rogueaps()
- list_routing()
- list_self() - list_self()
- list_settings() - list_settings()
- list_sites() - list_sites()
@@ -242,15 +246,29 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- cancel_rolling_upgrade() - cancel_rolling_upgrade()
- cmd_stat() - cmd_stat()
Internal functions, getters/setters: Other functions, getters/setters:
- set_debug() - set_debug()
- get_debug() - get_debug()
- set_site() - set_site()
- get_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_results_raw()
- get_last_error_message() - 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()
- get_class_version()
## Need help or have suggestions? ## Need help or have suggestions?

View File

@@ -47,7 +47,7 @@ $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $
$set_debug_mode = $unifi_connection->set_debug($debug); $set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login(); // always true regardless of site id $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 is always true even if mac address does not exist :(
$block_result = $unifi_connection->block_sta($mac); $block_result = $unifi_connection->block_sta($mac);

File diff suppressed because it is too large Load Diff