forked from Art-of-WiFi/UniFi-API-browser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·1489 lines (1396 loc) · 68.2 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* UniFi API browser
*
* This tool is for browsing data that is exposed through Ubiquiti's UniFi Controller API,
* and is developed with PHP, JavaScript and the Bootstrap CSS framework.
*
* Please keep the following in mind:
* - not all data collections/API endpoints are supported (yet), see the list of
* 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
* ------------------------------------------------------------------------------------
*
* Copyright (c) 2017, Art of WiFi
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.md
*
*/
define('API_BROWSER_VERSION', '1.0.34');
define('API_CLASS_VERSION', get_client_version());
/**
* check whether the required PHP curl module is available
* - if yes, collect cURL version details for the info modal
* - if not, stop and display an error message
*/
if (function_exists('curl_version')) {
$curl_info = curl_version();
$curl_version = $curl_info['version'];
$openssl_version = $curl_info['ssl_version'];
} else {
exit('The <b>PHP curl</b> module is not installed! Please correct this before proceeding!<br>');
$curl_version = 'unavailable';
$openssl_version = 'unavailable';
}
/**
* in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required
*/
session_start();
/**
* check whether user has requested to clear (force expiry) the PHP session
* - this feature can be useful when login errors occur, mostly after upgrades or credential changes
*/
if (isset($_GET['reset_session']) && $_GET['reset_session'] == true) {
$_SESSION = [];
session_unset();
session_destroy();
session_start();
header("Location: " . strtok($_SERVER['REQUEST_URI'], '?'));
exit;
}
/**
* starting timing of the session here
*/
$time_start = microtime(true);
/**
* declare variables which are required later on together with their default values
*/
$show_login = false;
$controller_id = '';
$action = '';
$site_id = '';
$site_name = '';
$selection = '';
$data = '';
$objects_count = '';
$alert_message = '';
$output_format = 'json';
$controlleruser = '';
$controllerpassword = '';
$controllerurl = '';
$controllername = 'Controller';
$cookietimeout = '3600';
$theme = 'bootstrap';
$debug = false;
/**
* load the optional configuration file if readable
* - allows override of several of the previously declared variables
*/
if (is_file('config.php') && is_readable('config.php')) {
include('config.php');
}
/**
* load the UniFi API client and Kint classes using composer autoloader
*/
require('vendor/autoload.php');
/**
* set relevant Kint options
* more info on Kint usage: http://kint-php.github.io/kint/
*/
Kint::$display_called_from = false;
/**
* determine whether we have reached the cookie timeout, if so, refresh the PHP session
* else, update last activity time stamp
*/
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > $cookietimeout)) {
/**
* last activity was longer than $cookietimeout seconds ago
*/
session_unset();
session_destroy();
if ($debug) {
error_log('UniFi API browser INFO: session cookie timed out');
}
}
$_SESSION['last_activity'] = time();
/**
* process the GET variables and store them in the $_SESSION array
* if a GET variable is not set, get the values from the $_SESSION array (if available)
*
* process in this order:
* - controller_id
* only process this after controller_id is set:
* - site_id
* only process these after site_id is set:
* - action
* - output_format
*/
if (isset($_GET['controller_id'])) {
/**
* user has requested a controller switch
*/
if (!isset($controllers)) {
header("Location: " . strtok($_SERVER['REQUEST_URI'], '?') . "?reset_session=true");
exit;
}
$controller = $controllers[$_GET['controller_id']];
$controller_id = $_GET['controller_id'];
$_SESSION['controller'] = $controller;
$_SESSION['controller_id'] = $_GET['controller_id'];
/**
* clear the variables from the $_SESSION array that are associated with the previous controller session
*/
unset($_SESSION['site_id']);
unset($_SESSION['site_name']);
unset($_SESSION['sites']);
unset($_SESSION['action']);
unset($_SESSION['detected_controller_version']);
unset($_SESSION['unificookie']);
} else {
if (isset($_SESSION['controller']) && isset($controllers)) {
$controller = $_SESSION['controller'];
$controller_id = $_SESSION['controller_id'];
} else {
if (!isset($controllers)) {
/**
* pre-load $controller array with $_SESSION['controllers'] if present
* then load configured single site credentials
*/
$controller = [];
if (isset($_SESSION['controller'])) {
$controller = $_SESSION['controller'];
}
if (!isset($controller['user']) || !isset($controller['password']) || !isset($controller['url'])) {
$_SESSION['controller'] = [
'user' => $controlleruser,
'password' => $controllerpassword,
'url' => $controllerurl,
'name' => $controllername
];
$controller = $_SESSION['controller'];
}
}
}
if (isset($_GET['site_id'])) {
$site_id = $_GET['site_id'];
$_SESSION['site_id'] = $site_id;
$site_name = $_GET['site_name'];
$_SESSION['site_name'] = $site_name;
} else {
if (isset($_SESSION['site_id'])) {
$site_id = $_SESSION['site_id'];
$site_name = $_SESSION['site_name'];
}
}
}
/**
* load login form data, if present, and save to credential variables
*/
if (isset($_POST['controller_user']) && !empty($_POST['controller_user'])) {
$controller['user'] = $_POST['controller_user'];
}
if (isset($_POST['controller_password']) && !empty($_POST['controller_password'])) {
$controller['password'] = $_POST['controller_password'];
}
if (isset($_POST['controller_url']) && !empty($_POST['controller_url'])) {
$controller['url'] = $_POST['controller_url'];
}
if (isset($controller)) {
$_SESSION['controller'] = $controller;
}
/**
* get requested theme or use the theme stored in the $_SESSION array
*/
if (isset($_GET['theme'])) {
$theme = $_GET['theme'];
$_SESSION['theme'] = $theme;
$theme_changed = true;
} else {
if (isset($_SESSION['theme'])) {
$theme = $_SESSION['theme'];
}
$theme_changed = false;
}
/**
* get requested output_format or use the output_format stored in the $_SESSION array
*/
if (isset($_GET['output_format'])) {
$output_format = $_GET['output_format'];
$_SESSION['output_format'] = $output_format;
} else {
if (isset($_SESSION['output_format'])) {
$output_format = $_SESSION['output_format'];
}
}
/**
* get requested action or use the action stored in the $_SESSION array
*/
if (isset($_GET['action'])) {
$action = $_GET['action'];
$_SESSION['action'] = $action;
} else {
if (isset($_SESSION['action'])) {
$action = $_SESSION['action'];
}
}
/**
* display info message when no controller, site or data collection is selected
* placed here so they can be overwritten by more "severe" error messages later on
*/
if ($action === '') {
$alert_message = '<div class="alert alert-info" role="alert">Please select a data collection/API endpoint from the dropdown menus ' .
'<i class="fa fa-arrow-circle-up"></i></div>';
}
if ($site_id === '') {
$alert_message = '<div class="alert alert-info" role="alert">Please select a site from the Sites dropdown menu ' .
'<i class="fa fa-arrow-circle-up"></i></div>';
}
if (!isset($controller['name']) && isset($controllers)) {
$alert_message = '<div class="alert alert-info" role="alert">Please select a controller from the Controllers dropdown menu ' .
'<i class="fa fa-arrow-circle-up"></i></div>';
} else {
if (!isset($_SESSION['unificookie']) && (empty($controller['user']) || empty($controller['password']) || empty($controller['url']))) {
$show_login = true;
$alert_message = '<div class="alert alert-info" role="alert">Please login to ';
if (!empty($controller['url'])) {
$alert_message .= '<a href="' . $controller['url'] . '">';
}
$alert_message .= $controller['name'];
if (!empty($controller['url'])) {
$alert_message .= '</a>';
}
if (!empty($controller['user'])) {
$alert_message .= ' with username ' . $controller['user'];
}
$alert_message .= ' <i class="fa fa-sign-in"></i></div>';
}
}
/**
* do this when a controller has been selected and was stored in the $_SESSION array and login isn't needed
*/
if (isset($_SESSION['controller']) && $show_login !== true) {
/**
* create a new instance of the API client class and log in to the UniFi controller
* - if an error occurs during the login process, an alert is displayed on the page
*/
$unifidata = new UniFi_API\Client(trim($controller['user']), $controller['password'], rtrim(trim($controller['url']), '/'), $site_id);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();
if ($loginresults === 400) {
$alert_message = '<div class="alert alert-danger" role="alert">HTTP response status: 400' .
'<br>This is probably caused by a UniFi controller login failure. Please check your credentials and ' .
'<a href="?reset_session=true">try again</a>.</div>';
/**
* to prevent unwanted errors we assign empty values to the following variables
*/
$sites = [];
$detected_controller_version = 'undetected';
} else {
/**
* remember authentication cookie to the controller.
*/
$_SESSION['unificookie'] = $unifidata->get_cookie();
/**
* 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 = [];
$alert_message = '<div class="alert alert-danger" role="alert">No sites available' .
'<br>This is probably caused by incorrect access rights in the UniFi controller, or the controller is not ' .
'accepting connections. Please check your credentials and/or your server error logs and ' .
'<a href="?reset_session=true">try again</a>.</div>';
}
} else {
$sites = $_SESSION['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();
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'];
}
}
}
/**
* execute timing of controller login
*/
$time_1 = microtime(true);
$time_after_login = $time_1 - $time_start;
if (isset($unifidata)) {
/**
* array containing attributes to fetch for the gateway stats, overriding
* the default attributes
*/
$gateway_stats_attribs = [
'time',
'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'
];
/**
* select the required call to the UniFi Controller API based on the selected action
*/
switch ($action) {
case 'list_clients':
$selection = 'list online clients';
$data = $unifidata->list_clients();
break;
case 'stat_allusers':
$selection = 'stat all users';
$data = $unifidata->stat_allusers();
break;
case 'stat_auths':
$selection = 'stat active authorisations';
$data = $unifidata->stat_auths();
break;
case 'list_guests':
$selection = 'list guests';
$data = $unifidata->list_guests();
break;
case 'list_usergroups':
$selection = 'list usergroups';
$data = $unifidata->list_usergroups();
break;
case 'stat_5minutes_site':
$selection = '5 minutes site stats';
$data = $unifidata->stat_5minutes_site();
break;
case 'stat_hourly_site':
$selection = 'hourly site stats';
$data = $unifidata->stat_hourly_site();
break;
case 'stat_daily_site':
$selection = 'daily site stats';
$data = $unifidata->stat_daily_site();
break;
case 'stat_5minutes_aps':
$selection = '5 minutes ap stats';
$data = $unifidata->stat_5minutes_aps();
break;
case 'stat_hourly_aps':
$selection = 'hourly ap stats';
$data = $unifidata->stat_hourly_aps();
break;
case 'stat_daily_aps':
$selection = 'daily ap stats';
$data = $unifidata->stat_daily_aps();
break;
case 'stat_5minutes_gateway':
$selection = '5 minutes gateway stats';
$data = $unifidata->stat_5minutes_gateway(null, null, $gateway_stats_attribs);
break;
case 'stat_hourly_gateway':
$selection = 'hourly gateway stats';
$data = $unifidata->stat_hourly_gateway(null, null, $gateway_stats_attribs);
break;
case 'stat_daily_gateway':
$selection = 'daily gateway stats';
$data = $unifidata->stat_daily_gateway(null, null, $gateway_stats_attribs);
break;
case 'stat_sysinfo':
$selection = 'sysinfo';
$data = $unifidata->stat_sysinfo();
break;
case 'list_devices':
$selection = 'list devices';
$data = $unifidata->list_devices();
break;
case 'list_tags':
$selection = 'list tags';
$data = $unifidata->list_tags();
break;
case 'list_wlan_groups':
$selection = 'list wlan groups';
$data = $unifidata->list_wlan_groups();
break;
case 'stat_sessions':
$selection = 'stat sessions';
$data = $unifidata->stat_sessions();
break;
case 'list_users':
$selection = 'list users';
$data = $unifidata->list_users();
break;
case 'list_rogueaps':
$selection = 'list rogue access points';
$data = $unifidata->list_rogueaps();
break;
case 'list_known_rogueaps':
$selection = 'list known rogue access points';
$data = $unifidata->list_known_rogueaps();
break;
case 'list_events':
$selection = 'list events';
$data = $unifidata->list_events();
break;
case 'list_alarms':
$selection = 'list alarms';
$data = $unifidata->list_alarms();
break;
case 'list_firewallgroups':
$selection = 'list firewall groups';
$data = $unifidata->list_firewallgroups();
break;
case 'count_alarms':
$selection = 'count all alarms';
$data = $unifidata->count_alarms();
break;
case 'count_active_alarms':
$selection = 'count active alarms';
$data = $unifidata->count_alarms(false);
break;
case 'list_wlanconf':
$selection = 'list wlan config';
$data = $unifidata->list_wlanconf();
break;
case 'list_health':
$selection = 'site health metrics';
$data = $unifidata->list_health();
break;
case 'list_5minutes_dashboard':
$selection = '5 minutes site dashboard metrics';
$data = $unifidata->list_dashboard(true);
break;
case 'list_hourly_dashboard':
$selection = 'hourly site dashboard metrics';
$data = $unifidata->list_dashboard();
break;
case 'list_settings':
$selection = 'list site settings';
$data = $unifidata->list_settings();
break;
case 'list_sites':
$selection = 'details of available sites';
$data = $sites;
break;
case 'list_extension':
$selection = 'list VoIP extensions';
$data = $unifidata->list_extension();
break;
case 'list_portconf':
$selection = 'list port configuration';
$data = $unifidata->list_portconf();
break;
case 'list_networkconf':
$selection = 'list network configuration';
$data = $unifidata->list_networkconf();
break;
case 'list_dynamicdns':
$selection = 'dynamic dns configuration';
$data = $unifidata->list_dynamicdns();
break;
case 'list_current_channels':
$selection = 'current channels';
$data = $unifidata->list_current_channels();
break;
case 'list_portforwarding':
$selection = 'list port forwarding rules';
$data = $unifidata->list_portforwarding();
break;
case 'list_portforward_stats':
$selection = 'list port forwarding stats';
$data = $unifidata->list_portforward_stats();
break;
case 'list_dpi_stats':
$selection = 'list DPI stats';
$data = $unifidata->list_dpi_stats();
break;
case 'stat_voucher':
$selection = 'list hotspot vouchers';
$data = $unifidata->stat_voucher();
break;
case 'stat_payment':
$selection = 'list hotspot payments';
$data = $unifidata->stat_payment();
break;
case 'list_hotspotop':
$selection = 'list hotspot operators';
$data = $unifidata->list_hotspotop();
break;
case 'list_self':
$selection = 'self';
$data = $unifidata->list_self();
break;
case 'stat_sites':
$selection = 'all site stats';
$data = $unifidata->stat_sites();
break;
case 'list_admins':
$selection = 'list_admins';
$data = $unifidata->list_admins();
break;
case 'list_radius_accounts':
$selection = 'list radius accounts';
$data = $unifidata->list_radius_accounts();
break;
case 'list_radius_profiles':
$selection = 'list radius profiles';
$data = $unifidata->list_radius_profiles();
break;
case 'list_country_codes':
$selection = 'list country codes';
$data = $unifidata->list_country_codes();
break;
case 'list_backups':
$selection = 'list auto backups';
$data = $unifidata->list_backups();
break;
case 'stat_ips_events':
$selection = 'list IPS/IDS events';
$data = $unifidata->stat_ips_events();
break;
default:
break;
}
}
/**
* count the number of objects collected from the UniFi controller
*/
if ($action != '' && !empty($data)) {
$objects_count = count($data);
}
/**
* execute timing of data collection from UniFi controller
*/
$time_2 = microtime(true);
$time_after_load = $time_2 - $time_start;
/**
* calculate all the timings/percentages
*/
$time_end = microtime(true);
$time_total = $time_end - $time_start;
$login_perc = ($time_after_login / $time_total) * 100;
$load_perc = (($time_after_load - $time_after_login) / $time_total) * 100;
$remain_perc = 100 - $login_perc - $load_perc;
/**
* shared functions
*/
/**
* function to print the output
* switch depending on the selected $output_format
*/
function print_output($output_format, $data)
{
switch ($output_format) {
case 'json':
echo json_encode($data, JSON_PRETTY_PRINT);
break;
case 'json_color':
echo json_encode($data);
break;
case 'php_array':
print_r($data);
break;
case 'php_array_kint':
+d($data);
break;
case 'php_var_dump':
var_dump($data);
break;
case 'php_var_export':
var_export($data);
break;
default:
echo json_encode($data, JSON_PRETTY_PRINT);
break;
}
}
/**
* function to sort the sites collection alpabetically by description
*/
function sites_sort($site_a, $site_b)
{
return strcmp($site_a->desc, $site_b->desc);
}
/**
* function which returns the version of the included API client class by
* extracting it from the composer.lock file
*/
function get_client_version()
{
if (is_readable('composer.lock')) {
$composer_lock = file_get_contents('composer.lock');
$json_decoded = json_decode($composer_lock, true);
if (isset($json_decoded['packages'])) {
foreach ($json_decoded['packages'] as $package) {
if ($package['name'] === 'art-of-wifi/unifi-api-client') {
return substr($package['version'], 1);
}
}
}
}
return 'unknown';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>UniFi API browser</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- latest compiled and minified versions of Bootstrap, Font-awesome and Highlight.js CSS, loaded from CDN -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- load the default Bootstrap CSS file from CDN -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- placeholder to dynamically load the appropriate Bootswatch CSS file from CDN -->
<link rel="stylesheet" href="" id="bootswatch_theme_stylesheet">
<!-- load the jsonview CSS file from CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-jsonview/1.2.3/jquery.jsonview.min.css" integrity="sha256-OhImf+9TMPW5iYXKNT4eRNntf3fCtVYe5jZqo/mrSQA=" crossorigin="anonymous">
<!-- define favicon -->
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" sizes="16x16" href="favicon.ico" type="image/x-icon" >
<!-- custom CSS styling -->
<style>
body {
padding-top: 70px;
}
.scrollable-menu {
height: auto;
max-height: 80vh;
overflow-x: hidden;
overflow-y: auto;
}
#output_panel_loading {
color: rgba(0,0,0,.4);
}
#output {
display: none;
position:relative;
}
.back-to-top {
cursor: pointer;
position: fixed;
bottom: 20px;
right: 20px;
display:none;
}
#copy_to_clipboard_button {
position: absolute;
top: 0;
right: 0;
}
#toggle_buttons {
display: none;
}
</style>
<!-- /custom CSS styling -->
</head>
<body>
<!-- top navbar -->
<nav id="navbar" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand hidden-sm hidden-md" href="index.php"><i class="fa fa-search fa-fw fa-lg" aria-hidden="true"></i> UniFi API browser</a>
</div>
<div id="navbar-main" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-left">
<!-- controllers dropdown, only show when multiple controllers have been configured -->
<?php if (isset($controllers)) { ?>
<li id="site-menu" class="dropdown">
<a id="controller-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<?php
/**
* here we display the UniFi controller name, if selected, else just label it
*/
if (isset($controller['name'])) {
echo $controller['name'];
} else {
echo 'Controllers';
}
?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu" id="controllerslist">
<li class="dropdown-header">Select a controller</li>
<li role="separator" class="divider"></li>
<?php
/**
* here we loop through the configured UniFi controllers
*/
foreach ($controllers as $key => $value) {
echo '<li id="controller_' . $key . '"><a href="?controller_id=' . $key . '">' . $value['name'] . '</a></li>' . "\n";
}
?>
</ul>
</li>
<?php } ?>
<!-- /controllers dropdown -->
<!-- sites dropdown, only show when a controller has been selected -->
<?php if ($show_login === false && isset($controller['name'])) { ?>
<li id="site-menu" class="dropdown">
<a id="site-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<?php
/**
* here we display the site name, if selected, else just label it
*/
if (!empty($site_name)) {
echo $site_name;
} else {
echo 'Sites';
}
?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu" id="siteslist">
<li class="dropdown-header">Select a site</li>
<li role="separator" class="divider"></li>
<?php
/**
* here we loop through the available sites, after we've sorted the sites collection
*/
usort($sites, "sites_sort");
foreach ($sites as $site) {
$link_row = '<li id="' . $site->name . '"><a href="?site_id=' .
urlencode($site->name) . '&site_name=' . urlencode($site->desc) .
'">' . $site->desc . '</a></li>' . "\n";
echo $link_row;
}
?>
</ul>
</li>
<?php } ?>
<!-- /sites dropdown -->
<!-- data collection dropdowns, only show when a site_id is selected -->
<?php if ($site_id && isset($_SESSION['unificookie'])) { ?>
<li id="output-menu" class="dropdown">
<a id="output-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Output
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu" id="outputselection">
<li class="dropdown-header">Select an output format</li>
<li role="separator" class="divider"></li>
<li id="json"><a href="?output_format=json">JSON (default)</a></li>
<li role="separator" class="divider"></li>
<li id="php_array"><a href="?output_format=php_array">PHP array</a></li>
<li id="php_var_dump"><a href="?output_format=php_var_dump">PHP var_dump</a></li>
<li id="php_var_export"><a href="?output_format=php_var_export">PHP var_export</a></li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nice but slow with large collections</li>
<li id="json_color"><a href="?output_format=json_color">JSON highlighted</a></li>
<li id="php_array_kint"><a href="?output_format=php_array_kint">PHP array using Kint</a></li>
</ul>
</li>
<li id="user-menu" class="dropdown">
<a id="user-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Clients
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_clients"><a href="?action=list_clients">list online clients</a></li>
<li id="list_guests"><a href="?action=list_guests">list guests</a></li>
<li id="list_users"><a href="?action=list_users">list users</a></li>
<li id="list_usergroups"><a href="?action=list_usergroups">list user groups</a></li>
<li role="separator" class="divider"></li>
<li id="stat_allusers"><a href="?action=stat_allusers">stat all users</a></li>
<li id="stat_auths"><a href="?action=stat_auths">stat authorisations</a></li>
<li id="stat_sessions"><a href="?action=stat_sessions">stat sessions</a></li>
</ul>
</li>
<li id="ap-menu" class="dropdown">
<a id="ap-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Devices
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_devices"><a href="?action=list_devices">list devices</a></li>
<li id="list_wlan_groups"><a href="?action=list_wlan_groups">list wlan groups</a></li>
<li id="list_rogueaps"><a href="?action=list_rogueaps">list rogue access points</a></li>
<li id="list_known_rogueaps"><a href="?action=list_known_rogueaps">list known rogue access points</a></li>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.5.0') >= 0) { ?>
<!-- list tags, only to be displayed when we have detected a capable controller version -->
<li role="separator" class="divider"></li>
<li id="list_tags"><a href="?action=list_tags">list tags</a></li>
<?php } ?>
</ul>
</li>
<li id="stats-menu" class="dropdown">
<a id="stats-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Stats
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="stat_5minutes_site"><a href="?action=stat_5minutes_site">5 minutes site stats</a></li>
<li id="stat_hourly_site"><a href="?action=stat_hourly_site">hourly site stats</a></li>
<li id="stat_daily_site"><a href="?action=stat_daily_site">daily site stats</a></li>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.2.9') >= 0) { ?>
<!-- all sites stats, only to be displayed when we have detected a capable controller version -->
<li id="stat_sites"><a href="?action=stat_sites">all sites stats</a></li>
<?php } ?>
<!-- /all sites stats -->
<!-- access point stats -->
<li role="separator" class="divider"></li>
<li id="stat_5minutes_aps"><a href="?action=stat_5minutes_aps">5 minutes access point stats</a></li>
<li id="stat_hourly_aps"><a href="?action=stat_hourly_aps">hourly access point stats</a></li>
<li id="stat_daily_aps"><a href="?action=stat_daily_aps">daily access point stats</a></li>
<!-- /access point stats -->
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.8.0') >= 0) { ?>
<!-- gateway stats, only to be displayed when we have detected a capable controller version -->
<li role="separator" class="divider"></li>
<li class="dropdown-header">USG required:</li>
<li id="stat_5minutes_gateway"><a href="?action=stat_5minutes_gateway">5 minutes gateway stats</a></li>
<li id="stat_hourly_gateway"><a href="?action=stat_hourly_gateway">hourly gateway stats</a></li>
<li id="stat_daily_gateway"><a href="?action=stat_daily_gateway">daily gateway stats</a></li>
<!-- /gateway stats -->
<?php } ?>
<li role="separator" class="divider"></li>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '4.9.1') >= 0) { ?>
<!-- site dashboard metrics, only to be displayed when we have detected a capable controller version -->
<li id="list_5minutes_dashboard"><a href="?action=list_5minutes_dashboard">5 minutes site dashboard metrics</a></li>
<li id="list_hourly_dashboard"><a href="?action=list_hourly_dashboard">hourly site dashboard metrics</a></li>
<li role="separator" class="divider"></li>
<?php } ?>
<!-- /site dashboard metrics -->
<li id="list_health"><a href="?action=list_health">site health metrics</a></li>
<li id="list_portforward_stats"><a href="?action=list_portforward_stats">port forwarding stats</a></li>
<li id="list_dpi_stats"><a href="?action=list_dpi_stats">DPI stats</a></li>
</ul>
</li>
<li id="hotspot-menu" class="dropdown">
<a id="msg-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Hotspot
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="stat_voucher"><a href="?action=stat_voucher">stat vouchers</a></li>
<li id="stat_payment"><a href="?action=stat_payment">stat payments</a></li>
<li role="separator" class="divider"></li>
<li id="list_hotspotop"><a href="?action=list_hotspotop">list hotspot operators</a></li>
</ul>
</li>
<li id="config-menu" class="dropdown">
<a id="config-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Configuration
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_sites"><a href="?action=list_sites">list sites on this controller</a></li>
<li id="stat_sysinfo"><a href="?action=stat_sysinfo">sysinfo</a></li>
<li id="list_self"><a href="?action=list_self">self</a></li>
<li role="separator" class="divider"></li>
<li id="list_settings"><a href="?action=list_settings">list site settings</a></li>
<li id="list_admins"><a href="?action=list_admins">list admins for current site</a></li>
<li role="separator" class="divider"></li>
<li id="list_wlanconf"><a href="?action=list_wlanconf">list wlan configuration</a></li>
<li id="list_current_channels"><a href="?action=list_current_channels">list current channels</a></li>
<li role="separator" class="divider"></li>
<li id="list_extension"><a href="?action=list_extension">list VoIP extensions</a></li>
<li role="separator" class="divider"></li>
<li id="list_networkconf"><a href="?action=list_networkconf">list network configuration</a></li>
<li id="list_portconf"><a href="?action=list_portconf">list port configuration</a></li>
<li id="list_portforwarding"><a href="?action=list_portforwarding">list port forwarding rules</a></li>
<li id="list_firewallgroups"><a href="?action=list_firewallgroups">list firewall groups</a></li>
<li id="list_dynamicdns"><a href="?action=list_dynamicdns">dynamic DNS configuration</a></li>
<li role="separator" class="divider"></li>
<li id="list_country_codes"><a href="?action=list_country_codes">list country codes</a></li>
<li role="separator" class="divider"></li>
<li id="list_backups"><a href="?action=list_backups">list auto backups</a></li>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.5.19') >= 0) { ?>
<!-- Radius-related collections, only to be displayed when we have detected a capable controller version -->
<li role="separator" class="divider"></li>
<li id="list_radius_profiles"><a href="?action=list_radius_profiles">list Radius profiles</a></li>
<li id="list_radius_accounts"><a href="?action=list_radius_accounts">list Radius accounts</a></li>
<?php } ?>
</ul>
</li>
<li id="msg-menu" class="dropdown">
<a id="msg-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Messages
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_alarms"><a href="?action=list_alarms">list alarms</a></li>
<li id="count_alarms"><a href="?action=count_alarms">count all alarms</a></li>
<li id="count_active_alarms"><a href="?action=count_active_alarms">count active alarms</a></li>
<li role="separator" class="divider"></li>
<li id="list_events"><a href="?action=list_events">list events</a></li>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.9.10') >= 0) { ?>