diff --git a/Moonlight/App/Database/DataContext.cs b/Moonlight/App/Database/DataContext.cs index 3e2875f..906ce00 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 da79d53..0000000 --- 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 c14c139..0000000 --- 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 d5c86d9..0000000 --- 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 0000000..5220ef2 --- /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 0000000..aee8be1 --- /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 d670d74..65062e1 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 92870f8..0000000 --- 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 020c72e..0000000 --- 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 aedf91f..0000000 --- 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 33e5988..0000000 --- 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 4cdda65..0000000 --- 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 cb4fdcf..5b4efeb 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 e4ccd49..7fc0a18 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 44de796..585cac6 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()