HTTP response status: 400'
. ' This is probably caused by a UniFi controller login failure, please check your credentials in '
- . 'config.php. After correcting your credentials, please close your browser before attempting to use the API browser tool again.
';
+ . 'config.php. After correcting your credentials, please restart your browser before attempting to use the API Browser tool again.';
}
/**
* Get the list of sites managed by the controller (if not already stored in $_SESSION)
*/
- if (!isset($_SESSION['sites']) || $_SESSION['sites'] == '') {
+ if (!isset($_SESSION['sites']) || $_SESSION['sites'] === '') {
$sites = $unifidata->list_sites();
$_SESSION['sites'] = $sites;
} else {
@@ -216,16 +233,17 @@
}
/**
- * Get the version of the controller (if not already stored in $_SESSION or when empty)
+ * Get the version of the controller (if not already stored in $_SESSION or when 'undetected')
*/
- if (!isset($_SESSION['detected_controller_version']) || $_SESSION['detected_controller_version'] == '') {
+ if (!isset($_SESSION['detected_controller_version']) || $_SESSION['detected_controller_version'] === 'undetected') {
$site_info = $unifidata->stat_sysinfo();
- $detected_controller_version = $site_info[0]->version;
- if ($detected_controller_version == '') {
- $_SESSION['detected_controller_version'] = 'undetected';
- } else {
+ 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'];
@@ -238,140 +256,142 @@
$time_1 = microtime(true);
$time_after_login = $time_1 - $time_start;
-/**
- * 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_hourly_site':
- $selection = 'hourly site stats';
- $data = $unifidata->stat_hourly_site();
- break;
- case 'stat_sysinfo':
- $selection = 'sysinfo';
- $data = $unifidata->stat_sysinfo();
- break;
- case 'stat_hourly_aps':
- $selection = 'hourly ap stats';
- $data = $unifidata->stat_hourly_aps();
- break;
- case 'stat_daily_site':
- $selection = 'daily site stats';
- $data = $unifidata->stat_daily_site();
- break;
- case 'list_devices':
- $selection = 'list devices';
- $data = $unifidata->list_aps();
- 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_events':
- $selection = 'list events';
- $data = $unifidata->list_events();
- break;
- case 'list_alarms':
- $selection = 'list alerts';
- $data = $unifidata->list_alarms();
- 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_dashboard':
- $selection = '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_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 '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;
- default:
- break;
+if (isset($unifidata)) {
+ /**
+ * 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_hourly_site':
+ $selection = 'hourly site stats';
+ $data = $unifidata->stat_hourly_site();
+ break;
+ case 'stat_sysinfo':
+ $selection = 'sysinfo';
+ $data = $unifidata->stat_sysinfo();
+ break;
+ case 'stat_hourly_aps':
+ $selection = 'hourly ap stats';
+ $data = $unifidata->stat_hourly_aps();
+ break;
+ case 'stat_daily_site':
+ $selection = 'daily site stats';
+ $data = $unifidata->stat_daily_site();
+ break;
+ case 'list_devices':
+ $selection = 'list devices';
+ $data = $unifidata->list_aps();
+ 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_events':
+ $selection = 'list events';
+ $data = $unifidata->list_events();
+ break;
+ case 'list_alarms':
+ $selection = 'list alerts';
+ $data = $unifidata->list_alarms();
+ 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_dashboard':
+ $selection = '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_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 '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;
+ default:
+ break;
+ }
}
/**
@@ -464,6 +484,7 @@ function sites_sort($a, $b)
+