mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-03 22:12:00 +10:00
Redesign the Hosts page around source-aware grouped rows with shared table shell styling, fix effective-config save session synchronization, and move read-ethers into the DHCP model where dnsmasq actually applies it.
52 lines
2.3 KiB
C#
52 lines
2.3 KiB
C#
using DnsmasqWebUI.Models.Dnsmasq;
|
|
|
|
namespace DnsmasqWebUI.Models.Dnsmasq.PageStates;
|
|
|
|
/// <summary>
|
|
/// Page state for the Hosts specialized page. Derived from DnsmasqServiceStatus to keep Razor markup clean.
|
|
/// </summary>
|
|
public sealed record HostsPageState(
|
|
bool ManagedHostsAvailable,
|
|
string? ManagedHostsUnavailableReason,
|
|
bool SystemHostsActive,
|
|
string? SystemHostsInactiveReason,
|
|
bool ExpandHostsEnabled,
|
|
string? ExpansionDomain)
|
|
{
|
|
public static HostsPageState FromStatus(DnsmasqServiceStatus? status)
|
|
{
|
|
if (status == null)
|
|
{
|
|
return new HostsPageState(
|
|
ManagedHostsAvailable: false,
|
|
ManagedHostsUnavailableReason: "Status not available.",
|
|
SystemHostsActive: false,
|
|
SystemHostsInactiveReason: "Status not available.",
|
|
ExpandHostsEnabled: false,
|
|
ExpansionDomain: null);
|
|
}
|
|
|
|
var managedHostsAvailable = !string.IsNullOrEmpty(status.ManagedHostsFilePath);
|
|
var noHosts = status.NoHosts;
|
|
var systemHostsActive = !noHosts && !string.IsNullOrEmpty(status.SystemHostsPath) && status.SystemHostsPathExists;
|
|
var expandHosts = status.EffectiveConfig?.ExpandHosts ?? false;
|
|
var domain = status.EffectiveConfig?.DomainValues?.FirstOrDefault();
|
|
|
|
return new HostsPageState(
|
|
ManagedHostsAvailable: managedHostsAvailable,
|
|
ManagedHostsUnavailableReason: managedHostsAvailable
|
|
? null
|
|
: "Hosts editing is unavailable: managed hosts path is not configured. Set Dnsmasq:MainConfigPath (and optionally Dnsmasq:ManagedHostsFileName) so the app can create and edit the managed hosts file.",
|
|
SystemHostsActive: systemHostsActive,
|
|
SystemHostsInactiveReason: noHosts
|
|
? "System hosts is ignored because no-hosts is enabled in dnsmasq config."
|
|
: string.IsNullOrEmpty(status.SystemHostsPath)
|
|
? "System hosts path is not configured."
|
|
: !status.SystemHostsPathExists
|
|
? $"System hosts file not found: {status.SystemHostsPath}"
|
|
: null,
|
|
ExpandHostsEnabled: expandHosts,
|
|
ExpansionDomain: expandHosts ? domain : null);
|
|
}
|
|
}
|