Skip to content

Commit d340d8f

Browse files
committed
UniFi API browser 2.0.0
major overhaul to support Bootstrap 4 and to switch to AJAX for data transfer between server and browser added user authentication many more features
1 parent 3fcf079 commit d340d8f

File tree

647 files changed

+36795
-2244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

647 files changed

+36795
-2244
lines changed

.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# Ignore personal config file
2-
config.php
2+
config/config.php
3+
config/users.php
4+
5+
# ignore these files
6+
desktop.ini
7+
*.sublime-workspace
8+
.DS_Store
9+
.DS_Store?
10+
._*
11+
.Spotlight-V100
12+
.Trashes
13+
ehthumbs.db
14+
Thumbs.db

README.md

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ You will find examples and detailed instructions there.
1111
Please keep the following in mind:
1212

1313
- the API browser tool doesn't support all available data collections/API endpoints, see the list below of those that are currently supported
14-
- currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.10.12 has been confirmed to work)
14+
- currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.11.50 has been confirmed to work)
1515
- 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.
1616
- please read the Security Notice below before installing this tool!
1717

18+
19+
### Upgrading from 1.X to 2.X
20+
21+
Because the structure of the configuration file has changed slightly, we recommend creating a fresh install when upgrading from 1.X to 2.X.
22+
23+
1824
### Features
1925

2026
The UniFi API browser tool offers the following features:
2127

2228
- browse data collections/API endpoints exposed by the UniFi Controller API in an easy manner
2329
- switch between sites managed by the connected controller
24-
- switch between output formats (currently `json`, `PHP array`, `PHP var_dump`, `PHP var_export`, `json highlighted` and `PHP array using Kint` have been implemented)
25-
- copy the results to clipboard (only output formats `json`, `PHP array`, `PHP var_dump` and `PHP var_export` are supported, will fail gracefully with large collections)
30+
- switch between output formats (currently `JSON`, `JSON highlighted`, `PHP array, interactive` and `PHP array, highlighted` have been implemented)
31+
- copy the results to clipboard (this is only supported with the `JSON` output format, will fail gracefully with large collections)
2632
- switch between default Bootstrap theme and the [Bootswatch](https://bootswatch.com/) themes
2733
- an "About" modal which shows version information for PHP, cURL and the UniFi Controller
2834
- very easy setup with minimal dependencies
@@ -52,9 +58,9 @@ The UniFi API browser tool offers the following features:
5258
- daily site stats
5359
- hourly access point stats
5460
- daily access point stats
55-
- all sites stats (supported on controller version 5.2.9 and higher)
61+
- all sites stats
5662
- health metrics
57-
- dashboard metrics (supported on controller version 4.9.1.alpha and higher)
63+
- dashboard metrics
5864
- port forward stats
5965
- Hotspot
6066
- stat vouchers
@@ -84,11 +90,13 @@ The UniFi API browser tool offers the following features:
8490

8591
Please note that the bundled API client supports many more API endpoints, not all make sense to add to the API browser though.
8692

93+
8794
### Requirements
8895

89-
- a web server with PHP and cURL modules installed (tested on apache2 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.0.7 and cURL 7.37.0)
96+
- a web server with PHP and cURL modules installed (tested on apache2 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.2.5 and cURL 7.60.0)
9097
- network connectivity between this web server and the server (and port) where the UniFi controller is running (in case you are seeing errors, please check out [this issue](https://github.com/Art-of-WiFi/UniFi-API-browser/issues/4))
91-
- clients using this tool should have internet access because the CSS and JS files are loaded from CDNs.
98+
- clients using this tool should have internet access because several CSS and JS files are loaded from public CDNs.
99+
92100

93101
### Installation
94102

@@ -101,40 +109,53 @@ git clone https://github.com/Art-of-WiFi/UniFi-API-browser.git
101109

102110
Alternatively you may choose to download the zip file and unzip it in your directory of choice, then follow the configuration steps below.
103111

112+
104113
### Configuration
105114

106-
- credentials for access to the UniFi Controller API can be configured, in part or in whole, in the file named `config.template.php` which should be copied/renamed to `config.php`
107-
- starting with API browser tool version 1.0.34, if all or a portion of the credentials are not specified in the `config.php` file or this file is not present, then a login form will ask for the missing credential information
108-
- starting with version 1.0.3, you can store **multiple controller configurations** in an array inside the `config.php` file
109-
- please refer to the comments in the `config.template.php` file for further instructions
115+
- credentials for access to the UniFi Controller API can be configured, in part or in whole, in the file named `config/config-template.php` which should be copied/renamed to `config/config.php`
116+
- starting with version 1.0.3, you can store **multiple controller configurations** in an array inside the `config/config.php` file
117+
- please refer to the instructions in the `config/config-template.php` file for further configuration instructions
118+
- starting with API browser tool version 2.0.0 you can restrict access to the tool by creating user accounts and passwords, please refer to the instructions in the `config/users-template.php` file for further details
110119
- after following these steps, you can open the tool in your browser (assuming you installed it in the root folder of your web server as suggested above) by going to this url: `http(s)://<server IP address>/UniFi-API-browser/`
111120

121+
112122
### Updates
113123

114124
If you have installed the tool using the `git clone` command, you can install updates by going into the directory where the tool has been installed, and running the `git pull` command from there.
115125

116126
Otherwise you can simply copy the contents from the latest [zip file](https://github.com/Art-of-WiFi/UniFi-API-browser/archive/master.zip) to the directory where the tool has been installed.
117127

128+
118129
### Credits
119130

120-
The PHP API client that comes bundled with this tool is based on the work done by the following developers:
131+
The PHP API client that comes bundled with this tool is based on the work by the following developers:
121132

122133
- domwo: http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051
123134
- fbagnol: https://github.com/fbagnol/class.unifi.php
124-
- and the API as published by Ubiquiti: https://dl.ubnt.com/unifi/5.6.18-8261dc5066/unifi_sh_api
135+
136+
and the API as published by Ubiquiti:
137+
138+
- https://dl.ui.com/unifi/5.12.21-a25e774adb/unifi_sh_api
125139

126140
Other included libraries:
127141

128-
- Bootstrap (version 3.3.7) https://getbootstrap.com
129-
- Font-awesome (version 4.7.0) https://fortawesome.github.io/Font-Awesome
130-
- jQuery (version 2.2.4) https://jquery.com
131-
- jQuery JSONView (version 1.2.3) https://github.com/yesmeck/jquery-jsonview
132-
- Kint (version 2.1.2) https://kint-php.github.io/kint
133-
- clipboard.js (2.0.1) https://clipboardjs.com/
142+
- Bootstrap 4 (version 4.3.1) https://getbootstrap.com
143+
- Bootswatch themes (version 4.3.1) https://bootswatch.com/
144+
- Font Awesome icons (version 5.11.2) https://fontawesome.com/
145+
- jQuery (version 3.4.1) https://jquery.com
146+
- Highlight.js (version 9.15.10) https://highlightjs.org/
147+
- Kint (version 2.2) https://kint-php.github.io/kint
148+
- clipboard.js (2.0.4) https://clipboardjs.com/
149+
134150

135151
### Security notice
136152

137-
The use of this tool is **not secured in any way**! Make sure to prevent unauthorised access to it, preventing exposure of details and credentials such as user names and passwords for access to the UniFi Controller!
153+
We highly recommend enabling user name/password authentication by creating a `config/users.php` based on the included `config/users-template.php` file. When creating passwords and their SHA512 hashes for entry in the `config/users.php` file, please make sure to use strong random passwords.
154+
155+
Please refer to the instructions in the `config/users-template.php` file for further details
156+
157+
It is your own responsibility to implement the necessary additional controls in securing this application and preventing unwanted access.
158+
138159

139160
### Screenshots
140161

TODO.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
## TODO:
22

33
1. Make the output format selectable like with the siteid, so that after selection we can switch between the two lines below for different output presentation. Possible options to add are ~~PHP array/json~~/table/chart:
4-
- ~~print_r ($data);~~
5-
- ~~echo json_encode($data, JSON_PRETTY_PRINT);~~
64
- DataTables for table output and more
75
- requires "flattening" of multidimensional arrays/objects
86
- or else only expose a selection of attributes
97
- Chart output as option for certain data collections (and selected attributes)
8+
- same requirements as for tables
109

1110
2. Add the option to export data to CSV file format
1211
- need to have the option to select which fields to export
1312
- could be combined with the DataTables output option
1413
- requires "flattening" of multidimensional arrays/objects
1514

16-
3. ~~Add simple user/password login~~
17-
- ~~consider setting user name/password in the config file, though not very secure~~
18-
- ~~avoid dependencies such as MySQL etc. as much as possible~~
1915

2016
### Call for suggestions
2117

ajax/fetch_about_modal_metrics.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2019, Art of WiFi
4+
* www.artofwifi.net
5+
*
6+
* This file is subject to the MIT license that is bundled
7+
* with this package in the file LICENSE.md
8+
*
9+
*/
10+
11+
/**
12+
* load the files containing shared functions and the collections
13+
*/
14+
require_once('../common.php');
15+
require_once('../collections.php');
16+
17+
/**
18+
* load the configuration file if readable
19+
*/
20+
if (is_file('../config/config.php') && is_readable('../config/config.php')) {
21+
include('../config/config.php');
22+
} else {
23+
die();
24+
}
25+
26+
/**
27+
* in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required
28+
*/
29+
session_start();
30+
31+
/**
32+
* initialize the results array
33+
*/
34+
$results = [
35+
'controller_url' => 'unknown',
36+
'controller_user' => 'unknown',
37+
'controller_version' => 'not detected',
38+
'memory_used' => $_SESSION['memory_used'],
39+
];
40+
41+
/**
42+
* and fill in the details for the controller if available
43+
*/
44+
if (!empty($_SESSION['controller'])) {
45+
$results['controller_url'] = $_SESSION['controller']['url'];
46+
$results['controller_user'] = $_SESSION['controller']['user'];
47+
48+
if (!empty($_SESSION['controller']['detected_version'])) {
49+
$results['controller_version'] = $_SESSION['controller']['detected_version'];
50+
}
51+
}
52+
53+
/**
54+
* output the results with correct JSON formatting
55+
*/
56+
header('Content-Type: application/json; charset=utf-8');
57+
echo (json_encode($results));

0 commit comments

Comments
 (0)