mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-03 22:12:00 +10:00
- Effective config: track value sources (ConfigValueSource, EffectiveConfigSources) and show readonly badges/tooltips for non-managed files. Multi-value options use ValueWithSource/PathWithSource for JSON. StatusClient uses camelCase serialization for reliable deserialization. - Parsing: align with dnsmasq (conf-file/conf-dir order, suffix filter, case- sensitive keys). DnsmasqConfIncludeParser and DnsmasqConfigSetService build effective config and sources. New DnsmasqConfigSetServiceTests. - UI: rename Overview/Home to Dnsmasq (page, nav, doc comments). Add EffectiveConfigOptionItem and EffectiveConfigMultiValueRow components. Dnsmasq.razor uses them; Hosts.razor shows addn-hosts with source. Encode server-derived strings in markup to avoid XSS. - Home section namespace: Components.Home -> Components.Dnsmasq (LogsSection, StatusSection, _Imports). - Test data: expand testdata (README, resolv.dnsmasq, hosts.extra, dnsmasq.d configs). dhcp.conf static IP aligned with testnet. - agents.md: add agent instructions for test harness and conventions.
75 lines
2.9 KiB
C#
75 lines
2.9 KiB
C#
namespace DnsmasqWebUI.Models;
|
|
|
|
/// <summary>
|
|
/// Effective dnsmasq config after reading all config files (main + conf-file + conf-dir)
|
|
/// in the order returned by <see cref="DnsmasqConfIncludeParser.GetIncludedPathsWithSource"/>.
|
|
/// Represents the final values dnsmasq uses: single-value (last wins), flags (set if any),
|
|
/// and multi-value (all occurrences in order). Source per value is in <see cref="EffectiveConfigSources"/>
|
|
/// from <see cref="IDnsmasqConfigSetService.GetEffectiveConfigWithSources"/> (file path, IsManaged).
|
|
/// Non-managed source → readonly in UI; flags set in a non-managed file cannot be unset from the UI.
|
|
///
|
|
/// Single-value (ARG_ONE): last occurrence wins; can be overridden by writing to the managed file.
|
|
/// Flags: set if any file contains the option (key-only line).
|
|
/// Multi-value (ARG_DUP): addn-hosts, server/local, address, interface, listen-address, except-interface,
|
|
/// dhcp-range, dhcp-host, dhcp-option, resolv-file — all values in order; each has source in EffectiveConfigSources.
|
|
/// </summary>
|
|
public record EffectiveDnsmasqConfig(
|
|
// --- Hosts (already used by Hosts UI) ---
|
|
bool NoHosts,
|
|
IReadOnlyList<string> AddnHostsPaths,
|
|
|
|
// --- Multi-value (ARG_DUP): all occurrences in order ---
|
|
IReadOnlyList<string> ServerLocalValues,
|
|
IReadOnlyList<string> AddressValues,
|
|
IReadOnlyList<string> Interfaces,
|
|
IReadOnlyList<string> ListenAddresses,
|
|
IReadOnlyList<string> ExceptInterfaces,
|
|
IReadOnlyList<string> DhcpRanges,
|
|
IReadOnlyList<string> DhcpHostLines,
|
|
IReadOnlyList<string> DhcpOptionLines,
|
|
IReadOnlyList<string> ResolvFiles,
|
|
|
|
// --- Boolean flags (set if any file contains the option) ---
|
|
bool ExpandHosts,
|
|
bool BogusPriv,
|
|
bool StrictOrder,
|
|
bool NoResolv,
|
|
bool DomainNeeded,
|
|
bool NoPoll,
|
|
bool BindInterfaces,
|
|
bool NoNegcache,
|
|
bool DhcpAuthoritative,
|
|
bool LeasefileRo,
|
|
|
|
// --- Single-value options (last occurrence wins; null = not set, dnsmasq default) ---
|
|
string? DhcpLeaseFilePath,
|
|
int? CacheSize,
|
|
int? Port,
|
|
int? LocalTtl,
|
|
string? PidFilePath,
|
|
string? User,
|
|
string? Group,
|
|
string? LogFacility,
|
|
int? DhcpLeaseMax,
|
|
int? NegTtl,
|
|
int? MaxTtl,
|
|
int? MaxCacheTtl,
|
|
int? MinCacheTtl,
|
|
int? DhcpTtl
|
|
)
|
|
{
|
|
/// <summary>
|
|
/// Returns the log file path when <see cref="LogFacility"/> is a file path (e.g. starts with / or contains /).
|
|
/// Returns null when LogFacility is not set, is a syslog facility name (e.g. local0), or is not a file path.
|
|
/// Used for full log download in the UI.
|
|
/// </summary>
|
|
public static string? GetLogsPath(EffectiveDnsmasqConfig? config)
|
|
{
|
|
var logFacility = config?.LogFacility?.Trim();
|
|
if (string.IsNullOrEmpty(logFacility)) return null;
|
|
if (logFacility.StartsWith('/') || logFacility.Contains('/'))
|
|
return logFacility;
|
|
return null;
|
|
}
|
|
}
|