diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-02-14 17:55:58 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-14 17:55:58 -0600 |
| commit | 7f0312a1ea28e611a126ddb07117aa1072f1c36a (patch) | |
| tree | c78c5372d6bb23464480a509e3aee1789b5b78a1 /src/slskd/Core/Options.cs | |
| parent | 8d30845f59d693aa6909c9fe8291493422dc10aa (diff) | |
| parent | 9f3b7217dd4554482c904becc101a4cf3074544e (diff) | |
| download | slskd-7f0312a1ea28e611a126ddb07117aa1072f1c36a.tar.gz | |
Merge pull request #1632 from slskd/gluetun
Add VPN integration and gluetun client
Diffstat (limited to 'src/slskd/Core/Options.cs')
| -rw-r--r-- | src/slskd/Core/Options.cs | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 200b0ee8..644fb885 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -33,6 +33,7 @@ namespace slskd using slskd.Authentication; using slskd.Configuration; using slskd.Events; + using slskd.Integrations.VPN; using slskd.Relay; using slskd.Shares; using slskd.Validation; @@ -2275,6 +2276,12 @@ namespace slskd public class IntegrationOptions { /// <summary> + /// Gets VPN options. + /// </summary> + [Validate] + public VpnOptions Vpn { get; init; } = new(); + + /// <summary> /// Gets webhook configuration. /// </summary> [Validate] @@ -2299,6 +2306,119 @@ namespace slskd public PushbulletOptions Pushbullet { get; init; } = new PushbulletOptions(); /// <summary> + /// VPN options. + /// </summary> + public class VpnOptions : IValidatableObject + { + /// <summary> + /// Gets a value indicating whether the VPN integration is enabled. + /// </summary> + [Argument(default, "vpn")] + [EnvironmentVariable("VPN")] + [Description("enable VPN integration")] + [RequiresRestart] + public bool Enabled { get; init; } = false; + + /// <summary> + /// Gets a value indicating whether the configured VPN supports dynamic port forwarding. + /// </summary> + [Argument(default, "vpn-port-forwarding")] + [EnvironmentVariable("VPN_PORT_FORWARDING")] + [Description("VPN supports dynamic port forwarding")] + public bool PortForwarding { get; init; } = false; + + /// <summary> + /// Gets the rate at which to poll the configured VPN client for status updates, in milliseconds. + /// </summary> + [Argument(default, "vpn-polling-interval")] + [EnvironmentVariable("VPN_POLLING_INTERVAL")] + [Description("VPN client status polling interval")] + [Range(500, int.MaxValue)] + [RequiresRestart] + public int PollingInterval { get; init; } = 2500; + + /// <summary> + /// Gets Gluetun options. + /// </summary> + [Validate] + public GluetunVpnOptions Gluetun { get; init; } = new GluetunVpnOptions(); + + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + if (Enabled) + { + // as/if more VPN clients are added, update this logic to ensure that exactly one is configured + if (string.IsNullOrWhiteSpace(Gluetun?.Url)) + { + yield return new ValidationResult("VPN is enabled but no client is configured"); + yield break; + } + + if (!Uri.TryCreate(Gluetun.Url, UriKind.Absolute, out _)) + { + yield return new ValidationResult("The gluetun URL must be absolute, e.g. 'http://127.0.0.1:8000'"); + } + } + } + + /// <summary> + /// Gluetun options. + /// </summary> + public class GluetunVpnOptions + { + /// <summary> + /// Gets the Gluetun integration version. + /// </summary> + /// <remarks> + /// Only v1 of the Gluetun API exists right now; this is to ease a transition if there's ever a v2. + /// </remarks> + [Range(1, 1)] + public int Version { get; init; } = 1; + + /// <summary> + /// Gets the fully qualified root URL for the Gluetun control server. + /// </summary> + [Argument(default, "vpn-gluetun-url")] + [EnvironmentVariable("VPN_GLUETUN_URL")] + [Description("URL for gluetun control server")] + public string Url { get; init; } + + /// <summary> + /// Gets the timeout for HTTP requests to the Gluetun control server, in milliseconds. + /// </summary> + [Argument(default, "vpn-gluetun-timeout")] + [EnvironmentVariable("VPN_GLUETUN_TIMEOUT")] + [Description("timeout for HTTP requests to gluetun control server")] + [Range(500, 10_000)] + public int Timeout { get; init; } = 1000; + + /// <summary> + /// Gets the username used for basic auth. + /// </summary> + [Argument(default, "vpn-gluetun-username")] + [EnvironmentVariable("VPN_GLUETUN_USERNAME")] + [Description("username for gluetun control server")] + public string Username { get; init; } + + /// <summary> + /// Gets the password used for basic auth. + /// </summary> + [Argument(default, "vpn-gluetun-password")] + [EnvironmentVariable("VPN_GLUETUN_PASSWORD")] + [Description("password for gluetun control server")] + public string Password { get; init; } + + /// <summary> + /// Gets the API key used for API key auth. + /// </summary> + [Argument(default, "vpn-gluetun-api-key")] + [EnvironmentVariable("VPN_GLUETUN_API_KEY")] + [Description("API key for gluetun control server")] + public string ApiKey { get; init; } + } + } + + /// <summary> /// Webhook configuration. /// </summary> public class WebhookOptions |
