Browse Source

Merge pull request #1265 from causefx/v2-develop

V2 develop
causefx 6 years ago
parent
commit
cdc55ce895
3 changed files with 43 additions and 5 deletions
  1. 33 2
      api/functions/homepage-connect-functions.php
  2. 3 3
      api/functions/static-globals.php
  3. 7 0
      js/version.json

+ 33 - 2
api/functions/homepage-connect-functions.php

@@ -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']);

+ 3 - 3
api/functions/static-globals.php

@@ -1,7 +1,7 @@
 <?php
 // ===================================
 // Organizr Version
-$GLOBALS['installedVersion'] = '2.0.320';
+$GLOBALS['installedVersion'] = '2.0.325';
 // ===================================
 // Quick php Version check
 $GLOBALS['minimumPHP'] = '7.1.3';
@@ -33,8 +33,8 @@ function pluginFiles($type)
 			}
 			break;
 		case 'css':
-			foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . "*.js") as $filename) {
-				$files .= '<link href="api/plugins/css/' . basename($filename) . $GLOBALS['fileHash'] . '" rel="stylesheet">';
+			foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
+				$files .= '<link href="api/plugins/css/' . basename($filename) . '?v=' . $GLOBALS['fileHash'] . '" rel="stylesheet">';
 			}
 			break;
 		default:

+ 7 - 0
js/version.json

@@ -208,5 +208,12 @@
     "new": "Unifi Homepage Item|Login and Top Bar Logo (#1029)|Add 5 minute buffer to plex thumbs",
     "fixed": "Quick and dirty fix for Google iCal Not working (#1233)|Forgot to add License back (#1247)|Fix context menu disabled on lock screen (#1243)|Dropdown arrows on Tab Groups not animating (#1239)|Fix Unifi cookie to be loaded on first api call|Cannot re-order new tabs from bottom upwards in Settings after adding many (#1175)",
     "notes": "Add a class and data-tab-name to sidenav groups (#1249)|Please report bugs in GitHub issues page|Updated language translations"
+  },
+  "2.0.325": {
+    "date": "2019-10-18 20:20",
+    "title": "Fix Unifi Homepage",
+    "new": "",
+    "fixed": "Plugin Files not loading css files|Remove unifiCookie from unif homepage check",
+    "notes": "Please report bugs in GitHub issues page|Updated language translations"
   }
 }