From 70f982d52506a714565fdafb1c02d8155e3abfa6 Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Mon, 12 Dec 2016 13:23:25 +0100 Subject: [PATCH] API Browser version 1.0.8, API client class version 1.0.12 - API Browser: added option to clear PHP session, useful when login errors occur, mostly after upgrades or incorrect credential changes - API client class: modified list_clients() function/method to also allow request for a single device --- index.php | 23 ++++++++++++++++++++--- phpapi/class.unifi.php | 18 +++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index b10d876..15fd0df 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,7 @@ * the currently supported data collections/API endpoints in the README.md file * - this tool currently supports versions 4.x and 5.x of the UniFi Controller software * - * VERSION: 1.0.7 + * VERSION: 1.0.8 * * ------------------------------------------------------------------------------------ * @@ -20,13 +20,24 @@ * with this package in the file LICENSE.md * */ -define('API_BROWSER_VERSION', '1.0.7'); +define('API_BROWSER_VERSION', '1.0.8'); /** * in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required */ session_start(); +/** + * check whether user has requested to clear the PHP session + * - this function can be useful when login errors occur, mostly after upgrades or incorrect credential changes + */ +if (isset($_GET['reset_session']) && $_GET['reset_session'] == true) { + $_SESSION = array(); + session_unset(); + session_destroy(); + session_start(); +} + /** * starting timing of the session here */ @@ -707,6 +718,8 @@ function sites_sort($a, $b)
  • United
  • Yeti
  • +
  • Reset PHP session
  • +
  • About UniFi API Browser
  • @@ -833,11 +846,15 @@ function sites_sort($a, $b) /** * highlight and mark the selected options in the dropdown menus for $controller_id, $action, $site_id, $theme and $output_format * NOTE: - * these actions are performed conditionally when values are set for the respective PHP variables + * these actions are performed conditionally if values are set for the respective PHP variables */ ('' != '') ? $('#').addClass('active').find('a').append(' ') : false; ('' != '') ? $('#').addClass('active').find('a').append(' ') : false; ('' != '') ? $('#controller_').addClass('active').find('a').append(' ') : false; + + /** + * these two options have default values so no conditions needed here + */ $('#').addClass('active').find('a').append(' '); $('#').addClass('active').find('a').append(' '); diff --git a/phpapi/class.unifi.php b/phpapi/class.unifi.php index 320da1d..4543316 100644 --- a/phpapi/class.unifi.php +++ b/phpapi/class.unifi.php @@ -9,7 +9,7 @@ * and the API as published by Ubiquiti: * https://www.ubnt.com/downloads/unifi/5.3.8/unifi_sh_api * - * VERSION: 1.0.11 + * VERSION: 1.0.12 * * NOTES: * - this Class will only work with UniFi Controller versions 4.x and 5.x. There are no checks to prevent @@ -26,7 +26,7 @@ * with this package in the file LICENSE.md * */ -define('API_CLASS_VERSION', '1.0.11'); +define('API_CLASS_VERSION', '1.0.12'); class unifiapi { public $user = ''; @@ -37,7 +37,6 @@ class unifiapi { public $is_loggedin = FALSE; public $debug = FALSE; private $cookies = ''; - private $payload_len = ''; private $request_type = 'POST'; function __construct($user = '', $password = '', $baseurl = '', $site = '', $version = '') { @@ -524,14 +523,15 @@ public function list_guests($within = 8760) { } /** - * List client devices - * ------------------- - * returns an array of client device objects + * List online client device(s) + * ---------------------------- + * returns an array of online client device objects, or in case of a single device request, returns a single client device object + * optional parameter = the MAC address of a single online client device for which the call must be made */ - public function list_clients() { + public function list_clients($client_mac = NULL) { if (!$this->is_loggedin) return FALSE; $return = array(); - $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/sta')); + $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/sta/'.$client_mac)); if (isset($content_decoded->meta->rc)) { if ($content_decoded->meta->rc == 'ok') { if (is_array($content_decoded->data)) { @@ -549,7 +549,7 @@ public function list_clients() { * Get data for a single client device * ----------------------------------- * returns an object with the client device information - * required parameter = client MAC address + * required parameter = client device MAC address */ public function stat_client($client_mac) { if (!$this->is_loggedin) return FALSE;