mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-04 04:18:13 +10:00
- Dnsmasq page: Config (Main config, Managed file, Config set) under Service configuration; remove Paths/Leases (in Effective config DHCP); EffectiveConfigSection collapsible groups; StatusSection flex-wrap - Hosts: HostsFileSection always shows table; 'No host entries' in tbody when empty - Models: reorganize into sub-namespaces (Config, EffectiveConfig, Hosts, Dhcp, Status); move EffectiveConfig/Status/Logs components under Dnsmasq - Test harness: prepare-test-mount.sh runs 'docker compose down' before mount+up so all containers (including DHCP clients) restart; exclude testdata/leases from sync (unit tests only); testdata/README
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using DnsmasqWebUI.Models.Dhcp;
|
|
using DnsmasqWebUI.Models.Status;
|
|
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 (ArgumentException ex)
|
|
{
|
|
return BadRequest(new { error = ex.Message });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
}
|