From d67ff45892cd8b19896a286a7321002e28ff8daf Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Thu, 10 Dec 2020 16:21:00 +0100 Subject: [PATCH] UniFi API browser 2.0.14 - added menu options for new monthly stats functions/methods - updated PHP API client to 1.1.62 - updated CDN links for Javascript and CSS resources --- README.md | 71 +++-- collections.php | 25 +- common.php | 4 +- composer.lock | 10 +- templates/collections_view.html.twig | 4 +- templates/layout/main.html.twig | 12 +- vendor/art-of-wifi/unifi-api-client/README.md | 6 +- .../examples/modify_smartpower_pdu_outlet.php | 3 + .../unifi-api-client/src/Client.php | 251 +++++++++++++----- vendor/composer/installed.json | 12 +- 10 files changed, 276 insertions(+), 122 deletions(-) diff --git a/README.md b/README.md index b2b31c3..2ac6c3e 100755 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You will find examples and detailed instructions there. Please keep the following in mind: - the API browser tool doesn't support all available data collections/API endpoints, see the list below of those that are currently supported -- currently, versions 4.x.x, 5.x.x, and 6.0.x of the UniFi Controller software are supported (version 6.0.33 has been confirmed to work) as well as UbiOS-based controllers (version 5.12.59 has been confirmed to work) +- currently, versions 4.x.x, 5.x.x, and 6.0.x of the UniFi Controller software are supported (version 6.0.42 has been confirmed to work) as well as UbiOS-based controllers (version 5.12.59 has been confirmed to work) - when accessing UbiOS-based controllers (e.g. UDM PRO) through this tool, please read the remarks below regarding UbiOS support - 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](https://github.com/Art-of-WiFi/UniFi-API-browser/issues) 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/questions. - please read the Security Notice below before installing this tool! @@ -45,6 +45,23 @@ The UniFi API browser tool offers the following features: ### Data collections/API endpoints currently implemented in the API browser +- Configuration + - list sites on this controller + - list site settings + - list admins for current site + - sysinfo + - self + - list wlan config + - list VoIP extension + - list network configuration + - list port configurations + - list port forwarding rules + - list firewall groups + - list current channels + - list DPI stats + - dynamic DNS configuration + - list country codes + - list Radius accounts (supported on controller version 5.5.19 and higher) - Clients/users - list online clients - list guests @@ -56,43 +73,38 @@ The UniFi API browser tool offers the following features: - Devices - list devices (access points, USG routers and USW switches) - list wlan groups + - list AP groups (supported on controller version 6.0.X and higher) - list rogue access points - list_known_rogueaps - list devices tags (supported on controller version 5.5.19 and higher) - Stats + - all sites stats + - 5-minute site stats - hourly site stats - daily site stats + - monthly site stats + - 5-minute access point stats - hourly access point stats - daily access point stats - - all sites stats - - health metrics - - dashboard metrics + - monthly access point stats + - 5-minute gateway stats + - hourly gateway stats + - daily gateway stats + - monthly gateway stats + - 5-minute dashboard metrics + - hourly dashboard metrics + - site health metrics - port forward stats + - DPI stats - Hotspot - stat vouchers - stat payments - list hotspot operators -- Configuration - - list sites on this controller - - list site settings - - list admins for current site - - sysinfo - - self - - list wlan config - - list VoIP extension - - list network configuration - - list port configurations - - list port forwarding rules - - list firewall groups - - list current channels - - list DPI stats - - dynamic DNS configuration - - list country codes - - list Radius accounts (supported on controller version 5.5.19 and higher) - Messages - list events - list alarms - count alarms + - list IDS/IPS events Please note that the bundled API client supports many more API endpoints, not all make sense to add to the API browser though. @@ -201,18 +213,19 @@ The PHP API client that comes bundled with this tool is based on the work by the and the API as published by Ubiquiti: -- https://dl.ui.com/unifi/5.12.21-a25e774adb/unifi_sh_api +- https://dl.ui.com/unifi/6.0.41/unifi_sh_api Other included libraries: -- Bootstrap 4 (version 4.3.1) https://getbootstrap.com -- Bootswatch themes (version 4.3.1) https://bootswatch.com -- Font Awesome icons (version 5.11.2) https://fontawesome.com -- jQuery (version 3.4.1) https://jquery.com -- Twig template engine (version 2.12.1) https://twig.symfony.com -- Highlight.js (version 9.15.10) https://highlightjs.org +- Bootstrap 4 (version 4.5.3) https://getbootstrap.com +- Bootswatch themes (version 4.5.3) https://bootswatch.com +- Font Awesome icons (version 5.15.1) https://fontawesome.com +- jQuery (version 3.5.1) https://jquery.com +- Twig template engine (version 1.44.1) https://twig.symfony.com +- Highlight.js (version 10.4.1) https://highlightjs.org - Kint (version 2.2) https://kint-php.github.io/kint -- clipboard.js (2.0.4) https://clipboardjs.com +- clipboard.js (version 2.0.6) https://clipboardjs.com +- Moment.js (version 2.29.1) https://momentjs.com ### Security notice diff --git a/collections.php b/collections.php index f99f89b..d1cc005 100755 --- a/collections.php +++ b/collections.php @@ -276,6 +276,15 @@ [ 'label' => 'Stats', 'options' => [ + [ + 'type' => 'collection', // or divider + 'label' => 'all sites stats', + 'method' => 'stat_sites', + 'params' => [] + ], + [ + 'type' => 'divider', // or collection + ], [ 'type' => 'collection', // or divider 'label' => '5 minutes site stats', @@ -296,8 +305,8 @@ ], [ 'type' => 'collection', // or divider - 'label' => 'all sites stats', - 'method' => 'stat_sites', + 'label' => 'monthly site stats', + 'method' => 'stat_monthly_site', 'params' => [] ], [ @@ -321,6 +330,12 @@ 'method' => 'stat_daily_aps', 'params' => [] ], + [ + 'type' => 'collection', // or divider + 'label' => 'monthly access point stats', + 'method' => 'stat_monthly_aps', + 'params' => [] + ], [ 'type' => 'divider', // or collection ], @@ -342,6 +357,12 @@ 'method' => 'stat_daily_gateway', 'params' => [] ], + [ + 'type' => 'collection', // or divider + 'label' => 'monthly gateway stats', + 'method' => 'stat_monthly_gateway', + 'params' => [] + ], [ 'type' => 'divider', // or collection ], diff --git a/common.php b/common.php index 04cc112..2ddc3e0 100755 --- a/common.php +++ b/common.php @@ -7,12 +7,12 @@ * with this package in the file LICENSE.md * */ -define('TOOL_VERSION', '2.0.13'); +define('TOOL_VERSION', '2.0.14'); /** * gather some basic information for the About modal */ -$curl_info = curl_version(); +$curl_info = curl_version(); $unknown_string = 'unknown'; /** diff --git a/composer.lock b/composer.lock index c3bd54f..476fc28 100755 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "art-of-wifi/unifi-api-client", - "version": "v1.1.60", + "version": "v1.1.62", "source": { "type": "git", "url": "https://github.com/Art-of-WiFi/UniFi-API-client.git", - "reference": "32252e56d7906feb7b80daaad47d29bce041a3bc" + "reference": "c82481a28a7cca2f96686e291826bf2f2854784d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/32252e56d7906feb7b80daaad47d29bce041a3bc", - "reference": "32252e56d7906feb7b80daaad47d29bce041a3bc", + "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/c82481a28a7cca2f96686e291826bf2f2854784d", + "reference": "c82481a28a7cca2f96686e291826bf2f2854784d", "shasum": "" }, "require": { @@ -52,7 +52,7 @@ "ubiquiti", "unifi" ], - "time": "2020-11-12T10:09:37+00:00" + "time": "2020-12-10T13:52:39+00:00" }, { "name": "kint-php/kint", diff --git a/templates/collections_view.html.twig b/templates/collections_view.html.twig index c992ece..b5b14ba 100755 --- a/templates/collections_view.html.twig +++ b/templates/collections_view.html.twig @@ -95,8 +95,8 @@ {% endblock %} {% block page_scripts %} - - + + - - + + diff --git a/vendor/art-of-wifi/unifi-api-client/README.md b/vendor/art-of-wifi/unifi-api-client/README.md index 1839625..c65205c 100755 --- a/vendor/art-of-wifi/unifi-api-client/README.md +++ b/vendor/art-of-wifi/unifi-api-client/README.md @@ -1,6 +1,6 @@ ## UniFi Controller API client class -A PHP class that provides access to Ubiquiti's [**UniFi Network Controller**](https://unifi-network.ui.com/) API, versions 4.X.X and 5.X.X of the UniFi Network Controller software are supported (version 5.12.72 has been confirmed to work) as well as UbiOS-based controllers (version 5.12.59 has been confirmed to work). This class is used by our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser). +A PHP class that provides access to Ubiquiti's [**UniFi Network Controller**](https://unifi-network.ui.com/) API, versions 4.X.X, 5.X.X and 6.0.X of the UniFi Network Controller software are supported (version 6.0.37 has been confirmed to work) as well as UbiOS-based controllers (version 5.12.59 has been confirmed to work). This class is used by our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser). The package can be installed manually or by using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects. @@ -249,6 +249,10 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL - stat_status() - stat_sysinfo() - stat_voucher() +- stat_monthly_aps() +- stat_monthly_gateway() +- stat_monthly_site() +- stat_monthly_user() - unauthorize_guest() - unblock_sta() - unset_locate_ap() (deprecated but still available as alias) diff --git a/vendor/art-of-wifi/unifi-api-client/examples/modify_smartpower_pdu_outlet.php b/vendor/art-of-wifi/unifi-api-client/examples/modify_smartpower_pdu_outlet.php index 0ad40f3..cedda41 100755 --- a/vendor/art-of-wifi/unifi-api-client/examples/modify_smartpower_pdu_outlet.php +++ b/vendor/art-of-wifi/unifi-api-client/examples/modify_smartpower_pdu_outlet.php @@ -55,6 +55,9 @@ if ($loginresults) { $pdu_details = $unifi_connection->list_devices($pdu_mac); + /** + * change the model below from USPPDUP to UP1 when using a USP-Plug (thanks to @thesohoguy for contributing this) + */ if (!empty($pdu_details) && property_exists($pdu_details[0], 'model') && $pdu_details[0]->model === 'USPPDUP' && property_exists($pdu_details[0], 'outlet_overrides')) { $device_id = $pdu_details[0]->_id; $outlet_overrides = $pdu_details[0]->outlet_overrides; diff --git a/vendor/art-of-wifi/unifi-api-client/src/Client.php b/vendor/art-of-wifi/unifi-api-client/src/Client.php index 2de856b..1122154 100755 --- a/vendor/art-of-wifi/unifi-api-client/src/Client.php +++ b/vendor/art-of-wifi/unifi-api-client/src/Client.php @@ -12,9 +12,9 @@ * * @package UniFi Controller API client class * @author Art of WiFi - * @version 1.1.60 + * @version 1.1.62 * @license This class is subject to the MIT license that is bundled with this package in the file LICENSE.md - * @example See this directory in the package repository for a collection of examples: + * @example This directory in the package repository contains a collection of examples: * https://github.com/Art-of-WiFi/UniFi-API-client/tree/master/examples */ class Client @@ -31,7 +31,7 @@ class Client protected $is_loggedin = false; protected $is_unifi_os = false; protected $exec_retries = 0; - protected $class_version = '1.1.60'; + protected $class_version = '1.1.62'; private $cookies = ''; private $request_type = 'GET'; private $request_types_allowed = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; @@ -46,9 +46,9 @@ class Client * * @param string $user user name to use when connecting to the UniFi controller * @param string $password password to use when connecting to the UniFi controller - * @param string $baseurl optional, base URL of the UniFi controller which *must* include 'https://'' prefix, + * @param string $baseurl optional, base URL of the UniFi controller which *must* include an 'https://' prefix, * a port suffix (e.g. :8443) is required for non-UniFi OS controllers, - * do not add trailing slashes, defaults to 'https://127.0.0.1:8443' + * do not add trailing slashes, default value is 'https://127.0.0.1:8443' * @param string $site optional, short site name to access, defaults to 'default' * @param string $version optional, the version number of the controller * @param bool $ssl_verify optional, whether to validate the controller's SSL certificate or not, a value of true is @@ -301,20 +301,20 @@ public function logout() /** * Authorize a client device * - * @param string $mac client MAC address - * @param int $minutes minutes (from now) until authorization expires - * @param int $up optional, upload speed limit in kbps - * @param int $down optional, download speed limit in kbps - * @param int $MBytes optional, data transfer limit in MB - * @param int $ap_mac optional, AP MAC address to which client is connected, should result in faster authorization - * @return bool returns true upon success + * @param string $mac client MAC address + * @param int $minutes minutes (from now) until authorization expires + * @param int $up optional, upload speed limit in kbps + * @param int $down optional, download speed limit in kbps + * @param int $megabytes optional, data transfer limit in MB + * @param int $ap_mac optional, AP MAC address to which client is connected, should result in faster authorization + * @return bool returns true upon success */ - public function authorize_guest($mac, $minutes, $up = null, $down = null, $MBytes = null, $ap_mac = null) + public function authorize_guest($mac, $minutes, $up = null, $down = null, $megabytes = null, $ap_mac = null) { $payload = ['cmd' => 'authorize-guest', 'mac' => strtolower($mac), 'minutes' => intval($minutes)]; /** - * if we have received values for up/down/MBytes/ap_mac we append them to the payload array to be submitted + * if we have received values for up/down/megabytes/ap_mac we append them to the payload array to be submitted */ if (!is_null($up)) { $payload['up'] = intval($up); @@ -324,8 +324,8 @@ public function authorize_guest($mac, $minutes, $up = null, $down = null, $MByte $payload['down'] = intval($down); } - if (!is_null($MBytes)) { - $payload['bytes'] = intval($MBytes); + if (!is_null($megabytes)) { + $payload['bytes'] = intval($megabytes); } if (!is_null($ap_mac)) { @@ -446,7 +446,7 @@ public function create_user($mac, $user_group_id, $name = null, $note = null, $i * * @param string $user_id id of the client-device to be modified * @param string $note optional, note to be applied to the client-device, when empty or not set, - * the existing note for the client-device will be removed and "noted" attribute set to false + * the existing note for the client-device is removed and "noted" attribute set to false * @return bool returns true upon success */ public function set_sta_note($user_id, $note = null) @@ -462,7 +462,7 @@ public function set_sta_note($user_id, $note = null) * * @param string $user_id id of the client-device to be modified * @param string $name optional, name to be applied to the client device, when empty or not set, - * the existing name for the client device will be removed + * the existing name for the client device is removed * @return bool returns true upon success */ public function set_sta_name($user_id, $name = null) @@ -564,6 +564,36 @@ public function stat_daily_site($start = null, $end = null) return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.site', $payload); } + /** + * Fetch monthly site stats + * + * NOTES: + * - defaults to the past 52 weeks (52*7*24 hours) + * - "bytes" are no longer returned with controller version 4.9.1 and later + * + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of monthly stats objects for the current site + */ + public function stat_monthly_site($start = null, $end = null) + { + $end = empty($end) ? (time() - (time() % 3600)) * 1000 : intval($end); + $start = empty($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start); + $attribs = [ + 'bytes', + 'wan-tx_bytes', + 'wan-rx_bytes', + 'wlan_bytes', + 'num_sta', + 'lan-num_sta', + 'wlan-num_sta', + 'time' + ]; + $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; + + return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.site', $payload); + } + /** * Fetch 5 minutes stats for a single access point or all access points * @@ -646,6 +676,33 @@ public function stat_daily_aps($start = null, $end = null, $mac = null) return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.ap', $payload); } + /** + * Fetch monthly stats for a single access point or all access points + * + * NOTES: + * - defaults to the past 52 weeks (52*7*24 hours) + * - make sure that the retention policy for hourly stats is set to the correct value in + * the controller settings + * + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param string $mac optional, AP MAC address to return stats for, when empty, + * stats for all APs are returned + * @return array returns an array of monthly stats objects + */ + public function stat_monthly_aps($start = null, $end = null, $mac = null) + { + $end = empty($end) ? time() * 1000 : intval($end); + $start = empty($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start); + $attribs = ['bytes', 'num_sta', 'time']; + $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; + if (!empty($mac)) { + $payload['mac'] = strtolower($mac); + } + + return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.ap', $payload); + } + /** * Fetch 5 minutes stats for a single user/client device * @@ -730,6 +787,34 @@ public function stat_daily_user($mac, $start = null, $end = null, $attribs = nul return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.user', $payload); } + /** + * Fetch monthly stats for a single user/client device + * + * NOTES: + * - defaults to the past 13 weeks (52*7*24 hours) + * - only supported with UniFi controller versions 5.8.X and higher + * - make sure that the retention policy for monthly stats is set to the correct value in + * the controller settings + * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance section + * + * @param string $mac MAC address of user/client device to return stats for + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, tx_packets + * default is ['rx_bytes', 'tx_bytes'] + * @return array returns an array of monthly stats objects + */ + public function stat_monthly_user($mac, $start = null, $end = null, $attribs = null) + { + $end = empty($end) ? time() * 1000 : intval($end); + $start = empty($start) ? $end - (13 * 7 * 24 * 3600 * 1000) : intval($start); + $attribs = empty($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); + $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; + + return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.user', $payload); + } + /** * Fetch 5 minutes gateway stats * @@ -787,7 +872,7 @@ public function stat_hourly_gateway($start = null, $end = null, $attribs = null) * Fetch daily gateway stats * * NOTES: - * - defaults to the past 52*7*24 hours + * - defaults to the past 52 weeks (52*7*24 hours) * - requires a USG * * @param int $start optional, Unix timestamp in milliseconds @@ -808,6 +893,31 @@ public function stat_daily_gateway($start = null, $end = null, $attribs = null) return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.gw', $payload); } + /** + * Fetch monthly gateway stats + * + * NOTES: + * - defaults to the past 52 weeks (52*7*24 hours) + * - requires a USG + * + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, + * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped + * default is ['time', 'mem', 'cpu', 'loadavg_5'] + * @return array returns an array of monthly stats objects for the gateway belonging to the current site + */ + public function stat_monthly_gateway($start = null, $end = null, $attribs = null) + { + $end = empty($end) ? (time() - (time() % 3600)) * 1000 : intval($end); + $start = empty($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start); + $attribs = empty($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); + $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; + + return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.gw', $payload); + } + /** * Fetch speed test results * @@ -1085,7 +1195,7 @@ public function delete_usergroup($group_id) */ public function list_apgroups() { - return $this->fetch_results('/v2/api/site/' . $this->site . '/apgroups/' . trim($group_id)); + return $this->fetch_results('/v2/api/site/' . $this->site . '/apgroups'); } /** @@ -1108,7 +1218,7 @@ public function create_apgroup($group_name, $device_macs = []) * @param string $group_id _id value of the AP group to modify * @param string $group_name name to assign to the AP group * @param array $device_macs array containing the members of the AP group which overwrites the existing - * group_members (passing an empty array will clear the AP member list) + * group_members (passing an empty array clears the AP member list) * @return object returns a single object with attributes of the updated AP group on success */ public function edit_apgroup($group_id, $group_name, $device_macs) @@ -1177,7 +1287,7 @@ public function create_firewallgroup($group_name, $group_type, $group_members = * @param string $group_type firewall group type; valid values are address-group, ipv6-address-group, port-group, * group_type cannot be changed for an existing firewall group! * @param array $group_members array containing the members of the group (IPv4 addresses, IPv6 addresses or port numbers) - * which will overwrite the existing group_members (default is an empty array) + * which overwrites the existing group_members (default is an empty array) * @return array containing a single object with attributes of the updated firewall group on success */ public function edit_firewallgroup($group_id, $site_id, $group_name, $group_type, $group_members = []) @@ -1267,10 +1377,10 @@ public function list_users() } /** - * Fetch client devices + * Fetch UniFi devices * - * @param string $device_mac optional, the MAC address of a single device for which the call must be made - * @return array containing known device objects (or a single device when using the parameter) + * @param string $device_mac optional, the MAC address of a single UniFi device for which the call must be made + * @return array containing known UniFi device objects (or a single device when using the parameter) */ public function list_devices($device_mac = null) { @@ -1389,7 +1499,7 @@ public function delete_site($site_id) /** * Change the current site's name * - * NOTES: immediately after being changed, the site will be available in the output of the list_sites() function + * NOTES: immediately after being changed, the site is available in the output of the list_sites() function * * @param string $site_name the new long name for the current site * @return bool true on success @@ -1408,7 +1518,7 @@ public function set_site_name($site_name) * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) * object/array structured in the same manner as is returned by list_settings() for the section with the "country" key. * Valid country codes can be obtained using the list_country_codes() function/method. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_country($country_id, $payload) @@ -1427,7 +1537,7 @@ public function set_site_country($country_id, $payload) * Valid timezones can be obtained in Javascript as explained here: * https://stackoverflow.com/questions/38399465/how-to-get-list-of-all-timezones-in-javascript * or in PHP using timezone_identifiers_list(). - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_locale($locale_id, $payload) @@ -1443,7 +1553,7 @@ public function set_site_locale($locale_id, $payload) * @param string $snmp_id _id value of the snmp section * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) * object/array structured in the same manner as is returned by list_settings() for the section with the "snmp" key. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_snmp($snmp_id, $payload) @@ -1459,7 +1569,7 @@ public function set_site_snmp($snmp_id, $payload) * @param string $mgmt_id _id value of the mgmt section * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) * object/array structured in the same manner as is returned by list_settings() for the section with the "mgmt" key. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_mgmt($mgmt_id, $payload) @@ -1475,7 +1585,7 @@ public function set_site_mgmt($mgmt_id, $payload) * @param string $guest_access_id _id value of the guest_access section * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) * object/array structured in the same manner as is returned by list_settings() for the section with the "guest_access" key. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_guest_access($guest_access_id, $payload) @@ -1491,7 +1601,7 @@ public function set_site_guest_access($guest_access_id, $payload) * @param string $ntp_id _id value of the ntp section * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) * object/array structured in the same manner as is returned by list_settings() for the section with the "ntp" key. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_ntp($ntp_id, $payload) @@ -1507,7 +1617,7 @@ public function set_site_ntp($ntp_id, $payload) * @param string $connectivity_id _id value of the connectivity section * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) * object/array structured in the same manner as is returned by list_settings() for the section with the "connectivity" key. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return bool true on success */ public function set_site_connectivity($connectivity_id, $payload) @@ -1543,20 +1653,20 @@ public function list_all_admins() * Invite a new admin for access to the current site * * NOTES: - * - after issuing a valid request, an invite will be sent to the email address provided - * - issuing this command against an existing admin will trigger a "re-invite" + * - after issuing a valid request, an invite is sent to the email address provided + * - issuing this command against an existing admin triggers a "re-invite" * * @param string $name name to assign to the new admin user * @param string $email email address to assign to the new admin user - * @param bool $enable_sso optional, whether or not SSO will be allowed for the new admin + * @param bool $enable_sso optional, whether or not SSO is allowed for the new admin * default value is true which enables the SSO capability - * @param bool $readonly optional, whether or not the new admin will have readonly + * @param bool $readonly optional, whether or not the new admin has readonly * permissions, default value is false which gives the new admin * Administrator permissions - * @param bool $device_adopt optional, whether or not the new admin will have permissions to + * @param bool $device_adopt optional, whether or not the new admin has permissions to * adopt devices, default value is false. With versions < 5.9.X this only applies * when readonly is true. - * @param bool $device_restart optional, whether or not the new admin will have permissions to + * @param bool $device_restart optional, whether or not the new admin has permissions to * restart devices, default value is false. With versions < 5.9.X this only applies * when readonly is true. * @return bool true on success @@ -1605,13 +1715,13 @@ public function invite_admin( * * @param string $admin_id _id value of the admin user to assign, can be obtained using the * list_all_admins() method/function - * @param bool $readonly optional, whether or not the new admin will have readonly + * @param bool $readonly optional, whether or not the new admin has readonly * permissions, default value is false which gives the new admin * Administrator permissions - * @param bool $device_adopt optional, whether or not the new admin will have permissions to + * @param bool $device_adopt optional, whether or not the new admin has permissions to * adopt devices, default value is false. With versions < 5.9.X this only applies * when readonly is true. - * @param bool $device_restart optional, whether or not the new admin will have permissions to + * @param bool $device_restart optional, whether or not the new admin has permissions to * restart devices, default value is false. With versions < 5.9.X this only applies * when readonly is true. * @return bool true on success @@ -1759,15 +1869,15 @@ public function list_hotspotop() * * NOTES: please use the stat_voucher() method/function to retrieve the newly created voucher(s) by create_time * - * @param int $minutes minutes the voucher is valid after activation (expiration time) - * @param int $count number of vouchers to create, default value is 1 - * @param int $quota single-use or multi-use vouchers, value '0' is for multi-use, '1' is for single-use, - * 'n' is for multi-use n times - * @param string $note note text to add to voucher when printing - * @param int $up upload speed limit in kbps - * @param int $down download speed limit in kbps - * @param int $MBytes data transfer limit in MB - * @return array containing a single object which contains the create_time(stamp) of the voucher(s) created + * @param int $minutes minutes the voucher is valid after activation (expiration time) + * @param int $count number of vouchers to create, default value is 1 + * @param int $quota single-use or multi-use vouchers, value '0' is for multi-use, '1' is for single-use, + * 'n' is for multi-use n times + * @param string $note note text to add to voucher when printing + * @param int $up upload speed limit in kbps + * @param int $down download speed limit in kbps + * @param int $megabytes data transfer limit in MB + * @return array containing a single object which contains the create_time(stamp) of the voucher(s) created */ public function create_voucher( $minutes, @@ -1776,7 +1886,7 @@ public function create_voucher( $note = null, $up = null, $down = null, - $MBytes = null + $megabytes = null ) { $payload = [ 'cmd' => 'create-voucher', @@ -1797,8 +1907,8 @@ public function create_voucher( $payload['down'] = intval($down); } - if (!is_null($MBytes)) { - $payload['bytes'] = intval($MBytes); + if (!is_null($megabytes)) { + $payload['bytes'] = intval($megabytes); } return $this->fetch_results('/api/s/' . $this->site . '/cmd/hotspot', $payload); @@ -2004,7 +2114,7 @@ public function reboot_cloudkey() * Disable/enable an access point (using REST) * * NOTES: - * - a disabled device will be excluded from the dashboard status and device count and its LED and WLAN will be turned off + * - a disabled device is excluded from the dashboard status and device count and its LED and WLAN are turned off * - appears to only be supported for access points * - available since controller versions 5.2.X * @@ -2031,9 +2141,9 @@ public function disable_ap($ap_id, $disable) * - available since controller versions 5.2.X * * @param string $device_id value of _id for the device which can be obtained from the device list - * @param string $override_mode off/on/default; "off" will disable the LED of the device, - * "on" will enable the LED of the device, - * "default" will apply the site-wide setting for device LEDs + * @param string $override_mode off/on/default; "off" disables the LED of the device, + * "on" enables the LED of the device, + * "default" applies the site-wide setting for device LEDs * @return bool true on success */ public function led_override($device_id, $override_mode) @@ -2055,7 +2165,7 @@ public function led_override($device_id, $override_mode) * replaces the old set_locate_ap() and unset_locate_ap() methods/functions * * @param string $mac device MAC address - * @param bool $enable true will enable flashing LED, false will disable + * @param bool $enable true enables flashing LED, false disables flashing LED * @return bool true on success */ public function locate_ap($mac, $enable) @@ -2073,7 +2183,7 @@ public function locate_ap($mac, $enable) /** * Toggle LEDs of all the access points ON or OFF * - * @param bool $enable true will switch LEDs of all the access points ON, false will switch them OFF + * @param bool $enable true switches LEDs of all the access points ON, false switches them OFF * @return bool true on success */ public function site_leds($enable) @@ -2338,7 +2448,7 @@ public function list_networkconf($network_id = '') * * @param object|array $payload stdClass object or associative array containing the configuration to apply to the network, must be a (partial) * object structured in the same manner as is returned by list_networkconf() for the specific network type. - * Do not include the _id property, it will be assigned by the controller and returned upon success. + * Do not include the _id property, it is assigned by the controller and returned upon success. * @return array|bool containing a single object with details of the new network on success, else returns false */ public function create_network($payload) @@ -2405,6 +2515,7 @@ public function list_wlanconf($wlan_id = null) * @param boolean $uapsd_enabled optional, enable/disable Unscheduled Automatic Power Save Delivery * @param boolean $schedule_enabled optional, enable/disable wlan schedule * @param array $schedule optional, schedule rules + * @param array $ap_group_ids optional, array of ap group ids, required for UniFi controller versions 6.0.X and higher * @return bool true on success */ public function create_wlan( @@ -2422,7 +2533,8 @@ public function create_wlan( $vlan = null, $uapsd_enabled = false, $schedule_enabled = false, - $schedule = [] + $schedule = [], + $ap_group_ids = null ) { $payload = [ 'name' => $name, @@ -2448,6 +2560,10 @@ public function create_wlan( $payload['x_passphrase'] = $x_passphrase; } + if (!empty($ap_group_ids) && is_array($ap_group_ids)) { + $payload['ap_group_ids'] = $ap_group_ids; + } + return $this->fetch_results_boolean('/api/s/' . $this->site . '/add/wlanconf', $payload); } @@ -2471,7 +2587,7 @@ public function set_wlansettings_base($wlan_id, $payload) * * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function * @param string $x_passphrase new pre-shared key, minimal length is 8 characters, maximum length is 63, - * will be ignored if set to null + * is ignored if set to null * @param string $name optional, SSID * @return bool true on success */ @@ -2587,7 +2703,7 @@ public function list_alarms($payload = []) /** * Count alarms * - * @param bool $archived if true all alarms will be counted, if false only non-archived (active) alarms will be counted + * @param bool $archived if true all alarms are counted, if false only non-archived (active) alarms are counted * @return array containing the alarm count */ public function count_alarms($archived = null) @@ -3171,7 +3287,7 @@ public function get_last_error_message() * Get Cookie from UniFi controller (singular and plural) * * NOTES: - * - when the results from this method are stored in $_SESSION['unificookie'], the Class will initially not + * - when the results from this method are stored in $_SESSION['unificookie'], the Class initially does not * log in to the controller when a subsequent request is made using a new instance. This speeds up the * overall request considerably. Only when a subsequent request fails (e.g. cookies have expired) is a new login * executed and the value of $_SESSION['unificookie'] updated. @@ -3583,9 +3699,6 @@ private function extract_csrf_token_from_cookie() return false; } - /** - */ - /** * Execute the cURL request * @@ -3764,7 +3877,7 @@ protected function exec_curl($path, $payload = null) protected function get_curl_resource() { $ch = curl_init(); - if (is_resource($ch)) { + if (is_object($ch) || is_resource($ch)) { $curl_options = [ CURLOPT_SSL_VERIFYPEER => $this->curl_ssl_verify_peer, CURLOPT_SSL_VERIFYHOST => $this->curl_ssl_verify_host, diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index c0cceb6..080fe08 100755 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1,17 +1,17 @@ [ { "name": "art-of-wifi/unifi-api-client", - "version": "v1.1.60", - "version_normalized": "1.1.60.0", + "version": "v1.1.62", + "version_normalized": "1.1.62.0", "source": { "type": "git", "url": "https://github.com/Art-of-WiFi/UniFi-API-client.git", - "reference": "32252e56d7906feb7b80daaad47d29bce041a3bc" + "reference": "c82481a28a7cca2f96686e291826bf2f2854784d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/32252e56d7906feb7b80daaad47d29bce041a3bc", - "reference": "32252e56d7906feb7b80daaad47d29bce041a3bc", + "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/c82481a28a7cca2f96686e291826bf2f2854784d", + "reference": "c82481a28a7cca2f96686e291826bf2f2854784d", "shasum": "" }, "require": { @@ -19,7 +19,7 @@ "ext-json": "*", "php": ">=5.5.0" }, - "time": "2020-11-12T10:09:37+00:00", + "time": "2020-12-10T13:52:39+00:00", "type": "library", "installation-source": "dist", "autoload": {