From aad5a71c98a3a6979102851df6b9440604a2242a Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 8 Nov 2017 09:05:54 +0000 Subject: [PATCH] Finsihed adding preset themes. Added query string support for api key #1689 Added swedish lang #1691 --- src/Ombi.Api.Github/GithubApi.cs | 2 +- .../Settings/Models/CustomizationSettings.cs | 2 +- src/Ombi/ClientApp/app/app.component.ts | 4 +- .../customization.component.html | 23 +++---- .../customization/customization.component.ts | 18 +++++- src/Ombi/Controllers/SettingsController.cs | 1 + src/Ombi/Startup.cs | 42 +------------ src/Ombi/StartupExtensions.cs | 62 +++++++++++++++++++ src/Ombi/Views/Shared/_Layout.cshtml | 7 +++ src/Ombi/wwwroot/translations/ach.json | 54 ---------------- src/Ombi/wwwroot/translations/sv.json | 3 + 11 files changed, 105 insertions(+), 113 deletions(-) delete mode 100644 src/Ombi/wwwroot/translations/ach.json create mode 100644 src/Ombi/wwwroot/translations/sv.json diff --git a/src/Ombi.Api.Github/GithubApi.cs b/src/Ombi.Api.Github/GithubApi.cs index f7b3fbcbf..287908b07 100644 --- a/src/Ombi.Api.Github/GithubApi.cs +++ b/src/Ombi.Api.Github/GithubApi.cs @@ -19,7 +19,7 @@ namespace Ombi.Api.Github public async Task> GetCakeThemes() { - var request = new Request("repos/leram84/layer.Cake/contents/ombi/themes", BaseUrl, HttpMethod.Get); + var request = new Request("repos/tidusjar/layer.Cake/contents/ombi/themes", BaseUrl, HttpMethod.Get); request.AddHeader("Accept", "application/vnd.github.v3+json"); request.AddHeader("User-Agent", "Ombi"); return await _api.Request>(request); diff --git a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs index efcc2ebdb..f367188a6 100644 --- a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs +++ b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs @@ -16,7 +16,7 @@ namespace Ombi.Settings.Settings.Models public string PresetThemeContent { get; set; } [NotMapped] - public string PresetThemeVersionVersion + public string PresetThemeVersion { get { diff --git a/src/Ombi/ClientApp/app/app.component.ts b/src/Ombi/ClientApp/app/app.component.ts index 28435041b..4229ac7de 100644 --- a/src/Ombi/ClientApp/app/app.component.ts +++ b/src/Ombi/ClientApp/app/app.component.ts @@ -26,13 +26,13 @@ export class AppComponent implements OnInit { private readonly settingsService: SettingsService, private readonly jobService: JobService, public readonly translate: TranslateService) { - this.translate.addLangs(["en", "de", "fr","da","es","it","nl"]); + this.translate.addLangs(["en", "de", "fr","da","es","it","nl","sv"]); // this language will be used as a fallback when a translation isn't found in the current language this.translate.setDefaultLang("en"); // See if we can match the supported langs with the current browser lang const browserLang: string = translate.getBrowserLang(); - this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl/) ? browserLang : "en"); + this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl|sv/) ? browserLang : "en"); } public ngOnInit() { diff --git a/src/Ombi/ClientApp/app/settings/customization/customization.component.html b/src/Ombi/ClientApp/app/settings/customization/customization.component.html index b996f1296..5c89cd9c0 100644 --- a/src/Ombi/ClientApp/app/settings/customization/customization.component.html +++ b/src/Ombi/ClientApp/app/settings/customization/customization.component.html @@ -3,7 +3,7 @@
Customization -
+
@@ -27,6 +27,12 @@ tooltipPosition="top" pTooltip="Use a URL e.g. www.google.com/logo.png">
+
+ +
+ +
+
@@ -46,7 +52,7 @@
- +
+ -
- -
- -
-
\ No newline at end of file diff --git a/src/Ombi/ClientApp/app/settings/customization/customization.component.ts b/src/Ombi/ClientApp/app/settings/customization/customization.component.ts index 34777d950..46b76f549 100644 --- a/src/Ombi/ClientApp/app/settings/customization/customization.component.ts +++ b/src/Ombi/ClientApp/app/settings/customization/customization.component.ts @@ -19,6 +19,18 @@ export class CustomizationComponent implements OnInit { this.settings = x; this.settingsService.getThemes().subscribe(t => { this.themes = t; + + const existingTheme = this.themes.filter((item) => { + return item.fullName === this.settings.presetThemeName; + })[0]; + + if(existingTheme) { + const index = this.themes.indexOf(existingTheme, 0); + if (index > -1) { + this.themes.splice(index, 1); + } + } + if(x.hasPresetTheme) { this.themes.unshift({displayName: x.presetThemeDisplayName, fullName: x.presetThemeName, url: "", version: x.presetThemeVersion}); } else { @@ -45,9 +57,9 @@ export class CustomizationComponent implements OnInit { return val.fullName === selectedThemeFullName; }); - // if(selectedTheme[0].fullName === this.settings.presetThemeName) { - // return; - // } + if(selectedTheme[0].fullName === this.settings.presetThemeName) { + return; + } this.settings.presetThemeName = selectedThemeFullName; this.settingsService.getThemeContent(selectedTheme[0].url).subscribe(x => { diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index ea76864eb..bf315e88d 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -259,6 +259,7 @@ namespace Ombi.Controllers /// /// [HttpGet("themecontent")] + [AllowAnonymous] public async Task GetThemeContent([FromQuery]string url) { var content = await _githubApi.GetThemesRawContent(url); diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 2d1451433..08b3822ec 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -194,7 +194,7 @@ namespace Ombi app.UseAuthentication(); - ApiKeyMiddlewear(app, serviceProvider); + app.ApiKeyMiddlewear(serviceProvider); app.UseSwagger(); app.UseSwaggerUI(c => { @@ -213,46 +213,6 @@ namespace Ombi defaults: new { controller = "Home", action = "Index" }); }); } - - private static void ApiKeyMiddlewear(IApplicationBuilder app, IServiceProvider serviceProvider) - { - app.Use(async (context, next) => - { - if (context.Request.Path.StartsWithSegments(new PathString("/api"))) - { - // Let's check if this is an API Call - if (context.Request.Headers["ApiKey"].Any()) - { - // validate the supplied API key - // Validate it - var headerKey = context.Request.Headers["ApiKey"].FirstOrDefault(); - var settingsProvider = serviceProvider.GetService>(); - var ombiSettings = settingsProvider.GetSettings(); - var valid = ombiSettings.ApiKey.Equals(headerKey, StringComparison.CurrentCultureIgnoreCase); - if (!valid) - { - context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; - await context.Response.WriteAsync("Invalid API Key"); - } - else - { - var identity = new GenericIdentity("API"); - var principal = new GenericPrincipal(identity, new[] { "Admin", "ApiUser" }); - context.User = principal; - await next(); - } - } - else - { - await next(); - } - } - else - { - await next(); - } - }); - } } public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter diff --git a/src/Ombi/StartupExtensions.cs b/src/Ombi/StartupExtensions.cs index 97611d627..ee6301a9a 100644 --- a/src/Ombi/StartupExtensions.cs +++ b/src/Ombi/StartupExtensions.cs @@ -1,14 +1,23 @@ using System; using System.IO; +using System.Linq; +using System.Net; +using System.Security.Principal; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.Extensions.Primitives; using Microsoft.IdentityModel.Tokens; using Ombi.Config; +using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Models.Identity; +using Ombi.Settings.Settings.Models; using Swashbuckle.AspNetCore.Swagger; namespace Ombi @@ -103,5 +112,58 @@ namespace Ombi x.TokenValidationParameters = tokenValidationParameters; }); } + + + public static void ApiKeyMiddlewear(this IApplicationBuilder app, IServiceProvider serviceProvider) + { + app.Use(async (context, next) => + { + if (context.Request.Path.StartsWithSegments(new PathString("/api"))) + { + // Let's check if this is an API Call + if (context.Request.Headers["ApiKey"].Any()) + { + // validate the supplied API key + // Validate it + var headerKey = context.Request.Headers["ApiKey"].FirstOrDefault(); + await ValidateApiKey(serviceProvider, context, next, headerKey); + } + else if (context.Request.Query.ContainsKey("apikey")) + { + if (context.Request.Query.TryGetValue("apikey", out var queryKey)) + { + await ValidateApiKey(serviceProvider, context, next, queryKey); + } + } + else + { + await next(); + } + } + else + { + await next(); + } + }); + } + + private static async Task ValidateApiKey(IServiceProvider serviceProvider, HttpContext context, Func next, string key) + { + var settingsProvider = serviceProvider.GetService>(); + var ombiSettings = settingsProvider.GetSettings(); + var valid = ombiSettings.ApiKey.Equals(key, StringComparison.CurrentCultureIgnoreCase); + if (!valid) + { + context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; + await context.Response.WriteAsync("Invalid API Key"); + } + else + { + var identity = new GenericIdentity("API"); + var principal = new GenericPrincipal(identity, new[] { "Admin", "ApiUser" }); + context.User = principal; + await next(); + } + } } } \ No newline at end of file diff --git a/src/Ombi/Views/Shared/_Layout.cshtml b/src/Ombi/Views/Shared/_Layout.cshtml index db244d6d5..847a41f73 100644 --- a/src/Ombi/Views/Shared/_Layout.cshtml +++ b/src/Ombi/Views/Shared/_Layout.cshtml @@ -56,6 +56,13 @@ @{ + if (customization.HasPresetTheme) + { + + } + if (!string.IsNullOrEmpty(customization.CustomCssLink)) { diff --git a/src/Ombi/wwwroot/translations/ach.json b/src/Ombi/wwwroot/translations/ach.json deleted file mode 100644 index 4d9e90a3e..000000000 --- a/src/Ombi/wwwroot/translations/ach.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "Login": { - "SignInButton": "crwdns37:0crwdne37:0", - "UsernamePlaceholder": "crwdns38:0crwdne38:0", - "PasswordPlaceholder": "crwdns39:0crwdne39:0", - "RememberMe": "crwdns40:0crwdne40:0", - "ForgottenPassword": "crwdns41:0crwdne41:0", - "Errors": { - "IncorrectCredentials": "crwdns71:0crwdne71:0" - } - }, - "Common": { - "ContinueButton": "crwdns42:0crwdne42:0", - "Errors": { - "Validation": "crwdns72:0crwdne72:0" - } - }, - "PasswordReset": { - "EmailAddressPlaceholder": "crwdns43:0crwdne43:0", - "ResetPasswordButton": "crwdns44:0crwdne44:0" - }, - "LandingPage": { - "OnlineHeading": "crwdns45:0crwdne45:0", - "OnlineParagraph": "crwdns46:0crwdne46:0", - "PartiallyOnlineHeading": "crwdns47:0crwdne47:0", - "PartiallyOnlineParagraph": "crwdns48:0crwdne48:0", - "MultipleServersUnavailable": "crwdns49:0{{serversUnavailable}}crwdnd49:0{{totalServers}}crwdne49:0", - "SingleServerUnavailable": "crwdns50:0{{serversUnavailable}}crwdnd50:0{{totalServers}}crwdne50:0", - "OfflineHeading": "crwdns51:0crwdne51:0", - "OfflineParagraph": "crwdns52:0crwdne52:0", - "CheckPageForUpdates": "crwdns73:0crwdne73:0" - }, - "NavigationBar": { - "Search": "crwdns54:0crwdne54:0", - "Requests": "crwdns55:0crwdne55:0", - "UserManagement": "crwdns56:0crwdne56:0", - "Donate": "crwdns57:0crwdne57:0", - "DonateTooltip": "crwdns58:0crwdne58:0", - "UpdateAvailableTooltip": "crwdns59:0crwdne59:0", - "Settings": "crwdns60:0crwdne60:0", - "Welcome": "crwdns61:0{{username}}crwdne61:0", - "UpdateDetails": "crwdns62:0crwdne62:0", - "Logout": "crwdns63:0crwdne63:0", - "Language": { - "English": "crwdns64:0crwdne64:0", - "French": "crwdns65:0crwdne65:0", - "Spanish": "crwdns66:0crwdne66:0", - "German": "crwdns67:0crwdne67:0", - "Italian": "crwdns68:0crwdne68:0", - "Danish": "crwdns69:0crwdne69:0", - "Dutch": "crwdns70:0crwdne70:0" - } - } -} \ No newline at end of file diff --git a/src/Ombi/wwwroot/translations/sv.json b/src/Ombi/wwwroot/translations/sv.json new file mode 100644 index 000000000..0db3279e4 --- /dev/null +++ b/src/Ombi/wwwroot/translations/sv.json @@ -0,0 +1,3 @@ +{ + +}