cleanup exceptions (hopefully)
This commit is contained in:
@@ -43,7 +43,6 @@ public class DataContext : DbContext
|
|||||||
public DbSet<AaPanel> AaPanels { get; set; }
|
public DbSet<AaPanel> AaPanels { get; set; }
|
||||||
public DbSet<Website> Websites { get; set; }
|
public DbSet<Website> Websites { get; set; }
|
||||||
public DbSet<DdosAttack> DdosAttacks { get; set; }
|
public DbSet<DdosAttack> DdosAttacks { get; set; }
|
||||||
public DbSet<CleanupException> CleanupExceptions { get; set; }
|
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ public class Server
|
|||||||
public NodeAllocation MainAllocation { get; set; } = null!;
|
public NodeAllocation MainAllocation { get; set; } = null!;
|
||||||
public Node Node { get; set; } = null!;
|
public Node Node { get; set; } = null!;
|
||||||
public User Owner { get; set; } = null!;
|
public User Owner { get; set; } = null!;
|
||||||
|
public bool IsCleanupException { get; set; } = false;
|
||||||
}
|
}
|
||||||
1098
Moonlight/App/Database/Migrations/20230402215155_ChengedCleanupExceptionModel.Designer.cs
generated
Normal file
1098
Moonlight/App/Database/Migrations/20230402215155_ChengedCleanupExceptionModel.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.App.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class ChengedCleanupExceptionModel : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "CreatedAt",
|
||||||
|
table: "CleanupExceptions",
|
||||||
|
type: "datetime(6)",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CleanupExceptions_ServerId",
|
||||||
|
table: "CleanupExceptions",
|
||||||
|
column: "ServerId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_CleanupExceptions_Servers_ServerId",
|
||||||
|
table: "CleanupExceptions",
|
||||||
|
column: "ServerId",
|
||||||
|
principalTable: "Servers",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_CleanupExceptions_Servers_ServerId",
|
||||||
|
table: "CleanupExceptions");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_CleanupExceptions_ServerId",
|
||||||
|
table: "CleanupExceptions");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CreatedAt",
|
||||||
|
table: "CleanupExceptions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1067
Moonlight/App/Database/Migrations/20230402220651_RemovedCleanupExceptionChangedServerModel.Designer.cs
generated
Normal file
1067
Moonlight/App/Database/Migrations/20230402220651_RemovedCleanupExceptionChangedServerModel.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.App.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemovedCleanupExceptionChangedServerModel : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CleanupExceptions");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "IsCleanupException",
|
||||||
|
table: "Servers",
|
||||||
|
type: "tinyint(1)",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "IsCleanupException",
|
||||||
|
table: "Servers");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CleanupExceptions",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
ServerId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||||
|
Note = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CleanupExceptions", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CleanupExceptions_Servers_ServerId",
|
||||||
|
column: x => x.ServerId,
|
||||||
|
principalTable: "Servers",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CleanupExceptions_ServerId",
|
||||||
|
table: "CleanupExceptions",
|
||||||
|
column: "ServerId");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -482,6 +482,9 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
b.Property<bool>("Installing")
|
b.Property<bool>("Installing")
|
||||||
.HasColumnType("tinyint(1)");
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsCleanupException")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
b.Property<int>("MainAllocationId")
|
b.Property<int>("MainAllocationId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
@@ -827,24 +830,6 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
b.ToTable("Websites");
|
b.ToTable("Websites");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Moonlight.App.Models.Misc.CleanupException", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<string>("Note")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("longtext");
|
|
||||||
|
|
||||||
b.Property<int>("ServerId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("CleanupExceptions");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Moonlight.App.Database.Entities.Database", b =>
|
modelBuilder.Entity("Moonlight.App.Database.Entities.Database", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel")
|
b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel")
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Moonlight.App.Models.Misc;
|
|
||||||
|
|
||||||
public class CleanupException
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public int ServerId { get; set; }
|
|
||||||
public string Note { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Moonlight.App.Database;
|
|
||||||
using Moonlight.App.Models.Misc;
|
|
||||||
|
|
||||||
namespace Moonlight.App.Repositories;
|
|
||||||
|
|
||||||
public class CleanupExceptionRepository : IDisposable
|
|
||||||
{
|
|
||||||
private readonly DataContext DataContext;
|
|
||||||
|
|
||||||
public CleanupExceptionRepository(DataContext dataContext)
|
|
||||||
{
|
|
||||||
DataContext = dataContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbSet<CleanupException> Get()
|
|
||||||
{
|
|
||||||
return DataContext.CleanupExceptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CleanupException Add(CleanupException cleanupException)
|
|
||||||
{
|
|
||||||
var x = DataContext.CleanupExceptions.Add(cleanupException).Entity;
|
|
||||||
DataContext.SaveChanges();
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(CleanupException cleanupException)
|
|
||||||
{
|
|
||||||
DataContext.CleanupExceptions.Update(cleanupException);
|
|
||||||
DataContext.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Delete(CleanupException cleanupException)
|
|
||||||
{
|
|
||||||
DataContext.CleanupExceptions.Remove(cleanupException);
|
|
||||||
DataContext.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
DataContext.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -104,7 +104,6 @@ public class CleanupService
|
|||||||
// Get repos from dependency injection
|
// Get repos from dependency injection
|
||||||
var serverRepository = scope.ServiceProvider.GetRequiredService<ServerRepository>();
|
var serverRepository = scope.ServiceProvider.GetRequiredService<ServerRepository>();
|
||||||
var nodeRepository = scope.ServiceProvider.GetRequiredService<NodeRepository>();
|
var nodeRepository = scope.ServiceProvider.GetRequiredService<NodeRepository>();
|
||||||
var cleanupExceptionRepository = scope.ServiceProvider.GetRequiredService<CleanupExceptionRepository>();
|
|
||||||
var nodeService = scope.ServiceProvider.GetRequiredService<NodeService>();
|
var nodeService = scope.ServiceProvider.GetRequiredService<NodeService>();
|
||||||
var imageRepo = scope.ServiceProvider.GetRequiredService<ImageRepository>();
|
var imageRepo = scope.ServiceProvider.GetRequiredService<ImageRepository>();
|
||||||
var serverService = scope.ServiceProvider.GetRequiredService<ServerService>();
|
var serverService = scope.ServiceProvider.GetRequiredService<ServerService>();
|
||||||
@@ -114,7 +113,7 @@ public class CleanupService
|
|||||||
.Include(x => x.Image)
|
.Include(x => x.Image)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
var nodes = nodeRepository.Get().ToArray();
|
var nodes = nodeRepository.Get().ToArray();
|
||||||
var exceptions = cleanupExceptionRepository.Get().ToArray();
|
var exceptions = servers.Where(x => x.IsCleanupException);
|
||||||
var images = imageRepo.Get().ToArray();
|
var images = imageRepo.Get().ToArray();
|
||||||
|
|
||||||
var nodeCount = nodes.Count();
|
var nodeCount = nodes.Count();
|
||||||
@@ -228,7 +227,7 @@ public class CleanupService
|
|||||||
var players = GetPlayers(serverData.Node, serverData.MainAllocation);
|
var players = GetPlayers(serverData.Node, serverData.MainAllocation);
|
||||||
var stats = await serverService.GetDetails(server);
|
var stats = await serverService.GetDetails(server);
|
||||||
|
|
||||||
var exception = exceptions.FirstOrDefault(x => x.ServerId == server.Id) != null;
|
var exception = exceptions.FirstOrDefault(x => x.Id == server.Id) != null;
|
||||||
|
|
||||||
if (stats != null)
|
if (stats != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,8 @@
|
|||||||
<_ContentIncludedByDefault Remove="wwwroot\css\site.css" />
|
<_ContentIncludedByDefault Remove="wwwroot\css\site.css" />
|
||||||
<_ContentIncludedByDefault Remove="Shared\Components\Tables\Column.razor" />
|
<_ContentIncludedByDefault Remove="Shared\Components\Tables\Column.razor" />
|
||||||
<_ContentIncludedByDefault Remove="Shared\Components\Tables\Table.razor" />
|
<_ContentIncludedByDefault Remove="Shared\Components\Tables\Table.razor" />
|
||||||
|
<_ContentIncludedByDefault Remove="Shared\Views\Admin\Servers\Cleanup\Exceptions\Add.razor" />
|
||||||
|
<_ContentIncludedByDefault Remove="Shared\Views\Admin\Servers\Cleanup\Exceptions\Edit.razor" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ namespace Moonlight
|
|||||||
builder.Services.AddScoped<AaPanelRepository>();
|
builder.Services.AddScoped<AaPanelRepository>();
|
||||||
builder.Services.AddScoped<WebsiteRepository>();
|
builder.Services.AddScoped<WebsiteRepository>();
|
||||||
builder.Services.AddScoped<DdosAttackRepository>();
|
builder.Services.AddScoped<DdosAttackRepository>();
|
||||||
builder.Services.AddScoped<CleanupExceptionRepository>();
|
|
||||||
|
|
||||||
builder.Services.AddScoped<AuditLogEntryRepository>();
|
builder.Services.AddScoped<AuditLogEntryRepository>();
|
||||||
builder.Services.AddScoped<ErrorLogEntryRepository>();
|
builder.Services.AddScoped<ErrorLogEntryRepository>();
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
|
|
||||||
<PageTitle><TL>Cleanup</TL></PageTitle>
|
<PageTitle>
|
||||||
|
<TL>Cleanup</TL>
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
<IsAdmin>
|
<IsAdmin>
|
||||||
<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
|
<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
|
||||||
@@ -25,8 +27,12 @@
|
|||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersCleaned)</span>
|
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersCleaned)</span>
|
||||||
<div class="fw-bold fs-6 text-white">
|
<div class="fw-bold fs-6 text-white">
|
||||||
<span class="d-block"><TL>Servers</TL></span>
|
<span class="d-block">
|
||||||
<span><TL>stopped</TL></span>
|
<TL>Servers</TL>
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<TL>stopped</TL>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -43,8 +49,12 @@
|
|||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.CleanupsPerformed)</span>
|
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.CleanupsPerformed)</span>
|
||||||
<div class="fw-bold fs-6 text-white">
|
<div class="fw-bold fs-6 text-white">
|
||||||
<span class="d-block"><TL>Cleanups</TL></span>
|
<span class="d-block">
|
||||||
<span><TL>executed</TL></span>
|
<TL>Cleanups</TL>
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<TL>executed</TL>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -61,8 +71,12 @@
|
|||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersRunning)</span>
|
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersRunning)</span>
|
||||||
<div class="fw-bold fs-6 text-white">
|
<div class="fw-bold fs-6 text-white">
|
||||||
<span class="d-block"><TL>Used clanup</TL></span>
|
<span class="d-block">
|
||||||
<span><TL>Servers</TL></span>
|
<TL>Used clanup</TL>
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<TL>Servers</TL>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -142,6 +156,7 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
|
|
||||||
protected async override Task OnAfterRenderAsync(bool firstRender)
|
protected async override Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender)
|
if (firstRender)
|
||||||
@@ -111,6 +111,10 @@
|
|||||||
<option value="@(DockerImages.IndexOf(image))">@(image.Name)</option>
|
<option value="@(DockerImages.IndexOf(image))">@(image.Name)</option>
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Cleanup exception</TL>
|
||||||
|
</label>
|
||||||
|
<input @bind="Server.IsCleanupException" class="form-control" type="checkbox" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-5">
|
<div class="row mb-5">
|
||||||
|
|||||||
@@ -427,3 +427,5 @@ Cleanup finished. Duration: 0.14 Minutes;Cleanup finished. Duration: 0.14 Minute
|
|||||||
Cleanup finished. Duration: 0.09 Minutes;Cleanup finished. Duration: 0.09 Minutes
|
Cleanup finished. Duration: 0.09 Minutes;Cleanup finished. Duration: 0.09 Minutes
|
||||||
Cleanup finished. Duration: 0.1 Minutes;Cleanup finished. Duration: 0.1 Minutes
|
Cleanup finished. Duration: 0.1 Minutes;Cleanup finished. Duration: 0.1 Minutes
|
||||||
Cleanup finished. Duration: 0.11 Minutes;Cleanup finished. Duration: 0.11 Minutes
|
Cleanup finished. Duration: 0.11 Minutes;Cleanup finished. Duration: 0.11 Minutes
|
||||||
|
Cleanup Exceptions;Cleanup Exceptions
|
||||||
|
Server not found;Server not found
|
||||||
|
|||||||
Reference in New Issue
Block a user