Files
dnsmasq-webui/src/DnsmasqWebUI/Controllers/LeasesController.cs
T
alex d0391ef058 Effective config, hosts/addn-hosts logic, test harness status & logs
- EffectiveDnsmasqConfig: overridable single-value options (no-hosts, addn-hosts,
  flags, dhcp-leasefile, cache-size, port, etc.) from dnsmasq source/docs.
- Hosts UI: allow editing when no-hosts but SystemHostsPath is in addn-hosts;
  HostsController and Hosts.razor check pathInAddnHosts.
- Config comments: managed file ensures one addn-hosts line in our file only;
  DnsmasqOptions/validator docs for SystemHostsPath and addn-hosts.
- Test harness: dnsmasq logs to /data/dnsmasq.log (log-facility + log-queries in
  dnsmasq-test.conf); entrypoint touches log file for write access.
- dnsmasq-status.sh: simulates systemctl status output in container (ps/pgrep);
  Dockerfile copies and chmod +x; StatusShowCommand/LogsCommand use script and
  tail /data/dnsmasq.log.
- Project: Models/Config namespace, typed HTTP clients, combined DHCP+Leases
  page, ProcessRunner, shared models (PascalCase).
2026-02-01 01:17:32 +10:00

36 lines
1.0 KiB
C#

using DnsmasqWebUI.Models;
using DnsmasqWebUI.Services.Abstractions;
using Microsoft.AspNetCore.Mvc;
namespace DnsmasqWebUI.Controllers;
[ApiController]
[Route("api/[controller]")]
public class LeasesController : ControllerBase
{
private readonly ILeasesFileService _leasesService;
public LeasesController(ILeasesFileService leasesService)
{
_leasesService = leasesService;
}
[HttpGet]
public async Task<ActionResult<LeasesResult>> Get(CancellationToken ct)
{
try
{
var (available, entries) = await _leasesService.TryReadAsync(ct);
if (!available)
return Ok(new LeasesResult(false, null, "Leases not configured."));
if (entries == null)
return Ok(new LeasesResult(true, Array.Empty<LeaseEntry>(), "Leases file not readable."));
return Ok(new LeasesResult(true, entries, null));
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.Message });
}
}
}