From 2353497de417021aafec760a89348245f3237f74 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 14 Mar 2016 16:27:35 -0400 Subject: [PATCH 1/8] update shared components --- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index fb52b58b75..8b14ceccbe 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -140,6 +140,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest From 9bd02a6d178a41f2058c9cbde2ab54a60c17b56c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Mar 2016 01:26:04 -0400 Subject: [PATCH 2/8] add home --- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 8b14ceccbe..4d167c4375 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -146,6 +146,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest From 2b3fcaa01e01a9c4574bd3c9d67bc102c1713bc0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Mar 2016 15:11:53 -0400 Subject: [PATCH 3/8] remove tokens from log --- .../HttpServer/HttpListenerHost.cs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index c284007f7c..93bfcbbab3 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -288,6 +288,36 @@ namespace MediaBrowser.Server.Implementations.HttpServer return Path.GetExtension(parts[0]); } + public static string RemoveQueryStringByKey(string url, string key) + { + var uri = new Uri(url); + + // this gets all the query string key value pairs as a collection + var newQueryString = MyHttpUtility.ParseQueryString(uri.Query); + + if (newQueryString.Count == 0) + { + return url; + } + + // this removes the key if exists + newQueryString.Remove(key); + + // this gets the page path from root without QueryString + string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); + + return newQueryString.Count > 0 + ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) + : pagePathWithoutQueryString; + } + + private string GetUrlToLog(string url) + { + url = RemoveQueryStringByKey(url, "api_key"); + + return url; + } + /// /// Overridable method that can be used to implement a custom hnandler /// @@ -305,10 +335,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer var urlString = url.OriginalString; var enableLog = EnableLogging(urlString, localPath); + var urlToLog = urlString; if (enableLog) { - LoggerUtils.LogRequest(_logger, urlString, httpReq.HttpMethod, httpReq.UserAgent); + urlToLog = GetUrlToLog(urlString); + LoggerUtils.LogRequest(_logger, urlToLog, httpReq.HttpMethod, httpReq.UserAgent); } if (string.Equals(localPath, "/mediabrowser/", StringComparison.OrdinalIgnoreCase) || @@ -390,7 +422,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (enableLog) { - LoggerUtils.LogResponse(_logger, statusCode, urlString, remoteIp, duration); + LoggerUtils.LogResponse(_logger, statusCode, urlToLog, remoteIp, duration); } }, TaskContinuationOptions.None); From b6665e3b4dbebed37d602aeac157a4443201233b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Mar 2016 15:12:10 -0400 Subject: [PATCH 4/8] add api key to subtitle url --- MediaBrowser.Model/Dlna/StreamInfo.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 69733cefbc..700b6ef7df 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -345,6 +345,11 @@ namespace MediaBrowser.Model.Dlna StringHelper.ToStringCultureInvariant(startPositionTicks), subtitleProfile.Format); + if (!string.IsNullOrWhiteSpace(accessToken)) + { + info.Url += "?api_key=" + accessToken; + } + info.IsExternalUrl = false; } else From e321d3c544405994b08b48421eaf80c27e10f6ab Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Mar 2016 00:14:38 -0400 Subject: [PATCH 5/8] add error checking --- .../LiveTv/EmbyTV/EmbyTV.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index e00a68e32b..463e91fd4c 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -498,7 +498,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV private bool IsListingProviderEnabledForTuner(ListingsProviderInfo info, string tunerHostId) { - return info.EnableAllTuners || info.EnabledTuners.Contains(tunerHostId ?? string.Empty, StringComparer.OrdinalIgnoreCase); + if (info.EnableAllTuners) + { + return true; + } + + if (string.IsNullOrWhiteSpace(tunerHostId)) + { + throw new ArgumentNullException("tunerHostId"); + } + + return info.EnabledTuners.Contains(tunerHostId, StringComparer.OrdinalIgnoreCase); } private async Task> GetProgramsAsyncInternal(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) From dafbd48f46f7ef96a6ba06563da391e0a7e6b5ff Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Mar 2016 01:33:31 -0400 Subject: [PATCH 6/8] enable unified routing --- MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs | 2 +- MediaBrowser.WebDashboard/Api/PackageCreator.cs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs b/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs index a4504f25a6..3915e91538 100644 --- a/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs +++ b/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs @@ -49,7 +49,7 @@ namespace MediaBrowser.Server.Startup.Common.Browser /// The logger. public static void OpenDashboard(IServerApplicationHost appHost, ILogger logger) { - OpenDashboardPage("dashboard.html", appHost, logger); + OpenDashboardPage("index.html#!/dashboard.html", appHost, logger); } /// diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 982edb5f72..3192545116 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -294,9 +294,6 @@ namespace MediaBrowser.WebDashboard.Api _logger.ErrorException("Error minifying html", ex); } } - - html = html.Replace("", "
"); } html = html.Replace("", "" + GetMetaTags(mode) + GetCommonCss(mode, appVersion)); From 67642b6f579c2de7acd6f1ab5c78ed80f53b0c8e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Mar 2016 12:53:53 -0400 Subject: [PATCH 7/8] fix 3.5 build error --- MediaBrowser.Model/Dlna/StreamInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 700b6ef7df..9118efb35c 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -345,7 +345,7 @@ namespace MediaBrowser.Model.Dlna StringHelper.ToStringCultureInvariant(startPositionTicks), subtitleProfile.Format); - if (!string.IsNullOrWhiteSpace(accessToken)) + if (!string.IsNullOrEmpty(accessToken)) { info.Url += "?api_key=" + accessToken; } From fee7cbdc4adc99dc256e2c46a89931c14cdf0f43 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Mar 2016 14:09:58 -0400 Subject: [PATCH 8/8] update components --- .../Browser/BrowserLauncher.cs | 2 +- .../Api/DashboardService.cs | 2 +- .../Api/PackageCreator.cs | 21 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs b/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs index 3915e91538..a4504f25a6 100644 --- a/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs +++ b/MediaBrowser.Server.Startup.Common/Browser/BrowserLauncher.cs @@ -49,7 +49,7 @@ namespace MediaBrowser.Server.Startup.Common.Browser /// The logger. public static void OpenDashboard(IServerApplicationHost appHost, ILogger logger) { - OpenDashboardPage("index.html#!/dashboard.html", appHost, logger); + OpenDashboardPage("dashboard.html", appHost, logger); } /// diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 128060bb82..a5bfebea98 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -142,7 +142,7 @@ namespace MediaBrowser.WebDashboard.Api { var page = ServerEntryPoint.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); - return ResultFactory.GetStaticResult(Request, page.Plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml(page.GetHtmlStream(), null, _appHost.ApplicationVersion.ToString(), null, false)); + return ResultFactory.GetStaticResult(Request, page.Plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml(null, page.GetHtmlStream(), null, _appHost.ApplicationVersion.ToString(), null, false)); } /// diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 3192545116..55f6ca7a43 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.WebDashboard.Api { if (IsCoreHtml(path)) { - resourceStream = await ModifyHtml(resourceStream, mode, appVersion, localizationCulture, enableMinification).ConfigureAwait(false); + resourceStream = await ModifyHtml(path, resourceStream, mode, appVersion, localizationCulture, enableMinification).ConfigureAwait(false); } } else if (IsFormat(path, "js")) @@ -238,13 +238,14 @@ namespace MediaBrowser.WebDashboard.Api /// /// Modifies the HTML by adding common meta tags, css and js. /// + /// The path. /// The source stream. /// The mode. /// The application version. /// The localization culture. /// if set to true [enable minification]. /// Task{Stream}. - public async Task ModifyHtml(Stream sourceStream, string mode, string appVersion, string localizationCulture, bool enableMinification) + public async Task ModifyHtml(string path, Stream sourceStream, string mode, string appVersion, string localizationCulture, bool enableMinification) { using (sourceStream) { @@ -260,6 +261,12 @@ namespace MediaBrowser.WebDashboard.Api { html = ModifyForCordova(html); } + else if (!string.IsNullOrWhiteSpace(path) && !string.Equals(path, "index.html", StringComparison.OrdinalIgnoreCase) && html.IndexOf("", "
" + html + "
"); + } if (!string.IsNullOrWhiteSpace(localizationCulture)) { @@ -306,6 +313,16 @@ namespace MediaBrowser.WebDashboard.Api } } + public string ReplaceFirst(string text, string search, string replace) + { + int pos = text.IndexOf(search, StringComparison.OrdinalIgnoreCase); + if (pos < 0) + { + return text; + } + return text.Substring(0, pos) + replace + text.Substring(pos + search.Length); + } + private string ModifyForCordova(string html) { // Replace CORDOVA_REPLACE_SUPPORTER_SUBMIT_START