From 29874a22bddf634fe3cbab186bb98a77c8f08413 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 4 Apr 2023 16:27:54 +0200 Subject: [PATCH 1/4] Added server node status screen check thingy --- Moonlight/Shared/Views/Server/Index.razor | 246 ++++++++++-------- Moonlight/resources/lang/de_de.lang | 4 + .../wwwroot/assets/media/svg/serverdown.svg | 1 + 3 files changed, 147 insertions(+), 104 deletions(-) create mode 100644 Moonlight/wwwroot/assets/media/svg/serverdown.svg diff --git a/Moonlight/Shared/Views/Server/Index.razor b/Moonlight/Shared/Views/Server/Index.razor index a6a6567d..eccbd3f9 100644 --- a/Moonlight/Shared/Views/Server/Index.razor +++ b/Moonlight/Shared/Views/Server/Index.razor @@ -17,6 +17,7 @@ @inject ServerRepository ServerRepository @inject WingsConsoleHelper WingsConsoleHelper @inject MessageService MessageService +@inject NodeService NodeService @inject NavigationManager NavigationManager @implements IDisposable @@ -26,10 +27,12 @@ {
- Not found image + Not found image
-

Server not found

-

+

+ Server not found +

+

A server with that id cannot be found or you have no access for this server

@@ -38,107 +41,126 @@ } else { - if (Console.ConnectionState == ConnectionState.Connected) + if (NodeOnline) { - if (Console.ServerState == ServerState.Installing) + if (Console.ConnectionState == ConnectionState.Connected) { -
-
-
-
- - Server installation is currently running - + if (Console.ServerState == ServerState.Installing) + { +
+
+
+
+ + Server installation is currently running + +
+
-
-
- } - else if (CurrentServer.Installing) - { -
-
-
-
- - Server installation is currently running - + } + else if (CurrentServer.Installing) + { +
+
+
+
+ + Server installation is currently running + +
+
-
-
- } - else - { - - - - - - - @{ - var index = 0; + } + else + { + + + + + + + @{ + var index = 0; - switch (Route) - { - case "files": - index = 1; - break; - case "backups": - index = 2; - break; - case "network": - index = 3; - break; - case "addons": - index = 4; - break; - case "settings": - index = 5; - break; - default: - index = 0; - break; + switch (Route) + { + case "files": + index = 1; + break; + case "backups": + index = 2; + break; + case "network": + index = 3; + break; + case "addons": + index = 4; + break; + case "settings": + index = 5; + break; + default: + index = 0; + break; + } } - } - - @switch (Route) - { - case "files": - - break; - case "backups": - - break; - case "network": - - break; - case "addons": - - break; - case "settings": - - break; - default: - - break; - } - + + @switch (Route) + { + case "files": + + break; + case "backups": + + break; + case "network": + + break; + case "addons": + + break; + case "settings": + + break; + default: + + break; + } + + - + } + } + else + { +
+ Connecting +
} } else { -
- Connecting +
+
+ Not found image +
+

+ Node offline +

+

+ The node the server is running on is currently offline +

+
+
} } @@ -149,7 +171,7 @@ [Parameter] public string ServerUuid { get; set; } - + [CascadingParameter] public User User { get; set; } @@ -159,6 +181,7 @@ private PteroConsole? Console; private Server? CurrentServer; private Node Node; + private bool NodeOnline = false; private Image Image; private NodeAllocation NodeAllocation; private string[] Tags; @@ -205,7 +228,7 @@ .Include(x => x.Owner) .First(x => x.Uuid == uuid); - if (CurrentServer.Owner.Id != User!.Id && User.Admin) + if (CurrentServer.Owner.Id != User!.Id && !User.Admin) CurrentServer = null; } catch (Exception) @@ -215,28 +238,43 @@ if (CurrentServer != null) { - await lazyLoader.SetText("Requesting tags"); + await lazyLoader.SetText("Checking node online status"); - var image = ImageRepository - .Get() - .First(x => x.Id == CurrentServer.Image.Id); - - Tags = JsonConvert.DeserializeObject(image.TagsJson) ?? Array.Empty(); - Image = image; - - await lazyLoader.SetText("Connecting to console"); - - await WingsConsoleHelper.ConnectWings(Console!, CurrentServer); - - MessageService.Subscribe($"server.{CurrentServer.Uuid}.installcomplete", this, server => + try { - Task.Run(() => + //TODO: Implement status caching + var data = await NodeService.GetStatus(CurrentServer.Node); + + if (data != null) + NodeOnline = true; + } + catch (Exception) + { + // ignored + } + + if (NodeOnline) + { + await lazyLoader.SetText("Requesting tags"); + + var image = ImageRepository + .Get() + .First(x => x.Id == CurrentServer.Image.Id); + + Tags = JsonConvert.DeserializeObject(image.TagsJson) ?? Array.Empty(); + Image = image; + + await lazyLoader.SetText("Connecting to console"); + + await WingsConsoleHelper.ConnectWings(Console!, CurrentServer); + + MessageService.Subscribe($"server.{CurrentServer.Uuid}.installcomplete", this, server => { - NavigationManager.NavigateTo(NavigationManager.Uri); + Task.Run(() => { NavigationManager.NavigateTo(NavigationManager.Uri); }); + + return Task.CompletedTask; }); - - return Task.CompletedTask; - }); + } } else { diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 8e6714e3..429e88a1 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -478,3 +478,7 @@ Enter your information;Enter your information You need to enter your full name in order to use moonlight;You need to enter your full name in order to use moonlight No node found;No node found No node found to deploy to found;No node found to deploy to found +Node offline;Node offline +The node the server is running on is currently offline;The node the server is running on is currently offline +Server not found;Server not found +A server with that id cannot be found or you have no access for this server;A server with that id cannot be found or you have no access for this server diff --git a/Moonlight/wwwroot/assets/media/svg/serverdown.svg b/Moonlight/wwwroot/assets/media/svg/serverdown.svg new file mode 100644 index 00000000..ca37dc52 --- /dev/null +++ b/Moonlight/wwwroot/assets/media/svg/serverdown.svg @@ -0,0 +1 @@ +server down \ No newline at end of file From a80807f2464cf8ab85e2c268413d6ab7f4efc4e5 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 4 Apr 2023 16:31:09 +0200 Subject: [PATCH 2/4] Update CacheLogger.cs --- Moonlight/App/Helpers/CacheLogger.cs | 45 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/Moonlight/App/Helpers/CacheLogger.cs b/Moonlight/App/Helpers/CacheLogger.cs index b8feb5ad..ef9e0c37 100644 --- a/Moonlight/App/Helpers/CacheLogger.cs +++ b/Moonlight/App/Helpers/CacheLogger.cs @@ -29,8 +29,11 @@ public class CacheLogger : ILogger } } - public void Info(string s) + public void Info(string? s) { + if (s == null) + return; + lock (Messages) { Messages.Add(new() @@ -39,12 +42,15 @@ public class CacheLogger : ILogger Message = s }); } - + SbLogger.Info(s); } - public void Debug(string s) + public void Debug(string? s) { + if (s == null) + return; + lock (Messages) { Messages.Add(new() @@ -53,12 +59,15 @@ public class CacheLogger : ILogger Message = s }); } - + SbLogger.Debug(s); } - public void Warn(string s) + public void Warn(string? s) { + if (s == null) + return; + lock (Messages) { Messages.Add(new() @@ -67,12 +76,15 @@ public class CacheLogger : ILogger Message = s }); } - + SbLogger.Warn(s); } - public void Error(string s) + public void Error(string? s) { + if (s == null) + return; + lock (Messages) { Messages.Add(new() @@ -81,12 +93,15 @@ public class CacheLogger : ILogger Message = s }); } - + SbLogger.Error(s); } - public void Fatal(string s) + public void Fatal(string? s) { + if (s == null) + return; + lock (Messages) { Messages.Add(new() @@ -95,7 +110,7 @@ public class CacheLogger : ILogger Message = s }); } - + SbLogger.Fatal(s); } @@ -109,7 +124,7 @@ public class CacheLogger : ILogger Message = ex.ToStringDemystified() }); } - + SbLogger.InfoEx(ex); } @@ -123,7 +138,7 @@ public class CacheLogger : ILogger Message = ex.ToStringDemystified() }); } - + SbLogger.DebugEx(ex); } @@ -137,7 +152,7 @@ public class CacheLogger : ILogger Message = ex.ToStringDemystified() }); } - + SbLogger.WarnEx(ex); } @@ -151,7 +166,7 @@ public class CacheLogger : ILogger Message = ex.ToStringDemystified() }); } - + SbLogger.ErrorEx(ex); } @@ -165,7 +180,7 @@ public class CacheLogger : ILogger Message = ex.ToStringDemystified() }); } - + SbLogger.FatalEx(ex); } From 2f0483da13dcd83262cd77c3e19024f40d091d67 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 4 Apr 2023 16:41:14 +0200 Subject: [PATCH 3/4] Update View.razor --- Moonlight/Shared/Views/Admin/Users/View.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moonlight/Shared/Views/Admin/Users/View.razor b/Moonlight/Shared/Views/Admin/Users/View.razor index b4851f22..0d4d9e66 100644 --- a/Moonlight/Shared/Views/Admin/Users/View.razor +++ b/Moonlight/Shared/Views/Admin/Users/View.razor @@ -186,7 +186,7 @@ else Discord
- @* TODO: Implement discord fetching here *@ + @(User.DiscordId)
From 96cc8b8b970c7ebd81c55e1ed993a5b4fe7a9b50 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 4 Apr 2023 18:46:42 +0200 Subject: [PATCH 4/4] Removed legacy aaPanel stuff --- Moonlight/App/Database/DataContext.cs | 3 - Moonlight/App/Database/Entities/AaPanel.cs | 9 - Moonlight/App/Database/Entities/Database.cs | 10 - Moonlight/App/Database/Entities/Website.cs | 13 - ...3809_RemovedLegacyAaPanelStuff.Designer.cs | 876 ++++++++++++++++++ ...0230404163809_RemovedLegacyAaPanelStuff.cs | 133 +++ .../Migrations/DataContextModelSnapshot.cs | 129 --- .../App/Repositories/AaPanelRepository.cs | 44 - .../App/Repositories/DatabaseRepository.cs | 43 - .../App/Repositories/WebsiteRepository.cs | 44 - Moonlight/App/Services/DatabaseService.cs | 76 -- Moonlight/App/Services/WebsiteService.cs | 39 - Moonlight/Program.cs | 4 - Moonlight/Shared/Views/Admin/Index.razor | 3 +- Moonlight/Shared/Views/Index.razor | 9 +- 15 files changed, 1012 insertions(+), 423 deletions(-) delete mode 100644 Moonlight/App/Database/Entities/AaPanel.cs delete mode 100644 Moonlight/App/Database/Entities/Database.cs delete mode 100644 Moonlight/App/Database/Entities/Website.cs create mode 100644 Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.Designer.cs create mode 100644 Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.cs delete mode 100644 Moonlight/App/Repositories/AaPanelRepository.cs delete mode 100644 Moonlight/App/Repositories/DatabaseRepository.cs delete mode 100644 Moonlight/App/Repositories/WebsiteRepository.cs delete mode 100644 Moonlight/App/Services/DatabaseService.cs delete mode 100644 Moonlight/App/Services/WebsiteService.cs diff --git a/Moonlight/App/Database/DataContext.cs b/Moonlight/App/Database/DataContext.cs index 3e2875f4..906ce00c 100644 --- a/Moonlight/App/Database/DataContext.cs +++ b/Moonlight/App/Database/DataContext.cs @@ -30,7 +30,6 @@ public class DataContext : DbContext public DbSet AuditLog { get; set; } public DbSet ErrorLog { get; set; } public DbSet SecurityLog { get; set; } - public DbSet Databases { get; set; } public DbSet SupportMessages { get; set; } public DbSet SharedDomains { get; set; } @@ -38,8 +37,6 @@ public class DataContext : DbContext public DbSet Revokes { get; set; } public DbSet NotificationClients { get; set; } public DbSet NotificationActions { get; set; } - public DbSet AaPanels { get; set; } - public DbSet Websites { get; set; } public DbSet DdosAttacks { get; set; } public DbSet Subscriptions { get; set; } diff --git a/Moonlight/App/Database/Entities/AaPanel.cs b/Moonlight/App/Database/Entities/AaPanel.cs deleted file mode 100644 index da79d53e..00000000 --- a/Moonlight/App/Database/Entities/AaPanel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Moonlight.App.Database.Entities; - -public class AaPanel -{ - public int Id { get; set; } - public string Url { get; set; } = ""; - public string Key { get; set; } = ""; - public string BaseDomain { get; set; } = ""; -} \ No newline at end of file diff --git a/Moonlight/App/Database/Entities/Database.cs b/Moonlight/App/Database/Entities/Database.cs deleted file mode 100644 index c14c1392..00000000 --- a/Moonlight/App/Database/Entities/Database.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Moonlight.App.Database.Entities; - -public class Database -{ - public int Id { get; set; } - public int InternalAaPanelId { get; set; } - public User Owner { get; set; } - public AaPanel AaPanel { get; set; } - public string Name { get; set; } -} \ No newline at end of file diff --git a/Moonlight/App/Database/Entities/Website.cs b/Moonlight/App/Database/Entities/Website.cs deleted file mode 100644 index d5c86d97..00000000 --- a/Moonlight/App/Database/Entities/Website.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Moonlight.App.Database.Entities; - -public class Website -{ - public int Id { get; set; } - public int InternalAaPanelId { get; set; } - public AaPanel AaPanel { get; set; } - public User Owner { get; set; } - public string DomainName { get; set; } - public string PhpVersion { get; set; } - public string FtpUsername { get; set; } - public string FtpPassword { get; set; } -} \ No newline at end of file diff --git a/Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.Designer.cs b/Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.Designer.cs new file mode 100644 index 00000000..5220ef2c --- /dev/null +++ b/Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.Designer.cs @@ -0,0 +1,876 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Moonlight.App.Database; + +#nullable disable + +namespace Moonlight.App.Database.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20230404163809_RemovedLegacyAaPanelStuff")] + partial class RemovedLegacyAaPanelStuff + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DdosAttack", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("bigint"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Ongoing") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.ToTable("DdosAttacks"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DockerImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Default") + .HasColumnType("tinyint(1)"); + + b.Property("ImageId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.ToTable("DockerImages"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Domain", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("SharedDomainId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.HasIndex("SharedDomainId"); + + b.ToTable("Domains"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Image", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Allocations") + .HasColumnType("int"); + + b.Property("ConfigFiles") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallDockerImage") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallEntrypoint") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("InstallScript") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Startup") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StartupDetection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StopCommand") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TagsJson") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Uuid") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ImageTag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("ImageTags"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ImageVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("DefaultValue") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ImageId") + .HasColumnType("int"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.ToTable("ImageVariables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LoadingMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Message") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("LoadingMessages"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LogsEntries.AuditLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("JsonData") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("System") + .HasColumnType("tinyint(1)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("AuditLog"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LogsEntries.ErrorLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Class") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("JsonData") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Stacktrace") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("System") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("ErrorLog"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.LogsEntries.SecurityLogEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("JsonData") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("System") + .HasColumnType("tinyint(1)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("SecurityLog"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Node", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Fqdn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HttpPort") + .HasColumnType("int"); + + b.Property("MoonlightDaemonPort") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("SftpPort") + .HasColumnType("int"); + + b.Property("Ssl") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TokenId") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Nodes"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.NodeAllocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.HasIndex("ServerId"); + + b.ToTable("NodeAllocations"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationAction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Action") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NotificationClientId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("NotificationClientId"); + + b.ToTable("NotificationActions"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("NotificationClients"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Revoke", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Identifier") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Revokes"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Cpu") + .HasColumnType("int"); + + b.Property("Disk") + .HasColumnType("bigint"); + + b.Property("DockerImageIndex") + .HasColumnType("int"); + + b.Property("ImageId") + .HasColumnType("int"); + + b.Property("Installing") + .HasColumnType("tinyint(1)"); + + b.Property("IsCleanupException") + .HasColumnType("tinyint(1)"); + + b.Property("MainAllocationId") + .HasColumnType("int"); + + b.Property("Memory") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NodeId") + .HasColumnType("int"); + + b.Property("OverrideStartup") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OwnerId") + .HasColumnType("int"); + + b.Property("Suspended") + .HasColumnType("tinyint(1)"); + + b.Property("Uuid") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.HasIndex("MainAllocationId"); + + b.HasIndex("NodeId"); + + b.HasIndex("OwnerId"); + + b.ToTable("Servers"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerBackup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Bytes") + .HasColumnType("bigint"); + + b.Property("Created") + .HasColumnType("tinyint(1)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Uuid") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerBackups"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerVariable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Key") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ServerId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ServerId"); + + b.ToTable("ServerVariables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.SharedDomain", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CloudflareId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("SharedDomains"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LimitsJson") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.SupportMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Answer") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsQuestion") + .HasColumnType("tinyint(1)"); + + b.Property("IsSupport") + .HasColumnType("tinyint(1)"); + + b.Property("IsSystem") + .HasColumnType("tinyint(1)"); + + b.Property("Message") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RecipientId") + .HasColumnType("int"); + + b.Property("SenderId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RecipientId"); + + b.HasIndex("SenderId"); + + b.ToTable("SupportMessages"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Address") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Admin") + .HasColumnType("tinyint(1)"); + + b.Property("City") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Country") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CurrentSubscriptionId") + .HasColumnType("int"); + + b.Property("DiscordId") + .HasColumnType("bigint"); + + b.Property("Email") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Password") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("State") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("SubscriptionDuration") + .HasColumnType("int"); + + b.Property("SubscriptionSince") + .HasColumnType("datetime(6)"); + + b.Property("SupportPending") + .HasColumnType("tinyint(1)"); + + b.Property("TokenValidTime") + .HasColumnType("datetime(6)"); + + b.Property("TotpEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("TotpSecret") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("CurrentSubscriptionId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DdosAttack", b => + { + b.HasOne("Moonlight.App.Database.Entities.Node", "Node") + .WithMany() + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Node"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.DockerImage", b => + { + b.HasOne("Moonlight.App.Database.Entities.Image", null) + .WithMany("DockerImages") + .HasForeignKey("ImageId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Domain", b => + { + b.HasOne("Moonlight.App.Database.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.SharedDomain", "SharedDomain") + .WithMany() + .HasForeignKey("SharedDomainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Owner"); + + b.Navigation("SharedDomain"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ImageVariable", b => + { + b.HasOne("Moonlight.App.Database.Entities.Image", null) + .WithMany("Variables") + .HasForeignKey("ImageId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.NodeAllocation", b => + { + b.HasOne("Moonlight.App.Database.Entities.Node", null) + .WithMany("Allocations") + .HasForeignKey("NodeId"); + + b.HasOne("Moonlight.App.Database.Entities.Server", null) + .WithMany("Allocations") + .HasForeignKey("ServerId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationAction", b => + { + b.HasOne("Moonlight.App.Database.Entities.Notification.NotificationClient", "NotificationClient") + .WithMany() + .HasForeignKey("NotificationClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("NotificationClient"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Notification.NotificationClient", b => + { + b.HasOne("Moonlight.App.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Server", b => + { + b.HasOne("Moonlight.App.Database.Entities.Image", "Image") + .WithMany() + .HasForeignKey("ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.NodeAllocation", "MainAllocation") + .WithMany() + .HasForeignKey("MainAllocationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.Node", "Node") + .WithMany() + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Moonlight.App.Database.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + + b.Navigation("MainAllocation"); + + b.Navigation("Node"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerBackup", b => + { + b.HasOne("Moonlight.App.Database.Entities.Server", null) + .WithMany("Backups") + .HasForeignKey("ServerId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.ServerVariable", b => + { + b.HasOne("Moonlight.App.Database.Entities.Server", null) + .WithMany("Variables") + .HasForeignKey("ServerId"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.SupportMessage", b => + { + b.HasOne("Moonlight.App.Database.Entities.User", "Recipient") + .WithMany() + .HasForeignKey("RecipientId"); + + b.HasOne("Moonlight.App.Database.Entities.User", "Sender") + .WithMany() + .HasForeignKey("SenderId"); + + b.Navigation("Recipient"); + + b.Navigation("Sender"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.User", b => + { + b.HasOne("Moonlight.App.Database.Entities.Subscription", "CurrentSubscription") + .WithMany() + .HasForeignKey("CurrentSubscriptionId"); + + b.Navigation("CurrentSubscription"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Image", b => + { + b.Navigation("DockerImages"); + + b.Navigation("Variables"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Node", b => + { + b.Navigation("Allocations"); + }); + + modelBuilder.Entity("Moonlight.App.Database.Entities.Server", b => + { + b.Navigation("Allocations"); + + b.Navigation("Backups"); + + b.Navigation("Variables"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.cs b/Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.cs new file mode 100644 index 00000000..aee8be1d --- /dev/null +++ b/Moonlight/App/Database/Migrations/20230404163809_RemovedLegacyAaPanelStuff.cs @@ -0,0 +1,133 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Moonlight.App.Database.Migrations +{ + /// + public partial class RemovedLegacyAaPanelStuff : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Databases"); + + migrationBuilder.DropTable( + name: "Websites"); + + migrationBuilder.DropTable( + name: "AaPanels"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AaPanels", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + BaseDomain = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Key = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Url = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_AaPanels", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Databases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + AaPanelId = table.Column(type: "int", nullable: false), + OwnerId = table.Column(type: "int", nullable: false), + InternalAaPanelId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Databases", x => x.Id); + table.ForeignKey( + name: "FK_Databases_AaPanels_AaPanelId", + column: x => x.AaPanelId, + principalTable: "AaPanels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Databases_Users_OwnerId", + column: x => x.OwnerId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Websites", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + AaPanelId = table.Column(type: "int", nullable: false), + OwnerId = table.Column(type: "int", nullable: false), + DomainName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + FtpPassword = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + FtpUsername = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + InternalAaPanelId = table.Column(type: "int", nullable: false), + PhpVersion = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Websites", x => x.Id); + table.ForeignKey( + name: "FK_Websites_AaPanels_AaPanelId", + column: x => x.AaPanelId, + principalTable: "AaPanels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Websites_Users_OwnerId", + column: x => x.OwnerId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Databases_AaPanelId", + table: "Databases", + column: "AaPanelId"); + + migrationBuilder.CreateIndex( + name: "IX_Databases_OwnerId", + table: "Databases", + column: "OwnerId"); + + migrationBuilder.CreateIndex( + name: "IX_Websites_AaPanelId", + table: "Websites", + column: "AaPanelId"); + + migrationBuilder.CreateIndex( + name: "IX_Websites_OwnerId", + table: "Websites", + column: "OwnerId"); + } + } +} diff --git a/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs b/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs index d670d747..65062e19 100644 --- a/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs +++ b/Moonlight/App/Database/Migrations/DataContextModelSnapshot.cs @@ -19,57 +19,6 @@ namespace Moonlight.App.Database.Migrations .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 64); - modelBuilder.Entity("Moonlight.App.Database.Entities.AaPanel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("BaseDomain") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Key") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Url") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("AaPanels"); - }); - - modelBuilder.Entity("Moonlight.App.Database.Entities.Database", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("AaPanelId") - .HasColumnType("int"); - - b.Property("InternalAaPanelId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("AaPanelId"); - - b.HasIndex("OwnerId"); - - b.ToTable("Databases"); - }); - modelBuilder.Entity("Moonlight.App.Database.Entities.DdosAttack", b => { b.Property("Id") @@ -748,65 +697,6 @@ namespace Moonlight.App.Database.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("Moonlight.App.Database.Entities.Website", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("AaPanelId") - .HasColumnType("int"); - - b.Property("DomainName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("FtpPassword") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("FtpUsername") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("InternalAaPanelId") - .HasColumnType("int"); - - b.Property("OwnerId") - .HasColumnType("int"); - - b.Property("PhpVersion") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("AaPanelId"); - - b.HasIndex("OwnerId"); - - b.ToTable("Websites"); - }); - - modelBuilder.Entity("Moonlight.App.Database.Entities.Database", b => - { - b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel") - .WithMany() - .HasForeignKey("AaPanelId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Moonlight.App.Database.Entities.User", "Owner") - .WithMany() - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("AaPanel"); - - b.Navigation("Owner"); - }); - modelBuilder.Entity("Moonlight.App.Database.Entities.DdosAttack", b => { b.HasOne("Moonlight.App.Database.Entities.Node", "Node") @@ -957,25 +847,6 @@ namespace Moonlight.App.Database.Migrations b.Navigation("CurrentSubscription"); }); - modelBuilder.Entity("Moonlight.App.Database.Entities.Website", b => - { - b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel") - .WithMany() - .HasForeignKey("AaPanelId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Moonlight.App.Database.Entities.User", "Owner") - .WithMany() - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("AaPanel"); - - b.Navigation("Owner"); - }); - modelBuilder.Entity("Moonlight.App.Database.Entities.Image", b => { b.Navigation("DockerImages"); diff --git a/Moonlight/App/Repositories/AaPanelRepository.cs b/Moonlight/App/Repositories/AaPanelRepository.cs deleted file mode 100644 index 92870f85..00000000 --- a/Moonlight/App/Repositories/AaPanelRepository.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database; -using Moonlight.App.Database.Entities; - -namespace Moonlight.App.Repositories; - -public class AaPanelRepository : IDisposable -{ - private readonly DataContext DataContext; - - public AaPanelRepository(DataContext dataContext) - { - DataContext = dataContext; - } - - public DbSet Get() - { - return DataContext.AaPanels; - } - - public AaPanel Add(AaPanel aaPanel) - { - var x = DataContext.AaPanels.Add(aaPanel); - DataContext.SaveChanges(); - return x.Entity; - } - - public void Update(AaPanel aaPanel) - { - DataContext.AaPanels.Update(aaPanel); - DataContext.SaveChanges(); - } - - public void Delete(AaPanel aaPanel) - { - DataContext.AaPanels.Remove(aaPanel); - DataContext.SaveChanges(); - } - - public void Dispose() - { - DataContext.Dispose(); - } -} \ No newline at end of file diff --git a/Moonlight/App/Repositories/DatabaseRepository.cs b/Moonlight/App/Repositories/DatabaseRepository.cs deleted file mode 100644 index 020c72e8..00000000 --- a/Moonlight/App/Repositories/DatabaseRepository.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database; - -namespace Moonlight.App.Repositories; - -public class DatabaseRepository : IDisposable -{ - private readonly DataContext DataContext; - - public DatabaseRepository(DataContext dataContext) - { - DataContext = dataContext; - } - - public DbSet Get() - { - return DataContext.Databases; - } - - public Database.Entities.Database Add(Database.Entities.Database database) - { - var x = DataContext.Databases.Add(database); - DataContext.SaveChanges(); - return x.Entity; - } - - public void Update(Database.Entities.Database database) - { - DataContext.Databases.Update(database); - DataContext.SaveChanges(); - } - - public void Delete(Database.Entities.Database database) - { - DataContext.Databases.Remove(database); - DataContext.SaveChanges(); - } - - public void Dispose() - { - DataContext.Dispose(); - } -} \ No newline at end of file diff --git a/Moonlight/App/Repositories/WebsiteRepository.cs b/Moonlight/App/Repositories/WebsiteRepository.cs deleted file mode 100644 index aedf91f4..00000000 --- a/Moonlight/App/Repositories/WebsiteRepository.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database; -using Moonlight.App.Database.Entities; - -namespace Moonlight.App.Repositories; - -public class WebsiteRepository : IDisposable -{ - private readonly DataContext DataContext; - - public WebsiteRepository(DataContext dataContext) - { - DataContext = dataContext; - } - - public DbSet Get() - { - return DataContext.Websites; - } - - public Website Add(Website website) - { - var x = DataContext.Websites.Add(website); - DataContext.SaveChanges(); - return x.Entity; - } - - public void Update(Website website) - { - DataContext.Websites.Update(website); - DataContext.SaveChanges(); - } - - public void Delete(Website website) - { - DataContext.Websites.Remove(website); - DataContext.SaveChanges(); - } - - public void Dispose() - { - DataContext.Dispose(); - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/DatabaseService.cs b/Moonlight/App/Services/DatabaseService.cs deleted file mode 100644 index 33e5988f..00000000 --- a/Moonlight/App/Services/DatabaseService.cs +++ /dev/null @@ -1,76 +0,0 @@ -using aaPanelSharp; -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database.Entities; -using Moonlight.App.Exceptions; -using Moonlight.App.Repositories; - -namespace Moonlight.App.Services; - -public class DatabaseService -{ - private readonly DatabaseRepository DatabaseRepository; - private readonly AaPanelRepository AaPanelRepository; - - public DatabaseService(DatabaseRepository databaseRepository, AaPanelRepository aaPanelRepository) - { - DatabaseRepository = databaseRepository; - AaPanelRepository = aaPanelRepository; - } - - public Task Create(string name, string password, User u, AaPanel? a = null) - { - if (DatabaseRepository.Get().Any(x => x.Name == name)) - throw new DisplayException("A database with this name has been already created"); - - var aaPanel = a ?? AaPanelRepository.Get().First(); - - var access = new aaPanel(a!.Url, a.Key); - - if (access.CreateDatabase(name, name, password)) - { - var aaDb = access.Databases.First(x => x.Name == name); - - return Task.FromResult(DatabaseRepository.Add(new() - { - Name = name, - AaPanel = aaPanel, - Owner = u, - InternalAaPanelId = aaDb.Id - })); - } - else - throw new DisplayException("An unknown error occured while creating the database"); - } - - public Task ChangePassword(Database.Entities.Database database, string newPassword) - { - var access = CreateApiAccess(database); - - access.Databases.First(x => x.Id == database.InternalAaPanelId).ChangePassword(newPassword); - - return Task.CompletedTask; - } - - public Task GetPassword(Database.Entities.Database database) - { - var access = CreateApiAccess(database); - - return Task.FromResult( - access.Databases - .First(x => x.Id == database.InternalAaPanelId).Password - ); - } - - private aaPanel CreateApiAccess(Database.Entities.Database database) - { - if (database.AaPanel == null) - { - database = DatabaseRepository - .Get() - .Include(x => x.AaPanel) - .First(x => x.Id == database.Id); - } - - return new aaPanel(database.AaPanel.Url, database.AaPanel.Key); - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/WebsiteService.cs b/Moonlight/App/Services/WebsiteService.cs deleted file mode 100644 index 4cdda657..00000000 --- a/Moonlight/App/Services/WebsiteService.cs +++ /dev/null @@ -1,39 +0,0 @@ -using aaPanelSharp; -using Microsoft.EntityFrameworkCore; -using Moonlight.App.Database.Entities; -using Moonlight.App.Exceptions; -using Moonlight.App.Repositories; - -namespace Moonlight.App.Services; - -public class WebsiteService -{ - private readonly WebsiteRepository WebsiteRepository; - - public WebsiteService(WebsiteRepository websiteRepository) - { - WebsiteRepository = websiteRepository; - } - - public Website Create(AaPanel aaPanel, User user, string name) - { - if (WebsiteRepository.Get().Any(x => x.DomainName == name)) - throw new DisplayException("A website with this domain has already been created"); - - var access = new aaPanel(aaPanel.Url, aaPanel.Key); - return null; - } - - private aaPanel CreateApiAccess(Website website) - { - if (website.AaPanel == null) - { - website = WebsiteRepository - .Get() - .Include(x => x.AaPanel) - .First(x => x.Id == website.Id); - } - - return new aaPanel(website.AaPanel.Url, website.AaPanel.Key); - } -} \ No newline at end of file diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index cb4fdcf3..5b4efebf 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -52,15 +52,12 @@ namespace Moonlight builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -108,7 +105,6 @@ namespace Moonlight builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); - builder.Services.AddScoped(); // Support builder.Services.AddSingleton(); diff --git a/Moonlight/Shared/Views/Admin/Index.razor b/Moonlight/Shared/Views/Admin/Index.razor index e4ccd49e..7fc0a182 100644 --- a/Moonlight/Shared/Views/Admin/Index.razor +++ b/Moonlight/Shared/Views/Admin/Index.razor @@ -3,7 +3,6 @@ @using Moonlight.App.Repositories @inject ServerRepository ServerRepository -@inject DatabaseRepository DatabaseRepository @inject UserRepository UserRepository @@ -126,7 +125,7 @@ private Task Load(LazyLoader lazyLoader) { - DatabaseCount = DatabaseRepository.Get().Count(); + DatabaseCount = 0; ServerCount = ServerRepository.Get().Count(); UserCount = UserRepository.Get().Count(); diff --git a/Moonlight/Shared/Views/Index.razor b/Moonlight/Shared/Views/Index.razor index 44de7963..585cac6b 100644 --- a/Moonlight/Shared/Views/Index.razor +++ b/Moonlight/Shared/Views/Index.razor @@ -1,11 +1,9 @@ @page "/" -@using Moonlight.App.Repositories + @using Moonlight.App.Repositories.Servers @using Microsoft.EntityFrameworkCore @using Moonlight.App.Database.Entities -@using Moonlight.App.Services.Sessions -@inject DatabaseRepository DatabaseRepository @inject ServerRepository ServerRepository @@ -246,10 +244,7 @@ private async Task Load(LazyLoader lazyLoader) { - DatabaseCount = DatabaseRepository - .Get() - .Include(x => x.Owner) - .Count(x => x.Owner.Id == User.Id); + DatabaseCount = 0; ServerCount = ServerRepository .Get()