diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-04-23 14:04:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-23 14:04:27 -0500 |
| commit | 4b8db3f42698c05b592cc0688ad7244746af1aec (patch) | |
| tree | 4ec3394493bfde5fc97f4424dcf82166150d4cb0 | |
| parent | 480e9a17919b98a7a4f35d2b09c1232d30ffc679 (diff) | |
| parent | 612a1574b040f5c2fc577ffbe4e37f11bedbe4b4 (diff) | |
| download | slskd-4b8db3f42698c05b592cc0688ad7244746af1aec.tar.gz | |
Merge pull request #445 from slskd/no-ssl
Add an option to disable HTTPS
| -rw-r--r-- | config/slskd.example.yml | 1 | ||||
| -rw-r--r-- | docs/config.md | 1 | ||||
| -rw-r--r-- | slskd.sln | 6 | ||||
| -rw-r--r-- | src/slskd/Options.cs | 9 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 31 |
5 files changed, 34 insertions, 14 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml index e0704fdd..fbf0371e 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -50,6 +50,7 @@ # web: # port: 5000 # https: +# disabled: false # port: 5001 # force: false # certificate: diff --git a/docs/config.md b/docs/config.md index e80de398..605b159b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -496,6 +496,7 @@ The application can produce a self-signed `.pfx` file and random password using | `-f\|--force-https` | `HTTPS_FORCE` | Determines whether HTTP requests are to be redirected to HTTPS | | `--https-cert-pfx` | `HTTPS_CERT_PFX` | The path to the X509 certificate .pfx file | | `--https-cert-password` | `HTTPS_CERT_PASSWORD` | The password for the X509 certificate | +| `--no-https` | `NO_HTTPS` | Determines whether HTTPS is to be disabled | #### **YAML** ```yaml @@ -42,6 +42,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{98F684 config\slskd.example.yml = config\slskd.example.yml EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{53D80066-A655-42EC-9C8D-2591C3E4B034}" + ProjectSection(SolutionItems) = preProject + docs\config.md = docs\config.md + docs\docker.md = docs\docker.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 507006a4..00ae670e 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -1057,6 +1057,15 @@ namespace slskd public class HttpsOptions { /// <summary> + /// Gets a value indicating whether HTTPS should be disabled. + /// </summary> + [Argument(default, "no-https")] + [EnvironmentVariable("NO_HTTPS")] + [Description("disable HTTPS")] + [RequiresRestart] + public bool Disabled { get; init; } = false; + + /// <summary> /// Gets the HTTPS listen port. /// </summary> [Argument('L', "https-port")] diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 289e898c..a5c35dca 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -382,22 +382,25 @@ namespace slskd logger.Information($"Listening for HTTP requests at http://{IPAddress.Any}:{OptionsAtStartup.Web.Port}/"); options.Listen(IPAddress.Any, OptionsAtStartup.Web.Port); - logger.Information($"Listening for HTTPS requests at https://{IPAddress.Any}:{OptionsAtStartup.Web.Https.Port}/"); - options.Listen(IPAddress.Any, OptionsAtStartup.Web.Https.Port, listenOptions => + if (!OptionsAtStartup.Web.Https.Disabled) { - var cert = OptionsAtStartup.Web.Https.Certificate; - - if (!string.IsNullOrEmpty(cert.Pfx)) - { - logger.Information($"Using certificate from {cert.Pfx}"); - listenOptions.UseHttps(cert.Pfx, cert.Password); - } - else + logger.Information($"Listening for HTTPS requests at https://{IPAddress.Any}:{OptionsAtStartup.Web.Https.Port}/"); + options.Listen(IPAddress.Any, OptionsAtStartup.Web.Https.Port, listenOptions => { - logger.Information($"Using randomly generated self-signed certificate"); - listenOptions.UseHttps(X509.Generate(subject: AppName)); - } - }); + var cert = OptionsAtStartup.Web.Https.Certificate; + + if (!string.IsNullOrEmpty(cert.Pfx)) + { + logger.Information($"Using certificate from {cert.Pfx}"); + listenOptions.UseHttps(cert.Pfx, cert.Password); + } + else + { + logger.Information($"Using randomly generated self-signed certificate"); + listenOptions.UseHttps(X509.Generate(subject: AppName)); + } + }); + } }) .UseStartup<Startup>() .Build(); |
