Did some small fixes, added connection timeout check, improved ux

This commit is contained in:
Marcel Baumgartner
2023-08-02 03:06:54 +02:00
parent ecda2ec6d1
commit 600bec3417
11 changed files with 170 additions and 87 deletions

View File

@@ -17,6 +17,15 @@ public class ConfigV1
[Description("The url moonlight is accesible with from the internet")]
public string AppUrl { get; set; } = "http://your-moonlight-url-without-slash";
[JsonProperty("EnableLatencyCheck")]
[Description(
"This will enable a latency check for connections to moonlight. Users with an too high latency will be warned that moonlight might be buggy for them")]
public bool EnableLatencyCheck { get; set; } = true;
[JsonProperty("LatencyCheckThreshold")]
[Description("Specify the latency threshold which has to be reached in order to trigger the warning message")]
public int LatencyCheckThreshold { get; set; } = 500;
[JsonProperty("Auth")] public AuthData Auth { get; set; } = new();
[JsonProperty("Database")] public DatabaseData Database { get; set; } = new();

View File

@@ -43,19 +43,22 @@ public class WingsFileAccess : FileAccess
$"api/servers/{Server.Uuid}/files/list-directory?directory={CurrentPath}"
);
var x = new List<FileData>();
var result = new List<FileData>();
foreach (var response in res)
foreach (var resGrouped in res.GroupBy(x => x.Directory))
{
x.Add(new()
foreach (var resItem in resGrouped.OrderBy(x => x.Name))
{
Name = response.Name,
Size = response.File ? response.Size : 0,
IsFile = response.File,
});
result.Add(new()
{
Name = resItem.Name,
Size = resItem.File ? resItem.Size : 0,
IsFile = resItem.File,
});
}
}
return x.ToArray();
return result.ToArray();
}
public override Task Cd(string dir)

View File

@@ -19,6 +19,7 @@ public class MalwareScanService
private readonly IServiceScopeFactory ServiceScopeFactory;
public bool IsRunning { get; private set; }
public bool ScanAllServers { get; set; }
public readonly Dictionary<Server, MalwareScanResult[]> ScanResults;
public string Status { get; private set; } = "N/A";
@@ -26,7 +27,6 @@ public class MalwareScanService
{
ServiceScopeFactory = serviceScopeFactory;
Event = eventSystem;
ScanResults = new();
}
@@ -42,6 +42,7 @@ public class MalwareScanService
private async Task Run()
{
// Clean results
IsRunning = true;
Status = "Clearing last results";
await Event.Emit("malwareScan.status", IsRunning);
@@ -53,6 +54,55 @@ public class MalwareScanService
await Event.Emit("malwareScan.result");
// Load servers to scan
using var scope = ServiceScopeFactory.CreateScope();
// Load services from di scope
NodeRepository = scope.ServiceProvider.GetRequiredService<Repository<Node>>();
ServerRepository = scope.ServiceProvider.GetRequiredService<Repository<Server>>();
NodeService = scope.ServiceProvider.GetRequiredService<NodeService>();
ServerService = scope.ServiceProvider.GetRequiredService<ServerService>();
Status = "Fetching servers to scan";
await Event.Emit("malwareScan.status", IsRunning);
Server[] servers;
if (ScanAllServers)
servers = ServerRepository.Get().ToArray();
else
servers = await GetOnlineServers();
// Perform scan
int i = 1;
foreach (var server in servers)
{
Status = $"[{i} / {servers.Length}] Scanning server {server.Name}";
await Event.Emit("malwareScan.status", IsRunning);
var results = await PerformScanOnServer(server);
if (results.Any())
{
lock (ScanResults)
{
ScanResults.Add(server, results);
}
await Event.Emit("malwareScan.result");
}
i++;
}
IsRunning = false;
await Event.Emit("malwareScan.status", IsRunning);
}
private async Task<Server[]> GetOnlineServers()
{
using var scope = ServiceScopeFactory.CreateScope();
// Load services from di scope
@@ -102,43 +152,11 @@ public class MalwareScanService
containerServerMapped.Add(server, container);
}
}
// Perform scan
var resultsMapped = new Dictionary<Server, MalwareScanResult[]>();
foreach (var mapping in containerServerMapped)
{
Logger.Verbose($"Scanning server {mapping.Key.Name} for malware");
Status = $"Scanning server {mapping.Key.Name} for malware";
await Event.Emit("malwareScan.status", IsRunning);
var results = await PerformScanOnServer(mapping.Key, mapping.Value);
if (results.Any())
{
resultsMapped.Add(mapping.Key, results);
Logger.Verbose($"{results.Length} findings on server {mapping.Key.Name}");
}
}
Logger.Verbose($"Scan complete. Detected {resultsMapped.Count} servers with findings");
IsRunning = false;
Status = $"Scan complete. Detected {resultsMapped.Count} servers with findings";
await Event.Emit("malwareScan.status", IsRunning);
lock (ScanResults)
{
foreach (var mapping in resultsMapped)
{
ScanResults.Add(mapping.Key, mapping.Value);
}
}
await Event.Emit("malwareScan.result");
return containerServerMapped.Keys.ToArray();
}
private async Task<MalwareScanResult[]> PerformScanOnServer(Server server, Container container)
private async Task<MalwareScanResult[]> PerformScanOnServer(Server server)
{
var results = new List<MalwareScanResult>();

View File

@@ -9,8 +9,8 @@ namespace Moonlight.App.Services.Plugins;
public class PluginService
{
public List<MoonlightPlugin> Plugins { get; private set; }
public Dictionary<MoonlightPlugin, string> PluginFiles { get; private set; }
public readonly List<MoonlightPlugin> Plugins = new();
public readonly Dictionary<MoonlightPlugin, string> PluginFiles = new();
public PluginService()
{
@@ -19,6 +19,9 @@ public class PluginService
public Task ReloadPlugins()
{
PluginFiles.Clear();
Plugins.Clear();
// Try to update all plugins ending with .dll.cache
foreach (var pluginFile in Directory.EnumerateFiles(
PathBuilder.Dir(Directory.GetCurrentDirectory(), "storage", "plugins"))