Procházet zdrojové kódy

More Fixes

Fixed Auth.php to include whitelist and now has debug tool
Fixed Error.php to go back to one directory
Fixed now-playing plex id
Added goto plex tab from homepage items
causefx před 8 roky
rodič
revize
551b707a82
6 změnil soubory, kde provedl 107 přidání a 60 odebrání
  1. 16 38
      auth.php
  2. 1 1
      error.php
  3. 58 12
      functions.php
  4. 18 2
      homepage.php
  5. 2 2
      index.php
  6. 12 5
      settings.php

+ 16 - 38
auth.php

@@ -1,57 +1,35 @@
 <?php
-
-$data = false;
-
-function getBannedUsers($string){
-    if (strpos($string, ',') !== false) {
-        $banned = explode(",", $string);     
-    }else{
-        $banned = array($string);  
-    }
-    return $banned;
-}
-
-function getWhitelist($string){
-    if (strpos($string, ',') !== false) {
-        $whitelist = explode(",", $string); 
-    }else{
-        $whitelist = array($string);
-    }
-    foreach($whitelist as &$ip){
-        $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
-    }
-    return $whitelist;
-}
-
-//if (isset($_GET['ban'])) : $ban = strtoupper($_GET['ban']); else : $ban = ""; endif;
-//if (isset($_GET['whitelist'])) : $whitelist = $_GET['whitelist']; else : $whitelist = ""; endif;
-$ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
-$whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
-$currentIP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
-
+$debug = false;
 require_once("user.php");
 $USER = new User("registration_callback");
+$ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
+$whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
+$currentIP = get_client_ip();
 
 if ($whitelist) {
     if(in_array($currentIP, getWhitelist($whitelist))) {
-       exit(http_response_code(200)); 
-	} else {
-       exit(http_response_code(401));
+       !$debug ? exit(http_response_code(200)) : die("$currentIP is Whitelist Authorized");
 	}
 } elseif (isset($_GET['admin'])) {
     if($USER->authenticated && $USER->role == "admin" && !in_array(strtoupper($USER->username), getBannedUsers($ban))) {
-        exit(http_response_code(200));
+        !$debug ? exit(http_response_code(200)) : die("$USER->username Authorized At Admin Level");
 	} else {
-        exit(http_response_code(401));
+        !$debug ? exit(http_response_code(401)) : die("$USER->username Not Authorized At Admin Level");
     }
 } elseif (isset($_GET['user'])) {
     if($USER->authenticated && !in_array(strtoupper($USER->username), getBannedUsers($ban))) {
-        exit(http_response_code(200));
+        !$debug ? exit(http_response_code(200)) : die("$USER->username Authorized At User Level");
 	} else {
-        exit(http_response_code(401));
+        !$debug ? exit(http_response_code(401)) : die("$USER->username Not Authorized At User Level");
 	}
 } elseif (!isset($_GET['user']) && !isset($_GET['admin']) && !isset($_GET['whitelist'])) {
-    exit(http_response_code(401));
+    !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
+}
+
+if ($skipped) {
+	!$debug ? exit(http_response_code(401)) : die("$currentIP Not Authorized On Whitelist");
 }
 
+!$debug ? exit(http_response_code(401)) : die("$USER->username on $currentIP $skipped Not Authorized");
+
 ?>

+ 1 - 1
error.php

@@ -82,7 +82,7 @@ $errorImage = $codes[$status][2];
                                     <div class="big-box text-left">
                                         <center><img src="<?php echo checkRootPath(dirname($_SERVER['SCRIPT_NAME'])); ?>images/<?=$errorImage;?>.png" style="height: 200px;"></center>
                                         <h4 style="color: <?=$topbar;?>;" class="text-center"><?php echo $message;?></h4>
-                                        <button style="background:<?=$topbar;?>;" onclick="window.history.back();" type="button" class="btn log-in btn-block btn-primary text-uppercase waves waves-effect waves-float"><text style="color:<?=$topbartext;?>;"><?php echo $language->translate("GO_BACK");?></text></button>
+                                        <button style="background:<?=$topbar;?>;" onclick="parent.location='../'" type="button" class="btn log-in btn-block btn-primary text-uppercase waves waves-effect waves-float"><text style="color:<?=$topbartext;?>;"><?php echo $language->translate("GO_BACK");?></text></button>
                                     </div>
                                 </div>
                             </div>

+ 58 - 12
functions.php

@@ -632,12 +632,10 @@ if($nowPlaying){
 // Format item from Plex for Carousel
 function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false) {
     // Static Height
-    $height = 444;
-
-    $address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
+    $height = 444;    
 
     switch ($item['type']) {
-        case 'season':
+    	case 'season':
             $title = $item['parentTitle'];
             $summary = $item['parentSummary'];
             $width = 300;
@@ -657,7 +655,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
                 $transcoded = floor($item->TranscodeSession['progress']- $watched);
                 $stream = $item->Media->Part->Stream['decision'];
                 $user = $role == "admin" ? $item->User['title'] : "";
-                $id = $item->Session['id'];
+                $id = $item->Player['machineIdentifier'];
                 $streamInfo = buildStream(array(
                     'platform' => (string) $item->Player['platform'],
                     'device' => (string) $item->Player['device'],
@@ -688,7 +686,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
                 $transcoded = floor($item->TranscodeSession['progress']- $watched);
                 $stream = $item->Media->Part->Stream['decision'];
                 $user = $role == "admin" ? $item->User['title'] : "";
-                $id = $item->Session['id'];
+                $id = $item->Player['machineIdentifier'];
                 $streamInfo = buildStream(array(
                     'platform' => (string) $item->Player['platform'],
                     'device' => (string) $item->Player['device'],
@@ -722,7 +720,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
                 $transcoded = floor($item->TranscodeSession['progress']- $watched);
                 $stream = $item->Media->Part->Stream['decision'];
                 $user = $role == "admin" ? $item->User['title'] : "";
-                $id = $item->Session['id'];
+                $id = $item->Player['machineIdentifier'];
                 $streamInfo = buildStream(array(
                     'platform' => (string) $item->Player['platform'],
                     'device' => (string) $item->Player['device'],
@@ -742,6 +740,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
             $summary = $item['title'];
             $image = 'slick-image-short';
             $style = 'left: 160px !important;';
+			$item['ratingKey'] = $item['parentRatingKey'];
             if(!$nowPlaying){ 
                 $width = 444;
                 $thumb = $item['thumb'];
@@ -757,7 +756,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
                 $transcoded = floor($item->TranscodeSession['progress']- $watched);
                 $stream = $item->Media->Part->Stream['decision'];
                 $user = $role == "admin" ? $item->User['title'] : "";
-                $id = $item->Session['id'];
+                $id = $item->Player['machineIdentifier'];
                 $streamInfo = buildStream(array(
                     'platform' => (string) $item->Player['platform'],
                     'device' => (string) $item->Player['device'],
@@ -790,7 +789,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
                 $transcoded = floor($item->TranscodeSession['progress']- $watched);
                 $stream = $item->Media->Part->Stream['decision'];
                 $user = $role == "admin" ? $item->User['title'] : "";
-                $id = $item->Session['id'];
+                $id = $item->Player['machineIdentifier'];
                 $streamInfo = buildStream(array(
                     'platform' => (string) $item->Player['platform'],
                     'device' => (string) $item->Player['device'],
@@ -803,7 +802,13 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
                 $bottomTitle = '<small class="zero-m">'.$item['year'].'</small>';
                 if($showNames == "true"){ $bottomTitle .= '<small class="zero-m pull-right">'.$user.'</small>'; }
             }
-	   }
+		}
+	
+		if (substr_count(PLEXURL, ':') == 2) {
+			$address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
+		}else{
+			$address = PLEXURL."/web/index.html#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
+		}
 
     // If No Overview
     if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; }
@@ -813,11 +818,12 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
         $image_url = 'ajax.php?a=plex-image&img='.$thumb.'&height='.$height.'&width='.$width.'&key='.$key.'';        
     }
     if(!$thumb){ $image_url = "images/no-np.png"; $key = "no-np"; }
+	$openTab = (PLEXTABNAME) ? "true" : "false";
     // Assemble Item And Cache Into Array 
     if($nowPlaying){
-        return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$address.'" target="_blank"><img style="width: 500px; display:inherit;" src="'.$image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
+        return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img style="width: 500px; display:inherit;" src="'.$image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
     }else{
-        return '<div class="item-'.$item['type'].'"><a href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
+        return '<div class="item-'.$item['type'].'"><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
     }
 }
 
@@ -3089,5 +3095,45 @@ function searchPlex($query){
     return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
 }
 
+function getBannedUsers($string){
+    if (strpos($string, ',') !== false) {
+        $banned = explode(",", $string);     
+    }else{
+        $banned = array($string);  
+    }
+    return $banned;
+}
+
+function getWhitelist($string){
+    if (strpos($string, ',') !== false) {
+        $whitelist = explode(",", $string); 
+    }else{
+        $whitelist = array($string);
+    }
+    foreach($whitelist as &$ip){
+        $ip = is_numeric(substr($ip, 0, 1)) ? $ip : gethostbyname($ip);
+    }
+    return $whitelist;
+}
+
+function get_client_ip() {
+    $ipaddress = '';
+    if (isset($_SERVER['HTTP_CLIENT_IP']))
+        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
+    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
+        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
+    else if(isset($_SERVER['HTTP_X_FORWARDED']))
+        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
+    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
+        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
+    else if(isset($_SERVER['HTTP_FORWARDED']))
+        $ipaddress = $_SERVER['HTTP_FORWARDED'];
+    else if(isset($_SERVER['REMOTE_ADDR']))
+        $ipaddress = $_SERVER['REMOTE_ADDR'];
+    else
+        $ipaddress = 'UNKNOWN';
+    return $ipaddress;
+}
+
 // Always run this
 dependCheck();

+ 18 - 2
homepage.php

@@ -254,7 +254,6 @@ endif; ?>
     <body class="scroller-body" style="padding: 0px;">
         <div class="main-wrapper" style="position: initial;">
             <div id="content" class="container-fluid">
-<!-- <button id="numBnt">Numerical</button> -->
                 <br/>
  
                 <?php if (qualifyUser(HOMEPAGENOTICEAUTH) && HOMEPAGENOTICETITLE && HOMEPAGENOTICETYPE && HOMEPAGENOTICEMESSAGE && HOMEPAGENOTICELAYOUT) { echo buildHomepageNotice(HOMEPAGENOTICELAYOUT, HOMEPAGENOTICETYPE, HOMEPAGENOTICETITLE, HOMEPAGENOTICEMESSAGE); } ?>
@@ -549,7 +548,24 @@ endif; ?>
             var closedBox = $(this).closest('div.content-box').remove();
             e.preventDefault();
         });
-            
+        
+		$('.openTab').click(function(e){
+			if($(this).attr("openTab") === "true") {
+				var isActive = parent.$("div[data-content-name^='<?php echo PLEXTABNAME;?>']");
+				var activeFrame = isActive.children('iframe');
+				if(isActive.length === 1){
+					activeFrame.attr("src", $(this).attr("href"));
+					parent.$("li[name='<?php echo PLEXTABNAME;?>']").trigger("click");
+				}else{
+					parent.$("li[name='<?php echo PLEXTABNAME;?>']").trigger("click");
+					parent.$("div[data-content-name^='<?php echo PLEXTABNAME;?>']").children('iframe').attr("src", $(this).attr("href"));
+				}
+				e.preventDefault();
+			}else{
+				console.log("nope");
+			}
+
+        });
         
             
         function localStorageSupport() {

+ 2 - 2
index.php

@@ -1460,7 +1460,7 @@ endif; ?>
 
                     $("#content div[class^='iframe active']").attr("class", "iframe hidden");
 
-                    $( '<div class="iframe active" data-content-url="'+thisid+'"><iframe scrolling="auto" sandbox="allow-forms allow-same-origin allow-pointer-lock allow-scripts allow-popups allow-modals allow-top-navigation" allowfullscreen="true" webkitallowfullscreen="true" frameborder="0" style="width:100%; height:100%; position: absolute;" src="'+thisid+'"></iframe></div>' ).appendTo( "#content" );
+                    $( '<div class="iframe active" data-content-name="'+thisname+'" data-content-url="'+thisid+'"><iframe scrolling="auto" sandbox="allow-forms allow-same-origin allow-pointer-lock allow-scripts allow-popups allow-modals allow-top-navigation" allowfullscreen="true" webkitallowfullscreen="true" frameborder="0" style="width:100%; height:100%; position: absolute;" src="'+thisid+'"></iframe></div>' ).appendTo( "#content" );
                     document.title = thistitle;
                    // window.location.href = '#' + thisname;
 
@@ -1515,7 +1515,7 @@ endif; ?>
 
                     $("#contentRight div[class^='iframe active']").attr("class", "iframe hidden");
 
-                    $( '<div class="iframe active" data-content-url="'+thisid+'"><iframe scrolling="auto" sandbox="allow-forms allow-same-origin allow-pointer-lock allow-scripts allow-popups allow-modals allow-top-navigation" allowfullscreen="true" webkitallowfullscreen="true" frameborder="0" style="width:100%; height:100%; position: absolute;" src="'+thisid+'"></iframe></div>' ).appendTo( "#contentRight" );
+                    $( '<div class="iframe active" data-content-name="'+thisname+'" data-content-url="'+thisid+'"><iframe scrolling="auto" sandbox="allow-forms allow-same-origin allow-pointer-lock allow-scripts allow-popups allow-modals allow-top-navigation" allowfullscreen="true" webkitallowfullscreen="true" frameborder="0" style="width:100%; height:100%; position: absolute;" src="'+thisid+'"></iframe></div>' ).appendTo( "#contentRight" );
                     document.title = thistitle;
                     window.location.href = '#' + thisname;
 

+ 12 - 5
settings.php

@@ -698,7 +698,7 @@ echo buildSettings(
 						'pattern' => '[a-zA-Z0-9]{20}',
 						'value' => PLEXTOKEN,
 					),
-     array(
+     				array(
 						'type' => 'text',
 						'placeholder' => "",
 						'labelTranslate' => 'RECENT_ITEMS_LIMIT',
@@ -706,12 +706,19 @@ echo buildSettings(
 						'pattern' => '[0-9]+',
 						'value' => PLEXRECENTITEMS,
 					),
+					array(
+						'type' => 'text',
+						'placeholder' => "plex",
+						'labelTranslate' => 'PLEX_TAB_NAME',
+						'name' => 'plexTabName',
+						'value' => PLEXTABNAME,
+					),
 					array(
 						'type' => 'custom',
 						'html' => '<a href="https://support.plex.tv/hc/en-us/articles/204059436-Finding-an-authentication-token-X-Plex-Token">Plex Token Wiki Article</a>',
 					),
 					array(
-      array(
+      					array(
 							'type' => 'checkbox',
 							'labelTranslate' => 'ALLOW_SEARCH',
 							'name' => 'plexSearch',
@@ -741,7 +748,7 @@ echo buildSettings(
 							'name' => 'plexPlayingNow',
 							'value' => PLEXPLAYINGNOW,
 						),
-      array(
+      					array(
 							'type' => 'checkbox',
 							'labelTranslate' => 'SHOW_NAMES',
 							'name' => 'plexShowNames',
@@ -779,7 +786,7 @@ echo buildSettings(
 						'pattern' => '[a-zA-Z0-9]{32}',
 						'value' => EMBYTOKEN,
 					),
-     array(
+     				array(
 						'type' => 'text',
 						'placeholder' => "",
 						'labelTranslate' => 'RECENT_ITEMS_LIMIT',
@@ -812,7 +819,7 @@ echo buildSettings(
 							'name' => 'embyPlayingNow',
 							'value' => EMBYPLAYINGNOW,
 						),
-      array(
+      					array(
 							'type' => 'checkbox',
 							'labelTranslate' => 'SHOW_NAMES',
 							'name' => 'embyShowNames',