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).
This commit is contained in:
2026-02-01 01:17:32 +10:00
parent 5bd9eaf55d
commit d0391ef058
64 changed files with 1184 additions and 512 deletions
@@ -1,4 +1,5 @@
using DnsmasqWebUI.Models;
using DnsmasqWebUI.Options;
using DnsmasqWebUI.Services.Abstractions;
using Microsoft.AspNetCore.Mvc;
@@ -10,11 +11,19 @@ public class HostsController : ControllerBase
{
private readonly IHostsFileService _hostsService;
private readonly IReloadService _reloadService;
private readonly IDnsmasqConfigSetService _configSetService;
private readonly DnsmasqOptions _options;
public HostsController(IHostsFileService hostsService, IReloadService reloadService)
public HostsController(
IHostsFileService hostsService,
IReloadService reloadService,
IDnsmasqConfigSetService configSetService,
Microsoft.Extensions.Options.IOptions<DnsmasqOptions> options)
{
_hostsService = hostsService;
_reloadService = reloadService;
_configSetService = configSetService;
_options = options.Value;
}
[HttpGet]
@@ -32,15 +41,23 @@ public class HostsController : ControllerBase
}
[HttpPut]
public async Task<ActionResult<object>> Put([FromBody] List<HostEntry>? entries, CancellationToken ct)
public async Task<ActionResult<SaveWithReloadResult>> Put([FromBody] List<HostEntry>? entries, CancellationToken ct)
{
if (entries == null)
return BadRequest(new { error = "Body required" });
var effectiveConfig = _configSetService.GetEffectiveConfig();
if (string.IsNullOrWhiteSpace(_options.SystemHostsPath))
return BadRequest(new { error = "No system hosts file configured. Set Dnsmasq:SystemHostsPath to enable hosts editing." });
// When no-hosts is set, dnsmasq only uses addn-hosts files; allow editing only if our path is in that list.
var systemPath = Path.GetFullPath(_options.SystemHostsPath.Trim());
var pathInAddnHosts = effectiveConfig.AddnHostsPaths?.Any(p => string.Equals(p, systemPath, StringComparison.Ordinal)) == true;
if (effectiveConfig.NoHosts && !pathInAddnHosts)
return BadRequest(new { error = "Hosts are disabled by no-hosts in dnsmasq config, and the configured path is not in addn-hosts, so dnsmasq would not read it." });
try
{
await _hostsService.WriteAsync(entries, ct);
var reload = await _reloadService.ReloadAsync(ct);
return Ok(new { saved = true, reload = new { reload.Success, reload.ExitCode, reload.StdErr } });
return Ok(new SaveWithReloadResult(true, reload));
}
catch (Exception ex)
{