Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
329ad595c9 | ||
|
|
badb615627 | ||
|
|
49d0986bd7 | ||
|
|
0ebbb4efac | ||
|
|
903d3e47d5 | ||
|
|
e72dea7357 | ||
|
|
17d895076f | ||
|
|
961d692125 | ||
|
|
796ad9a82d |
36
README.md
36
README.md
@@ -1,17 +1,21 @@
|
|||||||
## UniFi Controller API client class
|
## UniFi Controller API client class
|
||||||
|
|
||||||
A PHP class which 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). 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).
|
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).
|
||||||
|
|
||||||
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.
|
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
|
|
||||||
|
|
||||||
Currently, UniFi OS-based controllers (UniFi Dream Machine Pro) are **not supported** due to several breaking changes to the API.
|
## UbiOS Support
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
@@ -98,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()
|
||||||
@@ -240,15 +244,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?
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
$controlleruser = ''; // the user name for access to the UniFi Controller
|
$controlleruser = ''; // the user name for access to the UniFi Controller
|
||||||
$controllerpassword = ''; // the password for access to the UniFi Controller
|
$controllerpassword = ''; // the password for access to the UniFi Controller
|
||||||
$controllerurl = ''; // full url to the UniFi Controller, eg. 'https://22.22.11.11:8443'
|
$controllerurl = ''; // full url to the UniFi Controller, eg. 'https://22.22.11.11:8443', for UniFi OS-based
|
||||||
$controllerversion = ''; // the version of the Controller software, eg. '4.6.6' (must be at least 4.0.0)
|
// controllers a port suffix isn't required, no trailing slashes should be added
|
||||||
|
$controllerversion = ''; // the version of the Controller software, e.g. '4.6.6' (must be at least 4.0.0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set to true (without quotes) to enable debug output to the browser and the PHP error log
|
* set to true (without quotes) to enable debug output to the browser and the PHP error log
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ require_once('config.php');
|
|||||||
* Check whether the cURL module supports SSL
|
* Check whether the cURL module supports SSL
|
||||||
*/
|
*/
|
||||||
if (!curl_version()['features'] & CURL_VERSION_SSL) {
|
if (!curl_version()['features'] & CURL_VERSION_SSL) {
|
||||||
print 'SSL is not supported with this cURL installation!' . PHP_EOL;
|
print PHP_EOL . 'SSL is not supported with this cURL installation!' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,44 +25,48 @@ if (!curl_version()['features'] & CURL_VERSION_SSL) {
|
|||||||
*/
|
*/
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
/**
|
if (is_resource($ch)) {
|
||||||
* Set the required cURL options
|
/**
|
||||||
*/
|
* If we have a resource, we proceed and set the required cURL options
|
||||||
curl_setopt($ch, CURLOPT_URL, $controllerurl);
|
*/
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
curl_setopt($ch, CURLOPT_URL, $controllerurl);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This cURL option can have a value of 0-6
|
* This cURL option can have a value of 0-6
|
||||||
* see this URL for more details:
|
* see this URL for more details:
|
||||||
* http://php.net/manual/en/function.curl-setopt.php
|
* http://php.net/manual/en/function.curl-setopt.php
|
||||||
* 0 is the default value and is used by the PHP API client class
|
* 0 is the default value and is used by the PHP API client class
|
||||||
*/
|
*/
|
||||||
curl_setopt($ch, CURLOPT_SSLVERSION, 0);
|
curl_setopt($ch, CURLOPT_SSLVERSION, 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Be more verbose
|
* Be more verbose
|
||||||
*/
|
*/
|
||||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $results contains the output as returned by the cURL request,
|
* $results contains the output as returned by the cURL request,
|
||||||
* returns true when successful, else returns false
|
* returns true when successful, else returns false
|
||||||
*/
|
*/
|
||||||
print 'verbose output from the cURL request:' . PHP_EOL;
|
print PHP_EOL . 'verbose output from the cURL request:' . PHP_EOL;
|
||||||
$results = curl_exec($ch);
|
$results = curl_exec($ch);
|
||||||
|
|
||||||
print PHP_EOL . 'curl_getinfo output:' . PHP_EOL;
|
print PHP_EOL . 'curl_getinfo output:' . PHP_EOL;
|
||||||
print_r(curl_getinfo($ch));
|
print_r(curl_getinfo($ch));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we receive a cURL error, output it before the results
|
* If we receive a cURL error, output it before the results
|
||||||
*/
|
*/
|
||||||
if (curl_errno($ch)) {
|
if (curl_errno($ch)) {
|
||||||
print PHP_EOL . 'cURL error: ' . curl_error($ch) . PHP_EOL;
|
print PHP_EOL . 'cURL error: ' . curl_error($ch) . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
print PHP_EOL . '$results:' . PHP_EOL;
|
||||||
|
print_r($results);
|
||||||
|
print PHP_EOL;
|
||||||
|
} else {
|
||||||
|
print PHP_EOL . 'ERROR: cURL could not be initialized!' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
print PHP_EOL . '$results:' . PHP_EOL;
|
|
||||||
print_r($results);
|
|
||||||
print PHP_EOL;
|
|
||||||
@@ -72,8 +72,8 @@ $current_conf = $data[0]->port_overrides;
|
|||||||
/**
|
/**
|
||||||
* This reads in the values provided via URL or in the command line, if nothing is set than it will poe_mode will be set to "auto"
|
* This reads in the values provided via URL or in the command line, if nothing is set than it will poe_mode will be set to "auto"
|
||||||
*/
|
*/
|
||||||
if (isset($_GET[$poe_mode])) {
|
if (isset($_GET['poe_mode'])) {
|
||||||
$poe_mode = $_GET[poe_mode];
|
$poe_mode = $_GET['poe_mode'];
|
||||||
} elseif (isset($argv[1])) {
|
} elseif (isset($argv[1])) {
|
||||||
$poe_mode = $argv[1];
|
$poe_mode = $argv[1];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
1413
src/Client.php
1413
src/Client.php
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user