diff --git a/Moonlight/App/Models/Daemon/Resources/ContainerStats.cs b/Moonlight/App/Models/Daemon/Resources/ContainerStats.cs index 5c2e057..db1a2c8 100644 --- a/Moonlight/App/Models/Daemon/Resources/ContainerStats.cs +++ b/Moonlight/App/Models/Daemon/Resources/ContainerStats.cs @@ -6,7 +6,7 @@ public class ContainerStats public class Container { - public Guid Name { get; set; } + public string Name { get; set; } public long Memory { get; set; } public double Cpu { get; set; } public long NetworkIn { get; set; } diff --git a/Moonlight/Shared/Views/Admin/Servers/Manager.razor b/Moonlight/Shared/Views/Admin/Servers/Manager.razor new file mode 100644 index 0000000..06aebef --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Servers/Manager.razor @@ -0,0 +1,158 @@ +@page "/admin/servers/manager" +@using Moonlight.App.Repositories +@using Moonlight.App.Repositories.Servers +@using Moonlight.App.Services +@using Moonlight.App.Services.Interop +@using Moonlight.App.Database.Entities +@using Moonlight.App.Models.Daemon.Resources +@using Moonlight.App.Models.Wings +@using BlazorTable +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Helpers + +@inject NodeRepository NodeRepository +@inject NodeService NodeService +@inject ServerRepository ServerRepository +@inject SmartTranslateService SmartTranslateService +@inject AlertService AlertService +@inject ServerService ServerService + + +
+
+ + + + + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ +@code +{ + private LazyLoader LazyLoader; + + private Dictionary Containers = new(); + + private async Task Load(LazyLoader lazyLoader) + { + Containers.Clear(); + + foreach (var node in NodeRepository.Get().ToArray()) + { + await lazyLoader.SetText(node.Name); + + var containerStats = await NodeService.GetContainerStats(node); + + foreach (var container in containerStats.Containers) + { + if (Guid.TryParse(container.Name, out Guid uuid)) + { + var server = ServerRepository + .Get() + .Include(x => x.Owner) + .FirstOrDefault(x => x.Uuid == uuid); + + if (server != null) + { + Containers.Add(server, container); + } + } + } + } + } + + private async Task StopAll() + { + var b = await AlertService.YesNo( + SmartTranslateService.Translate("Stop all servers"), + SmartTranslateService.Translate("Do you really want to stop all running servers?"), + SmartTranslateService.Translate("Yes"), + SmartTranslateService.Translate("No") + ); + + if (b) + { + foreach (var containerData in Containers) + { + await ServerService.SetPowerState(containerData.Key, PowerSignal.Stop); + } + } + } + + private async Task KillAll() + { + var b = await AlertService.YesNo( + SmartTranslateService.Translate("Kill all servers"), + SmartTranslateService.Translate("Do you really want to kill all running servers?"), + SmartTranslateService.Translate("Yes"), + SmartTranslateService.Translate("No") + ); + + if (b) + { + foreach (var containerData in Containers) + { + await ServerService.SetPowerState(containerData.Key, PowerSignal.Kill); + } + } + } +} \ No newline at end of file diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index f6a2dfe..fe06631 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -374,3 +374,13 @@ DDos attack started;DDos attack started packets;packets DDos attack stopped;DDos attack stopped packets; packets +Stop all;Stop all +Kill all;Kill all +Network in;Network in +Network out;Network out +Kill all servers;Kill all servers +Do you really want to kill all running servers?;Do you really want to kill all running servers? +Change power state for;Change power state for +to;to +Stop all servers;Stop all servers +Do you really want to stop all running servers?;Do you really want to stop all running servers?