Skip to content

Commit 93cfc4b

Browse files
committed
- included API client class version 1.1.33
- added support for new methods implemented in API client class version 1.1.33 for gateway stats (requires controller version 5.8.X and higher) - general code cleanup
1 parent a61000a commit 93cfc4b

File tree

5 files changed

+1461
-536
lines changed

5 files changed

+1461
-536
lines changed

composer.lock

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

index.php

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* with this package in the file LICENSE.md
1818
*
1919
*/
20-
define('API_BROWSER_VERSION', '1.0.31');
20+
define('API_BROWSER_VERSION', '1.0.32');
2121
define('API_CLASS_VERSION', get_client_version());
2222

2323
/**
@@ -30,7 +30,7 @@
3030
$curl_version = $curl_info['version'];
3131
$openssl_version = $curl_info['ssl_version'];
3232
} else {
33-
exit('The <b>PHP curl</b> module is not installed! Please correct this before you proceed!<br>');
33+
exit('The <b>PHP curl</b> module is not installed! Please correct this before proceeding!<br>');
3434
$curl_version = 'unavailable';
3535
$openssl_version = 'unavailable';
3636
}
@@ -219,18 +219,18 @@
219219
* placed here so they can be overwritten by more "severe" error messages later on
220220
*/
221221
if ($action === '') {
222-
$alert_message = '<div class="alert alert-info" role="alert">Please select a data collection/API endpoint from the dropdown menus' .
223-
' <i class="fa fa-arrow-circle-up"></i></div>';
222+
$alert_message = '<div class="alert alert-info" role="alert">Please select a data collection/API endpoint from the dropdown menus ' .
223+
'<i class="fa fa-arrow-circle-up"></i></div>';
224224
}
225225

226226
if ($site_id === '' && isset($_SESSION['controller'])) {
227-
$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">' .
228-
'</i></div>';
227+
$alert_message = '<div class="alert alert-info" role="alert">Please select a site from the Sites dropdown menu ' .
228+
'<i class="fa fa-arrow-circle-up"></i></div>';
229229
}
230230

231231
if (!isset($_SESSION['controller'])) {
232-
$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">' .
233-
'</i></div>';
232+
$alert_message = '<div class="alert alert-info" role="alert">Please select a controller from the Controllers dropdown menu ' .
233+
'<i class="fa fa-arrow-circle-up"></i></div>';
234234
}
235235

236236
/**
@@ -310,6 +310,25 @@
310310
$time_after_login = $time_1 - $time_start;
311311

312312
if (isset($unifidata)) {
313+
/**
314+
* array containing attributes to fetch for the gateway stats, overriding
315+
* the default attributes
316+
*/
317+
$gateway_stats_attribs = [
318+
'time',
319+
'mem',
320+
'cpu',
321+
'loadavg_5',
322+
'lan-rx_errors',
323+
'lan-tx_errors',
324+
'lan-rx_bytes',
325+
'lan-tx_bytes',
326+
'lan-rx_packets',
327+
'lan-tx_packets',
328+
'lan-rx_dropped',
329+
'lan-tx_dropped'
330+
];
331+
313332
/**
314333
* select the required call to the UniFi Controller API based on the selected action
315334
*/
@@ -358,6 +377,18 @@
358377
$selection = 'daily ap stats';
359378
$data = $unifidata->stat_daily_aps();
360379
break;
380+
case 'stat_5minutes_gateway':
381+
$selection = '5 minutes gateway stats';
382+
$data = $unifidata->stat_5minutes_gateway(null, null, $gateway_stats_attribs);
383+
break;
384+
case 'stat_hourly_gateway':
385+
$selection = 'hourly gateway stats';
386+
$data = $unifidata->stat_hourly_gateway(null, null, $gateway_stats_attribs);
387+
break;
388+
case 'stat_daily_gateway':
389+
$selection = 'daily gateway stats';
390+
$data = $unifidata->stat_daily_gateway(null, null, $gateway_stats_attribs);
391+
break;
361392
case 'stat_sysinfo':
362393
$selection = 'sysinfo';
363394
$data = $unifidata->stat_sysinfo();
@@ -796,8 +827,8 @@ function get_client_version()
796827
<li id="list_wlan_groups"><a href="?action=list_wlan_groups">list wlan groups</a></li>
797828
<li id="list_rogueaps"><a href="?action=list_rogueaps">list rogue access points</a></li>
798829
<li id="list_known_rogueaps"><a href="?action=list_known_rogueaps">list known rogue access points</a></li>
799-
<!-- all sites stats, only to be displayed when we have detected a capable controller version -->
800830
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.5.0') >= 0) { ?>
831+
<!-- list tags, only to be displayed when we have detected a capable controller version -->
801832
<li role="separator" class="divider"></li>
802833
<li id="list_tags"><a href="?action=list_tags">list tags</a></li>
803834
<?php } ?>
@@ -813,18 +844,29 @@ function get_client_version()
813844
<li id="stat_5minutes_site"><a href="?action=stat_5minutes_site">5 minutes site stats</a></li>
814845
<li id="stat_hourly_site"><a href="?action=stat_hourly_site">hourly site stats</a></li>
815846
<li id="stat_daily_site"><a href="?action=stat_daily_site">daily site stats</a></li>
816-
<!-- all sites stats, only to be displayed when we have detected a capable controller version -->
817847
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.2.9') >= 0) { ?>
848+
<!-- all sites stats, only to be displayed when we have detected a capable controller version -->
818849
<li id="stat_sites"><a href="?action=stat_sites">all sites stats</a></li>
819850
<?php } ?>
820851
<!-- /all sites stats -->
852+
<!-- access point stats -->
821853
<li role="separator" class="divider"></li>
822854
<li id="stat_5minutes_aps"><a href="?action=stat_5minutes_aps">5 minutes access point stats</a></li>
823855
<li id="stat_hourly_aps"><a href="?action=stat_hourly_aps">hourly access point stats</a></li>
824856
<li id="stat_daily_aps"><a href="?action=stat_daily_aps">daily access point stats</a></li>
857+
<!-- /access point stats -->
858+
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.8.0') >= 0) { ?>
859+
<!-- gateway stats, only to be displayed when we have detected a capable controller version -->
860+
<li role="separator" class="divider"></li>
861+
<li class="dropdown-header">USG required:</li>
862+
<li id="stat_5minutes_gateway"><a href="?action=stat_5minutes_gateway">5 minutes gateway stats</a></li>
863+
<li id="stat_hourly_gateway"><a href="?action=stat_hourly_gateway">hourly gateway stats</a></li>
864+
<li id="stat_daily_gateway"><a href="?action=stat_daily_gateway">daily gateway stats</a></li>
865+
<!-- /gateway stats -->
866+
<?php } ?>
825867
<li role="separator" class="divider"></li>
826-
<!-- site dashboard metrics, only to be displayed when we have detected a capable controller version -->
827868
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '4.9.1') >= 0) { ?>
869+
<!-- site dashboard metrics, only to be displayed when we have detected a capable controller version -->
828870
<li id="list_5minutes_dashboard"><a href="?action=list_5minutes_dashboard">5 minutes site dashboard metrics</a></li>
829871
<li id="list_hourly_dashboard"><a href="?action=list_hourly_dashboard">hourly site dashboard metrics</a></li>
830872
<li role="separator" class="divider"></li>
@@ -876,8 +918,8 @@ function get_client_version()
876918
<li id="list_country_codes"><a href="?action=list_country_codes">list country codes</a></li>
877919
<li role="separator" class="divider"></li>
878920
<li id="list_backups"><a href="?action=list_backups">list auto backups</a></li>
879-
<!-- Radius-related collections, only to be displayed when we have detected a capable controller version -->
880921
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.5.19') >= 0) { ?>
922+
<!-- Radius-related collections, only to be displayed when we have detected a capable controller version -->
881923
<li role="separator" class="divider"></li>
882924
<li id="list_radius_profiles"><a href="?action=list_radius_profiles">list Radius profiles</a></li>
883925
<li id="list_radius_accounts"><a href="?action=list_radius_accounts">list Radius accounts</a></li>
@@ -1065,7 +1107,7 @@ function get_client_version()
10651107
var alert_message = '<?php echo $alert_message ?>',
10661108
action = '<?php echo $action ?>',
10671109
site_id = '<?php echo $site_id ?>',
1068-
site_name = "<?php echo htmlspecialchars($site_name) ?>",
1110+
site_name = '<?php echo htmlspecialchars($site_name) ?>',
10691111
controller_id = '<?php echo $controller_id ?>',
10701112
output_format = '<?php echo $output_format ?>',
10711113
selection = '<?php echo $selection ?>',
@@ -1113,8 +1155,8 @@ function get_client_version()
11131155
/**
11141156
* we hide the loading div and show the output panel
11151157
*/
1116-
$("#output_panel_loading").hide();
1117-
$("#output_panel").show();
1158+
$('#output_panel_loading').hide();
1159+
$('#output_panel').show();
11181160

11191161
/**
11201162
* update dynamic elements in the DOM using some of the above variables
@@ -1218,7 +1260,7 @@ function get_client_version()
12181260
}).fail(function(d, textStatus, error) {
12191261
$('#span_api_browser_update').html('error checking updates');
12201262
$('#span_api_browser_update').removeClass('label-success').addClass('label-danger');
1221-
console.error("getJSON failed, status: " + textStatus + ", error: " + error);
1263+
console.error('getJSON failed, status: ' + textStatus + ', error: ' + error);
12221264
});;
12231265
})
12241266

@@ -1289,9 +1331,15 @@ function hideTooltip(btn) {
12891331
$.uf.copy('.js-copy-trigger');
12901332

12911333
/**
1292-
* hide button if the ClipboardJS function isn't supported or the output format isn't supported
1334+
* hide "copy to clipboard" button if the ClipboardJS function isn't supported or the output format isn't supported
12931335
*/
1294-
if (!ClipboardJS.isSupported() || $.inArray(output_format, ['json', 'php_array', 'php_var_dump', 'php_var_export'] ) === -1) {
1336+
var unsupported_formats = [
1337+
'json',
1338+
'php_array',
1339+
'php_var_dump',
1340+
'php_var_export'
1341+
];
1342+
if (!ClipboardJS.isSupported() || $.inArray(output_format, unsupported_formats) === -1) {
12951343
$('.js-copy-trigger').hide();
12961344
}
12971345

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# Ignore personal config file
2-
examples/config.php
2+
/examples/config.php
3+
4+
# ignore accidentally generated vendor directory and composer.lock file, just in case...
5+
/vendor/
6+
/composer.lock
7+
8+
# ignore XML files
9+
*.xml

0 commit comments

Comments
 (0)