Initial commit

This commit is contained in:
Janus C. H. Knudsen 2026-02-03 00:17:08 +01:00
commit 77d35ff965
51 changed files with 5591 additions and 0 deletions

View 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
}
}
}
}
}