// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see https://www.gnu.org/licenses/. // using Microsoft.Extensions.Options; namespace slskd { using System; using System.Collections.Generic; 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; using FluentFTP; using slskd.Configuration; using slskd.Validation; using Soulseek.Diagnostics; using Utility.CommandLine; using Utility.EnvironmentVariables; using YamlDotNet.Serialization; /// /// Disambiguates options derived at startup from options that may update at run time. /// /// /// This class is added directly to dependency injection, but is not, so consumers must inject /// instead of to make it clear that these options will not change. Options that may change should be accessed by injecting /// or , depending on the lifetime of the component. /// public class OptionsAtStartup : Options { } /// /// Application options. /// /// /// /// This class contains all application options, which may be sourced from (in order of precedence): /// /// /// Defaults /// Default values, statically defined in this class. /// /// /// Environment Variables /// Environment variables set at either the system or user scope. /// /// /// YAML Configuration File /// A YAML file containing a mapping of this class. /// /// /// Command Line /// Options provided via the command line when starting the application. /// /// /// /// /// Only the YAML configuration source can change at runtime and consumers of this class must be aware of this, either injecting /// in components with a singleton lifetime, or for transient or scoped lifetimes. /// /// /// To obtain the Options specified at startup (discarding any updates that may have been applied since), inject . /// /// /// Options specified via the command line can not be overwritten by changes to the YAML file. This is by design due to the immutable /// nature of the command line string after the application is started. /// /// public class Options { /// /// Gets a value indicating whether to display the application version. /// [Argument('v', "version")] [Description("display version information")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] [YamlIgnore] public bool ShowVersion { get; init; } = false; /// /// Gets a value indicating whether to display a list of command line arguments. /// [Argument('h', "help")] [Description("display command line usage")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] [YamlIgnore] public bool ShowHelp { get; init; } = false; /// /// Gets a value indicating whether to display a list of configuration environment variables. /// [Argument('e', "envars")] [Description("display environment variables")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] [YamlIgnore] public bool ShowEnvironmentVariables { get; init; } = false; /// /// Gets a value indicating whether to generate an X509 certificate and password. /// [Argument('g', "generate-cert")] [Description("generate X509 certificate and password for HTTPS")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] [YamlIgnore] public bool GenerateCertificate { get; init; } = false; /// /// Gets a value indicating whether the application should run in debug mode. /// [Argument('d', "debug")] [EnvironmentVariable("DEBUG")] [Description("run in debug mode")] [RequiresRestart] public bool Debug { get; init; } = Debugger.IsAttached; /// /// Gets a value indicating whether the logo should be suppressed on startup. /// [Argument('n', "no-logo")] [EnvironmentVariable("NO_LOGO")] [Description("suppress logo on startup")] [RequiresRestart] public bool NoLogo { get; init; } = false; /// /// Gets a value indicating whether the application should quit after initialization. /// [Argument('x', "no-start")] [EnvironmentVariable("NO_START")] [Description("quit the application after initialization")] [RequiresRestart] public bool NoStart { get; init; } = false; /// /// Gets a value indicating whether the application should connect to the Soulseek network on startup. /// [Argument(default, "no-connect")] [EnvironmentVariable("NO_CONNECT")] [Description("do not connect to the Soulseek network on startup")] [RequiresRestart] public bool NoConnect { get; init; } = false; /// /// Gets a value indicating whether the application should scan shared directories on startup. /// [Argument(default, "no-share-scan")] [EnvironmentVariable("NO_SHARE_SCAN")] [Description("do not scan shares on startup")] [RequiresRestart] public bool NoShareScan { get; init; } = false; /// /// Gets a value indicating whether the application should check for a newer version on startup. /// [Argument(default, "no-version-check")] [EnvironmentVariable("NO_VERSION_CHECK")] [Description("do not check for newer version at startup")] [RequiresRestart] public bool NoVersionCheck { get; init; } = false; /// /// Gets a value indicating whether remote configuration of options is allowed. /// [Argument(default, "remote-configuration")] [EnvironmentVariable("REMOTE_CONFIGURATION")] [Description("allow remote configuration")] public bool RemoteConfiguration { get; init; } = false; /// /// Gets the unique name for this instance. /// [Argument('i', "instance-name")] [EnvironmentVariable("INSTANCE_NAME")] [Description("optional; a unique name for this instance")] [RequiresRestart] public string InstanceName { get; init; } = "default"; /// /// Gets the path where application data is saved. /// [Argument(default, "app")] [EnvironmentVariable("APP_DIR")] [Description("path where application data is saved")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] [YamlIgnore] public string AppDirectory { get; init; } = Program.DefaultAppDirectory; /// /// Gets the path where application data is saved. /// [Argument('c', "config")] [EnvironmentVariable("CONFIG")] [Description("path to configuration file")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] [YamlIgnore] public string ConfigurationFile { get; init; } = Program.DefaultConfigurationFile; /// /// Gets directory options. /// [Validate] [RequiresRestart] public DirectoriesOptions Directories { get; init; } = new DirectoriesOptions(); /// /// Gets filter options. /// [Validate] public FiltersOptions Filters { get; init; } = new FiltersOptions(); /// /// Gets a list of rooms to automatically join upon connection. /// [Argument(default, "rooms")] [EnvironmentVariable("ROOMS")] [Description("a list of rooms to automatically join")] public string[] Rooms { get; init; } = Array.Empty(); /// /// Gets options for the web UI. /// [Validate] public WebOptions Web { get; init; } = new WebOptions(); /// /// Gets logger options. /// [Validate] [RequiresRestart] public LoggerOptions Logger { get; init; } = new LoggerOptions(); /// /// Gets feature options. /// [Validate] [RequiresRestart] public FeatureOptions Feature { get; init; } = new FeatureOptions(); /// /// Gets options for the Soulseek client. /// [Validate] public SoulseekOptions Soulseek { get; init; } = new SoulseekOptions(); /// /// Gets options for external integrations. /// [Validate] public IntegrationOptions Integration { get; init; } = new IntegrationOptions(); /// /// Directory options. /// public class DirectoriesOptions : IValidatableObject { /// /// Gets the path where incomplete downloads are saved. /// [Argument(default, "incomplete")] [EnvironmentVariable("INCOMPLETE_DIR")] [Description("path where incomplete downloads are saved")] [DirectoryExists(ensureWriteable: true)] [RequiresRestart] public string Incomplete { get; init; } = Program.DefaultIncompleteDirectory; /// /// Gets the path where downloaded files are saved. /// [Argument('o', "downloads")] [EnvironmentVariable("DOWNLOADS_DIR")] [Description("path where downloaded files are saved")] [DirectoryExists(ensureWriteable: true)] [RequiresRestart] public string Downloads { get; init; } = Program.DefaultDownloadsDirectory; /// /// Gets the list of paths to shared files. /// [Argument('s', "shared")] [EnvironmentVariable("SHARED_DIR")] [Description("path to shared files")] public string[] Shared { get; init; } = Array.Empty(); /// /// Extended validation. /// /// /// public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); (string Raw, string Mask, string Alias, string Path) Digest(string share) { var matches = Regex.Matches(share, @"^(-?)\[(.*)\](.*)$"); if (matches.Any()) { return (share, Compute.MaskHash(Directory.GetParent(matches[0].Groups[3].Value)?.FullName ?? share), matches[0].Groups[2].Value, matches[0].Groups[3].Value); } return (share, Compute.MaskHash(Directory.GetParent(share)?.FullName ?? share), share.Split(new[] { '/', '\\' }).Last(), share); } bool IsRoot((string Raw, string Mask, string Alias, string Path) share) => share.Path == "/" || share.Path == "\\" || Path.GetPathRoot(share.Path) == share.Path; // starts with '/', 'X:\', or '\\' bool IsAbsolutePath(string share) => Regex.IsMatch(share.ToLocalOSPath(), @"^(\[.*\])?(\/|[a-zA-Z]:\\|\\\\).*$"); var relativePaths = Shared.Where(share => !IsAbsolutePath(share)); foreach (var relativePath in relativePaths) { results.Add(new ValidationResult($"Share {relativePath} contains a relative path; only absolute paths are supported.")); } var digestedShared = Shared .Select(share => Digest(share.TrimEnd('/', '\\'))) .ToHashSet(); var roots = digestedShared.Where(share => IsRoot(share)); foreach (var root in roots) { results.Add(new ValidationResult($"Share {root.Raw} is a root path, which is not supported.")); } digestedShared = digestedShared.Where(share => !IsRoot(share)).ToHashSet(); var overlapping = digestedShared.GroupBy(share => share.Mask + share.Alias).Where(group => group.Count() > 1); foreach (var overlap in overlapping) { results.Add(new ValidationResult($"Shares {string.Join(", ", overlap.Select(s => $"'{s.Raw}'"))} overlap")); } var duplicates = digestedShared.GroupBy(share => share.Path).Where(group => group.Count() > 1); foreach (var dupe in duplicates) { results.Add(new ValidationResult($"Shares {string.Join(", ", dupe.Select(s => $"'{s.Raw}'"))} alias the same path")); } foreach (var share in digestedShared.Where(s => s.Alias != null)) { if (string.IsNullOrWhiteSpace(share.Alias)) { results.Add(new ValidationResult($"Share '{share.Raw}' is invalid; alias may not be null, empty or consist of only whitespace")); } else if (share.Alias.Contains('\\') || share.Alias.Contains('/')) { results.Add(new ValidationResult($"Share '{share.Raw}' is invalid; aliases may not contain path separators '/' or '\\'")); } } return results; } } /// /// Feature options. /// public class FeatureOptions { /// /// Gets a value indicating whether prometheus metrics should be collected and published. /// [Argument(default, "prometheus")] [EnvironmentVariable("PROMETHEUS")] [Description("enable collection and publishing of prometheus metrics")] [RequiresRestart] public bool Prometheus { get; init; } = false; /// /// Gets a value indicating whether swagger documentation and UI should be enabled. /// [Argument(default, "swagger")] [EnvironmentVariable("SWAGGER")] [Description("enable swagger documentation and UI")] [RequiresRestart] public bool Swagger { get; init; } = false; } /// /// Filter options. /// public class FiltersOptions : IValidatableObject { /// /// Gets the list of shared file filters. /// [Argument(default, "share-filter")] [EnvironmentVariable("SHARE_FILTER")] [Description("regular expressions to filter files from shares")] public string[] Share { get; init; } = Array.Empty(); /// /// Extended validation. /// /// /// public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); foreach (var filter in Share) { if (!filter.IsValidRegex()) { results.Add(new ValidationResult($"Share filter '{filter}' is not a valid regular expression")); } } return results; } } /// /// Logger options. /// public class LoggerOptions { /// /// Gets the URL to a Grafana Loki instance to which to log. /// [Argument(default, "loki")] [EnvironmentVariable("LOKI")] [Description("optional; url to a Grafana Loki instance to which to log")] [RequiresRestart] public string Loki { get; init; } = null; } /// /// Soulseek client options. /// public class SoulseekOptions { /// /// Gets the username for the Soulseek network. /// [Argument(default, "slsk-username")] [EnvironmentVariable("SLSK_USERNAME")] [Description("username for the Soulseek network")] [RequiresReconnect] public string Username { get; init; } = null; /// /// Gets the password for the Soulseek network. /// [Argument(default, "slsk-password")] [EnvironmentVariable("SLSK_PASSWORD")] [Description("password for the Soulseek network")] [Secret] [RequiresReconnect] public string Password { get; init; } = null; /// /// Gets the port on which to listen for incoming connections. /// [Argument(default, "slsk-listen-port")] [EnvironmentVariable("SLSK_LISTEN_PORT")] [Description("port on which to listen for incoming connections")] [Range(1024, 65535)] public int ListenPort { get; init; } = 50000; /// /// Gets the minimum diagnostic level. /// [Argument(default, "slsk-diag-level")] [EnvironmentVariable("SLSK_DIAG_LEVEL")] [Description("minimum diagnostic level (None, Warning, Info, Debug)")] [RequiresRestart] public DiagnosticLevel DiagnosticLevel { get; init; } = DiagnosticLevel.Info; /// /// Gets options for the distributed network. /// [Validate] public DistributedNetworkOptions DistributedNetwork { get; init; } = new DistributedNetworkOptions(); /// /// Gets connection options. /// [Validate] public ConnectionOptions Connection { get; init; } = new ConnectionOptions(); /// /// Connection options. /// public class ConnectionOptions { /// /// Gets connection timeout options. /// [Validate] public TimeoutOptions Timeout { get; init; } = new TimeoutOptions(); /// /// Gets connection buffer options. /// [Validate] public BufferOptions Buffer { get; init; } = new BufferOptions(); /// /// Gets connection proxy options. /// [Validate] public ProxyOptions Proxy { get; init; } = new ProxyOptions(); /// /// Connection buffer options. /// public class BufferOptions { /// /// Gets the connection read buffer size, in bytes. /// [Argument(default, "slsk-read-buffer")] [EnvironmentVariable("SLSK_READ_BUFFER")] [Description("read buffer size for connections")] [Range(1024, int.MaxValue)] public int Read { get; init; } = 16384; /// /// Gets the connection write buffer size, in bytes. /// [Argument(default, "slsk-write-buffer")] [EnvironmentVariable("SLSK_WRITE_BUFFER")] [Description("write buffer size for connections")] [Range(1024, int.MaxValue)] public int Write { get; init; } = 16384; /// /// Gets the read/write buffer size for transfers, in bytes. /// [Argument(default, "slsk-transfer-buffer")] [EnvironmentVariable("SLSK_TRANSFER_BUFFER")] [Description("read/write buffer size for transfers")] [Range(81920, int.MaxValue)] public int Transfer { get; init; } = 262144; /// /// Gets the size of the queue for double buffered writes. /// [Argument(default, "slsk-write-queue")] [EnvironmentVariable("SLSK_WRITE_QUEUE")] [Description("queue size for double buffered writes")] [Range(5, 5000)] public int WriteQueue { get; init; } = 50; } /// /// Connection timeout options. /// public class TimeoutOptions { /// /// Gets the connection timeout value, in milliseconds. /// [Argument(default, "slsk-connection-timeout")] [EnvironmentVariable("SLSK_CONNECTION_TIMEOUT")] [Description("connection timeout, in milliseconds")] [Range(1000, int.MaxValue)] public int Connect { get; init; } = 10000; /// /// Gets the connection inactivity timeout, in milliseconds. /// [Argument(default, "slsk-inactivity-timeout")] [EnvironmentVariable("SLSK_INACTIVITY_TIMEOUT")] [Description("connection inactivity timeout, in milliseconds")] [Range(1000, int.MaxValue)] public int Inactivity { get; init; } = 15000; } /// /// Connection proxy options. /// public class ProxyOptions : IValidatableObject { /// /// Gets a value indicating whether the proxy is enabled. /// [Argument(default, "slsk-proxy")] [EnvironmentVariable("SLSK_PROXY_ENABLED")] [Description("enable connection proxy")] public bool Enabled { get; init; } = false; /// /// Gets the proxy address. /// [Argument(default, "slsk-proxy-address")] [EnvironmentVariable("SLSK_PROXY_ADDRESS")] [Description("connection proxy address")] [StringLength(255, MinimumLength = 1)] public string Address { get; init; } /// /// Gets the proxy port. /// [Argument(default, "slsk-proxy-port")] [EnvironmentVariable("SLSK_PROXY_PORT")] [Description("connection proxy port")] [Range(1, 65535)] public int? Port { get; init; } /// /// Gets the proxy username, if applicable. /// [Argument(default, "slsk-proxy-username")] [EnvironmentVariable("SLSK_PROXY_USERNAME")] [Description("connection proxy username")] [StringLength(255, MinimumLength = 1)] public string Username { get; init; } /// /// Gets the proxy password, if applicable. /// [Argument(default, "slsk-proxy-password")] [EnvironmentVariable("SLSK_PROXY_PASSWORD")] [Description("connection proxy password")] [StringLength(255, MinimumLength = 1)] [Secret] public string Password { get; init; } /// /// Extended validation. /// /// /// public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); if (Enabled && string.IsNullOrWhiteSpace(Address)) { results.Add(new ValidationResult($"The Enabled field is true, but no Address has been specified.")); } if (Enabled && !Port.HasValue) { results.Add(new ValidationResult($"The Enabled field is true, but no Port has been specified.")); } return results; } } } /// /// Distributed network options. /// public class DistributedNetworkOptions { /// /// Gets a value indicating whether the distributed network should be disabled. /// [Argument(default, "slsk-no-dnet")] [EnvironmentVariable("SLSK_NO_DNET")] [Description("disable the distributed network")] public bool Disabled { get; init; } = false; /// /// Gets a value indicating whether to accept distributed child connections. /// [Argument(default, "slsk-dnet-no-children")] [EnvironmentVariable("SLSK_DNET_NO_CHILDREN")] [Description("do not accept distributed children")] public bool DisableChildren { get; init; } = false; /// /// Gets the distributed child connection limit. /// [Argument(default, "slsk-dnet-children")] [EnvironmentVariable("SLSK_DNET_CHILDREN")] [Description("max number of distributed children")] [Range(1, int.MaxValue)] public int ChildLimit { get; init; } = 25; } } /// /// Web server options. /// public class WebOptions { /// /// Gets the HTTP listen port. /// [Argument('l', "http-port")] [EnvironmentVariable("HTTP_PORT")] [Description("HTTP listen port for web UI")] [Range(1, 65535)] [RequiresRestart] public int Port { get; init; } = 5000; /// /// Gets HTTPS options. /// [Validate] [RequiresRestart] public HttpsOptions Https { get; init; } = new HttpsOptions(); /// /// Gets the base url for web requests. /// [Argument(default, "url-base")] [EnvironmentVariable("URL_BASE")] [Description("base url for web requests")] [RequiresRestart] public string UrlBase { get; init; } = "/"; /// /// Gets the path to static web content. /// [Argument(default, "content-path")] [EnvironmentVariable("CONTENT_PATH")] [Description("path to static web content")] [StringLength(255, MinimumLength = 1)] [RequiresRestart] public string ContentPath { get; init; } = "wwwroot"; /// /// Gets a value indicating whether HTTP request logging should be enabled. /// [Argument(default, "http-logging")] [EnvironmentVariable("HTTP_LOGGING")] [Description("enable http request logging")] [RequiresRestart] public bool Logging { get; init; } = false; /// /// Gets authentication options. /// [Validate] public AuthenticationOptions Authentication { get; init; } = new AuthenticationOptions(); /// /// Authentication options. /// public class AuthenticationOptions { /// /// Gets a value indicating whether authentication should be disabled. /// [Argument('X', "no-auth")] [EnvironmentVariable("NO_AUTH")] [Description("disable authentication for web requests")] [RequiresRestart] public bool Disabled { get; init; } = false; /// /// Gets the username for the web UI. /// [Argument('u', "username")] [EnvironmentVariable("USERNAME")] [Description("username for web UI")] [StringLength(255, MinimumLength = 1)] public string Username { get; init; } = Program.AppName; /// /// Gets the password for the web UI. /// [Argument('p', "password")] [EnvironmentVariable("PASSWORD")] [Description("password for web UI")] [StringLength(255, MinimumLength = 1)] [Secret] public string Password { get; init; } = Program.AppName; /// /// Gets JWT options. /// [Validate] [RequiresRestart] public JwtOptions Jwt { get; init; } = new JwtOptions(); /// /// JWT options. /// public class JwtOptions { /// /// Gets the key with which to sign JWTs. /// [Argument(default, "jwt-key")] [EnvironmentVariable("JWT_KEY")] [Description("JWT signing key")] [StringLength(255, MinimumLength = 16)] [Secret] [RequiresRestart] public string Key { get; init; } = Cryptography.Random.GetBytes(16).ToBase62String(); /// /// Gets the TTL for JWTs, in milliseconds. /// [Argument(default, "jwt-ttl")] [EnvironmentVariable("JWT_TTL")] [Description("TTL for JWTs")] [Range(3600, int.MaxValue)] [RequiresRestart] public int Ttl { get; init; } = 604800000; } } /// /// HTTPS options. /// public class HttpsOptions { /// /// Gets the HTTPS listen port. /// [Argument('L', "https-port")] [EnvironmentVariable("HTTPS_PORT")] [Description("HTTPS listen port for web UI")] [Range(1, 65535)] [RequiresRestart] public int Port { get; init; } = 5001; /// /// Gets a value indicating whether HTTP requests should be redirected to HTTPS. /// [Argument('f', "force-https")] [EnvironmentVariable("HTTPS_FORCE")] [Description("redirect HTTP to HTTPS")] [RequiresRestart] public bool Force { get; init; } = false; /// /// Gets certificate options. /// [Validate] [RequiresRestart] public CertificateOptions Certificate { get; init; } = new CertificateOptions(); /// /// Certificate options. /// [X509Certificate] public class CertificateOptions { /// /// Gets the path to the the X509 certificate .pfx file. /// [Argument(default, "https-cert-pfx")] [EnvironmentVariable("HTTPS_CERT_PFX")] [Description("path to X509 certificate .pfx")] [FileExists] [RequiresRestart] public string Pfx { get; init; } /// /// Gets the password for the X509 certificate. /// [Argument(default, "https-cert-password")] [EnvironmentVariable("HTTPS_CERT_PASSWORD")] [Description("X509 certificate password")] [RequiresRestart] [Secret] public string Password { get; init; } } } } /// /// Options for external integrations. /// public class IntegrationOptions { /// /// Gets FTP options. /// [Validate] public FtpOptions Ftp { get; init; } = new FtpOptions(); /// /// Gets Pushbullet options. /// [Validate] public PushbulletOptions Pushbullet { get; init; } = new PushbulletOptions(); /// /// FTP options. /// public class FtpOptions : IValidatableObject { /// /// Gets a value indicating whether the FTP integration is enabled. /// [Argument(default, "ftp")] [EnvironmentVariable("FTP")] [Description("enable FTP integration")] public bool Enabled { get; init; } /// /// Gets the FTP address. /// [Argument(default, "ftp-address")] [EnvironmentVariable("FTP_ADDRESS")] [Description("FTP address")] public string Address { get; init; } /// /// Gets the FTP port. /// [Argument(default, "ftp-port")] [EnvironmentVariable("FTP_PORT")] [Description("FTP port")] [Range(1, 65535)] public int Port { get; init; } = 21; /// /// Gets the FTP encryption mode. /// [Argument(default, "ftp-encryption-mode")] [EnvironmentVariable("FTP_ENCRYPTION_MODE")] [Description("FTP encryption mode; none, implicit, explicit, auto")] [Enum(typeof(FtpEncryptionMode))] public string EncryptionMode { get; init; } = "auto"; /// /// Gets a value indicating whether FTP certificate errors should be ignored. /// [Argument(default, "ftp-ignore-certificate-errors")] [EnvironmentVariable("FTP_IGNORE_CERTIFICATE_ERRORS")] [Description("ignore FTP certificate errors")] public bool IgnoreCertificateErrors { get; init; } = false; /// /// Gets the FTP username. /// [Argument(default, "ftp-username")] [EnvironmentVariable("FTP_USERNAME")] [Description("FTP username")] public string Username { get; init; } /// /// Gets the FTP password. /// [Argument(default, "ftp-password")] [EnvironmentVariable("FTP_PASSWORD")] [Description("FTP password")] [Secret] public string Password { get; init; } /// /// Gets the remote path for uploads. /// [Argument(default, "ftp-remote-path")] [EnvironmentVariable("FTP_REMOTE_PATH")] [Description("remote path for FTP uploads")] public string RemotePath { get; init; } = "/"; /// /// Gets a value indicating whether existing files should be overwritten. /// [Argument(default, "ftp-overwrite-existing")] [EnvironmentVariable("FTP_OVERWRITE_EXISTING")] [Description("overwrite existing files when uploading to FTP")] public bool OverwriteExisting { get; init; } = true; /// /// Gets the connection timeout value, in milliseconds. /// [Argument(default, "ftp-connection-timeout")] [EnvironmentVariable("FTP_CONNECTION_TIMEOUT")] [Description("FTP connection timeout, in milliseconds")] [Range(0, int.MaxValue)] public int ConnectionTimeout { get; init; } = 5000; /// /// Gets the number of times failing uploads will be retried. /// [Argument(default, "ftp-retry-attempts")] [EnvironmentVariable("FTP_RETRY_ATTEMPTS")] [Description("number of times failing FTP uploads will be retried")] [Range(0, 5)] public int RetryAttempts { get; init; } = 3; /// /// Extended validation. /// /// /// public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); if (Enabled && string.IsNullOrWhiteSpace(Address)) { results.Add(new ValidationResult($"The Enabled field is true, but no Address has been specified.")); } return results; } } /// /// Pushbullet options. /// public class PushbulletOptions : IValidatableObject { /// /// Gets a value indicating whether the Pushbullet integration is enabled. /// [Argument(default, "pushbullet")] [EnvironmentVariable("PUSHBULLET")] [Description("enable Pushbullet integration")] public bool Enabled { get; init; } = false; /// /// Gets the Pushbullet API access token. /// [Argument(default, "pushbullet-token")] [EnvironmentVariable("PUSHBULLET_ACCESS_TOKEN")] [Description("Pushbullet access token")] [Secret] public string AccessToken { get; init; } /// /// Gets the prefix for Pushbullet notification titles. /// [Argument(default, "pushbullet-prefix")] [EnvironmentVariable("PUSHBULLET_NOTIFICATION_PREFIX")] [Description("prefix for Pushbullet notification titles")] public string NotificationPrefix { get; init; } = "From slskd:"; /// /// Gets a value indicating whether a Pushbullet notification should be sent when a private message is received. /// [Argument(default, "pushbullet-notify-on-pm")] [EnvironmentVariable("PUSHBULLET_NOTIFY_ON_PRIVATE_MESSAGE")] [Description("send Pushbullet notifications when private messages are received")] public bool NotifyOnPrivateMessage { get; init; } = true; /// /// Gets a value indicating whether a Pushbullet notification should be sent when the currently logged /// in user's username is mentioned in a room. /// [Argument(default, "pushbullet-notify-on-room-mention")] [EnvironmentVariable("PUSHBULLET_NOTIFY_ON_ROOM_MENTION")] [Description("send Pushbullet notifications when your username is mentioned in a room")] public bool NotifyOnRoomMention { get; init; } = true; /// /// Gets the number of times failing Pushbullet notifications will be retried. /// [Argument(default, "pushbullet-retry-attempts")] [EnvironmentVariable("PUSHBULLET_RETRY_ATTEMPTS")] [Description("number of times failing Pushbullet notifications will be retried")] [Range(0, 5)] public int RetryAttempts { get; init; } = 3; /// /// Gets the cooldown time for Pushbullet notifications, in milliseconds. /// [Argument(default, "pushbullet-cooldown")] [EnvironmentVariable("PUSHBULLET_COOLDOWN_TIME")] [Description("cooldown time for Pushbullet notifications, in milliseconds")] public int CooldownTime { get; init; } = 900000; // 15 minutes /// /// Extended validation. /// /// /// public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); if (Enabled && string.IsNullOrWhiteSpace(AccessToken)) { results.Add(new ValidationResult($"The Enabled field is true, but no AccessToken has been specified.")); } return results; } } } } }