From f92aded4f09713a543d2d95c8018530f52ab07cc Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 27 Mar 2014 23:13:31 +0100 Subject: [PATCH 1/6] Revised Authentication logic for api and logfiles. --- .../EnableStatelessAuthInNancy.cs | 19 +++---------------- .../Extensions/RequestExtensions.cs | 8 +------- src/NzbDrone.Api/Logs/LogFileModule.cs | 18 ++++++++++++++++++ src/UI/System/Logs/Files/ContentsModel.js | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/NzbDrone.Api/Authentication/EnableStatelessAuthInNancy.cs b/src/NzbDrone.Api/Authentication/EnableStatelessAuthInNancy.cs index 8996690bd..1bcb8685e 100644 --- a/src/NzbDrone.Api/Authentication/EnableStatelessAuthInNancy.cs +++ b/src/NzbDrone.Api/Authentication/EnableStatelessAuthInNancy.cs @@ -12,12 +12,10 @@ namespace NzbDrone.Api.Authentication { public class EnableStatelessAuthInNancy : IRegisterNancyPipeline { - private readonly IAuthenticationService _authenticationService; private static String API_KEY; - public EnableStatelessAuthInNancy(IAuthenticationService authenticationService, IConfigFileProvider configFileProvider) + public EnableStatelessAuthInNancy(IConfigFileProvider configFileProvider) { - _authenticationService = authenticationService; API_KEY = configFileProvider.ApiKey; } @@ -29,17 +27,12 @@ namespace NzbDrone.Api.Authentication public Response ValidateApiKey(NancyContext context) { Response response = null; - - if (!RuntimeInfo.IsProduction && context.Request.IsLocalRequest()) - { - return response; - } var authorizationHeader = context.Request.Headers.Authorization; var apiKeyHeader = context.Request.Headers["X-Api-Key"].FirstOrDefault(); var apiKey = apiKeyHeader.IsNullOrWhiteSpace() ? authorizationHeader : apiKeyHeader; - if (context.Request.IsApiRequest() && !ValidApiKey(apiKey) && !IsAuthenticated(context)) + if (context.Request.IsApiRequest() && !ValidApiKey(apiKey)) { response = new Response { StatusCode = HttpStatusCode.Unauthorized }; } @@ -49,15 +42,9 @@ namespace NzbDrone.Api.Authentication private bool ValidApiKey(string apiKey) { - if (apiKey.IsNullOrWhiteSpace()) return false; - if (!apiKey.Equals(API_KEY)) return false; + if (!API_KEY.Equals(apiKey)) return false; return true; } - - private bool IsAuthenticated(NancyContext context) - { - return _authenticationService.Enabled && _authenticationService.IsAuthenticated(context); - } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/Extensions/RequestExtensions.cs b/src/NzbDrone.Api/Extensions/RequestExtensions.cs index 672cdb7d5..02686deb6 100644 --- a/src/NzbDrone.Api/Extensions/RequestExtensions.cs +++ b/src/NzbDrone.Api/Extensions/RequestExtensions.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Api.Extensions { public static bool IsApiRequest(this Request request) { - return request.Path.StartsWith("/api/", StringComparison.InvariantCultureIgnoreCase) || request.IsLogFileRequest(); + return request.Path.StartsWith("/api/", StringComparison.InvariantCultureIgnoreCase); } public static bool IsSignalRRequest(this Request request) @@ -21,11 +21,5 @@ namespace NzbDrone.Api.Extensions request.UserHostAddress.Equals("127.0.0.1") || request.UserHostAddress.Equals("::1")); } - - private static bool IsLogFileRequest(this Request request) - { - return request.Path.StartsWith("/log/", StringComparison.InvariantCultureIgnoreCase) && - request.Path.EndsWith(".txt", StringComparison.InvariantCultureIgnoreCase); - } } } diff --git a/src/NzbDrone.Api/Logs/LogFileModule.cs b/src/NzbDrone.Api/Logs/LogFileModule.cs index 94153428a..b44e77b6d 100644 --- a/src/NzbDrone.Api/Logs/LogFileModule.cs +++ b/src/NzbDrone.Api/Logs/LogFileModule.cs @@ -4,11 +4,15 @@ using System.Linq; using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; +using Nancy; +using Nancy.Responses; namespace NzbDrone.Api.Logs { public class LogFileModule : NzbDroneRestModule { + private const string LOGFILE_ROUTE = @"/(?nzbdrone(?:\.\d+)?\.txt)"; + private readonly IAppFolderInfo _appFolderInfo; private readonly IDiskProvider _diskProvider; @@ -19,6 +23,8 @@ namespace NzbDrone.Api.Logs _appFolderInfo = appFolderInfo; _diskProvider = diskProvider; GetResourceAll = GetLogFiles; + + Get[LOGFILE_ROUTE] = options => GetLogFile(options.filename); } private List GetLogFiles() @@ -41,5 +47,17 @@ namespace NzbDrone.Api.Logs return result.OrderByDescending(l => l.LastWriteTime).ToList(); } + + private Response GetLogFile(string filename) + { + var filePath = Path.Combine(_appFolderInfo.GetLogFolder(), filename); + + if (!_diskProvider.FileExists(filePath)) + return new NotFoundResponse(); + + var data = _diskProvider.ReadAllText(filePath); + + return new TextResponse(data); + } } } \ No newline at end of file diff --git a/src/UI/System/Logs/Files/ContentsModel.js b/src/UI/System/Logs/Files/ContentsModel.js index b8d2bdc73..d109013dc 100644 --- a/src/UI/System/Logs/Files/ContentsModel.js +++ b/src/UI/System/Logs/Files/ContentsModel.js @@ -6,7 +6,7 @@ define( ], function (Backbone, StatusModel) { return Backbone.Model.extend({ url: function () { - return StatusModel.get('urlBase') + '/logfile/' + this.get('filename'); + return StatusModel.get('urlBase') + '/api/log/file/' + this.get('filename'); }, parse: function (contents) { From cfc29f4424742ba4ed755d0c5c8cf03a28dafdbf Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 27 Mar 2014 23:13:24 +0100 Subject: [PATCH 2/6] Fixed typo in delete episode. --- src/UI/Cells/DeleteEpisodeFileCell.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UI/Cells/DeleteEpisodeFileCell.js b/src/UI/Cells/DeleteEpisodeFileCell.js index ac754c002..8e88f9c6e 100644 --- a/src/UI/Cells/DeleteEpisodeFileCell.js +++ b/src/UI/Cells/DeleteEpisodeFileCell.js @@ -22,7 +22,7 @@ define( _onClick: function () { var self = this; - if (window.confirm('Are you sure you want to delete \'{0}\' form disk?'.format(this.model.get('path')))) { + if (window.confirm('Are you sure you want to delete \'{0}\' from disk?'.format(this.model.get('path')))) { this.model.destroy() .done(function () { vent.trigger(vent.Events.EpisodeFileDeleted, { episodeFile: self.model }); From 118089c272aae01805ebafbf46ff8facf64e8c94 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 27 Mar 2014 23:13:37 +0100 Subject: [PATCH 3/6] Process start logged as Debug instead of Info. --- src/NzbDrone.Common/Processes/ProcessProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Common/Processes/ProcessProvider.cs b/src/NzbDrone.Common/Processes/ProcessProvider.cs index f0ac02148..7581a4b5c 100644 --- a/src/NzbDrone.Common/Processes/ProcessProvider.cs +++ b/src/NzbDrone.Common/Processes/ProcessProvider.cs @@ -116,7 +116,7 @@ namespace NzbDrone.Common.Processes }; - logger.Info("Starting {0} {1}", path, args); + logger.Debug("Starting {0} {1}", path, args); var process = new Process { @@ -163,7 +163,7 @@ namespace NzbDrone.Common.Processes path = "mono"; } - Logger.Info("Starting {0} {1}", path, args); + Logger.Debug("Starting {0} {1}", path, args); var startInfo = new ProcessStartInfo(path, args); var process = new Process From fe02467a7167132ef7b1fe1322e847397f85b766 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 27 Mar 2014 23:13:45 +0100 Subject: [PATCH 4/6] Exceptron now uses 'en' culture if none is specified. --- src/Exceptron.Client/ExceptronClient.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Exceptron.Client/ExceptronClient.cs b/src/Exceptron.Client/ExceptronClient.cs index 149a739d7..89ac5170f 100644 --- a/src/Exceptron.Client/ExceptronClient.cs +++ b/src/Exceptron.Client/ExceptronClient.cs @@ -184,6 +184,9 @@ namespace Exceptron.Client { report.cul = Thread.CurrentThread.CurrentCulture.Name; + if (string.IsNullOrEmpty(report.cul)) + report.cul = "en"; + try { report.os = Environment.OSVersion.VersionString; From 73c3cca69c0a643dc50a23da180ea6b343179578 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 15 Feb 2014 11:56:28 +0100 Subject: [PATCH 5/6] Revised History Details labels. --- .../Details/HistoryDetailsViewTemplate.html | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/UI/History/Details/HistoryDetailsViewTemplate.html b/src/UI/History/Details/HistoryDetailsViewTemplate.html index 9c313a9ae..3df76c8e5 100644 --- a/src/UI/History/Details/HistoryDetailsViewTemplate.html +++ b/src/UI/History/Details/HistoryDetailsViewTemplate.html @@ -13,22 +13,22 @@ {{#if_eq eventType compare="grabbed"}}
-
Name
+
Name:
{{sourceTitle}}
{{#with data}} {{#if indexer}} -
Indexer
+
Indexer:
{{indexer}}
{{/if}} {{#if releaseGroup}} -
Release Group
+
Release Group:
{{releaseGroup}}
{{/if}} {{#if nzbInfoUrl}} -
Info
+
Info:
{{nzbInfoUrl}}
{{/if}} {{/with}} @@ -36,19 +36,25 @@ {{/if_eq}} {{#if_eq eventType compare="downloadFailed"}}
-
Source Title
+ +
Name:
{{sourceTitle}}
{{#with data}} -
Message
+
Message:
{{message}}
{{/with}}
{{/if_eq}} {{#if_eq eventType compare="downloadFolderImported"}} - {{#if data}} +
+ + {{#if sourceTitle}} +
Name:
+
{{sourceTitle}}
+ {{/if}} + {{#with data}} -
{{#if droppedPath}}
Source:
{{droppedPath}}
@@ -58,11 +64,8 @@
Imported To:
{{importedPath}}
{{/if}} -
{{/with}} - {{else}} - No details available - {{/if}} +
{{/if_eq}}