Skip to content

Commit 2da876e

Browse files
committed
UniFi API browser 2.0.13
- executed composer update - updated PHP API client to 1.1.59 - added menu option for new list_apgroups() function (supported with UniFi controller versions 6.0.X and higher)
1 parent d7226c3 commit 2da876e

30 files changed

+676
-234
lines changed

collections.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
[
8787
'type' => 'divider', // or collection
8888
],
89-
9089
[
9190
'type' => 'collection', // or divider
9291
'label' => 'list network configuration',
@@ -230,6 +229,12 @@
230229
'method' => 'list_wlan_groups',
231230
'params' => []
232231
],
232+
[
233+
'type' => 'collection', // or divider
234+
'label' => 'list AP groups', // supported from '6.0.23'
235+
'method' => 'list_apgroups',
236+
'params' => []
237+
],
233238
[
234239
'type' => 'collection', // or divider
235240
'label' => 'list rogue access points',

common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* with this package in the file LICENSE.md
88
*
99
*/
10-
define('TOOL_VERSION', '2.0.12');
10+
define('TOOL_VERSION', '2.0.13');
1111

1212
/**
1313
* gather some basic information for the About modal

composer.lock

Lines changed: 45 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/art-of-wifi/unifi-api-client/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## UniFi Controller API client class
22

3-
A PHP class that provides access to Ubiquiti's [**UniFi SDN Controller**](https://unifi-sdn.ui.com/) API, versions 4.X.X and 5.X.X of the UniFi SDN 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).
3+
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).
44

5-
The package can be installed manually or using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
5+
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.
66

77
## Requirements
88

@@ -92,7 +92,7 @@ Please refer to the `examples/` directory for some more detailed examples which
9292

9393
#### IMPORTANT NOTES:
9494

95-
1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when managing the site in the UniFi SDN Controller. For example with this URL:
95+
1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when managing the site in the UniFi Network Controller. For example with this URL:
9696

9797
`https://<controller IP address or FQDN>:8443/manage/site/jl3z2shm/dashboard`
9898

@@ -114,6 +114,9 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
114114
- cancel_rolling_upgrade()
115115
- cmd_stat()
116116
- count_alarms()
117+
- check_controller_update()
118+
- check_firmware_update()
119+
- create_apgroup() (supported with controller versions 6.0.X and higher)
117120
- create_dynamicdns()
118121
- create_firewallgroup()
119122
- create_hotspotop()
@@ -125,6 +128,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
125128
- create_voucher()
126129
- create_wlan()
127130
- custom_api_request()
131+
- delete_apgroup() (supported with controller versions 6.0.X and higher)
128132
- delete_device()
129133
- delete_firewallgroup()
130134
- delete_network()
@@ -133,6 +137,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
133137
- delete_usergroup()
134138
- delete_wlan()
135139
- disable_ap()
140+
- edit_apgroup() (supported with controller versions 6.0.X and higher)
136141
- edit_client_fixedip()
137142
- edit_firewallgroup()
138143
- edit_usergroup()
@@ -143,6 +148,7 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL
143148
- list_admins()
144149
- list_alarms()
145150
- list_all_admins()
151+
- list_apgroups() (supported with controller versions 6.0.X and higher)
146152
- list_aps() (deprecated but still available as alias)
147153
- list_backups()
148154
- list_clients()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* PHP API usage example
4+
*
5+
* contributed by: Art of WiFi
6+
* description: example PHP script to disable/enable the port of a UniFi switch
7+
* note: Requires controller version 5.5.X or higher. This example assumes an override alreay exists for the desired port.
8+
* To create a new port override simply append one (similar in structure to $updated_override) as needed to the
9+
* $existing_overrides array
10+
*/
11+
12+
/**
13+
* using the composer autoloader
14+
*/
15+
require_once('vendor/autoload.php');
16+
17+
/**
18+
* include the config file (place your credentials etc. there if not already present)
19+
* see the config.template.php file for an example
20+
*/
21+
require_once('config.php');
22+
23+
/**
24+
* the site to use to log in to the controller
25+
*/
26+
$site_id = '<enter your site id here>';
27+
28+
/**
29+
* the MAC address of the UniFi switch to re-configure
30+
*/
31+
$device_mac = '<enter MAC address>';
32+
33+
/**
34+
* index of port to modify/add
35+
*/
36+
$port_idx = 24;
37+
38+
/**
39+
* port configuration id to apply when enabling/disabling the port
40+
*
41+
* NOTE:
42+
* port configurations are available through list_portconf()
43+
*/
44+
$port_conf_id = '<enter _id value of desired port configuration>';
45+
46+
/**
47+
* initialize the UniFi API connection class and log in to the controller and do our thing
48+
*/
49+
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false);
50+
$set_debug_mode = $unifi_connection->set_debug($debug);
51+
$loginresults = $unifi_connection->login();
52+
$data = $unifi_connection->list_devices($device_mac);
53+
$device_id = $data[0]->device_id;
54+
$existing_overrides = $data[0]->port_overrides;
55+
56+
foreach ($existing_overrides as $key => $value) {
57+
if (!empty($value->port_idx) && $value->port_idx === $port_idx) {
58+
$updated_override = [
59+
'portconf_id' => $port_conf_id,
60+
'port_idx' => $port_idx,
61+
'poe_mode' => $value->poe_mode,
62+
'name' => 'Your-port-name',
63+
];
64+
65+
$existing_overrides[$key] = $updated_override;
66+
}
67+
}
68+
69+
$payload = [
70+
'port_overrides' => $existing_overrides
71+
];
72+
73+
$update_device = $unifi_connection->set_device_settings_base($device_id, $payload);
74+
75+
/**
76+
* provide feedback in json format
77+
*/
78+
echo json_encode($update_device, JSON_PRETTY_PRINT);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* PHP API usage example
4+
*
5+
* contributed by: Art of WiFi
6+
* description: example basic PHP script to toggle power of an outlet on the UniFi SmartPower PDU Pro,
7+
* last tested with UniFi controller version 6.1.19
8+
*/
9+
require 'vendor/autoload.php';
10+
11+
/**
12+
* include the config file (place your credentials etc. there if not already present)
13+
* see the config.template.php file for an example
14+
*/
15+
require_once('config.php');
16+
17+
/**
18+
* the site to use
19+
*/
20+
$site_id = 'default';
21+
22+
/**
23+
* MAC of UniFi SmartPower PDU Pro to work with
24+
*/
25+
$pdu_mac = '<MAC ADDRESS of PDU>';
26+
27+
/**
28+
* index value of the outlet to modify
29+
*/
30+
$outlet_idx = 20;
31+
32+
/**
33+
* new values for relay_state (enable/disable Power) and cycle_enabled (disable/enable Modem Power Cycle) for the above outlet,
34+
* values must be boolean (true/false)
35+
*
36+
* NOTES:
37+
* - here you can choose to also change the name of the outlet
38+
* - outlet overrides are structured like this:
39+
* {
40+
* "index": 1,
41+
* "name": "USB Outlet 1",
42+
* "cycle_enabled": false,
43+
* "relay_state": true
44+
* }
45+
*/
46+
$new_relay_state = true;
47+
$new_cycle_enabled = false;
48+
49+
/**
50+
* initialize the UniFi API connection class and log in to the controller and do our thing
51+
*/
52+
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
53+
$set_debug_mode = $unifi_connection->set_debug($debug);
54+
$loginresults = $unifi_connection->login();
55+
if ($loginresults) {
56+
$pdu_details = $unifi_connection->list_devices($pdu_mac);
57+
58+
if (!empty($pdu_details) && property_exists($pdu_details[0], 'model') && $pdu_details[0]->model === 'USPPDUP' && property_exists($pdu_details[0], 'outlet_overrides')) {
59+
$device_id = $pdu_details[0]->_id;
60+
$outlet_overrides = $pdu_details[0]->outlet_overrides;
61+
62+
foreach ($outlet_overrides as $key => $value) {
63+
if ($value->index === $outlet_idx) {
64+
$outlet_overrides[$key]->relay_state = $new_relay_state;
65+
$outlet_overrides[$key]->cycle_enabled = $new_cycle_enabled;
66+
}
67+
}
68+
69+
$pdu_update = $unifi_connection->set_device_settings_base($device_id, ['outlet_overrides' => $outlet_overrides]);
70+
71+
/**
72+
* provide feedback in json format
73+
*/
74+
echo 'results:' . PHP_EOL . PHP_EOL;
75+
echo json_encode($pdu_update, JSON_PRETTY_PRINT);
76+
echo PHP_EOL;
77+
} else {
78+
echo 'not a PDU device?';
79+
echo PHP_EOL;
80+
}
81+
} else {
82+
echo 'we encountered a login error!';
83+
echo PHP_EOL;
84+
}

0 commit comments

Comments
 (0)