From 67d318ca91145ee960e91ee7fb52a9e901197811 Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Tue, 28 Mar 2023 12:19:29 +0200 Subject: [PATCH] - bumped version to class v1.1.80 - added generate_backup_site() method, contributed by @labo-jad --- README.md | 11 +++++++---- examples/update_switch_poe-mode.php | 5 ++++- src/Client.php | 26 +++++++++++++++++++------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b09255b..8455db2 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A PHP class that provides access to Ubiquiti's [**UniFi Network Controller**](https://unifi-network.ui.com/) API. -UniFi Network Controller software versions 4.X.X, 5.X.X, 6.X.X, and 7.X.X (version 7.0.23 has been confirmed to work) +UniFi Network Controller software versions 4.X.X, 5.X.X, 6.X.X, and 7.X.X (version 7.2.93 has been confirmed to work) are supported as well as UniFi OS-based controllers. This class is used by our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser). @@ -27,8 +27,9 @@ Support for UniFi OS-based controllers has been added as of version 1.1.47: - UniFi Dream Router (UDR) - UniFi Dream Machine (UDM) - UniFi Dream Machine Pro (UDM PRO) -- Cloud Key Gen2 (UCK G2), firmware version 2.0.24 or higher -- Cloud Key Gen2 Plus (UCK G2 Plus), firmware version 2.0.24 or higher +- UniFi Cloud Key Gen2 (UCK G2), firmware version 2.0.24 or higher +- UniFi Cloud Key Gen2 Plus (UCK G2 Plus), firmware version 2.0.24 or higher +- UniFi Cloud Console, details [here](https://help.ui.com/hc/en-us/articles/4415364143511) The class automatically detects UniFi OS-based controllers and adjusts URLs and several functions/methods accordingly. If your own code implements strict validation of the URL that is passed to the constructor, please adapt your @@ -183,6 +184,8 @@ more details on each of the functions/methods and their respective parameters. - edit_usergroup() - extend_guest_validity() - forget_sta() (supported on controller version 5.9.X and higher) +- generate_backup() +- generate_backup_site() - invite_admin() - led_override() - list_admins() @@ -352,7 +355,7 @@ This class is based on the initial work by the following developers: and the API as published by Ubiquiti: -- https://dl.ui.com/unifi/7.0.23/unifi_sh_api +- https://dl.ui.com/unifi/7.0.25/unifi_sh_api ## Important Disclaimer diff --git a/examples/update_switch_poe-mode.php b/examples/update_switch_poe-mode.php index 132479a..9b0039f 100755 --- a/examples/update_switch_poe-mode.php +++ b/examples/update_switch_poe-mode.php @@ -8,6 +8,9 @@ * usage: If the file is called via a web URL, it should be called like: update_switch_poe-mode.php?poe_mode=off * If the file is called via the command line, it should be called like: php update_switch_poe-mode.php off * The values can be "off" or "auto" + * + * IMPORTANT INFORMATION: + * This example no longer works with controller versions 7.1.X and higher. You now need to work with port profiles to enable POE on a switch port. */ /** @@ -91,4 +94,4 @@ function update_ports($running_config, $ports, $poe_mode){ echo json_encode($error, JSON_PRETTY_PRINT); } -echo json_encode($update_device, JSON_PRETTY_PRINT); \ No newline at end of file +echo json_encode($update_device, JSON_PRETTY_PRINT); diff --git a/src/Client.php b/src/Client.php index d14e777..38b197c 100755 --- a/src/Client.php +++ b/src/Client.php @@ -13,7 +13,7 @@ * * @package UniFi_Controller_API_Client_Class * @author Art of WiFi - * @version Release: 1.1.79 + * @version Release: 1.1.80 * @license This class is subject to the MIT license that is bundled with this package in the file LICENSE.md * @example This directory in the package repository contains a collection of examples: * https://github.com/Art-of-WiFi/UniFi-API-client/tree/master/examples @@ -26,7 +26,7 @@ class Client * NOTE: * do not modify the values here, instead use the constructor or the getter and setter functions/methods */ - const CLASS_VERSION = '1.1.79'; + const CLASS_VERSION = '1.1.80'; protected $baseurl = 'https://127.0.0.1:8443'; protected $user = ''; protected $password = ''; @@ -424,8 +424,7 @@ public function create_user($mac, $user_group_id, $name = null, $note = null, $i * Add/modify/remove a client-device note * * @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 is removed and "noted" attribute set to false + * @param string $note optional, note to be applied to the client-device * @return bool returns true upon success */ public function set_sta_note($user_id, $note = '') @@ -1448,10 +1447,9 @@ public function list_known_rogueaps() } /** - * Generate backup + * Generate a backup * - * NOTES: - * this is an experimental function, please do not use unless you know exactly what you're doing + * NOTES: this is an experimental function, please do not use unless you know exactly what you're doing * * @return array|bool URL from where the backup file can be downloaded once generated, false upon failure */ @@ -1472,6 +1470,20 @@ public function list_backups() return $this->fetch_results('/api/s/' . $this->site . '/cmd/backup', $payload); } + /** + * Generate a backup/export of the current site + * + * NOTES: this is an experimental function, please do not use unless you know exactly what you're doing + * + * @return array|bool URL from where the backup/export file can be downloaded once generated, false upon failure + */ + public function generate_backup_site() + { + $payload = ['cmd' => 'export-site']; + + return $this->fetch_results('/api/s/' . $this->site . '/cmd/backup', $payload); + } + /** * Fetch sites *