API client class v1.1.44

- added example script reconnect_client.php
- fixed typo in URL linking to UniFi section on the UI.com site
- add function/method reboot_cloudkey(), contributed by @leonardogyn
This commit is contained in:
malle-pietje 2020-01-27 13:19:49 +01:00
parent 3fd8e69b4a
commit 2ac791a353
3 changed files with 71 additions and 5 deletions

View File

@ -1,12 +1,12 @@
## UniFi Controller API client class
A PHP class which provides access to Ubiquiti's [**UniFi SDN Controller API**](https://unifi-sdn.ui.com/), versions 4.X.X and 5.X.X of the UniFi SDN Controller software are supported (version 5.11.39 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 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).
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.
## 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.10 and cURL 7.58.0)
- 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
## Installation ##
@ -169,7 +169,9 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
- power_cycle_switch_port()
- reconnect_sta()
- rename_ap()
- restart_ap()
- restart_ap() (deprecated but still available as alias)
- restart_device()
- reboot_cloudkey()
- revoke_voucher()
- set_ap_radiosettings()
- set_device_settings_base()
@ -261,7 +263,7 @@ This class is based on the initial work by the following developers:
and the API as published by Ubiquiti:
- https://dl.ubnt.com/unifi/5.10.19/unifi_sh_api
- https://dl.ui.com/unifi/5.12.35/unifi_sh_api
## Important Disclaimer

45
examples/reconnect_client.php Executable file
View File

@ -0,0 +1,45 @@
<?php
/**
* PHP API usage example
*
* contributed by: Art of WiFi
* description: example basic PHP script to force a client device to reconnect
*/
/**
* using the composer autoloader
*/
require_once('vendor/autoload.php');
/**
* include the config file (place your credentials etc. there if not already present)
* see the config.template.php file for an example
*/
require_once('config.php');
/**
* the MAC address to reconnect
*/
$mac_to_reconnect = '<MAC address>';
/**
* site where the above MAC address is connected
*/
$site_id = '<enter your site id here>';
/**
* initialize the UniFi API connection class and log in to the controller
*/
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login();
/**
* then we force the device to reconnect
*/
$reconnect_result = $unifi_connection->reconnect_sta($mac_to_reconnect);
/**
* provide feedback in json format
*/
echo json_encode($reconnect_result, JSON_PRETTY_PRINT);

View File

@ -2219,6 +2219,25 @@ class Client
return $this->process_response_boolean($response);
}
/**
* Reboot a UniFi CloudKey
* -----------------------
* return true on success
*
* This API call does nothing on UniFi controllers *not* running on a UniFi CloudKey device
*/
public function reboot_cloudkey()
{
if (!$this->is_loggedin) {
return false;
}
$payload = ['cmd' => 'reboot'];
$response = $this->exec_curl('/api/s/' . $this->site . '/cmd/system', $payload);
return $this->process_response_boolean($response);
}
/**
* Disable/enable an access point (using REST)
* -------------------------------------------
@ -2379,7 +2398,7 @@ class Client
return false;
}
$payload = [
$payload = [
'wlan_overrides' => [],
'wlangroup_id_' . $wlantype_id => $wlangroup_id
];