From 8b4bcc2fa2af351f23593aaf538fb42fca3cf181 Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Sun, 23 Apr 2017 17:13:24 +0200 Subject: [PATCH] API Browser version 1.0.14, API client class version 1.1.3 - API client class: added methods/functions count_alarms(), list_current_channels(), list_dpi_stats() - API client class: added getter/setter methods set_debug, get_last_results_raw and get_last_error_message - API client class: improved code efficiency when handling responses - API browser tool: added support for count_alarms(), list_current_channels(), list_dpi_stats() - API browser tool: minor code cleanup - examples: updated examples with new set_debug() method/function --- README.md | 7 +- examples/auth_guest_with_note.php | 5 +- examples/extend_guest_auth.php | 6 +- examples/list_alarms.php | 8 +- examples/list_ap_connected_users.php | 7 +- examples/list_site_health.php | 7 +- examples/list_social_auth_details.php | 7 +- examples/toggle_led.php | 18 +- index.php | 50 +++--- phpapi/README.md | 7 + phpapi/class.unifi.php | 235 +++++++++++++++++++------- 11 files changed, 251 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index 6558114..f9dd11f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This tool is for browsing data that is exposed through Ubiquiti's UniFi Controll Please keep the following in mind: - not all data collections/API endpoints are supported (yet), see the list below of currently supported data collections/API endpoints -- currently supports versions 4.x.x and 5.x.x of the UniFi Controller software (version 5.3.8 has been confirmed to work) +- currently supports versions 4.x.x and 5.x.x of the UniFi Controller software (version 5.4.12 has been confirmed to work) - there is still work to be done to add/improve functionality and usability of this tool so suggestions/comments are welcome. Please use the github issue list or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/m-p/1392651) to share your ideas. - please read the Security Notice below before installing this tool! @@ -61,10 +61,13 @@ The UniFi API browser tool offers the following features: - list network configuration - list port configurations - list port forwarding rules + - list current channels + - list DPI stats - dynamic DNS configuration - Messages - list events - list alarms + - count alarms Please note that the bundled API client supports many more API endpoints, not all make sense to add to the API browser though. @@ -72,7 +75,7 @@ Please note that the bundled API client supports many more API endpoints, not al The PHP API client that comes bundled with this tool is based on the work done by the following developers: - domwo: http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051 - fbagnol: https://github.com/fbagnol/class.unifi.php -- and the API as published by Ubiquiti: https://www.ubnt.com/downloads/unifi/5.3.8/unifi_sh_api +- and the API as published by Ubiquiti: https://www.ubnt.com/downloads/unifi/5.4.14/unifi_sh_api Other included libraries: - Bootstrap (version 3.3.6) http://getbootstrap.com/ diff --git a/examples/auth_guest_with_note.php b/examples/auth_guest_with_note.php index 4303d84..d26f523 100644 --- a/examples/auth_guest_with_note.php +++ b/examples/auth_guest_with_note.php @@ -38,8 +38,9 @@ * load the Unifi API connection class and log in to the controller */ require_once('../phpapi/class.unifi.php'); -$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); -$loginresults = $unifidata->login(); +$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); /** * To add note to a new device we need to do the following before authorizing the device: diff --git a/examples/extend_guest_auth.php b/examples/extend_guest_auth.php index 25961f5..6909b4c 100644 --- a/examples/extend_guest_auth.php +++ b/examples/extend_guest_auth.php @@ -13,9 +13,9 @@ $site_id = "default"; $site_name = "*enter your site name*"; -$unifidata = new unifiapi ($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); -$unifidata->debug = false; -$loginresults = $unifidata->login(); +$unifidata = new unifiapi ($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); if ($loginresults === 400) { print "UniFi controller login failure, please check your credentials in config.php.\n"; diff --git a/examples/list_alarms.php b/examples/list_alarms.php index 24c9754..ef251bb 100644 --- a/examples/list_alarms.php +++ b/examples/list_alarms.php @@ -21,12 +21,12 @@ /** * load the Unifi API connection class and log in to the controller and do our thing - * list_alarms() */ require_once('../phpapi/class.unifi.php'); -$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); -$loginresults = $unifidata->login(); -$data = $unifidata->list_alarms(); +$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); +$data = $unifidata->list_alarms(); /** * provide feedback in json format diff --git a/examples/list_ap_connected_users.php b/examples/list_ap_connected_users.php index d3d48af..3dc325a 100644 --- a/examples/list_ap_connected_users.php +++ b/examples/list_ap_connected_users.php @@ -24,9 +24,10 @@ * load the Unifi API connection class and log in to the controller and pull the requested data */ require_once('../phpapi/class.unifi.php'); -$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); -$loginresults = $unifidata->login(); -$aps_array = $unifidata->list_aps(); +$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); +$aps_array = $unifidata->list_aps(); /** * output the results in HTML format diff --git a/examples/list_site_health.php b/examples/list_site_health.php index 5eddcb7..1926155 100644 --- a/examples/list_site_health.php +++ b/examples/list_site_health.php @@ -25,9 +25,10 @@ */ require_once('../phpapi/class.unifi.php'); -$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); -$loginresults = $unifidata->login(); -$result = $unifidata->list_health(); +$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); +$result = $unifidata->list_health(); /** * output the results in correct json formatting diff --git a/examples/list_social_auth_details.php b/examples/list_social_auth_details.php index c660fa6..320b12e 100644 --- a/examples/list_social_auth_details.php +++ b/examples/list_social_auth_details.php @@ -24,9 +24,10 @@ * load the Unifi API connection class and log in to the controller and do our thing */ require_once('../phpapi/class.unifi.php'); -$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); -$loginresults = $unifidata->login(); -$data = $unifidata->stat_payment(); +$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); +$data = $unifidata->stat_payment(); /** * cycle through the results and print social auth details if set, diff --git a/examples/toggle_led.php b/examples/toggle_led.php index 771b24c..b10b1d6 100644 --- a/examples/toggle_led.php +++ b/examples/toggle_led.php @@ -29,11 +29,21 @@ * load the Unifi API connection class and log in to the controller to do our thing */ require_once('../phpapi/class.unifi.php'); -$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); // initialize the class instance -$loginresults = $unifidata->login(); // log into the controller +$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); // initialize the class instance +$set_debug_mode = $unifidata->set_debug($debug); +$loginresults = $unifidata->login(); // log into the controller -$data = $unifidata->set_locate_ap($mac); // uncomment to switch locating on -//$data = $unifidata->unset_locate_ap($mac); // uncomment to switch locating off (choose either of these two lines!) +/** + * using the "old" deprecated methods/functions + */ +//$data = $unifidata->set_locate_ap($mac); // uncomment to switch locating on +//$data = $unifidata->unset_locate_ap($mac); // uncomment to switch locating off (choose either of these two lines!) + +/** + * using the new method/function + */ +$data = $unifidata->locate_ap($mac, true); // uncomment to switch locating on +//$data = $unifidata->locate_ap($mac, false); // uncomment to switch locating off (choose either of these two lines!) if ($data) { /** diff --git a/index.php b/index.php index bc49559..0428728 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.13 + * VERSION: 1.0.14 * * ------------------------------------------------------------------------------------ * @@ -20,7 +20,7 @@ * with this package in the file LICENSE.md * */ -define('API_BROWSER_VERSION', '1.0.13'); +define('API_BROWSER_VERSION', '1.0.14'); /** * in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required @@ -52,12 +52,9 @@ $site_name = ''; $selection = ''; $output_format = 'json'; -$theme = 'bootstrap'; $data = ''; $objects_count = ''; $alert_message = ''; -$cookietimeout = '1800'; -$debug = false; /** * load the configuration file @@ -227,9 +224,9 @@ * create a new instance of the API client class and log in to the UniFi controller * - if an error occurs during the login process, an alert is displayed on the page */ - $unifidata = new unifiapi($controller['user'], $controller['password'], $controller['url'], $site_id, $controller['version']); - $unifidata->debug = $debug; - $loginresults = $unifidata->login(); + $unifidata = new unifiapi($controller['user'], $controller['password'], $controller['url'], $site_id, $controller['version']); + $set_debug_mode = $unifidata->set_debug(trim($debug)); + $loginresults = $unifidata->login(); if($loginresults === 400) { $alert_message = '