aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-01-11 16:37:02 -0600
committerGitHub <noreply@github.com>2026-01-11 16:37:02 -0600
commit358a6b1912681d656ff3ff569ddc5bf1bb6a6ef7 (patch)
treeae86b9040faf8771c13b50406392dafbe50c506a /src/slskd/Core/Options.cs
parent8849d78cbe7057dacad9c00c471691af8e367cd9 (diff)
parent0f2df52cbfe2b8afd517a598cbaf9fc55c36083c (diff)
downloadslskd-358a6b1912681d656ff3ff569ddc5bf1bb6a6ef7.tar.gz
Merge branch 'master' into paths
Diffstat (limited to 'src/slskd/Core/Options.cs')
-rw-r--r--src/slskd/Core/Options.cs112
1 files changed, 108 insertions, 4 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 76dcd45c..a1d9953c 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -115,7 +115,7 @@ namespace slskd
/// <summary>
/// Gets a value indicating whether to display a list of configuration environment variables.
/// </summary>
- [Argument('e', "envars")]
+ [Argument(default, "envars")]
[Description("display environment variables")]
[Obsolete("Used only for documentation; see Program for actual implementation")]
[JsonIgnore]
@@ -125,7 +125,7 @@ namespace slskd
/// <summary>
/// Gets a value indicating whether to generate an X509 certificate and password.
/// </summary>
- [Argument('g', "generate-cert")]
+ [Argument(default, "generate-cert")]
[Description("generate X509 certificate and password for HTTPS")]
[Obsolete("Used only for documentation; see Program for actual implementation")]
[JsonIgnore]
@@ -135,7 +135,7 @@ namespace slskd
/// <summary>
/// Gets a value indicating whether to generate a random secret.
/// </summary>
- [Argument('k', "generate-secret")]
+ [Argument(default, "generate-secret")]
[Description("generate random secret of the specified length")]
[Obsolete("Used only for documentation; see Program for actual implementation")]
[JsonIgnore]
@@ -1423,6 +1423,12 @@ namespace slskd
/// </summary>
[Range(5, maximum: int.MaxValue)]
public int? Cancelled { get; init; } = null;
+
+ /// <summary>
+ /// Gets the time to retain unsuccessful (including errored and cancelled) transfers, in minutes.
+ /// </summary>
+ [Range(5, maximum: int.MaxValue)]
+ public int? Failed { get; init; } = null;
}
}
@@ -1839,6 +1845,16 @@ namespace slskd
public int Port { get; init; } = 5030;
/// <summary>
+ /// Gets the comma separated list of IPv4 or IPv6 IP addresses on which to listen for HTTP requests.
+ /// </summary>
+ [Argument(default, "http-ip-address")]
+ [EnvironmentVariable("HTTP_IP_ADDRESS")]
+ [Description("IP addresses on which to listen for HTTP requests")]
+ [IPAddress(allowCommaSeparatedValues: true)]
+ [RequiresRestart]
+ public string IpAddress { get; init; }
+
+ /// <summary>
/// Gets the HTTP listen unix domain socket (UDS) path.
/// </summary>
[Argument(default, "http-socket")]
@@ -1893,7 +1909,7 @@ namespace slskd
/// <summary>
/// Authentication options.
/// </summary>
- public class WebAuthenticationOptions
+ public class WebAuthenticationOptions : IValidatableObject
{
/// <summary>
/// Gets a value indicating whether authentication should be disabled.
@@ -1931,11 +1947,89 @@ namespace slskd
public JwtOptions Jwt { get; init; } = new JwtOptions();
/// <summary>
+ /// Gets the primary API key. Defaults to 'Administrator' role and CIDR '0.0.0.0/0,::/0'.
+ /// role and CIDR can be supplied by prefixing the key with 'role=[role];cidr=[cidrs];[key]'.
+ /// </summary>
+ [Argument('k', "api-key")]
+ [EnvironmentVariable("API_KEY")]
+ [Description("primary API key value")]
+ [Secret]
+ [RequiresRestart]
+ public string ApiKey { get; init; }
+
+ /// <summary>
/// Gets API keys.
/// </summary>
[Validate]
public Dictionary<string, ApiKeyOptions> ApiKeys { get; init; } = new Dictionary<string, ApiKeyOptions>();
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ if (string.IsNullOrWhiteSpace(ApiKey))
+ {
+ return results;
+ }
+
+ var tuples = ApiKey.Split(';');
+
+ // if only one tuple is supplied, it's just the key, no role or list of CIDRs
+ if (tuples.Length == 1)
+ {
+ var key = tuples.FirstOrDefault();
+
+ if (key?.Length < 16 || key?.Length > 255)
+ {
+ results.Add(new ValidationResult("API key must be between 16 and 255 characters"));
+ }
+
+ return results;
+ }
+
+ /*
+ if multiple tuples are supplied, verify that:
+
+ * if a tuple starts with 'role=', it's defining a role and it must match one of the Role enum values
+ * if a tuple starts with 'cidr=', it's defining a list of CIDRs which need to be valid
+ * if a tuple doesn't start with a prefix, it's the API key itself and it must be between 16 and 255 characters
+ */
+ foreach (var tuple in tuples)
+ {
+ if (tuple.StartsWith("role=", StringComparison.OrdinalIgnoreCase))
+ {
+ var role = tuple.Split('=').LastOrDefault();
+
+ if (!Enum.TryParse(typeof(Role), value: role, ignoreCase: true, out _))
+ {
+ results.Add(new ValidationResult($"API key role must be one of: {string.Join(", ", Enum.GetNames(typeof(Role)))}"));
+ }
+ }
+ else if (tuple.StartsWith("cidr=", StringComparison.OrdinalIgnoreCase))
+ {
+ var cidrs = tuple.Split('=').LastOrDefault();
+
+ foreach (var cidr in cidrs.Split(','))
+ {
+ try
+ {
+ _ = IPAddressRange.Parse(cidr);
+ }
+ catch (Exception ex)
+ {
+ results.Add(new ValidationResult($"API key CIDR {cidr} is invalid: {ex.Message}"));
+ }
+ }
+ }
+ else if (tuple?.Length < 16 || tuple?.Length > 255)
+ {
+ results.Add(new ValidationResult("API key must be between 16 and 255 characters"));
+ }
+ }
+
+ return results;
+ }
+
/// <summary>
/// JWT options.
/// </summary>
@@ -2040,6 +2134,16 @@ namespace slskd
public int Port { get; init; } = 5031;
/// <summary>
+ /// Gets the comma separated list of IPv4 or IPv6 IP addresses on which to listen for HTTPS requests.
+ /// </summary>
+ [Argument(default, "https-ip-address")]
+ [EnvironmentVariable("HTTPS_IP_ADDRESS")]
+ [Description("IP addresses on which to listen for HTTPS requests")]
+ [IPAddress(allowCommaSeparatedValues: true)]
+ [RequiresRestart]
+ public string IpAddress { get; init; }
+
+ /// <summary>
/// Gets a value indicating whether HTTP requests should be redirected to HTTPS.
/// </summary>
[Argument('f', "force-https")]