diff options
Diffstat (limited to 'src/slskd/Core/Options.cs')
| -rw-r--r-- | src/slskd/Core/Options.cs | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index cfe78eb1..81dc09f6 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -24,6 +24,7 @@ namespace slskd using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Diagnostics; + using System.IO; using System.Linq; using System.Text.Json.Serialization; using System.Text.RegularExpressions; @@ -234,6 +235,12 @@ namespace slskd public GroupsOptions Groups { get; init; } = new GroupsOptions(); /// <summary> + /// Gets blacklist options. + /// </summary> + [Validate] + public BlacklistOptions Blacklist { get; init; } = new BlacklistOptions(); + + /// <summary> /// Gets filter options. /// </summary> [Validate] @@ -1099,6 +1106,61 @@ namespace slskd } /// <summary> + /// Blacklist options. + /// </summary> + public class BlacklistOptions : IValidatableObject + { + /// <summary> + /// Gets a value indicating whether blacklist file support should be enabled. + /// </summary> + [Argument(default, "enable-blacklist")] + [EnvironmentVariable("BLACKLIST")] + [Description("enable blacklist file support")] + [RequiresRestart] + public bool Enabled { get; init; } + + /// <summary> + /// Gets the path to the blacklist file. + /// </summary> + [Argument(default, "blacklist-file")] + [EnvironmentVariable("BLACKLIST_FILE")] + [Description("path to blacklist file")] + [FileExists(FileAccess.Read)] + public string File { get; init; } + + /// <summary> + /// Extended validation. + /// </summary> + /// <param name="validationContext"></param> + /// <returns></returns> + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + var results = new List<ValidationResult>(); + + if (!Enabled) + { + return results; + } + + // loading/validating the entire list will be costly on low spec systems + // just make sure that we can detect a valid format and leave it at that + // if there's a problem with any of the entries, the load will fail and + // kill the application + try + { + // async not supported here, .Result is all we have + _ = slskd.Blacklist.DetectFormat(File).Result; + } + catch + { + results.Add(new ValidationResult("Failed to detect blacklist format. Only CIDR, P2P and DAT formats are supported")); + } + + return results; + } + } + + /// <summary> /// Filter options. /// </summary> public class FiltersOptions @@ -1845,7 +1907,7 @@ namespace slskd [Argument(default, "https-cert-pfx")] [EnvironmentVariable("HTTPS_CERT_PFX")] [Description("path to X509 certificate .pfx")] - [FileExists] + [FileExists(FileAccess.Read)] [RequiresRestart] public string Pfx { get; init; } @@ -2078,4 +2140,4 @@ namespace slskd } } } -}
\ No newline at end of file +} |
