Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad9b6bfdaf | |||
| d23a73c0d5 | |||
| 985d388a44 | |||
| 742eb37694 | |||
| b01cf1fd50 | |||
| a2c6071960 | |||
| 4523867a61 | |||
| 8727aff861 | |||
| 301d2309c9 | |||
| 7a096ee29c | |||
| 1d734f2951 | |||
| d8b164e3eb | |||
| 05e5a209da | |||
| 0b88292a85 | |||
| 5bae9328d9 | |||
| 3a872980da | |||
| 8cda82111d | |||
| 6e17dcb270 | |||
| a1f9a2008f |
@@ -44,6 +44,17 @@ services:
|
|||||||
# Aktualisierungsrate Frontend
|
# Aktualisierungsrate Frontend
|
||||||
- FRONTEND_REFRESH_INTERVAL_SECONDS=30
|
- FRONTEND_REFRESH_INTERVAL_SECONDS=30
|
||||||
|
|
||||||
|
# OIDC-Authentifizierung (Optional)
|
||||||
|
# - OIDC_ENABLED=true
|
||||||
|
# - OIDC_AUTHORITY=https://auth.example.com/realms/myrealm
|
||||||
|
# - OIDC_CLIENT_ID=watcher-client
|
||||||
|
# - OIDC_CLIENT_SECRET=your-client-secret
|
||||||
|
# - OIDC_SCOPES=openid profile email
|
||||||
|
# - OIDC_CALLBACK_PATH=/signin-oidc
|
||||||
|
# - OIDC_CLAIM_USERNAME=preferred_username
|
||||||
|
# - OIDC_CLAIM_EMAIL=email
|
||||||
|
# - OIDC_AUTO_PROVISION_USERS=true
|
||||||
|
|
||||||
# Ports
|
# Ports
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "5000:5000"
|
||||||
|
|||||||
58
watcher-monitoring/Attributes/ApiKeyAuthAttribute.cs
Normal file
58
watcher-monitoring/Attributes/ApiKeyAuthAttribute.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Attributes;
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
||||||
|
public class ApiKeyAuthAttribute : Attribute, IAsyncActionFilter
|
||||||
|
{
|
||||||
|
private const string ApiKeyHeaderName = "X-API-Key";
|
||||||
|
|
||||||
|
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||||
|
{
|
||||||
|
if (!context.HttpContext.Request.Headers.TryGetValue(ApiKeyHeaderName, out var extractedApiKey))
|
||||||
|
{
|
||||||
|
context.Result = new UnauthorizedObjectResult(new { error = "API-Key fehlt im Header" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiKeyString = extractedApiKey.ToString();
|
||||||
|
|
||||||
|
var dbContext = context.HttpContext.RequestServices.GetRequiredService<WatcherDbContext>();
|
||||||
|
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<ApiKeyAuthAttribute>>();
|
||||||
|
|
||||||
|
var apiKey = await dbContext.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(k => k.Key == apiKeyString);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Ungültiger API-Key verwendet: {ApiKey}", apiKeyString);
|
||||||
|
context.Result = new UnauthorizedObjectResult(new { error = "Ungültiger API-Key" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!apiKey.IsActive)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Inaktiver API-Key verwendet: {Name}", apiKey.Name);
|
||||||
|
context.Result = new UnauthorizedObjectResult(new { error = "API-Key ist deaktiviert" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiKey.IsExpired)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Abgelaufener API-Key verwendet: {Name}", apiKey.Name);
|
||||||
|
context.Result = new UnauthorizedObjectResult(new { error = "API-Key ist abgelaufen" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Letzten Verwendungszeitpunkt aktualisieren
|
||||||
|
apiKey.LastUsedAt = DateTime.UtcNow;
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
logger.LogInformation("API-Zugriff mit Key: {Name}", apiKey.Name);
|
||||||
|
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
}
|
||||||
53
watcher-monitoring/Configuration/OidcSettings.cs
Normal file
53
watcher-monitoring/Configuration/OidcSettings.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
namespace watcher_monitoring.Configuration;
|
||||||
|
|
||||||
|
public class OidcSettings
|
||||||
|
{
|
||||||
|
public bool Enabled { get; set; } = false;
|
||||||
|
|
||||||
|
public string Authority { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ClientId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ClientSecret { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Scopes { get; set; } = "openid profile email";
|
||||||
|
|
||||||
|
public string CallbackPath { get; set; } = "/signin-oidc";
|
||||||
|
|
||||||
|
public string ClaimUsername { get; set; } = "preferred_username";
|
||||||
|
|
||||||
|
public string ClaimEmail { get; set; } = "email";
|
||||||
|
|
||||||
|
public bool AutoProvisionUsers { get; set; } = true;
|
||||||
|
|
||||||
|
public bool IsValid => Enabled &&
|
||||||
|
!string.IsNullOrWhiteSpace(Authority) &&
|
||||||
|
!string.IsNullOrWhiteSpace(ClientId) &&
|
||||||
|
!string.IsNullOrWhiteSpace(ClientSecret);
|
||||||
|
|
||||||
|
public string[] GetScopes() => Scopes.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
public static OidcSettings FromEnvironment()
|
||||||
|
{
|
||||||
|
return new OidcSettings
|
||||||
|
{
|
||||||
|
Enabled = GetBoolEnv("OIDC_ENABLED", false),
|
||||||
|
Authority = Environment.GetEnvironmentVariable("OIDC_AUTHORITY") ?? string.Empty,
|
||||||
|
ClientId = Environment.GetEnvironmentVariable("OIDC_CLIENT_ID") ?? string.Empty,
|
||||||
|
ClientSecret = Environment.GetEnvironmentVariable("OIDC_CLIENT_SECRET") ?? string.Empty,
|
||||||
|
Scopes = Environment.GetEnvironmentVariable("OIDC_SCOPES") ?? "openid profile email",
|
||||||
|
CallbackPath = Environment.GetEnvironmentVariable("OIDC_CALLBACK_PATH") ?? "/signin-oidc",
|
||||||
|
ClaimUsername = Environment.GetEnvironmentVariable("OIDC_CLAIM_USERNAME") ?? "preferred_username",
|
||||||
|
ClaimEmail = Environment.GetEnvironmentVariable("OIDC_CLAIM_EMAIL") ?? "email",
|
||||||
|
AutoProvisionUsers = GetBoolEnv("OIDC_AUTO_PROVISION_USERS", true)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool GetBoolEnv(string key, bool defaultValue)
|
||||||
|
{
|
||||||
|
var value = Environment.GetEnvironmentVariable(key);
|
||||||
|
if (string.IsNullOrWhiteSpace(value)) return defaultValue;
|
||||||
|
return value.Equals("true", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
value.Equals("1", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,288 @@
|
|||||||
// Get Methoden um Metrics abzugreifen
|
using System.Diagnostics;
|
||||||
// Get Methden um Informationen über den Status des Servers einzuholen
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
using watcher_monitoring.Models;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
using watcher_monitoring.Attributes;
|
||||||
|
using watcher_monitoring.Payloads;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
[ApiKeyAuth]
|
||||||
|
public class APIController : Controller
|
||||||
|
{
|
||||||
|
private readonly WatcherDbContext _context;
|
||||||
|
|
||||||
|
private readonly ILogger<APIController> _logger;
|
||||||
|
|
||||||
|
public APIController(WatcherDbContext context, ILogger<APIController> logger)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
// API Calls
|
||||||
|
|
||||||
|
[HttpGet("get-server")]
|
||||||
|
public async Task<IActionResult> Servers()
|
||||||
|
{
|
||||||
|
List<Server> servers = await _context.Servers.ToListAsync();
|
||||||
|
return Ok(servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEVELOPMENT ONLY
|
||||||
|
[HttpPost("add-server")]
|
||||||
|
public async Task<IActionResult> AddServer([FromBody] Server serverDto)
|
||||||
|
{
|
||||||
|
// payload check
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = ModelState.Values
|
||||||
|
.SelectMany(v => v.Errors)
|
||||||
|
.Select(e => e.ErrorMessage)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_logger.LogError("Invalid server payload");
|
||||||
|
return BadRequest(new { error = "Invalid server payload", details = errors });
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Check if server with same IP already exists
|
||||||
|
var existingServer = await _context.Servers
|
||||||
|
.FirstOrDefaultAsync(s => s.IPAddress == serverDto.IPAddress);
|
||||||
|
|
||||||
|
if (existingServer != null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Server mit IP-Adresse {ip} existiert bereits", serverDto.IPAddress);
|
||||||
|
return BadRequest(new { error = "Server mit dieser IP-Adresse existiert bereits" });
|
||||||
|
}
|
||||||
|
|
||||||
|
Server server = new Server
|
||||||
|
{
|
||||||
|
Name = serverDto.Name,
|
||||||
|
IPAddress = serverDto.IPAddress,
|
||||||
|
CpuType = serverDto.CpuType,
|
||||||
|
CpuCores = serverDto.CpuCores,
|
||||||
|
GpuType = serverDto.GpuType,
|
||||||
|
RamSize = serverDto.RamSize,
|
||||||
|
DiskSpace = serverDto.DiskSpace,
|
||||||
|
IsOnline = serverDto.IsOnline,
|
||||||
|
IsVerified = serverDto.IsVerified
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.Servers.Add(server);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("Server '{name}' mit IP {ip} erfolgreich hinzugefügt", server.Name, server.IPAddress);
|
||||||
|
|
||||||
|
return Ok(new { message = "Server erfolgreich hinzugefügt", serverId = server.Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Fehler beim Hinzufügen des Servers");
|
||||||
|
return BadRequest(new { error = "Fehler beim Hinzufügen des Servers", details = ex.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("delete-server/{id}")]
|
||||||
|
public async Task<IActionResult> DeleteServer(int id)
|
||||||
|
{
|
||||||
|
var server = await _context.Servers.FindAsync(id);
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Server nicht gefunden");
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Servers.Remove(server);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("Server '{server}' erfolgreich gelöscht", server.Name);
|
||||||
|
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("edit-server")]
|
||||||
|
public async Task<IActionResult> EditServer()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Container Calls
|
||||||
|
[HttpGet("get-container")]
|
||||||
|
public async Task<IActionResult> Containers()
|
||||||
|
{
|
||||||
|
List<Container> containers = await _context.Containers.ToListAsync();
|
||||||
|
return Ok(containers);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("delete-container")]
|
||||||
|
public async Task<IActionResult> DeleteContainer(int id)
|
||||||
|
{
|
||||||
|
var container = await _context.Containers.FindAsync(id);
|
||||||
|
if (container == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Server nicht gefunden");
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Containers.Remove(container);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_logger.LogInformation("Container '{container}' erfolgreich gelöscht", container.Id);
|
||||||
|
return Ok();
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Agent Calls
|
||||||
|
|
||||||
|
// Registration Endpoint for watcher-agent
|
||||||
|
[HttpPost("agent-register")]
|
||||||
|
public async Task<IActionResult> Register([FromBody] RegistrationDto dto)
|
||||||
|
{
|
||||||
|
// payload check
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = ModelState.Values
|
||||||
|
.SelectMany(v => v.Errors)
|
||||||
|
.Select(e => e.ErrorMessage)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_logger.LogError("Invalid registration payload");
|
||||||
|
return BadRequest(new { error = "Invalid registration payload", details = errors });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Server newServer = new Server
|
||||||
|
{
|
||||||
|
Name = dto.hostName,
|
||||||
|
IPAddress = dto.ipAddress
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.Servers.Add(newServer);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
var server = await _context.Servers.FindAsync(dto.ipAddress);
|
||||||
|
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
return Ok(server.Id);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hardware Configuration Endpoint for watcher-agent
|
||||||
|
[HttpPost("agent-hardware")]
|
||||||
|
public async Task<IActionResult> HardwareConfiguration ([FromBody] HardwareDto dto)
|
||||||
|
{
|
||||||
|
// payload check
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = ModelState.Values
|
||||||
|
.SelectMany(v => v.Errors)
|
||||||
|
.Select(e => e.ErrorMessage)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_logger.LogError("Invalid hardware configuration");
|
||||||
|
return BadRequest(new { error = "Invalid Hardware Configuration Payload", details = errors });
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Find Server in Database
|
||||||
|
var server = await _context.Servers.FindAsync(dto.id);
|
||||||
|
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Server not found");
|
||||||
|
return BadRequest("Server not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Hardware Configuration
|
||||||
|
server.CpuType = dto.cpuType;
|
||||||
|
server.CpuCores = dto.cpuCores;
|
||||||
|
server.GpuType = dto.gpuType;
|
||||||
|
server.RamSize = dto.ramSize;
|
||||||
|
// TODO: Diskspace fehlt
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_logger.LogInformation("Harware configuration successfull for server {server}", server.Name);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-Metrics endpoint for watcher-agent
|
||||||
|
[HttpPost("agent-server-metrics/{id}")]
|
||||||
|
public async Task<IActionResult> ServerMetrics ([FromBody] MetricDto dto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = ModelState.Values
|
||||||
|
.SelectMany(v => v.Errors)
|
||||||
|
.Select(e => e.ErrorMessage)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_logger.LogError("Invalid monitoring payload");
|
||||||
|
return BadRequest(new { error = "Invalid monitoring payload", details = errors });
|
||||||
|
}
|
||||||
|
|
||||||
|
var server = await _context.Servers.FindAsync(dto.id);
|
||||||
|
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
// neues Objekt mit Typ Metric anlegen
|
||||||
|
|
||||||
|
// Metric in Datenbank eintragen
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogError("metric cannot be added to database");
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service-Detection endpoint for watcher-agent
|
||||||
|
[HttpPost("agent-container-detection")]
|
||||||
|
public async Task<IActionResult> ContainerDetection ([FromBody] HardwareDto dto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Container-Metrics endpoint for watcher-agent
|
||||||
|
[HttpPost("agent-container-metrics")]
|
||||||
|
public async Task<IActionResult> ContainerMetrics ([FromBody] HardwareDto dto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
153
watcher-monitoring/Controllers/ApiKeyController.cs
Normal file
153
watcher-monitoring/Controllers/ApiKeyController.cs
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
using watcher_monitoring.Models;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class ApiKeyController : Controller
|
||||||
|
{
|
||||||
|
private readonly WatcherDbContext _context;
|
||||||
|
private readonly ILogger<ApiKeyController> _logger;
|
||||||
|
|
||||||
|
public ApiKeyController(WatcherDbContext context, ILogger<ApiKeyController> logger)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generiert einen neuen API-Key
|
||||||
|
private static string GenerateApiKey()
|
||||||
|
{
|
||||||
|
var randomBytes = new byte[32];
|
||||||
|
using var rng = RandomNumberGenerator.Create();
|
||||||
|
rng.GetBytes(randomBytes);
|
||||||
|
return Convert.ToBase64String(randomBytes).Replace("+", "").Replace("/", "").Replace("=", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("create")]
|
||||||
|
public async Task<IActionResult> CreateApiKey([FromBody] CreateApiKeyRequest request)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Name))
|
||||||
|
{
|
||||||
|
return BadRequest(new { error = "Name ist erforderlich" });
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiKey = new ApiKey
|
||||||
|
{
|
||||||
|
Key = GenerateApiKey(),
|
||||||
|
Name = request.Name,
|
||||||
|
Description = request.Description,
|
||||||
|
ExpiresAt = request.ExpiresAt,
|
||||||
|
IsActive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.ApiKeys.Add(apiKey);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("Neuer API-Key erstellt: {Name}", apiKey.Name);
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
id = apiKey.Id,
|
||||||
|
key = apiKey.Key, // Wird nur einmal zurückgegeben!
|
||||||
|
name = apiKey.Name,
|
||||||
|
description = apiKey.Description,
|
||||||
|
createdAt = apiKey.CreatedAt,
|
||||||
|
expiresAt = apiKey.ExpiresAt,
|
||||||
|
isActive = apiKey.IsActive
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("list")]
|
||||||
|
public async Task<IActionResult> ListApiKeys()
|
||||||
|
{
|
||||||
|
var apiKeys = await _context.ApiKeys
|
||||||
|
.OrderByDescending(k => k.CreatedAt)
|
||||||
|
.Select(k => new
|
||||||
|
{
|
||||||
|
id = k.Id,
|
||||||
|
name = k.Name,
|
||||||
|
description = k.Description,
|
||||||
|
createdAt = k.CreatedAt,
|
||||||
|
expiresAt = k.ExpiresAt,
|
||||||
|
lastUsedAt = k.LastUsedAt,
|
||||||
|
isActive = k.IsActive,
|
||||||
|
isExpired = k.IsExpired,
|
||||||
|
keyPreview = k.Key.Substring(0, Math.Min(8, k.Key.Length)) + "..." // Nur die ersten 8 Zeichen
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Ok(apiKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetApiKey(int id)
|
||||||
|
{
|
||||||
|
var apiKey = await _context.ApiKeys.FindAsync(id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
{
|
||||||
|
return NotFound(new { error = "API-Key nicht gefunden" });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
id = apiKey.Id,
|
||||||
|
name = apiKey.Name,
|
||||||
|
description = apiKey.Description,
|
||||||
|
createdAt = apiKey.CreatedAt,
|
||||||
|
expiresAt = apiKey.ExpiresAt,
|
||||||
|
lastUsedAt = apiKey.LastUsedAt,
|
||||||
|
isActive = apiKey.IsActive,
|
||||||
|
isExpired = apiKey.IsExpired,
|
||||||
|
keyPreview = apiKey.Key.Substring(0, Math.Min(8, apiKey.Key.Length)) + "..."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id}/toggle")]
|
||||||
|
public async Task<IActionResult> ToggleApiKey(int id)
|
||||||
|
{
|
||||||
|
var apiKey = await _context.ApiKeys.FindAsync(id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
{
|
||||||
|
return NotFound(new { error = "API-Key nicht gefunden" });
|
||||||
|
}
|
||||||
|
|
||||||
|
apiKey.IsActive = !apiKey.IsActive;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("API-Key {Name} wurde {Status}", apiKey.Name, apiKey.IsActive ? "aktiviert" : "deaktiviert");
|
||||||
|
|
||||||
|
return Ok(new { isActive = apiKey.IsActive });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteApiKey(int id)
|
||||||
|
{
|
||||||
|
var apiKey = await _context.ApiKeys.FindAsync(id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
{
|
||||||
|
return NotFound(new { error = "API-Key nicht gefunden" });
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.ApiKeys.Remove(apiKey);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("API-Key gelöscht: {Name}", apiKey.Name);
|
||||||
|
|
||||||
|
return Ok(new { message = "API-Key erfolgreich gelöscht" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateApiKeyRequest
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public DateTime? ExpiresAt { get; set; }
|
||||||
|
}
|
||||||
266
watcher-monitoring/Controllers/AuthController.cs
Normal file
266
watcher-monitoring/Controllers/AuthController.cs
Normal file
@@ -0,0 +1,266 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using watcher_monitoring.Configuration;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
using watcher_monitoring.Models;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
public class AuthController : Controller
|
||||||
|
{
|
||||||
|
private readonly WatcherDbContext _context;
|
||||||
|
private readonly ILogger<AuthController> _logger;
|
||||||
|
private readonly OidcSettings _oidcSettings;
|
||||||
|
|
||||||
|
public AuthController(WatcherDbContext context, ILogger<AuthController> logger, OidcSettings oidcSettings)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
|
_oidcSettings = oidcSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Login(string? returnUrl = null)
|
||||||
|
{
|
||||||
|
// Wenn der Benutzer bereits angemeldet ist, zur Startseite weiterleiten
|
||||||
|
if (User.Identity?.IsAuthenticated == true)
|
||||||
|
{
|
||||||
|
return RedirectToAction("Index", "Home");
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewData["ReturnUrl"] = returnUrl;
|
||||||
|
ViewData["OidcEnabled"] = _oidcSettings.IsValid;
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult OidcLogin(string? returnUrl = null)
|
||||||
|
{
|
||||||
|
if (!_oidcSettings.IsValid)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("OIDC-Login versucht, aber OIDC ist nicht konfiguriert");
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
var properties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
RedirectUri = Url.Action("OidcCallback", "Auth", new { returnUrl }),
|
||||||
|
Items = { { "returnUrl", returnUrl ?? "/" } }
|
||||||
|
};
|
||||||
|
|
||||||
|
return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> OidcCallback(string? returnUrl = null)
|
||||||
|
{
|
||||||
|
var authenticateResult = await HttpContext.AuthenticateAsync(OpenIdConnectDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
|
if (!authenticateResult.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("OIDC-Authentifizierung fehlgeschlagen: {Failure}", authenticateResult.Failure?.Message);
|
||||||
|
TempData["Error"] = "OIDC-Anmeldung fehlgeschlagen. Bitte versuchen Sie es erneut.";
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
var oidcClaims = authenticateResult.Principal?.Claims;
|
||||||
|
var oidcSubject = oidcClaims?.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value
|
||||||
|
?? oidcClaims?.FirstOrDefault(c => c.Type == "sub")?.Value;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(oidcSubject))
|
||||||
|
{
|
||||||
|
_logger.LogError("OIDC-Claims enthalten keine Subject-ID");
|
||||||
|
TempData["Error"] = "OIDC-Anmeldung fehlgeschlagen: Keine Benutzer-ID erhalten.";
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
var username = oidcClaims?.FirstOrDefault(c => c.Type == _oidcSettings.ClaimUsername)?.Value
|
||||||
|
?? oidcClaims?.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value
|
||||||
|
?? oidcClaims?.FirstOrDefault(c => c.Type == "name")?.Value
|
||||||
|
?? oidcSubject;
|
||||||
|
|
||||||
|
var email = oidcClaims?.FirstOrDefault(c => c.Type == _oidcSettings.ClaimEmail)?.Value
|
||||||
|
?? oidcClaims?.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value
|
||||||
|
?? $"{username}@oidc.local";
|
||||||
|
|
||||||
|
var user = await _context.Users.FirstOrDefaultAsync(u => u.OidcSubject == oidcSubject);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
if (!_oidcSettings.AutoProvisionUsers)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("OIDC-User {Subject} existiert nicht und Auto-Provisioning ist deaktiviert", oidcSubject);
|
||||||
|
TempData["Error"] = "Ihr Benutzerkonto existiert nicht. Bitte kontaktieren Sie den Administrator.";
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
var existingUsername = await _context.Users.AnyAsync(u => u.Username == username);
|
||||||
|
if (existingUsername)
|
||||||
|
{
|
||||||
|
username = $"{username}_{oidcSubject[..Math.Min(8, oidcSubject.Length)]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
user = new User
|
||||||
|
{
|
||||||
|
Username = username,
|
||||||
|
Email = email,
|
||||||
|
OidcSubject = oidcSubject,
|
||||||
|
Password = string.Empty,
|
||||||
|
IsActive = true,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
LastLogin = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.Users.Add(user);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_logger.LogInformation("OIDC-User {Username} wurde automatisch erstellt (Subject: {Subject})", username, oidcSubject);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!user.IsActive)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("OIDC-User {Username} ist deaktiviert", user.Username);
|
||||||
|
TempData["Error"] = "Ihr Benutzerkonto ist deaktiviert.";
|
||||||
|
return RedirectToAction("Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastLogin = DateTime.UtcNow;
|
||||||
|
user.Email = email;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var claims = new List<Claim>
|
||||||
|
{
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.Username),
|
||||||
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
|
new Claim("LastLogin", user.LastLogin.ToString("o")),
|
||||||
|
new Claim("AuthMethod", "OIDC")
|
||||||
|
};
|
||||||
|
|
||||||
|
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
|
||||||
|
|
||||||
|
var authProperties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
IsPersistent = true,
|
||||||
|
ExpiresUtc = DateTimeOffset.UtcNow.AddHours(8)
|
||||||
|
};
|
||||||
|
|
||||||
|
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, authProperties);
|
||||||
|
|
||||||
|
_logger.LogInformation("OIDC-User {Username} erfolgreich angemeldet", user.Username);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
|
||||||
|
{
|
||||||
|
return Redirect(returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction("Index", "Home");
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Login(LoginViewModel model, string? returnUrl = null)
|
||||||
|
{
|
||||||
|
ViewData["ReturnUrl"] = returnUrl;
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Benutzer suchen
|
||||||
|
var user = await _context.Users
|
||||||
|
.FirstOrDefaultAsync(u => u.Username == model.Username && u.IsActive);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Login-Versuch mit ungültigem Benutzernamen: {Username}", model.Username);
|
||||||
|
TempData["Error"] = "Ungültiger Benutzername oder Passwort";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passwort überprüfen (BCrypt)
|
||||||
|
if (!BCrypt.Net.BCrypt.Verify(model.Password, user.Password))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Login-Versuch mit falschem Passwort für Benutzer: {Username}", model.Username);
|
||||||
|
TempData["Error"] = "Ungültiger Benutzername oder Passwort";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLogin aktualisieren
|
||||||
|
user.LastLogin = DateTime.UtcNow;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Claims erstellen
|
||||||
|
var claims = new List<Claim>
|
||||||
|
{
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.Username),
|
||||||
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
|
new Claim("LastLogin", user.LastLogin.ToString("o"))
|
||||||
|
};
|
||||||
|
|
||||||
|
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
|
||||||
|
|
||||||
|
var authProperties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
IsPersistent = model.RememberMe,
|
||||||
|
ExpiresUtc = model.RememberMe ? DateTimeOffset.UtcNow.AddDays(30) : DateTimeOffset.UtcNow.AddHours(8)
|
||||||
|
};
|
||||||
|
|
||||||
|
await HttpContext.SignInAsync(
|
||||||
|
CookieAuthenticationDefaults.AuthenticationScheme,
|
||||||
|
claimsPrincipal,
|
||||||
|
authProperties);
|
||||||
|
|
||||||
|
_logger.LogInformation("Benutzer {Username} erfolgreich angemeldet", user.Username);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
|
||||||
|
{
|
||||||
|
return Redirect(returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction("Index", "Home");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Fehler beim Login-Vorgang");
|
||||||
|
TempData["Error"] = "Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.";
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Logout()
|
||||||
|
{
|
||||||
|
var username = User.Identity?.Name ?? "Unbekannt";
|
||||||
|
|
||||||
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
|
_logger.LogInformation("Benutzer {Username} erfolgreich abgemeldet", username);
|
||||||
|
|
||||||
|
return RedirectToAction("Login", "Auth");
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
public IActionResult AccessDenied()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,45 +1,42 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using watcher_monitoring.Models;
|
using watcher_monitoring.Models;
|
||||||
|
|
||||||
using watcher_monitoring.Data;
|
using watcher_monitoring.Data;
|
||||||
using System.Threading.Tasks;
|
using watcher_monitoring.ViewModels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace watcher_monitoring.Controllers;
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly WatcherDbContext _dbContext;
|
private readonly WatcherDbContext _context;
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger, WatcherDbContext dbContext)
|
public HomeController(ILogger<HomeController> logger, WatcherDbContext dbContext)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_dbContext = dbContext;
|
_context = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dashboard
|
// Dashboard
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
List<Server> servers = await _dbContext.Servers.ToListAsync();
|
List<Server> _servers = await _context.Servers.ToListAsync();
|
||||||
|
List<Container> _containers = await _context.Containers.ToListAsync();
|
||||||
|
|
||||||
var servers1 = new List<dynamic>
|
var homeVm = new HomeViewModel
|
||||||
{
|
{
|
||||||
new { Name = "Web Server 01", IPAddress = "192.168.1.10", IsOnline = true },
|
servers = _servers,
|
||||||
new { Name = "Database Server", IPAddress = "192.168.1.20", IsOnline = true },
|
containers = _containers,
|
||||||
new { Name = "API Gateway", IPAddress = "192.168.1.30", IsOnline = true },
|
serversCount = _servers.Count,
|
||||||
new { Name = "Cache Server", IPAddress = "192.168.1.40", IsOnline = false },
|
serversOnline = (from server in _servers where server.IsOnline select server).Count(),
|
||||||
new { Name = "Backup Server", IPAddress = "192.168.1.50", IsOnline = true }
|
serversOffline = _servers.Count - (from server in _servers where server.IsOnline select server).Count()
|
||||||
};
|
};
|
||||||
|
|
||||||
ViewBag.TotalServers = servers.Count;
|
return View(homeVm);
|
||||||
ViewBag.OnlineServers = servers.Count(s => s.IsOnline);
|
|
||||||
ViewBag.OfflineServers = servers.Count(s => !s.IsOnline);
|
|
||||||
ViewBag.ServiceCount = 8;
|
|
||||||
ViewBag.Servers = servers;
|
|
||||||
|
|
||||||
return View();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
using watcher_monitoring.Payloads;
|
|
||||||
using watcher_monitoring.Data;
|
using watcher_monitoring.Data;
|
||||||
using watcher_monitoring.Models;
|
|
||||||
|
|
||||||
namespace watcher_monitoring.Controllers;
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class MonitoringController : Controller
|
public class MonitoringController : Controller
|
||||||
{
|
{
|
||||||
@@ -19,73 +19,16 @@ public class MonitoringController : Controller
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registration Endpoint for watcher-agent
|
[HttpGet("container")]
|
||||||
[HttpPost("register")]
|
public async Task<IActionResult> ContainerIndex()
|
||||||
public async Task<IActionResult> Register([FromBody] RegistrationDto dto)
|
|
||||||
{
|
{
|
||||||
// payload check
|
return View();
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
var errors = ModelState.Values
|
|
||||||
.SelectMany(v => v.Errors)
|
|
||||||
.Select(e => e.ErrorMessage)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_logger.LogError("Invalid registration payload");
|
|
||||||
return BadRequest(new { error = "Invalid registration payload", details = errors });
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hardware Configuration Endpoint for watcher-agent
|
[HttpGet("server")]
|
||||||
[HttpPost("hardware-configuration")]
|
public async Task <IActionResult> ServerIndex()
|
||||||
public async Task<IActionResult> HardwareConfiguration ([FromBody] HardwareDto dto)
|
|
||||||
{
|
{
|
||||||
// payload check
|
return View();
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
var errors = ModelState.Values
|
|
||||||
.SelectMany(v => v.Errors)
|
|
||||||
.Select(e => e.ErrorMessage)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
_logger.LogError("Invalid hardware configuration");
|
|
||||||
return BadRequest(new { error = "Invalid Hardware Configuration Payload", details = errors });
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Find Server in Database
|
|
||||||
Server server = await _context.Servers.FindAsync(dto.Id);
|
|
||||||
|
|
||||||
// Add Hardware Configuration
|
|
||||||
try
|
|
||||||
{
|
|
||||||
server.CpuType = dto.CpuType;
|
|
||||||
server.CpuCores = dto.CpuCores;
|
|
||||||
server.GpuType = dto.GpuType;
|
|
||||||
server.RamSize = dto.RamSize;
|
|
||||||
// Diskspace fehlt
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server-Metrics endpoint for watcher-agent
|
|
||||||
|
|
||||||
// Service-Detection endpoint for watcher-agent
|
|
||||||
|
|
||||||
// Service-Metrics endpoint for watcher-agent
|
|
||||||
|
|
||||||
}
|
}
|
||||||
311
watcher-monitoring/Controllers/UserController.cs
Normal file
311
watcher-monitoring/Controllers/UserController.cs
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
using watcher_monitoring.Models;
|
||||||
|
using BCrypt.Net;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class UserController : Controller
|
||||||
|
{
|
||||||
|
private readonly WatcherDbContext _context;
|
||||||
|
private readonly ILogger<UserController> _logger;
|
||||||
|
|
||||||
|
public UserController(WatcherDbContext context, ILogger<UserController> logger)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: /User
|
||||||
|
|
||||||
|
public async Task<IActionResult> Index()
|
||||||
|
{
|
||||||
|
var users = await _context.Users
|
||||||
|
.Include(u => u.ApiKeys)
|
||||||
|
.OrderByDescending(u => u.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return View(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: /User/Details/{id}
|
||||||
|
[HttpGet("Details/{id}")]
|
||||||
|
public async Task<IActionResult> Details(int id)
|
||||||
|
{
|
||||||
|
var user = await _context.Users
|
||||||
|
.Include(u => u.ApiKeys)
|
||||||
|
.FirstOrDefaultAsync(u => u.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: /User/Create
|
||||||
|
[HttpGet("Create")]
|
||||||
|
public IActionResult Create()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/Create
|
||||||
|
[HttpPost("Create")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Create([Bind("Username,Email,Password")] User user)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
// Prüfen, ob Username oder Email bereits existiert
|
||||||
|
var existingUser = await _context.Users
|
||||||
|
.FirstOrDefaultAsync(u => u.Username == user.Username || u.Email == user.Email);
|
||||||
|
|
||||||
|
if (existingUser != null)
|
||||||
|
{
|
||||||
|
if (existingUser.Username == user.Username)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Username", "Benutzername ist bereits vergeben");
|
||||||
|
}
|
||||||
|
if (existingUser.Email == user.Email)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Email", "E-Mail-Adresse ist bereits registriert");
|
||||||
|
}
|
||||||
|
return View(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passwort hashen mit BCrypt
|
||||||
|
user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);
|
||||||
|
user.CreatedAt = DateTime.UtcNow;
|
||||||
|
user.LastLogin = DateTime.UtcNow;
|
||||||
|
user.IsActive = true;
|
||||||
|
|
||||||
|
_context.Users.Add(user);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("Neuer User erstellt: {Username}", user.Username);
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: /User/Edit/{id}
|
||||||
|
[HttpGet("Edit/{id}")]
|
||||||
|
public async Task<IActionResult> Edit(int id)
|
||||||
|
{
|
||||||
|
var user = await _context.Users.FindAsync(id);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/Edit/{id}
|
||||||
|
[HttpPost("Edit/{id}")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Edit(int id, [Bind("Id,Username,Email,IsActive")] User updatedUser)
|
||||||
|
{
|
||||||
|
if (id != updatedUser.Id)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var user = await _context.Users.FindAsync(id);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfen, ob neuer Username oder Email bereits von anderem User verwendet wird
|
||||||
|
var duplicate = await _context.Users
|
||||||
|
.FirstOrDefaultAsync(u => u.Id != id && (u.Username == updatedUser.Username || u.Email == updatedUser.Email));
|
||||||
|
|
||||||
|
if (duplicate != null)
|
||||||
|
{
|
||||||
|
if (duplicate.Username == updatedUser.Username)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Username", "Benutzername ist bereits vergeben");
|
||||||
|
}
|
||||||
|
if (duplicate.Email == updatedUser.Email)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Email", "E-Mail-Adresse ist bereits registriert");
|
||||||
|
}
|
||||||
|
return View(updatedUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Username = updatedUser.Username;
|
||||||
|
user.Email = updatedUser.Email;
|
||||||
|
user.IsActive = updatedUser.IsActive;
|
||||||
|
|
||||||
|
_context.Update(user);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("User aktualisiert: {Username}", user.Username);
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if (!await UserExists(updatedUser.Id))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(updatedUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/Delete/{id}
|
||||||
|
[HttpPost("Delete/{id}")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Delete(int id)
|
||||||
|
{
|
||||||
|
var user = await _context.Users
|
||||||
|
.Include(u => u.ApiKeys)
|
||||||
|
.FirstOrDefaultAsync(u => u.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alle API-Keys des Users löschen
|
||||||
|
_context.ApiKeys.RemoveRange(user.ApiKeys);
|
||||||
|
_context.Users.Remove(user);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("User gelöscht: {Username}", user.Username);
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/ToggleActive/{id}
|
||||||
|
[HttpPost("ToggleActive/{id}")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> ToggleActive(int id)
|
||||||
|
{
|
||||||
|
var user = await _context.Users.FindAsync(id);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.IsActive = !user.IsActive;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("User {Username} wurde {Status}", user.Username, user.IsActive ? "aktiviert" : "deaktiviert");
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Details), new { id });
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/GenerateApiKey/{id}
|
||||||
|
[HttpPost("GenerateApiKey/{id}")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> GenerateApiKey(int id, string keyName, string? description, DateTime? expiresAt)
|
||||||
|
{
|
||||||
|
var user = await _context.Users.FindAsync(id);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(keyName))
|
||||||
|
{
|
||||||
|
TempData["Error"] = "API-Key-Name ist erforderlich";
|
||||||
|
return RedirectToAction(nameof(Details), new { id });
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiKey = new ApiKey
|
||||||
|
{
|
||||||
|
Key = GenerateApiKeyString(),
|
||||||
|
Name = keyName,
|
||||||
|
Description = description,
|
||||||
|
ExpiresAt = expiresAt,
|
||||||
|
IsActive = true,
|
||||||
|
UserId = user.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.ApiKeys.Add(apiKey);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("Neuer API-Key für User {Username} erstellt: {KeyName}", user.Username, keyName);
|
||||||
|
|
||||||
|
TempData["Success"] = $"API-Key erstellt: {apiKey.Key}";
|
||||||
|
TempData["NewApiKey"] = apiKey.Key;
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Details), new { id });
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/DeleteApiKey/{userId}/{keyId}
|
||||||
|
[HttpPost("DeleteApiKey/{userId}/{keyId}")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> DeleteApiKey(int userId, int keyId)
|
||||||
|
{
|
||||||
|
var apiKey = await _context.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(k => k.Id == keyId && k.UserId == userId);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.ApiKeys.Remove(apiKey);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("API-Key gelöscht: {KeyName}", apiKey.Name);
|
||||||
|
|
||||||
|
TempData["Success"] = "API-Key erfolgreich gelöscht";
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Details), new { id = userId });
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: /User/ToggleApiKey/{userId}/{keyId}
|
||||||
|
[HttpPost("ToggleApiKey/{userId}/{keyId}")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> ToggleApiKey(int userId, int keyId)
|
||||||
|
{
|
||||||
|
var apiKey = await _context.ApiKeys
|
||||||
|
.FirstOrDefaultAsync(k => k.Id == keyId && k.UserId == userId);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
apiKey.IsActive = !apiKey.IsActive;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("API-Key {KeyName} wurde {Status}", apiKey.Name, apiKey.IsActive ? "aktiviert" : "deaktiviert");
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Details), new { id = userId });
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<bool> UserExists(int id)
|
||||||
|
{
|
||||||
|
return await _context.Users.AnyAsync(u => u.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GenerateApiKeyString()
|
||||||
|
{
|
||||||
|
var randomBytes = new byte[32];
|
||||||
|
using var rng = RandomNumberGenerator.Create();
|
||||||
|
rng.GetBytes(randomBytes);
|
||||||
|
return Convert.ToBase64String(randomBytes).Replace("+", "").Replace("/", "").Replace("=", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,4 +19,8 @@ public class WatcherDbContext : DbContext
|
|||||||
public DbSet<Server> Servers { get; set; }
|
public DbSet<Server> Servers { get; set; }
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
public DbSet<Container> Containers { get; set; }
|
||||||
|
|
||||||
|
public DbSet<ApiKey> ApiKeys { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
114
watcher-monitoring/Migrations/20260108112653_containers-new.Designer.cs
generated
Normal file
114
watcher-monitoring/Migrations/20260108112653_containers-new.Designer.cs
generated
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(WatcherDbContext))]
|
||||||
|
[Migration("20260108112653_containers-new")]
|
||||||
|
partial class containersnew
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.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>("DiskSpace")
|
||||||
|
.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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Servers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastLogin")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class containersnew : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Containers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
ContainerName = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Containers", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Containers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
150
watcher-monitoring/Migrations/20260109080705_AddApiKeys.Designer.cs
generated
Normal file
150
watcher-monitoring/Migrations/20260109080705_AddApiKeys.Designer.cs
generated
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(WatcherDbContext))]
|
||||||
|
[Migration("20260109080705_AddApiKeys")]
|
||||||
|
partial class AddApiKeys
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpiresAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastUsedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.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>("DiskSpace")
|
||||||
|
.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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Servers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastLogin")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
41
watcher-monitoring/Migrations/20260109080705_AddApiKeys.cs
Normal file
41
watcher-monitoring/Migrations/20260109080705_AddApiKeys.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddApiKeys : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Key = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
|
||||||
|
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
||||||
|
Description = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
ExpiresAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
LastUsedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
IsActive = table.Column<bool>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ApiKeys", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ApiKeys");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
177
watcher-monitoring/Migrations/20260109081821_AddUserApiKeyRelationship.Designer.cs
generated
Normal file
177
watcher-monitoring/Migrations/20260109081821_AddUserApiKeyRelationship.Designer.cs
generated
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(WatcherDbContext))]
|
||||||
|
[Migration("20260109081821_AddUserApiKeyRelationship")]
|
||||||
|
partial class AddUserApiKeyRelationship
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpiresAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastUsedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.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>("DiskSpace")
|
||||||
|
.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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Servers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastLogin")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("watcher_monitoring.Models.User", "User")
|
||||||
|
.WithMany("ApiKeys")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ApiKeys");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddUserApiKeyRelationship : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
// Vorhandene API-Keys löschen, da sie keinem User zugeordnet werden können
|
||||||
|
migrationBuilder.Sql("DELETE FROM ApiKeys;");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "CreatedAt",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: DateTime.UtcNow);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "IsActive",
|
||||||
|
table: "Users",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "UserId",
|
||||||
|
table: "ApiKeys",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ApiKeys_UserId",
|
||||||
|
table: "ApiKeys",
|
||||||
|
column: "UserId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_ApiKeys_Users_UserId",
|
||||||
|
table: "ApiKeys",
|
||||||
|
column: "UserId",
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_ApiKeys_Users_UserId",
|
||||||
|
table: "ApiKeys");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_ApiKeys_UserId",
|
||||||
|
table: "ApiKeys");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CreatedAt",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "IsActive",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "UserId",
|
||||||
|
table: "ApiKeys");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
181
watcher-monitoring/Migrations/20260121084748_AddOidcSubjectToUser.Designer.cs
generated
Normal file
181
watcher-monitoring/Migrations/20260121084748_AddOidcSubjectToUser.Designer.cs
generated
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(WatcherDbContext))]
|
||||||
|
[Migration("20260121084748_AddOidcSubjectToUser")]
|
||||||
|
partial class AddOidcSubjectToUser
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpiresAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastUsedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.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>("DiskSpace")
|
||||||
|
.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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Servers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastLogin")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("OidcSubject")
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("watcher_monitoring.Models.User", "User")
|
||||||
|
.WithMany("ApiKeys")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ApiKeys");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddOidcSubjectToUser : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "OidcSubject",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
maxLength: 255,
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_OidcSubject",
|
||||||
|
table: "Users",
|
||||||
|
column: "OidcSubject",
|
||||||
|
unique: true,
|
||||||
|
filter: "OidcSubject IS NOT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Users_OidcSubject",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "OidcSubject",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,63 @@ namespace watcher_monitoring.Migrations
|
|||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpiresAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastUsedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("watcher_monitoring.Models.Server", b =>
|
modelBuilder.Entity("watcher_monitoring.Models.Server", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -69,13 +126,23 @@ namespace watcher_monitoring.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Email")
|
b.Property<string>("Email")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<DateTime>("LastLogin")
|
b.Property<DateTime>("LastLogin")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("OidcSubject")
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Password")
|
b.Property<string>("Password")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -89,6 +156,22 @@ namespace watcher_monitoring.Migrations
|
|||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("watcher_monitoring.Models.User", "User")
|
||||||
|
.WithMany("ApiKeys")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ApiKeys");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
watcher-monitoring/Models/ApiKey.cs
Normal file
35
watcher-monitoring/Models/ApiKey.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Models;
|
||||||
|
|
||||||
|
public class ApiKey
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string Key { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(100)]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public DateTime? ExpiresAt { get; set; }
|
||||||
|
|
||||||
|
public DateTime? LastUsedAt { get; set; }
|
||||||
|
|
||||||
|
public bool IsActive { get; set; } = true;
|
||||||
|
|
||||||
|
public bool IsExpired => ExpiresAt.HasValue && ExpiresAt.Value < DateTime.UtcNow;
|
||||||
|
|
||||||
|
// Foreign Key: Jeder API-Key gehört zu einem User
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
// Navigation Property
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
16
watcher-monitoring/Models/Container.cs
Normal file
16
watcher-monitoring/Models/Container.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Models;
|
||||||
|
|
||||||
|
public class Container
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(50)]
|
||||||
|
public required string ContainerName { get; set; } = null!;
|
||||||
|
|
||||||
|
}
|
||||||
18
watcher-monitoring/Models/LoginViewModel.cs
Normal file
18
watcher-monitoring/Models/LoginViewModel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Models;
|
||||||
|
|
||||||
|
public class LoginViewModel
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Benutzername ist erforderlich")]
|
||||||
|
[Display(Name = "Benutzername")]
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Passwort ist erforderlich")]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Passwort")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Display(Name = "Angemeldet bleiben")]
|
||||||
|
public bool RememberMe { get; set; }
|
||||||
|
}
|
||||||
@@ -22,4 +22,16 @@ public class User
|
|||||||
[Required]
|
[Required]
|
||||||
[DataType(DataType.Password)]
|
[DataType(DataType.Password)]
|
||||||
public required string Password { get; set; }
|
public required string Password { get; set; }
|
||||||
|
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public bool IsActive { get; set; } = true;
|
||||||
|
|
||||||
|
[StringLength(255)]
|
||||||
|
public string? OidcSubject { get; set; }
|
||||||
|
|
||||||
|
public bool IsOidcUser => !string.IsNullOrEmpty(OidcSubject);
|
||||||
|
|
||||||
|
// Navigation Property: Ein User kann mehrere API-Keys haben
|
||||||
|
public ICollection<ApiKey> ApiKeys { get; set; } = new List<ApiKey>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,18 @@ namespace watcher_monitoring.Payloads;
|
|||||||
public class HardwareDto
|
public class HardwareDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public required int Id;
|
public required int id;
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string? IpAddress { get; set; }
|
|
||||||
|
|
||||||
// Hardware Info
|
// Hardware Info
|
||||||
[Required]
|
[Required]
|
||||||
public string? CpuType { get; set; }
|
public string? cpuType { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int CpuCores { get; set; }
|
public int cpuCores { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string? GpuType { get; set; }
|
public string? gpuType { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public double RamSize { get; set; }
|
public double ramSize { get; set; }
|
||||||
}
|
}
|
||||||
44
watcher-monitoring/Payloads/MetricDto.cs
Normal file
44
watcher-monitoring/Payloads/MetricDto.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Payloads;
|
||||||
|
|
||||||
|
public class MetricDto
|
||||||
|
{
|
||||||
|
// Server Identity
|
||||||
|
[Required]
|
||||||
|
public int id { get; set; }
|
||||||
|
|
||||||
|
// Hardware Metrics
|
||||||
|
// CPU
|
||||||
|
public double cpuLoad { get; set; } // %
|
||||||
|
|
||||||
|
public double cpuTemp { get; set; } // deg C
|
||||||
|
|
||||||
|
// GPU
|
||||||
|
public double gpuLoad { get; set; } // %
|
||||||
|
|
||||||
|
public double gpuTemp { get; set; } // deg C
|
||||||
|
|
||||||
|
public double vRamSize { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double vRamLoad { get; set; } // %
|
||||||
|
|
||||||
|
// RAM
|
||||||
|
public double ramSize { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double ramLoad { get; set; } // %
|
||||||
|
|
||||||
|
// Disks
|
||||||
|
public double diskSize { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double diskLoad { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double diskTempp { get; set; } // deg C (if available)
|
||||||
|
|
||||||
|
// Network
|
||||||
|
public double netIn { get; set; } // Bytes/s
|
||||||
|
|
||||||
|
public double netOut { get; set; } // Bytes/s
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace watcher_monitoring.Payloads;
|
namespace watcher_monitoring.Payloads;
|
||||||
|
|
||||||
public class RegistrationDto
|
public class RegistrationDto
|
||||||
{
|
{
|
||||||
public required string IpAddress;
|
[Required]
|
||||||
public required string Key;
|
public required string ipAddress { get; set; }
|
||||||
|
|
||||||
|
public required string hostName { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
using watcher_monitoring.Configuration;
|
||||||
using watcher_monitoring.Data;
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -25,6 +30,10 @@ builder.Host.UseSerilog();
|
|||||||
DotNetEnv.Env.Load();
|
DotNetEnv.Env.Load();
|
||||||
builder.Configuration.AddEnvironmentVariables();
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
// OIDC-Einstellungen laden
|
||||||
|
var oidcSettings = OidcSettings.FromEnvironment();
|
||||||
|
builder.Services.AddSingleton(oidcSettings);
|
||||||
|
|
||||||
// Konfiguration laden
|
// Konfiguration laden
|
||||||
var configuration = builder.Configuration;
|
var configuration = builder.Configuration;
|
||||||
|
|
||||||
@@ -41,6 +50,52 @@ builder.Services.AddDbContext<WatcherDbContext>((serviceProvider, options) =>
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
|
// Cookie-basierte Authentifizierung
|
||||||
|
var authBuilder = builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||||
|
.AddCookie(options =>
|
||||||
|
{
|
||||||
|
options.LoginPath = "/Auth/Login";
|
||||||
|
options.LogoutPath = "/Auth/Logout";
|
||||||
|
options.AccessDeniedPath = "/Auth/AccessDenied";
|
||||||
|
options.ExpireTimeSpan = TimeSpan.FromHours(8);
|
||||||
|
options.SlidingExpiration = true;
|
||||||
|
options.Cookie.HttpOnly = true;
|
||||||
|
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
|
||||||
|
options.Cookie.SameSite = SameSiteMode.Lax;
|
||||||
|
});
|
||||||
|
|
||||||
|
// OIDC-Authentifizierung (wenn aktiviert)
|
||||||
|
if (oidcSettings.IsValid)
|
||||||
|
{
|
||||||
|
Log.Information("OIDC-Authentifizierung aktiviert für Authority: {Authority}", oidcSettings.Authority);
|
||||||
|
authBuilder.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
|
||||||
|
{
|
||||||
|
options.Authority = oidcSettings.Authority;
|
||||||
|
options.ClientId = oidcSettings.ClientId;
|
||||||
|
options.ClientSecret = oidcSettings.ClientSecret;
|
||||||
|
options.ResponseType = OpenIdConnectResponseType.Code;
|
||||||
|
options.SaveTokens = true;
|
||||||
|
options.GetClaimsFromUserInfoEndpoint = true;
|
||||||
|
options.CallbackPath = oidcSettings.CallbackPath;
|
||||||
|
options.SignedOutCallbackPath = "/signout-callback-oidc";
|
||||||
|
|
||||||
|
options.Scope.Clear();
|
||||||
|
foreach (var scope in oidcSettings.GetScopes())
|
||||||
|
{
|
||||||
|
options.Scope.Add(scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.TokenValidationParameters.NameClaimType = oidcSettings.ClaimUsername;
|
||||||
|
options.TokenValidationParameters.RoleClaimType = "roles";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (oidcSettings.Enabled)
|
||||||
|
{
|
||||||
|
Log.Warning("OIDC ist aktiviert aber nicht korrekt konfiguriert. Erforderlich: OIDC_AUTHORITY, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Services.AddAuthorization();
|
||||||
|
|
||||||
// Health Checks
|
// Health Checks
|
||||||
builder.Services.AddHealthChecks();
|
builder.Services.AddHealthChecks();
|
||||||
|
|
||||||
@@ -48,6 +103,17 @@ builder.Services.AddHealthChecks();
|
|||||||
builder.Services.AddSwaggerGen(options =>
|
builder.Services.AddSwaggerGen(options =>
|
||||||
{
|
{
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Watcher-Server API", Version = "v1" });
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Watcher-Server API", Version = "v1" });
|
||||||
|
|
||||||
|
// Nur API-Controller dokumentieren (mit [ApiController]-Attribut)
|
||||||
|
options.DocInclusionPredicate((docName, apiDesc) =>
|
||||||
|
{
|
||||||
|
var controllerActionDescriptor = apiDesc.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
|
||||||
|
if (controllerActionDescriptor == null) return false;
|
||||||
|
|
||||||
|
// Nur Controller mit [ApiController]-Attribut einbeziehen
|
||||||
|
return controllerActionDescriptor.ControllerTypeInfo
|
||||||
|
.GetCustomAttributes(typeof(ApiControllerAttribute), true).Any();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
@@ -69,6 +135,24 @@ using (var scope = app.Services.CreateScope())
|
|||||||
Log.Information("Führe Datenbank-Migrationen aus...");
|
Log.Information("Führe Datenbank-Migrationen aus...");
|
||||||
dbContext.Database.Migrate();
|
dbContext.Database.Migrate();
|
||||||
Log.Information("Datenbank-Migrationen erfolgreich angewendet");
|
Log.Information("Datenbank-Migrationen erfolgreich angewendet");
|
||||||
|
|
||||||
|
// Standard-Admin-User erstellen, falls noch kein User existiert
|
||||||
|
if (!dbContext.Users.Any())
|
||||||
|
{
|
||||||
|
Log.Information("Erstelle Standard-Admin-User...");
|
||||||
|
var adminUser = new watcher_monitoring.Models.User
|
||||||
|
{
|
||||||
|
Username = "admin",
|
||||||
|
Email = "admin@watcher.local",
|
||||||
|
Password = BCrypt.Net.BCrypt.HashPassword("admin"),
|
||||||
|
IsActive = true,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
LastLogin = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
dbContext.Users.Add(adminUser);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
Log.Information("Standard-Admin-User erstellt (Username: admin, Passwort: admin)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -98,6 +182,7 @@ app.UseSwaggerUI(options =>
|
|||||||
options.RoutePrefix = "api/v1/swagger";
|
options.RoutePrefix = "api/v1/swagger";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
// Health Check Endpoint
|
// Health Check Endpoint
|
||||||
|
|||||||
20
watcher-monitoring/ViewModels/HomeViewModel.cs
Normal file
20
watcher-monitoring/ViewModels/HomeViewModel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using SQLitePCL;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
using watcher_monitoring.Models;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.ViewModels;
|
||||||
|
|
||||||
|
public class HomeViewModel
|
||||||
|
{
|
||||||
|
public List<Server> servers { get; set; } = new();
|
||||||
|
|
||||||
|
public List<Container> containers { get; set; } = new();
|
||||||
|
|
||||||
|
public int serversCount { get; set; }
|
||||||
|
|
||||||
|
public int serversOnline { get; set; }
|
||||||
|
|
||||||
|
public int serversOffline { get; set; }
|
||||||
|
|
||||||
|
public int containersCount { get; set; }
|
||||||
|
}
|
||||||
18
watcher-monitoring/Views/Auth/AccessDenied.cshtml
Normal file
18
watcher-monitoring/Views/Auth/AccessDenied.cshtml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Zugriff verweigert";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card border-danger">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<h1 class="display-1 text-danger">🚫</h1>
|
||||||
|
<h2 class="card-title">Zugriff verweigert</h2>
|
||||||
|
<p class="card-text">Sie haben keine Berechtigung, auf diese Seite zuzugreifen.</p>
|
||||||
|
<a asp-controller="Auth" asp-action="Login" class="btn btn-primary">Zurück zum Login</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
123
watcher-monitoring/Views/Auth/Login.cshtml
Normal file
123
watcher-monitoring/Views/Auth/Login.cshtml
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
@model watcher_monitoring.Models.LoginViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Login";
|
||||||
|
Layout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>@ViewData["Title"] - Watcher Monitoring</title>
|
||||||
|
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||||
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.login-container {
|
||||||
|
max-width: 400px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.login-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
.login-header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
.login-header h2 {
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.login-header p {
|
||||||
|
color: #666;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.btn-login {
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
.btn-login:hover {
|
||||||
|
background: linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%);
|
||||||
|
}
|
||||||
|
.form-control:focus {
|
||||||
|
border-color: #667eea;
|
||||||
|
box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="login-container">
|
||||||
|
<div class="login-card">
|
||||||
|
<div class="login-header">
|
||||||
|
<h2>🔒 Watcher Monitoring</h2>
|
||||||
|
<p>Bitte melden Sie sich an</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (TempData["Error"] != null)
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
@TempData["Error"]
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<form asp-action="Login" asp-controller="Auth" method="post">
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label asp-for="Username" class="form-label">Benutzername</label>
|
||||||
|
<input asp-for="Username" class="form-control" placeholder="Benutzername eingeben" autofocus />
|
||||||
|
<span asp-validation-for="Username" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group mb-4">
|
||||||
|
<label asp-for="Password" class="form-label">Passwort</label>
|
||||||
|
<input asp-for="Password" type="password" class="form-control" placeholder="Passwort eingeben" />
|
||||||
|
<span asp-validation-for="Password" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-check mb-3">
|
||||||
|
<input asp-for="RememberMe" type="checkbox" class="form-check-input" />
|
||||||
|
<label asp-for="RememberMe" class="form-check-label">
|
||||||
|
Angemeldet bleiben
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary btn-login">Anmelden</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@if (ViewData["OidcEnabled"] is true)
|
||||||
|
{
|
||||||
|
<hr class="my-4" />
|
||||||
|
<div class="text-center">
|
||||||
|
<p class="text-muted mb-3">oder</p>
|
||||||
|
<a href="@Url.Action("OidcLogin", "Auth", new { returnUrl = ViewData["ReturnUrl"] })" class="btn btn-outline-secondary w-100">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shield-lock me-2" viewBox="0 0 16 16">
|
||||||
|
<path d="M5.338 1.59a61 61 0 0 0-2.837.856.48.48 0 0 0-.328.39c-.554 4.157.726 7.19 2.253 9.188a10.7 10.7 0 0 0 2.287 2.233c.346.244.652.42.893.533q.18.085.293.118a1 1 0 0 0 .101.025 1 1 0 0 0 .1-.025q.114-.034.294-.118c.24-.113.547-.29.893-.533a10.7 10.7 0 0 0 2.287-2.233c1.527-1.997 2.807-5.031 2.253-9.188a.48.48 0 0 0-.328-.39c-.651-.213-1.75-.56-2.837-.855C9.552 1.29 8.531 1.067 8 1.067c-.53 0-1.552.223-2.662.524zM5.072.56C6.157.265 7.31 0 8 0s1.843.265 2.928.56c1.11.3 2.229.655 2.887.87a1.54 1.54 0 0 1 1.044 1.262c.596 4.477-.787 7.795-2.465 9.99a11.8 11.8 0 0 1-2.517 2.453 7 7 0 0 1-1.048.625c-.28.132-.581.24-.829.24s-.548-.108-.829-.24a7 7 0 0 1-1.048-.625 11.8 11.8 0 0 1-2.517-2.453C1.928 10.487.545 7.169 1.141 2.692A1.54 1.54 0 0 1 2.185 1.43 63 63 0 0 1 5.072.56"/>
|
||||||
|
<path d="M9.5 6.5a1.5 1.5 0 0 1-1 1.415l.385 1.99a.5.5 0 0 1-.491.595h-.788a.5.5 0 0 1-.49-.595l.384-1.99a1.5 1.5 0 1 1 2-1.415"/>
|
||||||
|
</svg>
|
||||||
|
Mit oidc anmelden
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||||
|
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -16,37 +16,37 @@
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="metric-card">
|
<div class="metric-card">
|
||||||
<div class="metric-label">Total Servers</div>
|
<div class="metric-label">Total Servers</div>
|
||||||
<div class="metric-value">@ViewBag.TotalServers</div>
|
<div class="metric-value">@Model.serversCount</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="metric-card">
|
<div class="metric-card">
|
||||||
<div class="metric-label">Online</div>
|
<div class="metric-label">Online</div>
|
||||||
<div class="metric-value" style="color: var(--success)">@ViewBag.OnlineServers</div>
|
<div class="metric-value" style="color: var(--success)">@Model.serversOnline</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="metric-card">
|
<div class="metric-card">
|
||||||
<div class="metric-label">Offline</div>
|
<div class="metric-label">Offline</div>
|
||||||
<div class="metric-value" style="color: var(--danger)">@ViewBag.OfflineServers</div>
|
<div class="metric-value" style="color: var(--danger)">@Model.serversOffline</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="metric-card">
|
<div class="metric-card">
|
||||||
<div class="metric-label">Totoal Services</div>
|
<div class="metric-label">Total Containers</div>
|
||||||
<div class="metric-value">@ViewBag.ServiceCount</div>
|
<div class="metric-value">@Model.containersCount</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row g-4">
|
<div class="row g-4">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2 class="card-title">Monitored Servers</h2>
|
<h2 class="card-title"><a href="/Monitoring/server" style="text-decoration: none;">Monitored Servers</a></h2>
|
||||||
<ul class="server-list">
|
<ul class="server-list">
|
||||||
@if (ViewBag.Servers != null && ViewBag.Servers.Count > 0)
|
@if (Model.servers != null && Model.servers.Count > 0)
|
||||||
{
|
{
|
||||||
@foreach (var server in ViewBag.Servers)
|
@foreach (var server in Model.servers)
|
||||||
{
|
{
|
||||||
<li class="server-item">
|
<li class="server-item">
|
||||||
<div class="server-info">
|
<div class="server-info">
|
||||||
@@ -68,6 +68,31 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card">
|
||||||
|
<h2 class="card-title"><a href="/Monitoring/server" style="text-decoration: none;">Monitored Containers</a></h2>
|
||||||
|
<ul class="server-list">
|
||||||
|
@if (Model.containers != null && Model.containers.Count > 0)
|
||||||
|
{
|
||||||
|
@foreach (var container in Model.containers)
|
||||||
|
{
|
||||||
|
<li class="server-item">
|
||||||
|
<div class="server-info">
|
||||||
|
<span class="server-name">@container.Name</span>
|
||||||
|
<span class="server-ip">Container Image</span>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<li class="text-center py-4" style="color: var(--text-muted)">
|
||||||
|
No Containers added yet
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|||||||
471
watcher-monitoring/Views/Monitoring/ContainerIndex.cshtml
Normal file
471
watcher-monitoring/Views/Monitoring/ContainerIndex.cshtml
Normal file
@@ -0,0 +1,471 @@
|
|||||||
|
@model dynamic
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Container Overview";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1 class="section-title mb-0">Container Overview</h1>
|
||||||
|
<span class="text-muted">Last updated: @DateTime.Now.ToString("HH:mm:ss")</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-4">
|
||||||
|
<!-- Container Card 1 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">nginx:latest</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Running</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Usage</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart1" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Memory Usage -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Memory Usage</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="memChart1" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Network I/O -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Network I/O</span>
|
||||||
|
<span class="metric-value-small">400 MB/s</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="netChart1" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Container Card 2 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">postgres:14</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Running</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Usage</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart2" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Memory Usage -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Memory Usage</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="memChart2" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Network I/O -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Network I/O</span>
|
||||||
|
<span class="metric-value-small">400 MB/s</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="netChart2" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Container Card 3 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">redis:alpine</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-warning">Restarting</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Usage</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart3" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Memory Usage -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Memory Usage</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="memChart3" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Network I/O -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Network I/O</span>
|
||||||
|
<span class="metric-value-small">400 MB/s</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="netChart3" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Container Card 4 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">node:18-alpine</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Running</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Usage</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart4" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Memory Usage -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Memory Usage</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="memChart4" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Network I/O -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Network I/O</span>
|
||||||
|
<span class="metric-value-small">400 MB/s</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="netChart4" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Container Card 5 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">mongo:6.0</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-offline">Stopped</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Usage</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart5" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Memory Usage -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Memory Usage</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="memChart5" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Network I/O -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Network I/O</span>
|
||||||
|
<span class="metric-value-small">400 MB/s</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="netChart5" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Container Card 6 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">traefik:v2.9</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Running</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Usage</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart6" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Memory Usage -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Memory Usage</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="memChart6" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Network I/O -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">Network I/O</span>
|
||||||
|
<span class="metric-value-small">400 MB/s</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="netChart6" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
<script>
|
||||||
|
// Configuration for charts
|
||||||
|
const chartConfig = {
|
||||||
|
type: 'line',
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
display: false,
|
||||||
|
min: 0,
|
||||||
|
max: 100
|
||||||
|
}
|
||||||
|
},
|
||||||
|
elements: {
|
||||||
|
line: {
|
||||||
|
tension: 0.4,
|
||||||
|
borderWidth: 2
|
||||||
|
},
|
||||||
|
point: {
|
||||||
|
radius: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
intersect: false,
|
||||||
|
mode: 'index'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate random data for demo
|
||||||
|
function generateData() {
|
||||||
|
return Array.from({ length: 20 }, () => Math.floor(Math.random() * 60) + 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create CPU charts
|
||||||
|
for (let i = 1; i <= 6; i++) {
|
||||||
|
const ctx = document.getElementById(`cpuChart${i}`);
|
||||||
|
if (ctx) {
|
||||||
|
new Chart(ctx, {
|
||||||
|
...chartConfig,
|
||||||
|
data: {
|
||||||
|
labels: Array(20).fill(''),
|
||||||
|
datasets: [{
|
||||||
|
data: generateData(),
|
||||||
|
borderColor: '#58a6ff',
|
||||||
|
backgroundColor: 'rgba(88, 166, 255, 0.1)',
|
||||||
|
fill: true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Memory charts
|
||||||
|
for (let i = 1; i <= 6; i++) {
|
||||||
|
const ctx = document.getElementById(`memChart${i}`);
|
||||||
|
if (ctx) {
|
||||||
|
new Chart(ctx, {
|
||||||
|
...chartConfig,
|
||||||
|
data: {
|
||||||
|
labels: Array(20).fill(''),
|
||||||
|
datasets: [{
|
||||||
|
data: generateData(),
|
||||||
|
borderColor: '#3fb950',
|
||||||
|
backgroundColor: 'rgba(63, 185, 80, 0.1)',
|
||||||
|
fill: true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Network I/O charts
|
||||||
|
for (let i = 1; i <= 6; i++) {
|
||||||
|
const ctx = document.getElementById(`netChart${i}`);
|
||||||
|
if (ctx) {
|
||||||
|
new Chart(ctx, {
|
||||||
|
...chartConfig,
|
||||||
|
data: {
|
||||||
|
labels: Array(20).fill(''),
|
||||||
|
datasets: [{
|
||||||
|
data: generateData(),
|
||||||
|
borderColor: '#d29922',
|
||||||
|
backgroundColor: 'rgba(210, 153, 34, 0.1)',
|
||||||
|
fill: true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-refresh every 30 seconds
|
||||||
|
setInterval(function() {
|
||||||
|
location.reload();
|
||||||
|
}, 30000);
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.server-detail-card {
|
||||||
|
max-height: 500px;
|
||||||
|
height: 100%;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-detail-card:hover {
|
||||||
|
transform: translateY(-4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-metrics {
|
||||||
|
padding-top: 1rem;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-section {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
background-color: var(--bg-tertiary);
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-label-small {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value-small {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-canvas {
|
||||||
|
height: 50px !important;
|
||||||
|
max-height: 50px !important;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
398
watcher-monitoring/Views/Monitoring/ServerIndex.cshtml
Normal file
398
watcher-monitoring/Views/Monitoring/ServerIndex.cshtml
Normal file
@@ -0,0 +1,398 @@
|
|||||||
|
@model dynamic
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Server Overview";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1 class="section-title mb-0">Server Overview</h1>
|
||||||
|
<span class="text-muted">Last updated: @DateTime.Now.ToString("HH:mm:ss")</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-4">
|
||||||
|
<!-- Server Card 1 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">192.168.1.100</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Online</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Load</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart1" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RAM Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">RAM Load</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="ramChart1" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Card 2 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">192.168.1.101</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Online</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Load</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart2" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RAM Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">RAM Load</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="ramChart2" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Card 3 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">192.168.1.102</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-warning">Warning</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Load</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart3" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RAM Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">RAM Load</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="ramChart3" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Card 4 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">192.168.1.103</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Online</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Load</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart4" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RAM Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">RAM Load</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="ramChart4" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Card 5 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">192.168.1.104</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-offline">Offline</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Load</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart5" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RAM Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">RAM Load</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="ramChart5" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Server Card 6 -->
|
||||||
|
<div class="col-xl-4 col-lg-6">
|
||||||
|
<div class="card server-detail-card">
|
||||||
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title mb-1">test</h2>
|
||||||
|
<span class="server-ip">192.168.1.105</span>
|
||||||
|
</div>
|
||||||
|
<span class="status-badge status-online">Online</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="server-metrics">
|
||||||
|
<!-- CPU Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">CPU Load</span>
|
||||||
|
<span class="metric-value-small">400%</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="cpuChart6" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RAM Load -->
|
||||||
|
<div class="metric-section mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
|
<span class="metric-label-small">RAM Load</span>
|
||||||
|
<span class="metric-value-small">400 MB</span>
|
||||||
|
</div>
|
||||||
|
<canvas id="ramChart6" class="chart-canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Uptime -->
|
||||||
|
<div class="metric-section">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<span class="metric-label-small">Uptime</span>
|
||||||
|
<span class="metric-value-small">400 days</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
<script>
|
||||||
|
// Configuration for charts
|
||||||
|
const chartConfig = {
|
||||||
|
type: 'line',
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
display: false,
|
||||||
|
min: 0,
|
||||||
|
max: 100
|
||||||
|
}
|
||||||
|
},
|
||||||
|
elements: {
|
||||||
|
line: {
|
||||||
|
tension: 0.4,
|
||||||
|
borderWidth: 2
|
||||||
|
},
|
||||||
|
point: {
|
||||||
|
radius: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
intersect: false,
|
||||||
|
mode: 'index'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate random data for demo
|
||||||
|
function generateData() {
|
||||||
|
return Array.from({ length: 20 }, () => Math.floor(Math.random() * 60) + 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create CPU charts
|
||||||
|
for (let i = 1; i <= 6; i++) {
|
||||||
|
const ctx = document.getElementById(`cpuChart${i}`);
|
||||||
|
if (ctx) {
|
||||||
|
new Chart(ctx, {
|
||||||
|
...chartConfig,
|
||||||
|
data: {
|
||||||
|
labels: Array(20).fill(''),
|
||||||
|
datasets: [{
|
||||||
|
data: generateData(),
|
||||||
|
borderColor: '#58a6ff',
|
||||||
|
backgroundColor: 'rgba(88, 166, 255, 0.1)',
|
||||||
|
fill: true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create RAM charts
|
||||||
|
for (let i = 1; i <= 6; i++) {
|
||||||
|
const ctx = document.getElementById(`ramChart${i}`);
|
||||||
|
if (ctx) {
|
||||||
|
new Chart(ctx, {
|
||||||
|
...chartConfig,
|
||||||
|
data: {
|
||||||
|
labels: Array(20).fill(''),
|
||||||
|
datasets: [{
|
||||||
|
data: generateData(),
|
||||||
|
borderColor: '#3fb950',
|
||||||
|
backgroundColor: 'rgba(63, 185, 80, 0.1)',
|
||||||
|
fill: true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-refresh every 30 seconds
|
||||||
|
setInterval(function() {
|
||||||
|
location.reload();
|
||||||
|
}, 30000);
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.server-detail-card {
|
||||||
|
max-height: 420px;
|
||||||
|
height: 100%;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-detail-card:hover {
|
||||||
|
transform: translateY(-4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-metrics {
|
||||||
|
padding-top: 1rem;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-section {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
background-color: var(--bg-tertiary);
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-label-small {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value-small {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-canvas {
|
||||||
|
height: 50px !important;
|
||||||
|
max-height: 50px !important;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
@@ -8,11 +9,13 @@
|
|||||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
<link rel="stylesheet" href="~/watcher_monitoring.styles.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/watcher_monitoring.styles.css" asp-append-version="true" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg navbar-dark">
|
<nav class="navbar navbar-expand-lg navbar-dark">
|
||||||
<div class="container-fluid px-4">
|
<div class="container-fluid px-4">
|
||||||
<a class="navbar-brand fw-bold" asp-area="" asp-controller="Home" asp-action="Index">
|
<a class="navbar-brand fw-bold" asp-area="" asp-controller="Home" asp-action="Index">
|
||||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="me-2" style="display: inline-block; vertical-align: middle;">
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||||
|
class="me-2" style="display: inline-block; vertical-align: middle;">
|
||||||
<circle cx="12" cy="12" r="10"></circle>
|
<circle cx="12" cy="12" r="10"></circle>
|
||||||
<path d="M12 6v6l4 2"></path>
|
<path d="M12 6v6l4 2"></path>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -26,14 +29,57 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Dashboard</a>
|
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Dashboard</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
@if (User.Identity?.IsAuthenticated == true)
|
||||||
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Settings</a>
|
{
|
||||||
</li>
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
|
||||||
|
data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||||||
|
stroke-width="2" style="display: inline-block; vertical-align: middle;">
|
||||||
|
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
||||||
|
<circle cx="12" cy="7" r="4"></circle>
|
||||||
|
</svg>
|
||||||
|
@User.Identity.Name
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
||||||
|
<li>
|
||||||
|
<form asp-controller="User" asp-action="Index" method="post" style="display:inline;">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="dropdown-item">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"
|
||||||
|
stroke="currentColor" stroke-width="2"
|
||||||
|
style="display: inline-block; vertical-align: middle; margin-right: 8px;">
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
|
||||||
|
<polyline points="16 17 21 12 16 7"></polyline>
|
||||||
|
<line x1="21" y1="12" x2="9" y2="12"></line>
|
||||||
|
</svg>
|
||||||
|
Settings
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<form asp-controller="Auth" asp-action="Logout" method="post" style="display:inline;">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="dropdown-item">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"
|
||||||
|
stroke="currentColor" stroke-width="2"
|
||||||
|
style="display: inline-block; vertical-align: middle; margin-right: 8px;">
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
|
||||||
|
<polyline points="16 17 21 12 16 7"></polyline>
|
||||||
|
<line x1="21" y1="12" x2="9" y2="12"></line>
|
||||||
|
</svg>
|
||||||
|
Abmelden
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<main class="main-content">
|
<main class="main-content">
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
</main>
|
</main>
|
||||||
@@ -49,4 +95,5 @@
|
|||||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||||
@await RenderSectionAsync("Scripts", required: false)
|
@await RenderSectionAsync("Scripts", required: false)
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
||||||
47
watcher-monitoring/Views/User/Create.cshtml
Normal file
47
watcher-monitoring/Views/User/Create.cshtml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
@model watcher_monitoring.Models.User
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Neuer Benutzer";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8 offset-md-2">
|
||||||
|
<h1 class="section-title mb-4">Neuen Benutzer erstellen</h1>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<form asp-action="Create" method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="alert" style="background-color: rgba(248, 81, 73, 0.15); border: 1px solid var(--danger); color: var(--danger); border-radius: 6px; padding: 1rem; margin-bottom: 1rem;"></div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Username" class="form-label" style="color: var(--text-primary); font-weight: 500; margin-bottom: 0.5rem;">Benutzername</label>
|
||||||
|
<input asp-for="Username" class="form-control" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;" required />
|
||||||
|
<span asp-validation-for="Username" style="color: var(--danger); font-size: 0.875rem;"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Email" class="form-label" style="color: var(--text-primary); font-weight: 500; margin-bottom: 0.5rem;">E-Mail-Adresse</label>
|
||||||
|
<input asp-for="Email" type="email" class="form-control" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;" required />
|
||||||
|
<span asp-validation-for="Email" style="color: var(--danger); font-size: 0.875rem;"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Password" class="form-label" style="color: var(--text-primary); font-weight: 500; margin-bottom: 0.5rem;">Passwort</label>
|
||||||
|
<input asp-for="Password" type="password" class="form-control" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;" required />
|
||||||
|
<span asp-validation-for="Password" style="color: var(--danger); font-size: 0.875rem;"></span>
|
||||||
|
<div style="color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem;">Mindestens 8 Zeichen empfohlen</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<button type="submit" class="btn btn-primary">Erstellen</button>
|
||||||
|
<a asp-action="Index" class="btn" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.5rem 1rem; border-radius: 6px; text-decoration: none;">Abbrechen</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||||
|
}
|
||||||
217
watcher-monitoring/Views/User/Details.cshtml
Normal file
217
watcher-monitoring/Views/User/Details.cshtml
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
@model watcher_monitoring.Models.User
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Benutzerdetails";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1 class="section-title mb-0">Benutzerdetails</h1>
|
||||||
|
<div>
|
||||||
|
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn" style="background-color: var(--warning); color: #fff; margin-right: 0.5rem;">Bearbeiten</a>
|
||||||
|
<a asp-action="Index" class="btn" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary);">Zurück</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (TempData["Success"] != null)
|
||||||
|
{
|
||||||
|
<div class="alert" style="background-color: rgba(63, 185, 80, 0.15); border: 1px solid var(--success); color: var(--success); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; position: relative;">
|
||||||
|
@TempData["Success"]
|
||||||
|
@if (TempData["NewApiKey"] != null)
|
||||||
|
{
|
||||||
|
<hr style="border-color: var(--border-color); margin: 1rem 0;">
|
||||||
|
<strong>API-Key (wird nur einmal angezeigt!):</strong>
|
||||||
|
<div class="input-group mt-2" style="display: flex; gap: 0.5rem;">
|
||||||
|
<input type="text" class="form-control font-monospace" value="@TempData["NewApiKey"]" id="newApiKey" readonly style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px; flex: 1;">
|
||||||
|
<button class="btn" type="button" onclick="copyApiKey()" style="background-color: var(--accent-primary); color: #fff; border: none; padding: 0.75rem 1rem; border-radius: 6px;">
|
||||||
|
Kopieren
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" style="position: absolute; top: 1rem; right: 1rem; color: var(--success);"></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (TempData["Error"] != null)
|
||||||
|
{
|
||||||
|
<div class="alert" style="background-color: rgba(248, 81, 73, 0.15); border: 1px solid var(--danger); color: var(--danger); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; position: relative;">
|
||||||
|
@TempData["Error"]
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" style="position: absolute; top: 1rem; right: 1rem; color: var(--danger);"></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<h2 class="card-title">Benutzerinformationen</h2>
|
||||||
|
<div style="color: var(--text-secondary);">
|
||||||
|
<div class="row mb-3" style="padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);">
|
||||||
|
<div class="col-sm-4"><strong style="color: var(--text-primary);">Benutzername:</strong></div>
|
||||||
|
<div class="col-sm-8" style="color: var(--text-secondary);">@Model.Username</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3" style="padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);">
|
||||||
|
<div class="col-sm-4"><strong style="color: var(--text-primary);">E-Mail:</strong></div>
|
||||||
|
<div class="col-sm-8" style="color: var(--text-secondary);">@Model.Email</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3" style="padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);">
|
||||||
|
<div class="col-sm-4"><strong style="color: var(--text-primary);">Status:</strong></div>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
@if (Model.IsActive)
|
||||||
|
{
|
||||||
|
<span class="status-badge status-online">Aktiv</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span class="status-badge status-offline">Inaktiv</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3" style="padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);">
|
||||||
|
<div class="col-sm-4"><strong style="color: var(--text-primary);">Erstellt am:</strong></div>
|
||||||
|
<div class="col-sm-8" style="color: var(--text-secondary);">@Model.CreatedAt.ToString("dd.MM.yyyy HH:mm:ss")</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3" style="padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);">
|
||||||
|
<div class="col-sm-4"><strong style="color: var(--text-primary);">Letzter Login:</strong></div>
|
||||||
|
<div class="col-sm-8" style="color: var(--text-secondary);">@Model.LastLogin.ToString("dd.MM.yyyy HH:mm:ss")</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<form asp-action="ToggleActive" asp-route-id="@Model.Id" method="post" class="d-inline">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="btn btn-sm" style="background-color: @(Model.IsActive ? "var(--warning)" : "var(--success)"); color: #fff; margin-right: 0.5rem;">
|
||||||
|
@(Model.IsActive ? "Deaktivieren" : "Aktivieren")
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<form asp-action="Delete" asp-route-id="@Model.Id" method="post" class="d-inline" onsubmit="return confirm('Möchten Sie diesen Benutzer wirklich löschen? Alle API-Keys werden ebenfalls gelöscht.');">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="btn btn-sm" style="background-color: var(--danger); color: #fff;">Löschen</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<h2 class="card-title mb-0">API-Keys (@Model.ApiKeys.Count)</h2>
|
||||||
|
<button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#createApiKeyModal">
|
||||||
|
Neuer API-Key
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@if (Model.ApiKeys.Any())
|
||||||
|
{
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover" style="color: var(--text-primary); margin-bottom: 0;">
|
||||||
|
<thead style="border-bottom: 1px solid var(--border-color);">
|
||||||
|
<tr>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Name</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Beschreibung</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Status</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Erstellt</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Läuft ab</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Zuletzt verwendet</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Aktionen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var key in Model.ApiKeys.OrderByDescending(k => k.CreatedAt))
|
||||||
|
{
|
||||||
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
||||||
|
<td style="padding: 1rem;"><strong style="color: var(--text-primary);">@key.Name</strong></td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@(key.Description ?? "-")</td>
|
||||||
|
<td style="padding: 1rem;">
|
||||||
|
@if (key.IsExpired)
|
||||||
|
{
|
||||||
|
<span class="status-badge status-offline">Abgelaufen</span>
|
||||||
|
}
|
||||||
|
else if (!key.IsActive)
|
||||||
|
{
|
||||||
|
<span class="status-badge" style="background-color: rgba(139, 148, 158, 0.15); color: var(--text-secondary); border: 1px solid var(--text-secondary);">Inaktiv</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span class="status-badge status-online">Aktiv</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@key.CreatedAt.ToString("dd.MM.yyyy")</td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@(key.ExpiresAt?.ToString("dd.MM.yyyy") ?? "Nie")</td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@(key.LastUsedAt?.ToString("dd.MM.yyyy HH:mm") ?? "Nie")</td>
|
||||||
|
<td style="padding: 1rem;">
|
||||||
|
<form asp-action="ToggleApiKey" asp-route-userId="@Model.Id" asp-route-keyId="@key.Id" method="post" class="d-inline">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="btn btn-sm" style="background-color: @(key.IsActive ? "var(--warning)" : "var(--success)"); color: #fff; margin-right: 0.5rem;">
|
||||||
|
@(key.IsActive ? "Deaktivieren" : "Aktivieren")
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<form asp-action="DeleteApiKey" asp-route-userId="@Model.Id" asp-route-keyId="@key.Id" method="post" class="d-inline" onsubmit="return confirm('Möchten Sie diesen API-Key wirklich löschen?');">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="btn btn-sm" style="background-color: var(--danger); color: #fff;">Löschen</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<p style="color: var(--text-muted); margin-bottom: 0;">Noch keine API-Keys vorhanden.</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal für neuen API-Key -->
|
||||||
|
<div class="modal fade" id="createApiKeyModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content" style="background-color: var(--bg-secondary); border: 1px solid var(--border-color); color: var(--text-primary);">
|
||||||
|
<form asp-action="GenerateApiKey" asp-route-id="@Model.Id" method="post">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<div class="modal-header" style="border-bottom: 1px solid var(--border-color);">
|
||||||
|
<h5 class="modal-title" style="color: var(--text-primary);">Neuen API-Key erstellen</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" style="filter: invert(1);"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="keyName" class="form-label" style="color: var(--text-primary); font-weight: 500;">Name *</label>
|
||||||
|
<input type="text" class="form-control" id="keyName" name="keyName" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;" required>
|
||||||
|
<div style="color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem;">Ein eindeutiger Name für diesen API-Key</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="description" class="form-label" style="color: var(--text-primary); font-weight: 500;">Beschreibung</label>
|
||||||
|
<textarea class="form-control" id="description" name="description" rows="2" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="expiresAt" class="form-label" style="color: var(--text-primary); font-weight: 500;">Ablaufdatum (optional)</label>
|
||||||
|
<input type="datetime-local" class="form-control" id="expiresAt" name="expiresAt" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;">
|
||||||
|
<div style="color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem;">Leer lassen für unbegrenzte Gültigkeit</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer" style="border-top: 1px solid var(--border-color);">
|
||||||
|
<button type="button" class="btn" data-bs-dismiss="modal" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary);">Abbrechen</button>
|
||||||
|
<button type="submit" class="btn btn-primary">API-Key erstellen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script>
|
||||||
|
function copyApiKey() {
|
||||||
|
var copyText = document.getElementById("newApiKey");
|
||||||
|
copyText.select();
|
||||||
|
copyText.setSelectionRange(0, 99999);
|
||||||
|
navigator.clipboard.writeText(copyText.value);
|
||||||
|
|
||||||
|
var btn = event.target;
|
||||||
|
var originalText = btn.textContent;
|
||||||
|
btn.textContent = "Kopiert!";
|
||||||
|
setTimeout(function() {
|
||||||
|
btn.textContent = originalText;
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
}
|
||||||
46
watcher-monitoring/Views/User/Edit.cshtml
Normal file
46
watcher-monitoring/Views/User/Edit.cshtml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
@model watcher_monitoring.Models.User
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Benutzer bearbeiten";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8 offset-md-2">
|
||||||
|
<h1 class="section-title mb-4">Benutzer bearbeiten</h1>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<form asp-action="Edit" method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="alert" style="background-color: rgba(248, 81, 73, 0.15); border: 1px solid var(--danger); color: var(--danger); border-radius: 6px; padding: 1rem; margin-bottom: 1rem;"></div>
|
||||||
|
<input type="hidden" asp-for="Id" />
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Username" class="form-label" style="color: var(--text-primary); font-weight: 500; margin-bottom: 0.5rem;">Benutzername</label>
|
||||||
|
<input asp-for="Username" class="form-control" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;" required />
|
||||||
|
<span asp-validation-for="Username" style="color: var(--danger); font-size: 0.875rem;"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="Email" class="form-label" style="color: var(--text-primary); font-weight: 500; margin-bottom: 0.5rem;">E-Mail-Adresse</label>
|
||||||
|
<input asp-for="Email" type="email" class="form-control" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.75rem; border-radius: 6px;" required />
|
||||||
|
<span asp-validation-for="Email" style="color: var(--danger); font-size: 0.875rem;"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 form-check">
|
||||||
|
<input asp-for="IsActive" type="checkbox" class="form-check-input" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color);" />
|
||||||
|
<label asp-for="IsActive" class="form-check-label" style="color: var(--text-primary); margin-left: 0.5rem;">Benutzer ist aktiv</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||||
|
<a asp-action="Details" asp-route-id="@Model.Id" class="btn" style="background-color: var(--bg-tertiary); border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.5rem 1rem; border-radius: 6px; text-decoration: none;">Abbrechen</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||||
|
}
|
||||||
62
watcher-monitoring/Views/User/Index.cshtml
Normal file
62
watcher-monitoring/Views/User/Index.cshtml
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
@model IEnumerable<watcher_monitoring.Models.User>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Benutzerverwaltung";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1 class="section-title mb-0">Benutzerverwaltung</h1>
|
||||||
|
<a asp-action="Create" class="btn btn-primary">
|
||||||
|
Neuer Benutzer
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover" style="color: var(--text-primary); margin-bottom: 0;">
|
||||||
|
<thead style="border-bottom: 1px solid var(--border-color);">
|
||||||
|
<tr>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Benutzername</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">E-Mail</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Status</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">API-Keys</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Erstellt am</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Letzter Login</th>
|
||||||
|
<th style="color: var(--text-secondary); font-weight: 600; padding: 1rem;">Aktionen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var user in Model)
|
||||||
|
{
|
||||||
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
||||||
|
<td style="padding: 1rem;">
|
||||||
|
<strong style="color: var(--text-primary);">@user.Username</strong>
|
||||||
|
</td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@user.Email</td>
|
||||||
|
<td style="padding: 1rem;">
|
||||||
|
@if (user.IsActive)
|
||||||
|
{
|
||||||
|
<span class="status-badge status-online">Aktiv</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span class="status-badge status-offline">Inaktiv</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td style="padding: 1rem;">
|
||||||
|
<span class="status-badge" style="background-color: rgba(88, 166, 255, 0.15); color: var(--info); border: 1px solid var(--info);">@user.ApiKeys.Count</span>
|
||||||
|
</td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@user.CreatedAt.ToString("dd.MM.yyyy HH:mm")</td>
|
||||||
|
<td style="padding: 1rem; color: var(--text-secondary);">@user.LastLogin.ToString("dd.MM.yyyy HH:mm")</td>
|
||||||
|
<td style="padding: 1rem;">
|
||||||
|
<a asp-action="Details" asp-route-id="@user.Id" class="btn btn-sm" style="background-color: var(--info); color: #fff; margin-right: 0.5rem;">Details</a>
|
||||||
|
<a asp-action="Edit" asp-route-id="@user.Id" class="btn btn-sm" style="background-color: var(--warning); color: #fff;">Bearbeiten</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.11" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user