From 3f9a412b027667d2eabd3b05db2789e732a9a3ff Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 13 Apr 2013 15:40:49 -0400 Subject: [PATCH 01/10] fix user request logging --- MediaBrowser.Api/BaseApiService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 8fcef654dd..e644f1f313 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -110,9 +110,14 @@ namespace MediaBrowser.Api if (auth != null && auth.ContainsKey("UserId")) { - var user = UserManager.GetUserById(new Guid(auth["UserId"])); + var userId = auth["UserId"]; - UserManager.LogUserActivity(user, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty); + if (!string.IsNullOrEmpty(userId)) + { + var user = UserManager.GetUserById(new Guid(userId)); + + UserManager.LogUserActivity(user, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty); + } } } From 44ff7167f073c220289a864b100c5bdd46aee7f0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 13 Apr 2013 15:47:41 -0400 Subject: [PATCH 02/10] fix include/exclude item type queries --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 675ac0cd55..c907dfe9b8 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -357,6 +357,20 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{BaseItem}. internal static IEnumerable ApplyAdditionalFilters(GetItems request, IEnumerable items) { + // Exclude item types + if (!string.IsNullOrEmpty(request.ExcludeItemTypes)) + { + var vals = request.ExcludeItemTypes.Split(','); + items = items.Where(f => !vals.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase)); + } + + // Include item types + if (!string.IsNullOrEmpty(request.IncludeItemTypes)) + { + var vals = request.IncludeItemTypes.Split(','); + items = items.Where(f => vals.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase)); + } + // Filter by Series Status if (!string.IsNullOrEmpty(request.SeriesStatus)) { From dabf25777870124872f733563bf2d142a613c0ad Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 13 Apr 2013 16:20:04 -0400 Subject: [PATCH 03/10] more service stack logging --- .../HttpServer/HttpServer.cs | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs index b1402eec75..4c7dd1da6c 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs @@ -105,6 +105,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer DefaultRedirectPath = defaultRedirectpath; _logger = logger; + ServiceStack.Logging.LogManager.LogFactory = new NLogFactory(); + EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null; EndpointHostConfig.Instance.MetadataRedirectPath = "metadata"; @@ -136,58 +138,56 @@ namespace MediaBrowser.Server.Implementations.HttpServer Plugins.Add(new SwaggerFeature()); Plugins.Add(new CorsFeature()); - ServiceStack.Logging.LogManager.LogFactory = new NLogFactory(); - ResponseFilters.Add((req, res, dto) => + { + var exception = dto as Exception; + + if (exception != null) { - var exception = dto as Exception; + _logger.ErrorException("Error processing request for {0}", exception, req.RawUrl); - if (exception != null) + if (!string.IsNullOrEmpty(exception.Message)) { - _logger.ErrorException("Error processing request for {0}", exception, req.RawUrl); - - if (!string.IsNullOrEmpty(exception.Message)) - { - var error = exception.Message.Replace(Environment.NewLine, " "); - error = RemoveControlCharacters(error); + var error = exception.Message.Replace(Environment.NewLine, " "); + error = RemoveControlCharacters(error); - res.AddHeader("X-Application-Error-Code", error); - } + res.AddHeader("X-Application-Error-Code", error); } + } - if (dto is CompressedResult) - { - // Per Google PageSpeed - // This instructs the proxies to cache two versions of the resource: one compressed, and one uncompressed. - // The correct version of the resource is delivered based on the client request header. - // This is a good choice for applications that are singly homed and depend on public proxies for user locality. - res.AddHeader("Vary", "Accept-Encoding"); - } + if (dto is CompressedResult) + { + // Per Google PageSpeed + // This instructs the proxies to cache two versions of the resource: one compressed, and one uncompressed. + // The correct version of the resource is delivered based on the client request header. + // This is a good choice for applications that are singly homed and depend on public proxies for user locality. + res.AddHeader("Vary", "Accept-Encoding"); + } - var hasOptions = dto as IHasOptions; + var hasOptions = dto as IHasOptions; - if (hasOptions != null) + if (hasOptions != null) + { + // Content length has to be explicitly set on on HttpListenerResponse or it won't be happy + string contentLength; + + if (hasOptions.Options.TryGetValue("Content-Length", out contentLength) && !string.IsNullOrEmpty(contentLength)) { - // Content length has to be explicitly set on on HttpListenerResponse or it won't be happy - string contentLength; + var length = long.Parse(contentLength, UsCulture); - if (hasOptions.Options.TryGetValue("Content-Length", out contentLength) && !string.IsNullOrEmpty(contentLength)) + if (length > 0) { - var length = long.Parse(contentLength, UsCulture); - - if (length > 0) - { - var response = (HttpListenerResponse) res.OriginalResponse; + var response = (HttpListenerResponse)res.OriginalResponse; - response.ContentLength64 = length; + response.ContentLength64 = length; - // Disable chunked encoding. Technically this is only needed when using Content-Range, but - // anytime we know the content length there's no need for it - response.SendChunked = false; - } + // Disable chunked encoding. Technically this is only needed when using Content-Range, but + // anytime we know the content length there's no need for it + response.SendChunked = false; } } - }); + } + }); } /// From abed5b331bf82158d20c5ba7ddff589b58201fb6 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Sat, 13 Apr 2013 17:09:13 -0400 Subject: [PATCH 04/10] Pull in security objects from external assembly --- ...MediaBrowser.Common.Implementations.csproj | 6 +- .../Security/MBLicenseFile.cs | 106 +++++++++++++++++ .../Security/MBRegistration.cs | 109 ++++++++++++++++++ .../Security/PluginSecurityManager.cs | 2 +- 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs create mode 100644 MediaBrowser.Common.Implementations/Security/MBRegistration.cs diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj index b2872e22a8..79344bb0db 100644 --- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj +++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj @@ -35,9 +35,6 @@ Always - - ..\ThirdParty\PluginSecurity\Mediabrowser.PluginSecurity.dll - ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll @@ -79,6 +76,8 @@ + + @@ -104,7 +103,6 @@ if $(ConfigurationName) == Release ( xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i -xcopy "$(TargetDir)Mediabrowser.PluginSecurity.dll" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i )