Initial commit
This commit is contained in:
commit
77d35ff965
51 changed files with 5591 additions and 0 deletions
62
Pages/Caddy/Hosts.cshtml
Normal file
62
Pages/Caddy/Hosts.cshtml
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Caddy.HostsModel
|
||||
@{
|
||||
ViewData["Title"] = "Caddy Hosts";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Registrerede Hosts</h1>
|
||||
<p class="page-subtitle">Alle hostnames konfigureret i Caddy</p>
|
||||
</div>
|
||||
|
||||
@if (!Model.IsRunning)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="text-danger">Caddy server er ikke tilgængelig</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (Model.Hosts.Count == 0)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="text-muted">Ingen hosts fundet</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Hostname</th>
|
||||
<th>TLS</th>
|
||||
<th>Upstream</th>
|
||||
<th>Listen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var host in Model.Hosts)
|
||||
{
|
||||
<tr>
|
||||
<td><code>@host.Hostname</code></td>
|
||||
<td>
|
||||
@if (host.Tls)
|
||||
{
|
||||
<span class="badge badge-success">HTTPS</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge badge-warning">HTTP</span>
|
||||
}
|
||||
</td>
|
||||
<td><code>@(host.Upstream ?? "-")</code></td>
|
||||
<td><code>@string.Join(", ", host.Addresses)</code></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
27
Pages/Caddy/Hosts.cshtml.cs
Normal file
27
Pages/Caddy/Hosts.cshtml.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using PlanTempusAdmin.Models;
|
||||
using PlanTempusAdmin.Services;
|
||||
|
||||
namespace PlanTempusAdmin.Pages.Caddy;
|
||||
|
||||
public class HostsModel : PageModel
|
||||
{
|
||||
private readonly CaddyService _caddyService;
|
||||
|
||||
public bool IsRunning { get; set; }
|
||||
public List<CaddyHost> Hosts { get; set; } = new();
|
||||
|
||||
public HostsModel(CaddyService caddyService)
|
||||
{
|
||||
_caddyService = caddyService;
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
IsRunning = await _caddyService.IsRunningAsync();
|
||||
if (IsRunning)
|
||||
{
|
||||
Hosts = await _caddyService.GetHostsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Pages/Caddy/Index.cshtml
Normal file
41
Pages/Caddy/Index.cshtml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Caddy.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Caddy Oversigt";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Caddy Oversigt</h1>
|
||||
<p class="page-subtitle">Status for Caddy reverse proxy server</p>
|
||||
</div>
|
||||
|
||||
<div class="status-grid">
|
||||
<div class="status-item">
|
||||
<div class="status-label">Server Status</div>
|
||||
<div class="status-value @(Model.IsRunning ? "success" : "danger")">
|
||||
@(Model.IsRunning ? "ONLINE" : "OFFLINE")
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">Registrerede Hosts</div>
|
||||
<div class="status-value">@Model.HostCount</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.IsRunning && !string.IsNullOrEmpty(Model.RawConfig))
|
||||
{
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Aktiv Konfiguration</div>
|
||||
<div class="card-body">
|
||||
<pre>@Model.RawConfig</pre>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (!Model.IsRunning)
|
||||
{
|
||||
<div class="card mt-2">
|
||||
<div class="card-body">
|
||||
<p class="text-muted">Kan ikke forbinde til Caddy Admin API på @Model.CaddyAdminUrl</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
51
Pages/Caddy/Index.cshtml.cs
Normal file
51
Pages/Caddy/Index.cshtml.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using PlanTempusAdmin.Services;
|
||||
|
||||
namespace PlanTempusAdmin.Pages.Caddy;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly CaddyService _caddyService;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public bool IsRunning { get; set; }
|
||||
public int HostCount { get; set; }
|
||||
public string? RawConfig { get; set; }
|
||||
public string CaddyAdminUrl { get; set; } = string.Empty;
|
||||
|
||||
public IndexModel(CaddyService caddyService, IConfiguration configuration)
|
||||
{
|
||||
_caddyService = caddyService;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
CaddyAdminUrl = _configuration.GetValue<string>("Caddy:AdminUrl") ?? "http://localhost:2019";
|
||||
IsRunning = await _caddyService.IsRunningAsync();
|
||||
|
||||
if (IsRunning)
|
||||
{
|
||||
var hosts = await _caddyService.GetHostsAsync();
|
||||
HostCount = hosts.Count;
|
||||
RawConfig = await _caddyService.GetRawConfigAsync();
|
||||
|
||||
// Pretty print JSON
|
||||
if (!string.IsNullOrEmpty(RawConfig))
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonDoc = System.Text.Json.JsonDocument.Parse(RawConfig);
|
||||
RawConfig = System.Text.Json.JsonSerializer.Serialize(jsonDoc, new System.Text.Json.JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep raw config if parsing fails
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue