mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-17 17:31:29 +10:00
- 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).
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using DnsmasqWebUI.Models;
|
|
using DnsmasqWebUI.Services.Abstractions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DnsmasqWebUI.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class DhcpController : ControllerBase
|
|
{
|
|
private readonly IDnsmasqConfigService _configService;
|
|
private readonly IReloadService _reloadService;
|
|
|
|
public DhcpController(IDnsmasqConfigService configService, IReloadService reloadService)
|
|
{
|
|
_configService = configService;
|
|
_reloadService = reloadService;
|
|
}
|
|
|
|
[HttpGet("hosts")]
|
|
public async Task<ActionResult<IReadOnlyList<DhcpHostEntry>>> GetHosts(CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var entries = await _configService.ReadDhcpHostsAsync(ct);
|
|
return Ok(entries);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPut("hosts")]
|
|
public async Task<ActionResult<SaveWithReloadResult>> PutHosts([FromBody] List<DhcpHostEntry>? entries, CancellationToken ct)
|
|
{
|
|
if (entries == null)
|
|
return BadRequest(new { error = "Body required" });
|
|
try
|
|
{
|
|
await _configService.WriteDhcpHostsAsync(entries, ct);
|
|
var reload = await _reloadService.ReloadAsync(ct);
|
|
return Ok(new SaveWithReloadResult(true, reload));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
}
|