From 9de21bedbb0e23688f1e6b68135908cffcd9d687 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 18 Feb 2021 14:32:39 -0500 Subject: [PATCH 1/3] Webpanel redirection only occurs if Api header is missing - Remove browser detection library. - Move ControlPanelController route definition into the controller from Application. --- .../Controllers/ControlPanelController.cs | 10 +++++++--- .../Controllers/HomeController.cs | 19 ++++--------------- src/Tgstation.Server.Host/Core/Application.cs | 7 +------ .../Tgstation.Server.Host.csproj | 1 - 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/ControlPanelController.cs b/src/Tgstation.Server.Host/Controllers/ControlPanelController.cs index b632f7e690..cd3f70a75f 100644 --- a/src/Tgstation.Server.Host/Controllers/ControlPanelController.cs +++ b/src/Tgstation.Server.Host/Controllers/ControlPanelController.cs @@ -9,17 +9,21 @@ using System.Globalization; using System.Net.Mime; using Tgstation.Server.Api; using Tgstation.Server.Host.Configuration; -using Tgstation.Server.Host.Core; namespace Tgstation.Server.Host.Controllers { /// /// Controller for the web control panel. /// - [Route(Application.ControlPanelRoute)] + [Route(ControlPanelRoute)] [ApiExplorerSettings(IgnoreApi = true)] public class ControlPanelController : Controller { + /// + /// Route to the . + /// + public const string ControlPanelRoute = "/app"; + /// /// The for the . /// @@ -51,7 +55,7 @@ namespace Tgstation.Server.Host.Controllers { var controlPanelChannel = controlPanelConfiguration.Channel; if (controlPanelChannel == "local") - controlPanelChannel = Application.ControlPanelRoute; + controlPanelChannel = ControlPanelRoute; controlPanelChannel = controlPanelChannel .Replace("${Major}", ApiHeaders.Version.Major.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index 3dcdc1a4d4..fe2d94152b 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -24,7 +24,6 @@ using Tgstation.Server.Host.Security; using Tgstation.Server.Host.Security.OAuth; using Tgstation.Server.Host.Swarm; using Tgstation.Server.Host.System; -using Wangkanai.Detection; namespace Tgstation.Server.Host.Controllers { @@ -79,11 +78,6 @@ namespace Tgstation.Server.Host.Controllers /// readonly IServerControl serverControl; - /// - /// The for the - /// - readonly IBrowserResolver browserResolver; - /// /// The for the . /// @@ -106,7 +100,6 @@ namespace Tgstation.Server.Host.Controllers /// The value of /// The value of . /// The value of . - /// The value of /// The value of . /// The value of . /// The containing the value of . @@ -122,7 +115,6 @@ namespace Tgstation.Server.Host.Controllers IIdentityCache identityCache, IOAuthProviders oAuthProviders, IPlatformIdentifier platformIdentifier, - IBrowserResolver browserResolver, ISwarmService swarmService, IServerControl serverControl, IOptions generalConfigurationOptions, @@ -141,7 +133,6 @@ namespace Tgstation.Server.Host.Controllers this.identityCache = identityCache ?? throw new ArgumentNullException(nameof(identityCache)); this.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier)); this.oAuthProviders = oAuthProviders ?? throw new ArgumentNullException(nameof(oAuthProviders)); - this.browserResolver = browserResolver ?? throw new ArgumentNullException(nameof(browserResolver)); this.swarmService = swarmService ?? throw new ArgumentNullException(nameof(swarmService)); this.serverControl = serverControl ?? throw new ArgumentNullException(nameof(serverControl)); generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); @@ -167,22 +158,20 @@ namespace Tgstation.Server.Host.Controllers HeaderNames.Vary, new StringValues( new[]{ - HeaderNames.UserAgent, ApiHeaders.ApiVersionHeader })); - // we only allow authorization header issues if (ApiHeaders == null) { - // if we are using a browser and the control panel, redirect to the app page - if (controlPanelConfiguration.Enable && browserResolver.Browser.Type != BrowserType.Generic) + if (controlPanelConfiguration.Enable) { - Logger.LogDebug("Unauthorized browser request (User-Agent: \"{0}\"), redirecting to control panel...", browserResolver.UserAgent); - return Redirect(Core.Application.ControlPanelRoute); + Logger.LogDebug("No API headers on request, redirecting to control panel..."); + return Redirect(ControlPanelController.ControlPanelRoute); } try { + // we only allow authorization header issues var headers = new ApiHeaders(Request.GetTypedHeaders(), true); if (!headers.Compatible()) return StatusCode( diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 927ad2ce77..ee2e32a1dd 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -55,11 +55,6 @@ namespace Tgstation.Server.Host.Core #pragma warning disable CA1506 sealed class Application : SetupApplication { - /// - /// Route to the web control panel. - /// - public const string ControlPanelRoute = "/app"; - /// /// The for the . /// @@ -471,7 +466,7 @@ namespace Tgstation.Server.Host.Core logger.LogWarning("Web control panel enabled. This is a highly WIP feature!"); applicationBuilder.UseFileServer(new FileServerOptions { - RequestPath = ControlPanelRoute, + RequestPath = ControlPanelController.ControlPanelRoute, EnableDefaultFiles = true, EnableDirectoryBrowsing = false }); diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index bd024e8cad..93b8ee44e7 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -99,7 +99,6 @@ - From a7fa8c05a039696a770f5e63754cf75adfde37ec Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 18 Feb 2021 14:33:25 -0500 Subject: [PATCH 2/3] Logging cleanup regarding web control panel status --- src/Tgstation.Server.Host/Core/Application.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index ee2e32a1dd..1c88124313 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -463,7 +463,7 @@ namespace Tgstation.Server.Host.Core // spa loading if necessary if (controlPanelConfiguration.Enable) { - logger.LogWarning("Web control panel enabled. This is a highly WIP feature!"); + logger.LogInformation("Web control panel enabled."); applicationBuilder.UseFileServer(new FileServerOptions { RequestPath = ControlPanelController.ControlPanelRoute, @@ -472,7 +472,7 @@ namespace Tgstation.Server.Host.Core }); } else - logger.LogDebug("Web control panel disabled!"); + logger.LogTrace("Web control panel disabled!"); // authenticate JWT tokens using our security pipeline if present, returns 401 if bad applicationBuilder.UseAuthentication(); From af49818a975f06863526de08ade708dd34dfcd83 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 18 Feb 2021 14:49:26 -0500 Subject: [PATCH 3/3] Fix the build --- src/Tgstation.Server.Host/Core/Application.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 1c88124313..1737b56d04 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -220,9 +220,6 @@ namespace Tgstation.Server.Host.Core services.AddSwaggerGenNewtonsoftSupport(); } - // enable browser detection - services.AddDetectionCore().AddBrowser(); - // CORS conditionally enabled later services.AddCors();