From 88d93340b59d2158cd2cac1ddfeb4ac15166c9a9 Mon Sep 17 00:00:00 2001 From: causefx Date: Mon, 26 Jun 2017 16:57:35 -0700 Subject: [PATCH 01/37] Added New Layout for Emby like Plex - New Auth Whitelist --- ajax.php | 2 +- auth.php | 41 ++-- functions.php | 406 ++++++++++++++++++++++++++------------ homepage.php | 32 ++- images/livetv.png | Bin 0 -> 31343 bytes images/platforms/emby.png | Bin 0 -> 3706 bytes settings.php | 6 + 7 files changed, 327 insertions(+), 160 deletions(-) create mode 100644 images/livetv.png create mode 100644 images/platforms/emby.png diff --git a/ajax.php b/ajax.php index 168c4c20a..d6c9e91cd 100755 --- a/ajax.php +++ b/ajax.php @@ -39,7 +39,7 @@ break; case 'emby-streams': qualifyUser(EMBYHOMEAUTH, true); - echo getEmbyStreams(12); + echo getEmbyStreams(12, EMBYSHOWNAMES, $GLOBALS['USER']->role); die(); break; case 'plex-streams': diff --git a/auth.php b/auth.php index ae4608bf8..ebfe35283 100755 --- a/auth.php +++ b/auth.php @@ -3,22 +3,29 @@ $data = false; function getBannedUsers($string){ - if (strpos($string, ',') !== false) { - - $banned = explode(",", $string); - - }elseif (strpos($string, ',') == false) { - - $banned = array($string); - + $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 = strtoupper($_GET['whitelist']); else : $whitelist = ""; endif; +$currentIP = $_SERVER['REMOTE_ADDR']; require_once("user.php"); $USER = new User("registration_callback"); @@ -47,7 +54,19 @@ function getBannedUsers($string){ endif; -elseif (!isset($_GET['user']) && !isset($_GET['admin'])) : +elseif (isset($_GET['whitelist'])) : + + if(in_array($currentIP, getWhitelist($whitelist))) : + + exit(http_response_code(200)); + + else : + + exit(http_response_code(401)); + + endif; + +elseif (!isset($_GET['user']) && !isset($_GET['admin']) && !isset($_GET['whitelist'])) : exit(http_response_code(401)); diff --git a/functions.php b/functions.php index 280f9e7df..fbc0ec979 100755 --- a/functions.php +++ b/functions.php @@ -2,7 +2,7 @@ // =================================== // Define Version - define('INSTALLEDVERSION', '1.38'); + define('INSTALLEDVERSION', '1.39'); // =================================== // Debugging output functions @@ -249,22 +249,28 @@ function plugin_auth_emby_both_disabled() { // ==== General Class Definitions START ==== class setLanguage { private $language = null; - private $langCode = null; - - function __construct($language = false) { - // Default - if (!$language) { - $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en"; - } - - $this->langCode = $language; - - if (file_exists("lang/{$language}.ini")) { - $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW); - } else { - $this->language = parse_ini_file("lang/en.ini", false, INI_SCANNER_RAW); + private $langCode = null; + + function __construct($language = false) { + // Default + if (!$language) { + $language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en"; + } + + if (!file_exists("lang/{$language}.ini")) { + $language = 'en'; + } + + $this->langCode = $language; + + $this->language = parse_ini_file("lang/{$language}.ini", false, INI_SCANNER_RAW); + if (file_exists("lang/{$language}.cust.ini")) { + foreach($tmp = parse_ini_file("lang/{$language}.cust.ini", false, INI_SCANNER_RAW) as $k => $v) { + $this->language[$k] = $v; + } } } + public function getLang() { return $this->langCode; @@ -344,6 +350,7 @@ function curl_get($url, $headers = array()) { // As post request curl_setopt($curlReq, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curlReq, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curlReq, CURLOPT_CONNECTTIMEOUT, 5); // Format Headers $cHeaders = array(); foreach ($headers as $k => $v) { @@ -446,43 +453,169 @@ function post_request($url, $data, $headers = array(), $referer='') { } // Format item from Emby for Carousel -function resolveEmbyItem($address, $token, $item) { +function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $moreInfo = false) { // Static Height - $height = 150; + $height = 444; // Get Item Details - $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0]; + $itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0]; switch ($itemDetails['Type']) { - case 'Episode': - $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName'].': ':'').$itemDetails['Name'].(isset($itemDetails['ParentIndexNumber']) && isset($itemDetails['IndexNumber'])?' (Season '.$itemDetails['ParentIndexNumber'].': Episode '.$itemDetails['IndexNumber'].')':''); - $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']); - $width = 100; - $image = 'carousel-image season'; - $style = ''; - break; + case 'Episode': + $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:""); + $imageId = (isset($itemDetails['SeriesId'])?$itemDetails['SeriesId']:$itemDetails['Id']); + $width = 300; + $style = ''; + $image = 'slick-image-tall'; + if(!$nowPlaying){ + $imageType = "Primary"; + $key = $itemDetails['Id'] . "-list"; + }else{ + $height = 281; + $width = 500; + $imageType = "Thumb"; + $key = $itemDetails['Id'] . "-np"; + $elapsed = $moreInfo['PlayState']['PositionTicks']; + $duration = $moreInfo['NowPlayingItem']['RunTimeTicks']; + $watched = floor(($elapsed / $duration) * 100); + //$transcoded = floor($item->TranscodeSession['progress']- $watched); + $stream = $moreInfo['PlayState']['PlayMethod']; + $user = $role == "admin" ? $moreInfo['UserName'] : ""; + $id = $moreInfo['DeviceId']; + $streamInfo = buildStream(array( + 'platform' => (string) $moreInfo['Client'], + 'device' => (string) $moreInfo['DeviceName'], + 'stream' => " ".streamType($stream), + 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"), + 'audio' => " ".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"), + )); + $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play"); + $topTitle = '
'.$title.'
'; + $bottomTitle = ''.$moreInfo['NowPlayingItem']['ProductionYear'].''; + if($showNames == "true"){ $bottomTitle .= ''.$user.''; } + } + break; case 'MusicAlbum': + case 'Audio': $title = $itemDetails['Name']; $imageId = $itemDetails['Id']; - $width = 150; - $image = 'music'; - $style = 'left: 160px !important;'; + $width = 444; + $style = ''; + $image = 'slick-image-short'; + if(!$nowPlaying){ + $imageType = "Primary"; + $key = $itemDetails['Id'] . "-list"; + }else{ + $height = 281; + $width = 500; + $imageId = $itemDetails['ParentBackdropItemId']; + $imageType = "Backdrop"; + $key = $itemDetails['ParentBackdropItemId'] . "-np"; + $elapsed = $moreInfo['PlayState']['PositionTicks']; + $duration = $moreInfo['NowPlayingItem']['RunTimeTicks']; + $watched = floor(($elapsed / $duration) * 100); + //$transcoded = floor($item->TranscodeSession['progress']- $watched); + $stream = $moreInfo['PlayState']['PlayMethod']; + $user = $role == "admin" ? $moreInfo['UserName'] : ""; + $id = $moreInfo['DeviceId']; + $streamInfo = buildStream(array( + 'platform' => (string) $moreInfo['Client'], + 'device' => (string) $moreInfo['DeviceName'], + 'stream' => " ".streamType($stream), + 'audio' => " ".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"), + )); + $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play"); + $topTitle = '
'.$itemDetails['AlbumArtist'].' - '.$itemDetails['Album'].'
'; + $bottomTitle = ''.$title.''; + if($showNames == "true"){ $bottomTitle .= ''.$user.''; } + } break; + case 'TvChannel': + $title = $itemDetails['CurrentProgram']['Name']; + $imageId = $itemDetails['Id']; + $width = 300; + $style = ''; + $image = 'slick-image-tall'; + if(!$nowPlaying){ + $imageType = "Primary"; + $key = $itemDetails['Id'] . "-list"; + }else{ + $height = 281; + $width = 500; + $imageType = "Thumb"; + $key = $itemDetails['Id'] . "-np"; + $useImage = "images/livetv.png"; + $watched = "0"; + $stream = $moreInfo['PlayState']['PlayMethod']; + $user = $role == "admin" ? $moreInfo['UserName'] : ""; + $id = $moreInfo['DeviceId']; + $streamInfo = buildStream(array( + 'platform' => (string) $moreInfo['Client'], + 'device' => (string) $moreInfo['DeviceName'], + 'stream' => " ".streamType($stream), + 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"), + 'audio' => " ".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"), + )); + $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play"); + $topTitle = '
'.$title.'
'; + $bottomTitle = ''.$itemDetails['Name'].' - '.$itemDetails['ChannelNumber'].''; + if($showNames == "true"){ $bottomTitle .= ''.$user.''; } + } + break; default: $title = $itemDetails['Name']; $imageId = $itemDetails['Id']; - $width = 100; - $image = 'carousel-image movie'; - $style = ''; + $width = 300; + $style = ''; + $image = 'slick-image-tall'; + if(!$nowPlaying){ + $imageType = "Primary"; + $key = $itemDetails['Id'] . "-list"; + }else{ + $height = 281; + $width = 500; + $imageType = "Thumb"; + $key = $itemDetails['Id'] . "-np"; + $elapsed = $moreInfo['PlayState']['PositionTicks']; + $duration = $moreInfo['NowPlayingItem']['RunTimeTicks']; + $watched = floor(($elapsed / $duration) * 100); + //$transcoded = floor($item->TranscodeSession['progress']- $watched); + $stream = $moreInfo['PlayState']['PlayMethod']; + $user = $role == "admin" ? $moreInfo['UserName'] : ""; + $id = $moreInfo['DeviceId']; + $streamInfo = buildStream(array( + 'platform' => (string) $moreInfo['Client'], + 'device' => (string) $moreInfo['DeviceName'], + 'stream' => " ".streamType($stream), + 'video' => streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "video"), + 'audio' => " ".streamType($stream)." ".embyArray($moreInfo['NowPlayingItem']['MediaStreams'], "audio"), + )); + $state = (($moreInfo['PlayState']['IsPaused'] == "1") ? "pause" : "play"); + $topTitle = '
'.$title.'
'; + $bottomTitle = ''.$moreInfo['NowPlayingItem']['ProductionYear'].''; + if($showNames == "true"){ $bottomTitle .= ''.$user.''; } + } } // If No Overview if (!isset($itemDetails['Overview'])) { $itemDetails['Overview'] = ''; } + +if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key.'.jpg'; } + if (file_exists('images/cache/'.$key.'.jpg') && (time() - 604800) > filemtime('images/cache/'.$key.'.jpg') || !file_exists('images/cache/'.$key.'.jpg')) { + $image_url = 'ajax.php?a=emby-image&type='.$imageType.'&img='.$imageId.'&height='.$height.'&width='.$width.'&key='.$key.''; + } + if(!$itemDetails['Id']){ $image_url = "images/no-np.png"; $key = "no-np"; } + if(isset($useImage)){ $image_url = $useImage; } - // Assemble Item And Cache Into Array - return '
'.$itemDetails['Name'].'
'; + // Assemble Item And Cache Into Array +if($nowPlaying){ + //prettyPrint($moreInfo); + return '
'.$itemDetails['Name'].'
'.$topTitle.''.$bottomTitle.'
'; + }else{ + return '
'.$itemDetails['Name'].''.$title.'
'; +} } // Format item from Plex for Carousel @@ -677,33 +810,6 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames } } -// Create Carousel -function outputCarousel($header, $size, $type, $items, $script = false) { - // If None Populate Empty Item - if (!count($items)) { - $items = array('
nada
'); - } - - // Set First As Active - $items[0] = preg_replace('/^
/','
', $items[0]); - - // Add Buttons - $buttons = ''; - if (count($items) > 1) { - $buttons = ' - Previous - Next'; - } - - return ' -
-
'.$header.'
-
'.($script?'':''); -} - //Recent Added function outputRecentAdded($header, $items, $script = false, $array) { $hideMenu = '