Files
dnsmasq-webui/src/DnsmasqWebUI/Controllers/DhcpController.cs
T
alex a60d0e8db8 DHCP: read-only hosts from other configs, combobox inputs, polling, UI fixes
- Static hosts: read dhcp-host from all config files; show external as read-only
  with Source column; IsEditable + SourcePath on DhcpHostEntry; reject save if
  managed entry duplicates MAC from another file (400 + message)
- Lease field: single input + datalist (type or select), remove Other dropdown
- MAC field: single input + datalist from current leases, TryFillFromLeaseByMac
- Add host: default Name=*, suggest next free IP from DHCP range
- Leases: configurable refresh polling; Settings modal for interval (client-side)
- DhcpHostsClient: surface 400 error body message on save failure
- App title config (ApplicationOptions), nav/layout/error/hosts tweaks
2026-02-02 00:40:53 +10:00

55 lines
1.6 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 (ArgumentException ex)
{
return BadRequest(new { error = ex.Message });
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.Message });
}
}
}