Compare commits

...
3 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -330,7 +330,7 @@ namespace Duplicati.Server
parsedOptions.AllowedHostnames);
if (mappedSettings.AllowedHostnames == null || !mappedSettings.AllowedHostnames.Any())
mappedSettings = mappedSettings with { AllowedHostnames = ["localhost", "127.0.0.1", "::1", "http://localhost:8200"] };
mappedSettings = mappedSettings with { AllowedHostnames = ["localhost", "127.0.0.1", "::1"] };
var server = new DuplicatiWebserver();
@@ -162,8 +162,12 @@ public partial class DuplicatiWebserver
public Task Start(InitSettings settings)
{
var allowedOrigins = settings.AllowedHostnames.Any(x => x == "*")
? []
: settings.AllowedHostnames.Select(x => settings.Certificate == null ? $"http://{x}:{settings.Port}" : $"https://{x}:{settings.Port}");
App.AddEndpoints()
.UseNotifications(settings.AllowedHostnames, "/notifications");
.UseNotifications(allowedOrigins, "/notifications");
return App.RunAsync();
}
@@ -1,19 +1,17 @@
using System.Net.WebSockets;
using System.Text;
using Duplicati.WebserverCore.Abstractions;
using Duplicati.WebserverCore.Abstractions.Notifications;
using Duplicati.WebserverCore.Exceptions;
namespace Duplicati.WebserverCore.Middlewares;
public static class WebsocketExtensions
{
public static IApplicationBuilder UseNotifications(this IApplicationBuilder app, IEnumerable<string> allowedHostnames, string notificationPath)
public static IApplicationBuilder UseNotifications(this IApplicationBuilder app, IEnumerable<string> allowedOrigins, string notificationPath)
{
var opts = new WebSocketOptions();
if (!allowedHostnames.Any(x => x == "*"))
foreach (var allowedHostname in allowedHostnames)
opts.AllowedOrigins.Add(allowedHostname);
if (allowedOrigins.Any())
foreach (var origin in allowedOrigins)
opts.AllowedOrigins.Add(origin);
app.UseWebSockets(opts);
return app.Use(async (context, next) =>