aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-05-05 13:47:13 -0500
committerGitHub <noreply@github.com>2024-05-05 13:47:13 -0500
commitbbbd09d8208f005fd2a976c025e888e84a3448ec (patch)
tree3804a25c0af9bf4bb21017c1f9abfec74e342abd /src/slskd/Core/Options.cs
parent37dea1f91371900dcfb4fae8f46c6f3a6dc98126 (diff)
parent2a5c671499ac7bb542d7373464ac4a57465d971d (diff)
downloadslskd-bbbd09d8208f005fd2a976c025e888e84a3448ec.tar.gz
Merge pull request #1100 from slskd/blacklist
[WIP] Add support for blacklist files
Diffstat (limited to 'src/slskd/Core/Options.cs')
-rw-r--r--src/slskd/Core/Options.cs66
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
+}