|
|
@@ -2333,7 +2333,7 @@ function getOmbiRequests($type = "both", $limit = 50)
|
|
|
|
|
|
function unifiConnect()
|
|
|
{
|
|
|
- if ($GLOBALS['homepageUnifiEnabled'] && !empty($GLOBALS['unifiURL']) && !empty($GLOBALS['unifiSiteName']) && !empty($GLOBALS['unifiCookie']) && !empty($GLOBALS['unifiUsername']) && !empty($GLOBALS['unifiPassword']) && qualifyRequest($GLOBALS['homepageUnifiAuth'])) {
|
|
|
+ if ($GLOBALS['homepageUnifiEnabled'] && !empty($GLOBALS['unifiURL']) && !empty($GLOBALS['unifiSiteName']) && !empty($GLOBALS['unifiUsername']) && !empty($GLOBALS['unifiPassword']) && qualifyRequest($GLOBALS['homepageUnifiAuth'])) {
|
|
|
$api['content']['unifi'] = array();
|
|
|
$url = qualifyURL($GLOBALS['unifiURL']);
|
|
|
$urlStat = $url . '/api/s/' . $GLOBALS['unifiSiteName'] . '/stat/health';
|
|
|
@@ -2372,7 +2372,7 @@ function testAPIConnection($array)
|
|
|
{
|
|
|
switch ($array['data']['action']) {
|
|
|
case 'unifiSite':
|
|
|
- if (!empty($GLOBALS['unifiURL']) && !empty($GLOBALS['unifiCookie']) && !empty($GLOBALS['unifiUsername']) && !empty($GLOBALS['unifiPassword'])) {
|
|
|
+ if (!empty($GLOBALS['unifiURL']) && !empty($GLOBALS['unifiUsername']) && !empty($GLOBALS['unifiPassword'])) {
|
|
|
$url = qualifyURL($GLOBALS['unifiURL']);
|
|
|
try {
|
|
|
$options = array('verify' => false, 'verifyname' => false, 'follow_redirects' => false);
|
|
|
@@ -2404,6 +2404,37 @@ function testAPIConnection($array)
|
|
|
};
|
|
|
}
|
|
|
break;
|
|
|
+ case 'unifi':
|
|
|
+ if (!empty($GLOBALS['unifiURL']) && !empty($GLOBALS['unifiUsername']) && !empty($GLOBALS['unifiPassword']) && !empty($GLOBALS['unifiSiteName'])) {
|
|
|
+ $url = qualifyURL($GLOBALS['unifiURL']);
|
|
|
+ try {
|
|
|
+ $options = array('verify' => false, 'verifyname' => false, 'follow_redirects' => false);
|
|
|
+ $data = array(
|
|
|
+ 'username' => $GLOBALS['unifiUsername'],
|
|
|
+ 'password' => decrypt($GLOBALS['unifiPassword']),
|
|
|
+ 'remember' => true,
|
|
|
+ 'strict' => true
|
|
|
+ );
|
|
|
+ $response = Requests::post($url . '/api/login', array(), json_encode($data), $options);
|
|
|
+ if ($response->success) {
|
|
|
+ $cookie['unifises'] = ($response->cookies['unifises']->value) ?? false;
|
|
|
+ $cookie['csrf_token'] = ($response->cookies['csrf_token']->value) ?? false;
|
|
|
+ }else{
|
|
|
+ return 'Failed to Login';
|
|
|
+ }
|
|
|
+ $headers = array(
|
|
|
+ 'cookie' => 'unifises=' . $cookie['unifises'] . ';' . 'csrf_token=' . $cookie['csrf_token'] . ';'
|
|
|
+ );
|
|
|
+ $response = Requests::get($url . '/api/s/'.$GLOBALS['unifiSiteName'].'/self', $headers, $options);
|
|
|
+ $body = json_decode($response->body, true);
|
|
|
+ return ($body['meta']['rc'] == 'ok') ? true : $body['meta']['msg'];
|
|
|
+ } catch (Requests_Exception $e) {
|
|
|
+ writeLog('error', 'Unifi Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ return 'Not all data is filled in...';
|
|
|
+ }
|
|
|
+ break;
|
|
|
case 'ombi':
|
|
|
if (!empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken'])) {
|
|
|
$url = qualifyURL($GLOBALS['ombiURL']);
|