コード例 #1
0
*/
require 'phpapi/class.unifi.php';
if (!is_readable('config.php')) {
    $alertmessage = '<div class="alert alert-danger" role="alert">The file config.php is not readable or does not exist.<br>If you have not yet done so, please copy/rename the config.template.php file to config.php and modify the contents as required.</div>';
}
include 'config.php';
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
$loginresults = $unifidata->login();
if ($loginresults === 400) {
    $alertmessage = '<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 in config.php</div>';
}
/*
get the list of sites managed by the controller (if not already stored in $_SESSION)
*/
if (!isset($_SESSION['sites'])) {
    $sites = $unifidata->list_sites();
    $_SESSION['sites'] = $sites;
} else {
    $sites = $_SESSION['sites'];
}
/*
get the version of the controller (if not already stored in $_SESSION)
*/
if (!isset($_SESSION['detected_controller_version'])) {
    $site_info = $unifidata->stat_sysinfo();
    $_SESSION['detected_controller_version'] = $site_info[0]->version;
}
/*
starting timing of session here
*/
$time_1 = microtime(true);