Skip to content

Commit 70f982d

Browse files
committed
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
1 parent 0584fc4 commit 70f982d

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

index.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* the currently supported data collections/API endpoints in the README.md file
1111
* - this tool currently supports versions 4.x and 5.x of the UniFi Controller software
1212
*
13-
* VERSION: 1.0.7
13+
* VERSION: 1.0.8
1414
*
1515
* ------------------------------------------------------------------------------------
1616
*
@@ -20,13 +20,24 @@
2020
* with this package in the file LICENSE.md
2121
*
2222
*/
23-
define('API_BROWSER_VERSION', '1.0.7');
23+
define('API_BROWSER_VERSION', '1.0.8');
2424

2525
/**
2626
* in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required
2727
*/
2828
session_start();
2929

30+
/**
31+
* check whether user has requested to clear the PHP session
32+
* - this function can be useful when login errors occur, mostly after upgrades or incorrect credential changes
33+
*/
34+
if (isset($_GET['reset_session']) && $_GET['reset_session'] == true) {
35+
$_SESSION = array();
36+
session_unset();
37+
session_destroy();
38+
session_start();
39+
}
40+
3041
/**
3142
* starting timing of the session here
3243
*/
@@ -707,6 +718,8 @@ function sites_sort($a, $b)
707718
<li id="united"><a href="?theme=united">United</a></li>
708719
<li id="yeti"><a href="?theme=yeti">Yeti</a></li>
709720
<li role="separator" class="divider"></li>
721+
<li id="reset_session" data-toggle="tooltip" data-placement="top" data-original-title="In some cases this will fix login errors (empty sites list)"><a href="?reset_session=true"><i class="fa fa-refresh"></i> Reset PHP session</a></li>
722+
<li role="separator" class="divider"></li>
710723
<li id="info" data-toggle="modal" data-target="#aboutModal"><a href="#"><i class="fa fa-info-circle"></i> About UniFi API Browser</a></li>
711724
</ul>
712725
</li>
@@ -833,11 +846,15 @@ function sites_sort($a, $b)
833846
/**
834847
* highlight and mark the selected options in the dropdown menus for $controller_id, $action, $site_id, $theme and $output_format
835848
* NOTE:
836-
* these actions are performed conditionally when values are set for the respective PHP variables
849+
* these actions are performed conditionally if values are set for the respective PHP variables
837850
*/
838851
('<?php echo $action ?>' != '') ? $('#<?php echo $action ?>').addClass('active').find('a').append(' <i class="fa fa-check"></i>') : false;
839852
('<?php echo $site_id ?>' != '') ? $('#<?php echo $site_id ?>').addClass('active').find('a').append(' <i class="fa fa-check"></i>') : false;
840853
('<?php echo $controller_id ?>' != '') ? $('#controller_<?php echo $controller_id ?>').addClass('active').find('a').append(' <i class="fa fa-check"></i>') : false;
854+
855+
/**
856+
* these two options have default values so no conditions needed here
857+
*/
841858
$('#<?php echo $output_format ?>').addClass('active').find('a').append(' <i class="fa fa-check"></i>');
842859
$('#<?php echo $theme ?>').addClass('active').find('a').append(' <i class="fa fa-check"></i>');
843860

phpapi/class.unifi.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* and the API as published by Ubiquiti:
1010
* https://www.ubnt.com/downloads/unifi/5.3.8/unifi_sh_api
1111
*
12-
* VERSION: 1.0.11
12+
* VERSION: 1.0.12
1313
*
1414
* NOTES:
1515
* - this Class will only work with UniFi Controller versions 4.x and 5.x. There are no checks to prevent
@@ -26,7 +26,7 @@
2626
* with this package in the file LICENSE.md
2727
*
2828
*/
29-
define('API_CLASS_VERSION', '1.0.11');
29+
define('API_CLASS_VERSION', '1.0.12');
3030

3131
class unifiapi {
3232
public $user = '';
@@ -37,7 +37,6 @@ class unifiapi {
3737
public $is_loggedin = FALSE;
3838
public $debug = FALSE;
3939
private $cookies = '';
40-
private $payload_len = '';
4140
private $request_type = 'POST';
4241

4342
function __construct($user = '', $password = '', $baseurl = '', $site = '', $version = '') {
@@ -524,14 +523,15 @@ public function list_guests($within = 8760) {
524523
}
525524

526525
/**
527-
* List client devices
528-
* -------------------
529-
* returns an array of client device objects
526+
* List online client device(s)
527+
* ----------------------------
528+
* returns an array of online client device objects, or in case of a single device request, returns a single client device object
529+
* optional parameter <client_mac> = the MAC address of a single online client device for which the call must be made
530530
*/
531-
public function list_clients() {
531+
public function list_clients($client_mac = NULL) {
532532
if (!$this->is_loggedin) return FALSE;
533533
$return = array();
534-
$content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/sta'));
534+
$content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/sta/'.$client_mac));
535535
if (isset($content_decoded->meta->rc)) {
536536
if ($content_decoded->meta->rc == 'ok') {
537537
if (is_array($content_decoded->data)) {
@@ -549,7 +549,7 @@ public function list_clients() {
549549
* Get data for a single client device
550550
* -----------------------------------
551551
* returns an object with the client device information
552-
* required parameter <client_mac> = client MAC address
552+
* required parameter <client_mac> = client device MAC address
553553
*/
554554
public function stat_client($client_mac) {
555555
if (!$this->is_loggedin) return FALSE;

0 commit comments

Comments
 (0)