Merge pull request 'development' (#34) from development into enhancement/UserInfo

Reviewed-on: daniel-hbn/Watcher#34
This commit is contained in:
2025-06-21 13:39:05 +00:00
13 changed files with 1037 additions and 71 deletions

View File

@@ -36,7 +36,7 @@ public class AuthController : Controller
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(model); return View(model);
var user = await _context.Users.FirstOrDefaultAsync(u => u.PreferredUsername == model.Username); var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == model.Username);
if (user == null || !BCrypt.Net.BCrypt.Verify(model.Password, user.Password)) if (user == null || !BCrypt.Net.BCrypt.Verify(model.Password, user.Password))
{ {
ModelState.AddModelError("", "Benutzername oder Passwort ist falsch."); ModelState.AddModelError("", "Benutzername oder Passwort ist falsch.");
@@ -45,7 +45,7 @@ public class AuthController : Controller
var claims = new List<Claim> var claims = new List<Claim>
{ {
new Claim(ClaimTypes.Name, user.PreferredUsername), new Claim(ClaimTypes.Name, user.Username),
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
}; };
@@ -100,12 +100,12 @@ public class AuthController : Controller
public IActionResult Edit() public IActionResult Edit()
{ {
var username = User.Identity?.Name; var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); var user = _context.Users.FirstOrDefault(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
var model = new EditUserViewModel var model = new EditUserViewModel
{ {
Username = user.PreferredUsername Username = user.Username
}; };
return View(model); return View(model);
} }
@@ -119,10 +119,10 @@ public class AuthController : Controller
if (!ModelState.IsValid) return View(model); if (!ModelState.IsValid) return View(model);
var username = User.Identity?.Name; var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); var user = _context.Users.FirstOrDefault(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
user.PreferredUsername = model.Username; user.Username = model.Username;
if (!string.IsNullOrWhiteSpace(model.NewPassword)) if (!string.IsNullOrWhiteSpace(model.NewPassword))
{ {
@@ -144,7 +144,7 @@ public class AuthController : Controller
var username = User.Identity?.Name; var username = User.Identity?.Name;
var claims = User.Claims.Select(c => new { c.Type, c.Value }).ToList(); var claims = User.Claims.Select(c => new { c.Type, c.Value }).ToList();
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); var user = _context.Users.FirstOrDefault(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
var DbProvider = _context.Database.ProviderName; var DbProvider = _context.Database.ProviderName;
@@ -166,17 +166,17 @@ public class AuthController : Controller
if (!ModelState.IsValid) return View(model); if (!ModelState.IsValid) return View(model);
var username = User.Identity?.Name; var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); var user = _context.Users.FirstOrDefault(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
var databaseProvider = _context.Database.ProviderName; var databaseProvider = _context.Database.ProviderName;
user.PreferredUsername = model.Username; user.Username = model.Username;
// Passwort ändern // Passwort ändern
if (!string.IsNullOrWhiteSpace(model.NewPassword)) if (!string.IsNullOrWhiteSpace(model.NewPassword))
{ {
user.PreferredUsername = BCrypt.Net.BCrypt.HashPassword(model.NewPassword); user.Username = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
} }
_context.SaveChanges(); _context.SaveChanges();

View File

@@ -24,7 +24,7 @@ namespace Watcher.Controllers
var user = await _context.Users var user = await _context.Users
.Where(u => u.PreferredUsername == preferredUserName) .Where(u => u.Username == preferredUserName)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var viewModel = new DashboardViewModel var viewModel = new DashboardViewModel

View File

@@ -0,0 +1,316 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Watcher.Data;
#nullable disable
namespace Watcher.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250621124832_DB-Update Issue#32")]
partial class DBUpdateIssue32
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Hostname")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<bool>("IsRunning")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("TagId");
b.ToTable("Containers");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Tag")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Images");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("ContainerId")
.HasColumnType("INTEGER");
b.Property<string>("Level")
.HasColumnType("TEXT");
b.Property<string>("Message")
.HasColumnType("TEXT");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ContainerId");
b.HasIndex("ServerId");
b.ToTable("LogEvents");
});
modelBuilder.Entity("Watcher.Models.Metric", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double>("CPU_Load")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Size")
.HasColumnType("REAL");
b.Property<double>("DISK_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Usage")
.HasColumnType("REAL");
b.Property<double>("GPU_Load")
.HasColumnType("REAL");
b.Property<double>("GPU_Temp")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Size")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Usage")
.HasColumnType("REAL");
b.Property<double>("NET_In")
.HasColumnType("REAL");
b.Property<double>("NET_Out")
.HasColumnType("REAL");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Metrics");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CpuCores")
.HasColumnType("INTEGER");
b.Property<string>("CpuType")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("GpuType")
.HasColumnType("TEXT");
b.Property<string>("IPAddress")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsOnline")
.HasColumnType("INTEGER");
b.Property<DateTime>("LastSeen")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<double>("RamSize")
.HasColumnType("REAL");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TagId");
b.ToTable("Servers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Tags");
});
modelBuilder.Entity("Watcher.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<string>("IdentityProvider")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("LastLogin")
.HasColumnType("TEXT");
b.Property<string>("OIDC_Id")
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.HasOne("Watcher.Models.Image", "Image")
.WithMany("Containers")
.HasForeignKey("ImageId");
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Containers")
.HasForeignKey("TagId");
b.Navigation("Image");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.HasOne("Watcher.Models.Container", "Container")
.WithMany()
.HasForeignKey("ContainerId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.Navigation("Container");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Servers")
.HasForeignKey("TagId");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Navigation("Containers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Navigation("Containers");
b.Navigation("Servers");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,251 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Watcher.Migrations
{
/// <inheritdoc />
public partial class DBUpdateIssue32 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Metrics_Containers_ContainerId",
table: "Metrics");
migrationBuilder.DropForeignKey(
name: "FK_Metrics_Servers_ServerId",
table: "Metrics");
migrationBuilder.DropIndex(
name: "IX_Metrics_ContainerId",
table: "Metrics");
migrationBuilder.DropIndex(
name: "IX_Metrics_ServerId",
table: "Metrics");
migrationBuilder.DropColumn(
name: "PocketId",
table: "Users");
migrationBuilder.DropColumn(
name: "ContainerId",
table: "Metrics");
migrationBuilder.DropColumn(
name: "Type",
table: "Metrics");
migrationBuilder.RenameColumn(
name: "PreferredUsername",
table: "Users",
newName: "Username");
migrationBuilder.RenameColumn(
name: "Value",
table: "Metrics",
newName: "RAM_Size");
migrationBuilder.AddColumn<string>(
name: "OIDC_Id",
table: "Users",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<double>(
name: "CPU_Load",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "CPU_Temp",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "DISK_Size",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "DISK_Temp",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "DISK_Usage",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "GPU_Load",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "GPU_Temp",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "GPU_Vram_Size",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "GPU_Vram_Usage",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "NET_In",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "NET_Out",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<double>(
name: "RAM_Load",
table: "Metrics",
type: "REAL",
nullable: false,
defaultValue: 0.0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "OIDC_Id",
table: "Users");
migrationBuilder.DropColumn(
name: "CPU_Load",
table: "Metrics");
migrationBuilder.DropColumn(
name: "CPU_Temp",
table: "Metrics");
migrationBuilder.DropColumn(
name: "DISK_Size",
table: "Metrics");
migrationBuilder.DropColumn(
name: "DISK_Temp",
table: "Metrics");
migrationBuilder.DropColumn(
name: "DISK_Usage",
table: "Metrics");
migrationBuilder.DropColumn(
name: "GPU_Load",
table: "Metrics");
migrationBuilder.DropColumn(
name: "GPU_Temp",
table: "Metrics");
migrationBuilder.DropColumn(
name: "GPU_Vram_Size",
table: "Metrics");
migrationBuilder.DropColumn(
name: "GPU_Vram_Usage",
table: "Metrics");
migrationBuilder.DropColumn(
name: "NET_In",
table: "Metrics");
migrationBuilder.DropColumn(
name: "NET_Out",
table: "Metrics");
migrationBuilder.DropColumn(
name: "RAM_Load",
table: "Metrics");
migrationBuilder.RenameColumn(
name: "Username",
table: "Users",
newName: "PreferredUsername");
migrationBuilder.RenameColumn(
name: "RAM_Size",
table: "Metrics",
newName: "Value");
migrationBuilder.AddColumn<string>(
name: "PocketId",
table: "Users",
type: "TEXT",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<int>(
name: "ContainerId",
table: "Metrics",
type: "INTEGER",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Type",
table: "Metrics",
type: "TEXT",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Metrics_ContainerId",
table: "Metrics",
column: "ContainerId");
migrationBuilder.CreateIndex(
name: "IX_Metrics_ServerId",
table: "Metrics",
column: "ServerId");
migrationBuilder.AddForeignKey(
name: "FK_Metrics_Containers_ContainerId",
table: "Metrics",
column: "ContainerId",
principalTable: "Containers",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Metrics_Servers_ServerId",
table: "Metrics",
column: "ServerId",
principalTable: "Servers",
principalColumn: "Id");
}
}
}

View File

@@ -0,0 +1,319 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Watcher.Data;
#nullable disable
namespace Watcher.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250621125157_DB-Update Issue#32 IsVerified-Servers")]
partial class DBUpdateIssue32IsVerifiedServers
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Hostname")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<bool>("IsRunning")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("TagId");
b.ToTable("Containers");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Tag")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Images");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("ContainerId")
.HasColumnType("INTEGER");
b.Property<string>("Level")
.HasColumnType("TEXT");
b.Property<string>("Message")
.HasColumnType("TEXT");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ContainerId");
b.HasIndex("ServerId");
b.ToTable("LogEvents");
});
modelBuilder.Entity("Watcher.Models.Metric", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double>("CPU_Load")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Size")
.HasColumnType("REAL");
b.Property<double>("DISK_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Usage")
.HasColumnType("REAL");
b.Property<double>("GPU_Load")
.HasColumnType("REAL");
b.Property<double>("GPU_Temp")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Size")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Usage")
.HasColumnType("REAL");
b.Property<double>("NET_In")
.HasColumnType("REAL");
b.Property<double>("NET_Out")
.HasColumnType("REAL");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Metrics");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CpuCores")
.HasColumnType("INTEGER");
b.Property<string>("CpuType")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("GpuType")
.HasColumnType("TEXT");
b.Property<string>("IPAddress")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsOnline")
.HasColumnType("INTEGER");
b.Property<bool>("IsVerified")
.HasColumnType("INTEGER");
b.Property<DateTime>("LastSeen")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<double>("RamSize")
.HasColumnType("REAL");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TagId");
b.ToTable("Servers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Tags");
});
modelBuilder.Entity("Watcher.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<string>("IdentityProvider")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("LastLogin")
.HasColumnType("TEXT");
b.Property<string>("OIDC_Id")
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.HasOne("Watcher.Models.Image", "Image")
.WithMany("Containers")
.HasForeignKey("ImageId");
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Containers")
.HasForeignKey("TagId");
b.Navigation("Image");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.HasOne("Watcher.Models.Container", "Container")
.WithMany()
.HasForeignKey("ContainerId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.Navigation("Container");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Servers")
.HasForeignKey("TagId");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Navigation("Containers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Navigation("Containers");
b.Navigation("Servers");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Watcher.Migrations
{
/// <inheritdoc />
public partial class DBUpdateIssue32IsVerifiedServers : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsVerified",
table: "Servers",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsVerified",
table: "Servers");
}
}
}

View File

@@ -113,8 +113,44 @@ namespace Watcher.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int?>("ContainerId") b.Property<double>("CPU_Load")
.HasColumnType("INTEGER"); .HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Size")
.HasColumnType("REAL");
b.Property<double>("DISK_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Usage")
.HasColumnType("REAL");
b.Property<double>("GPU_Load")
.HasColumnType("REAL");
b.Property<double>("GPU_Temp")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Size")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Usage")
.HasColumnType("REAL");
b.Property<double>("NET_In")
.HasColumnType("REAL");
b.Property<double>("NET_Out")
.HasColumnType("REAL");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<int?>("ServerId") b.Property<int?>("ServerId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
@@ -122,18 +158,8 @@ namespace Watcher.Migrations
b.Property<DateTime>("Timestamp") b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Type")
.HasColumnType("TEXT");
b.Property<double>("Value")
.HasColumnType("REAL");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ContainerId");
b.HasIndex("ServerId");
b.ToTable("Metrics"); b.ToTable("Metrics");
}); });
@@ -165,6 +191,9 @@ namespace Watcher.Migrations
b.Property<bool>("IsOnline") b.Property<bool>("IsOnline")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<bool>("IsVerified")
.HasColumnType("INTEGER");
b.Property<DateTime>("LastSeen") b.Property<DateTime>("LastSeen")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -219,15 +248,14 @@ namespace Watcher.Migrations
b.Property<DateTime>("LastLogin") b.Property<DateTime>("LastLogin")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("OIDC_Id")
.HasColumnType("TEXT");
b.Property<string>("Password") b.Property<string>("Password")
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("PocketId") b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("PreferredUsername")
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -264,21 +292,6 @@ namespace Watcher.Migrations
b.Navigation("Server"); b.Navigation("Server");
}); });
modelBuilder.Entity("Watcher.Models.Metric", b =>
{
b.HasOne("Watcher.Models.Container", "Container")
.WithMany()
.HasForeignKey("ContainerId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.Navigation("Container");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.Server", b => modelBuilder.Entity("Watcher.Models.Server", b =>
{ {
b.HasOne("Watcher.Models.Tag", null) b.HasOne("Watcher.Models.Tag", null)

View File

@@ -2,15 +2,47 @@ namespace Watcher.Models;
public class Metric public class Metric
{ {
// Metric Metadata
public int Id { get; set; } public int Id { get; set; }
public DateTime Timestamp { get; set; } public DateTime Timestamp { get; set; }
public string? Type { get; set; } // z.B. "CPU", "RAM", "Disk", "Network"
public double Value { get; set; }
// Zuordnung zu einem Server -- Foreign Key
public int? ServerId { get; set; } public int? ServerId { get; set; }
public Server? Server { get; set; }
public int? ContainerId { get; set; }
public Container? Container { get; set; } // CPU-Daten
public double CPU_Load { get; set; } = 0.0; // %
public double CPU_Temp { get; set; } = 0.0; // deg C
// GPU-Daten
public double GPU_Load { get; set; } = 0.0; // %
public double GPU_Temp { get; set; } = 0.0; // deg C
public double GPU_Vram_Size { get; set; } // GB
public double GPU_Vram_Usage { get; set; } // %
// RAM-Daten
public double RAM_Size { get; set; } = 0.0; // GB
public double RAM_Load { get; set; } = 0.0; // %
// HDD-Daten
public double DISK_Size { get; set; } = 0.0; // GB
public double DISK_Usage { get; set; } = 0.0; // %
public double DISK_Temp { get; set; } = 0.0; // deg C
// Network-Daten
public double NET_In { get; set; } = 0.0; // Bit
public double NET_Out { get; set; } = 0.0; // Bit
} }

View File

@@ -5,32 +5,35 @@ namespace Watcher.Models;
public class Server public class Server
{ {
// System Infos
[Key] [Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = string.Empty; [Required]
public required string Name { get; set; }
public string IPAddress { get; set; } = string.Empty; public required string IPAddress { get; set; }
public required string Type { get; set; }
public string? Description { get; set; } = String.Empty;
// Hardware Infos
public string? CpuType { get; set; } = string.Empty;
public int CpuCores { get; set; } = 0;
public string? GpuType { get; set; } = string.Empty;
public double RamSize { get; set; } = 0;
// Database
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// z.B. "VPS", "standalone", "VM", etc.
public string Type { get; set; } = "VPS";
public Boolean IsOnline { get; set; } = false; public Boolean IsOnline { get; set; } = false;
public DateTime LastSeen { get; set; } public DateTime LastSeen { get; set; }
public string? Description { get; set; } public Boolean IsVerified { get; set; } = false;
// Hardware Infos
public string? CpuType { get; set; } = string.Empty;
public int CpuCores { get; set; }
public string? GpuType { get; set; } = string.Empty;
public double RamSize { get; set; }
} }

View File

@@ -1,12 +1,15 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Watcher.Models; namespace Watcher.Models;
public class User public class User
{ {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; } // PK public int Id { get; set; } // PK
public string PocketId { get; set; } = null!; public string? OIDC_Id { get; set; } = null!;
public string PreferredUsername { get; set; } = null!; public string Username { get; set; } = null!;
public string? Email { get; set; } public string? Email { get; set; }
public DateTime LastLogin { get; set; } public DateTime LastLogin { get; set; }

View File

@@ -95,14 +95,14 @@ builder.Services.AddAuthentication()
if (string.IsNullOrEmpty(pocketId)) if (string.IsNullOrEmpty(pocketId))
return; return;
var user = await db.Users.FirstOrDefaultAsync(u => u.PocketId == pocketId); var user = await db.Users.FirstOrDefaultAsync(u => u.OIDC_Id == pocketId);
if (user == null) if (user == null)
{ {
user = new User user = new User
{ {
PocketId = pocketId, OIDC_Id = pocketId,
PreferredUsername = preferredUsername ?? "", Username = preferredUsername ?? "",
Email = email, Email = email,
LastLogin = DateTime.UtcNow, LastLogin = DateTime.UtcNow,
IdentityProvider = "oidc", IdentityProvider = "oidc",
@@ -113,7 +113,7 @@ builder.Services.AddAuthentication()
else else
{ {
user.LastLogin = DateTime.UtcNow; user.LastLogin = DateTime.UtcNow;
user.PreferredUsername = preferredUsername ?? user.PreferredUsername; user.Username = preferredUsername ?? user.Username;
user.Email = email ?? user.Email; user.Email = email ?? user.Email;
db.Users.Update(user); db.Users.Update(user);
} }
@@ -151,8 +151,8 @@ using (var scope = app.Services.CreateScope())
var defaultUser = new User var defaultUser = new User
{ {
PocketId = string.Empty, OIDC_Id = string.Empty,
PreferredUsername = "admin", Username = "admin",
Email = string.Empty, Email = string.Empty,
LastLogin = DateTime.UtcNow, LastLogin = DateTime.UtcNow,
IdentityProvider = "local", IdentityProvider = "local",

Binary file not shown.

Binary file not shown.