From d2dd0c85b8966bf20b8bfbf896c460db794c461c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 18 Dec 2024 15:57:02 -0600 Subject: add headless option --- src/slskd/Core/Options.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 32188aef..ff9cc407 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -151,6 +151,15 @@ namespace slskd [RequiresRestart] public bool Debug { get; init; } = Debugger.IsAttached; + /// + /// Gets a value indicating whether the application should run in headless (no web UI) mode. + /// + [Argument('H', "headless")] + [EnvironmentVariable("HEADLESS")] + [Description("run in headless (no web UI) mode")] + [RequiresRestart] + public bool Headless { get; init; } = false; + /// /// Gets a value indicating whether remote configuration of options is allowed. /// -- cgit v1.2.3 From 30a3e14536685cea1cfafed29aba0a217ce86f03 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 18 Dec 2024 15:57:54 -0600 Subject: forbid login when running headless --- src/slskd/Core/API/Controllers/SessionController.cs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/API/Controllers/SessionController.cs b/src/slskd/Core/API/Controllers/SessionController.cs index ffd1bdb6..861fd468 100644 --- a/src/slskd/Core/API/Controllers/SessionController.cs +++ b/src/slskd/Core/API/Controllers/SessionController.cs @@ -22,6 +22,7 @@ namespace slskd.Core.API using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; + using Serilog; using slskd.Authentication; /// @@ -47,6 +48,7 @@ namespace slskd.Core.API private IOptionsSnapshot OptionsSnapshot { get; set; } private OptionsAtStartup OptionsAtStartup { get; set; } private ISecurityService Security { get; } + private ILogger Log { get; } = Serilog.Log.ForContext(); /// /// Checks whether the provided authentication is valid. @@ -96,6 +98,12 @@ namespace slskd.Core.API [ProducesResponseType(typeof(string), 500)] public IActionResult Login([FromBody] LoginRequest login) { + if (OptionsAtStartup.Headless) + { + Log.Warning("Login from {User} rejected; web UI is DISABLED when running in headless mode", login.Username); + return Forbid(); + } + if (login == default) { return BadRequest(); -- cgit v1.2.3