Kaynağa Gözat

Added user group permissions to tautulli stats

Tautulli stats are split into groups, each group has own user group permission.
Henry Whitaker 6 yıl önce
ebeveyn
işleme
f48eca4fca

+ 3 - 0
api/config/default.php

@@ -266,6 +266,9 @@ return array(
 	'traefikAuthEnable' => false,
 	'homepageTautulliEnabled' => false,
 	'homepageTautulliAuth' => '1',
+	'homepageTautulliLibraryAuth' => '1',
+	'homepageTautulliViewsAuth' => '1',
+	'homepageTautulliMiscAuth' => '1',
 	'homepageTautulliRefresh' => '60000',
 	'tautulliURL' => '',
 	'tautulliApikey' => '',

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

@@ -2403,7 +2403,7 @@ function unifiConnect()
 
 function getTautulli()
 {
-	if ($GLOBALS['homepageTautulliEnabled'] && !empty($GLOBALS['tautulliURL']) && !empty($GLOBALS['tautulliApikey'])) {
+	if ($GLOBALS['homepageTautulliEnabled'] && !empty($GLOBALS['tautulliURL']) && !empty($GLOBALS['tautulliApikey']) && qualifyRequest($GLOBALS['homepageTautulliAuth'])) {
 		$api = [];
 		$url = $GLOBALS['tautulliURL'] . '/api/v2?apikey=' . $GLOBALS['tautulliApikey'];
 		try {
@@ -2429,8 +2429,34 @@ function getTautulli()
 				'popularMovies' => $GLOBALS['tautulliPopularMovies'],
 				'popularTV' => $GLOBALS['tautulliPopularTV'],
 			];
+
+			$ids = []; // Array of stat_ids to remove from the returned array
+			if(!qualifyRequest($GLOBALS['homepageTautulliLibraryAuth'])) {
+				$api['options']['libraries'] = false;
+				unset($api['libstats']);
+			}
+			if(!qualifyRequest($GLOBALS['homepageTautulliViewsAuth'])) {
+				$api['options']['topMovies'] = false;
+				$api['options']['topTV'] = false;
+				$api['options']['popularMovies'] = false;
+				$api['options']['popularTV'] = false;
+				$ids = array_merge([ 'top_movies', 'popular_movies', 'popular_tv', 'top_tv' ], $ids);
+				$api['homestats']['data'] = array_values($api['homestats']['data']);
+			}
+			if(!qualifyRequest($GLOBALS['homepageTautulliMiscAuth'])) {
+				$api['options']['topUsers'] = false;
+				$api['options']['topPlatforms'] = false;
+				$ids = array_merge([ 'top_platforms', 'top_users' ], $ids);
+				$api['homestats']['data'] = array_values($api['homestats']['data']);
+			}
+			$ids = array_merge([ 'top_music', 'popular_music', 'last_watched', 'most_concurrent' ], $ids);
+			foreach($ids as $id) {
+				$key = array_search($id, array_column($api['homestats']['data'], 'stat_id'));
+				unset($api['homestats']['data'][$key]);
+				$api['homestats']['data'] = array_values($api['homestats']['data']);
+			}
 		} catch (Requests_Exception $e) {
-			writeLog('error', 'Pi-hole Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			writeLog('error', 'Tautulli Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
 		};
 		$api = isset($api) ? $api : false;
 		return $api;

+ 27 - 1
api/functions/homepage-functions.php

@@ -2539,7 +2539,7 @@ function getHomepageList()
 						'value' => $GLOBALS['tautulliApikey']
 					)
 				),
-				'Misc Options' => array(
+				'Library Stats' => array(
 					array(
 						'type' => 'switch',
 						'name' => 'tautulliLibraries',
@@ -2547,6 +2547,15 @@ function getHomepageList()
 						'value' => $GLOBALS['tautulliLibraries'],
 						'help' => 'Shows/hides the card with library information.',
 					),
+					array(
+						'type' => 'select',
+						'name' => 'homepageTautulliLibraryAuth',
+						'label' => 'Minimum Authentication',
+						'value' => $GLOBALS['homepageTautulliLibraryAuth'],
+						'options' => $groups
+					),
+				),
+				'Viewing Stats' => array(
 					array(
 						'type' => 'switch',
 						'name' => 'tautulliPopularMovies',
@@ -2575,6 +2584,16 @@ function getHomepageList()
 						'value' => $GLOBALS['tautulliTopTV'],
 						'help' => 'Shows/hides the card with Top TV information.',
 					),
+					array(
+						'type' => 'select',
+						'name' => 'homepageTautulliViewsAuth',
+						'label' => 'Minimum Authentication',
+						'value' => $GLOBALS['homepageTautulliViewsAuth'],
+						'options' => $groups
+					),
+				),
+				'Misc Stats' => array(
+					
 					array(
 						'type' => 'switch',
 						'name' => 'tautulliTopUsers',
@@ -2589,6 +2608,13 @@ function getHomepageList()
 						'value' => $GLOBALS['tautulliTopPlatforms'],
 						'help' => 'Shows/hides the card with Top Platforms information.',
 					),
+					array(
+						'type' => 'select',
+						'name' => 'homepageTautulliMiscAuth',
+						'label' => 'Minimum Authentication',
+						'value' => $GLOBALS['homepageTautulliMiscAuth'],
+						'options' => $groups
+					),
 				),
 			)
 		),