diff options
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 1c0a6852..16e549c2 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -131,7 +131,7 @@ namespace slskd /// <summary> /// Gets the semantic application version. /// </summary> - public static string SemanticVersion { get; } = InformationalVersion.Split('-').First(); + public static string SemanticVersion { get; } = InformationalVersion.Split('+').First(); /// <summary> /// Gets the full application version, including both assembly and informational versions. @@ -265,6 +265,36 @@ namespace slskd return; } + var reqInitialOwnership = false; + + using (var mutex = new Mutex(reqInitialOwnership, AppName)) + { + var hasHandle = false; + + try + { + try + { + if (!mutex.WaitOne(0, false)) + { + Console.WriteLine("Another instance of this program is running"); + Environment.Exit(0); + } + } + catch (AbandonedMutexException) + { + hasHandle = true; + } + } + finally + { + if (hasHandle) + { + mutex.ReleaseMutex(); + } + } + } + if (GenerateCertificate) { GenerateX509Certificate(password: Cryptography.Random.GetBytes(16).ToBase62(), filename: $"{AppName}.pfx"); @@ -591,6 +621,22 @@ namespace slskd if (!OptionsAtStartup.Web.Authentication.Disabled) { + services.AddAuthorization(options => + { + options.AddPolicy(AuthPolicy.JwtOnly, policy => + { + policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + + options.AddPolicy(AuthPolicy.Any, policy => + { + policy.AuthenticationSchemes.Add(ApiKeyAuthentication.AuthenticationScheme); + policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + }); + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { @@ -622,9 +668,7 @@ namespace slskd return Task.CompletedTask; }, }; - }); - - services.AddAuthentication(ApiKeyAuthentication.AuthenticationScheme) + }) .AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthentication.AuthenticationScheme, options => { options.EnableSignalRSupport = true; @@ -636,6 +680,21 @@ namespace slskd { Log.Warning("Authentication of web requests is DISABLED"); + services.AddAuthorization(options => + { + options.AddPolicy(AuthPolicy.Any, policy => + { + policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + + options.AddPolicy(AuthPolicy.JwtOnly, policy => + { + policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme); + policy.RequireAuthenticatedUser(); + }); + }); + services.AddAuthentication(PassthroughAuthentication.AuthenticationScheme) .AddScheme<PassthroughAuthenticationOptions, PassthroughAuthenticationHandler>(PassthroughAuthentication.AuthenticationScheme, options => { @@ -725,7 +784,7 @@ namespace slskd // serve static content from the configured path FileServerOptions fileServerOptions = default; - var contentPath = Path.GetFullPath(OptionsAtStartup.Web.ContentPath); + var contentPath = Path.Combine(AppContext.BaseDirectory, OptionsAtStartup.Web.ContentPath); fileServerOptions = new FileServerOptions { |
