mirror of
https://github.com/Art-of-WiFi/UniFi-API-client.git
synced 2024-11-24 03:00:32 +01:00
API client class v1.1.73
- minor spacing changes based on Scrutinizer feedback - updated create_wlan() method/function to work with the new way of assigning a VLAN which now requires passing the _id value of the VLAN, reported by @BeneReuthlinger - merged #132, README update, contributed by @pauloboc - merged #133, adds edit_client_name() method, contributed by @pauloboc
This commit is contained in:
parent
01eafb516a
commit
310abc43b5
@ -133,7 +133,7 @@ own PHP code.
|
||||
|
||||
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.
|
||||
more details on each of the functions/methods and their respective parameters.
|
||||
|
||||
- login()
|
||||
- logout()
|
||||
|
@ -29,24 +29,25 @@ $ch = curl_init();
|
||||
if (is_resource($ch) || is_object($ch)) {
|
||||
/**
|
||||
* If we have a resource or object (for PHP > 8.0), we proceed and set the required cURL options
|
||||
*/
|
||||
curl_setopt($ch, CURLOPT_URL, $controllerurl);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
|
||||
/**
|
||||
* This cURL option can have a value of 0-6
|
||||
*
|
||||
* NOTES:
|
||||
* The cURL option CURLOPT_SSLVERSION can have a value of 0-6
|
||||
* see this URL for more details:
|
||||
* http://php.net/manual/en/function.curl-setopt.php
|
||||
* 0 is the default value and is used by the PHP API client class
|
||||
*/
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 0);
|
||||
$curl_options = [
|
||||
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
|
||||
CURLOPT_URL => $controllerurl,
|
||||
CURLOPT_CUSTOMREQUEST => 'GET',
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_VERBOSE => true,
|
||||
CURLOPT_SSLVERSION => 0,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
];
|
||||
|
||||
/**
|
||||
* Be more verbose
|
||||
*/
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
curl_setopt_array($ch, $curl_options);
|
||||
|
||||
/**
|
||||
* $results contains the output as returned by the cURL request,
|
||||
|
@ -24,7 +24,7 @@ class Client
|
||||
* private and protected properties
|
||||
*
|
||||
* NOTE:
|
||||
* do not modify the values here, instead user the constructor or the getter and setter functions/methods
|
||||
* do not modify the values here, instead use the constructor or the getter and setter functions/methods
|
||||
*/
|
||||
const CLASS_VERSION = '1.1.73';
|
||||
protected $baseurl = 'https://127.0.0.1:8443';
|
||||
@ -60,7 +60,7 @@ class Client
|
||||
* @param string $version optional, the version number of the controller
|
||||
* @param bool $ssl_verify optional, whether to validate the controller's SSL certificate or not, a value of true
|
||||
* is recommended for production environments to prevent potential MitM attacks, default
|
||||
* value (false) disables validation of the controller certificate
|
||||
* value (false) disables validation of the controller's SSL certificate
|
||||
*/
|
||||
public function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false)
|
||||
{
|
||||
@ -1057,23 +1057,23 @@ class Client
|
||||
/**
|
||||
* Assign client device to another group
|
||||
*
|
||||
* @param string $user_id id of the user device to be modified
|
||||
* @param string $group_id id of the user group to assign user to
|
||||
* @param string $client_id _id value of the client device to be modified
|
||||
* @param string $group_id _id value of the user group to assign client device to
|
||||
* @return bool returns true upon success
|
||||
*/
|
||||
public function set_usergroup($user_id, $group_id)
|
||||
public function set_usergroup($client_id, $group_id)
|
||||
{
|
||||
$payload = ['usergroup_id' => $group_id];
|
||||
return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($user_id), $payload);
|
||||
return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($client_id), $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update client fixedip (using REST)
|
||||
* Update client device fixed IP address (using REST)
|
||||
*
|
||||
* @param string $client_id _id value for the client
|
||||
* @param bool $use_fixedip determines whether use_fixedip is true or false
|
||||
* @param string $client_id _id value for the client device
|
||||
* @param bool $use_fixedip determines whether to enable the fixed IP address or not
|
||||
* @param string $network_id optional, _id value for the network where the ip belongs to
|
||||
* @param string $fixed_ip optional, IP address, value of client's fixed_ip field
|
||||
* @param string $fixed_ip optional, IP address, value of client device's fixed_ip field
|
||||
* @return array|false returns an array containing a single object with attributes of the updated client on success
|
||||
*/
|
||||
public function edit_client_fixedip($client_id, $use_fixedip, $network_id = null, $fixed_ip = null)
|
||||
@ -1102,10 +1102,10 @@ class Client
|
||||
}
|
||||
|
||||
/**
|
||||
* Update client name (using REST)
|
||||
* Update client device name (using REST)
|
||||
*
|
||||
* @param string $client_id _id value for the client
|
||||
* @param bool $name of the client
|
||||
* @param string $client_id _id value for the client device
|
||||
* @param string $name name of the client
|
||||
* @return array|false returns an array containing a single object with attributes of the updated client on success
|
||||
*/
|
||||
public function edit_client_name($client_id, $name)
|
||||
@ -1116,8 +1116,8 @@ class Client
|
||||
|
||||
$this->curl_method = 'PUT';
|
||||
$payload = [
|
||||
'_id' => $client_id,
|
||||
'name' => $name,
|
||||
'_id' => $client_id,
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
return $this->fetch_results('/api/s/' . $this->site . '/rest/user/' . trim($client_id), $payload);
|
||||
@ -1825,7 +1825,7 @@ class Client
|
||||
/**
|
||||
* Fetch self
|
||||
*
|
||||
* @return array containing information about the logged in user
|
||||
* @return array containing information about the logged-in user
|
||||
*/
|
||||
public function list_self()
|
||||
{
|
||||
@ -3948,7 +3948,7 @@ class Client
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the HTTP response code
|
||||
* get the HTTP response code
|
||||
*/
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
@ -4027,7 +4027,7 @@ class Client
|
||||
/**
|
||||
* Create and return a new cURL handle
|
||||
*
|
||||
* @return object|bool|resource cURL handle (object or resource) upon success, false upon failure
|
||||
* @return object|resource|bool cURL handle (object or resource) upon success, false upon failure
|
||||
*/
|
||||
protected function get_curl_handle()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user