From 4cb1b7be34a19e992977192218007d9c862ad895 Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Wed, 26 Jul 2017 08:43:48 +0200 Subject: [PATCH] API Browser version 1.0.18, API client class version 1.1.7 - API client class: clarification of $site_id in the README - API client class: added method/function list_radius_accounts() - API browser tool: added support for new list_radius_accounts() function/method - API browser tool: added check for php-curl module - API browser tool: general code cleanup --- index.php | 84 ++++++++++++++++++++++++++++-------------- phpapi/README.md | 9 +++++ phpapi/class.unifi.php | 24 +++++++++--- 3 files changed, 85 insertions(+), 32 deletions(-) diff --git a/index.php b/index.php index f036195..d754736 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.17 + * VERSION: 1.0.18 * * ------------------------------------------------------------------------------------ * @@ -20,7 +20,14 @@ * with this package in the file LICENSE.md * */ -define('API_BROWSER_VERSION', '1.0.17'); +define('API_BROWSER_VERSION', '1.0.18'); + +/** + * check whether the PHP curl module is available + */ +if (!function_exists('curl_version')) { + exit('The PHP curl module is not installed! Please correct this before you proceed!
'); +} /** * in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required @@ -61,7 +68,7 @@ * - allows override of several of the previously declared variables * - if the config.php file is unreadable or does not exist, an alert is displayed on the page */ -if(!is_readable('config.php')) { +if (!is_readable('config.php')) { $alert_message = ''; @@ -228,39 +235,55 @@ $set_debug_mode = $unifidata->set_debug(trim($debug)); $loginresults = $unifidata->login(); - if($loginresults === 400) { + if ($loginresults === 400) { $alert_message = ''; - } - /** - * Get the list of sites managed by the UniFi controller (if not already stored in the $_SESSION array) - */ - if (!isset($_SESSION['sites']) || empty($_SESSION['sites'])) { - $sites = $unifidata->list_sites(); - $_SESSION['sites'] = $sites; + /** + * to prevent unwanted errors we assign empty values to the following variables + */ + $sites = []; + $detected_controller_version = 'undetected'; } else { - $sites = $_SESSION['sites']; - } + /** + * Get the list of sites managed by the UniFi controller (if not already stored in the $_SESSION array) + */ + if (!isset($_SESSION['sites']) || empty($_SESSION['sites'])) { + $sites = $unifidata->list_sites(); + if (is_array($sites)) { + $_SESSION['sites'] = $sites; + } else { + $sites = []; - /** - * Get the version of the UniFi controller (if not already stored in the $_SESSION array or when 'undetected') - */ - if (!isset($_SESSION['detected_controller_version']) || $_SESSION['detected_controller_version'] === 'undetected') { - $site_info = $unifidata->stat_sysinfo(); + $alert_message = ''; + } - if (isset($site_info[0]->version)) { - $detected_controller_version = $site_info[0]->version; - $_SESSION['detected_controller_version'] = $detected_controller_version; } else { - $detected_controller_version = 'undetected'; - $_SESSION['detected_controller_version'] = 'undetected'; + $sites = $_SESSION['sites']; } - } else { - $detected_controller_version = $_SESSION['detected_controller_version']; + /** + * Get the version of the UniFi controller (if not already stored in the $_SESSION array or when 'undetected') + */ + if (!isset($_SESSION['detected_controller_version']) || $_SESSION['detected_controller_version'] === 'undetected') { + $site_info = $unifidata->stat_sysinfo(); + + if (isset($site_info[0]->version)) { + $detected_controller_version = $site_info[0]->version; + $_SESSION['detected_controller_version'] = $detected_controller_version; + } else { + $detected_controller_version = 'undetected'; + $_SESSION['detected_controller_version'] = 'undetected'; + } + + } else { + $detected_controller_version = $_SESSION['detected_controller_version']; + } } } @@ -427,6 +450,10 @@ $selection = 'list_admins'; $data = $unifidata->list_admins(); break; + case 'list_radius_accounts': + $selection = 'list_radius_accounts'; + $data = $unifidata->list_radius_accounts(); + break; default: break; } @@ -518,7 +545,7 @@ function sites_sort($site_a, $site_b) - +