14.04.2026 Update
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
type InterfaceConfig struct {
|
||||
Label string `yaml:"label,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Auto bool `yaml:"auto"`
|
||||
Mode string `yaml:"mode"`
|
||||
Address string `yaml:"address,omitempty"`
|
||||
@@ -47,6 +48,12 @@ type KnownDevice struct {
|
||||
Hostname string `yaml:"hostname"`
|
||||
Blocked bool `yaml:"blocked,omitempty"`
|
||||
StaticIP string `yaml:"static_ip,omitempty"`
|
||||
Policy string `yaml:"policy,omitempty"` // "disabled" | "direct" | "vpn" | "" (use default)
|
||||
}
|
||||
|
||||
// ClientPolicyConfig holds the default routing policy for newly discovered clients.
|
||||
type ClientPolicyConfig struct {
|
||||
Default string `yaml:"default"` // "disabled" | "direct" | "vpn"
|
||||
}
|
||||
|
||||
type MihomoConfig struct {
|
||||
@@ -72,13 +79,32 @@ type FirewallConfig struct {
|
||||
VLANIsolation bool `yaml:"vlan_isolation" json:"vlan_isolation"`
|
||||
}
|
||||
|
||||
type CheckEndpoint struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
URL string `yaml:"url" json:"url"`
|
||||
}
|
||||
|
||||
type ConnectivityConfig struct {
|
||||
Direct []CheckEndpoint `yaml:"direct" json:"direct"`
|
||||
ViaProxy []CheckEndpoint `yaml:"via_proxy" json:"via_proxy"`
|
||||
}
|
||||
|
||||
type AuthConfig struct {
|
||||
Username string `yaml:"username,omitempty"`
|
||||
PasswordHash string `yaml:"password_hash,omitempty"`
|
||||
APIKey string `yaml:"api_key,omitempty"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
Interfaces map[string]*InterfaceConfig `yaml:"interfaces"`
|
||||
DHCP DHCPConfig `yaml:"dhcp"`
|
||||
NAT NATConfig `yaml:"nat"`
|
||||
Firewall FirewallConfig `yaml:"firewall"`
|
||||
KnownDevices []KnownDevice `yaml:"known_devices"`
|
||||
Mihomo MihomoConfig `yaml:"mihomo"`
|
||||
Interfaces map[string]*InterfaceConfig `yaml:"interfaces"`
|
||||
DHCP DHCPConfig `yaml:"dhcp"`
|
||||
NAT NATConfig `yaml:"nat"`
|
||||
Firewall FirewallConfig `yaml:"firewall"`
|
||||
KnownDevices []KnownDevice `yaml:"known_devices"`
|
||||
Mihomo MihomoConfig `yaml:"mihomo"`
|
||||
ClientPolicy ClientPolicyConfig `yaml:"client_policy,omitempty"`
|
||||
Connectivity ConnectivityConfig `yaml:"connectivity,omitempty" json:"connectivity,omitempty"`
|
||||
Auth AuthConfig `yaml:"auth,omitempty"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -187,6 +213,19 @@ func defaultConfig() *AppConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultConnectivity() ConnectivityConfig {
|
||||
return ConnectivityConfig{
|
||||
Direct: []CheckEndpoint{
|
||||
{Name: "Cloudflare", URL: "http://cp.cloudflare.com/generate_204"},
|
||||
{Name: "Google", URL: "http://connectivitycheck.gstatic.com/generate_204"},
|
||||
},
|
||||
ViaProxy: []CheckEndpoint{
|
||||
{Name: "Cloudflare", URL: "http://cp.cloudflare.com/generate_204"},
|
||||
{Name: "Google", URL: "http://connectivitycheck.gstatic.com/generate_204"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func EnsureDefaults(cfg *AppConfig) {
|
||||
if cfg.Interfaces == nil {
|
||||
cfg.Interfaces = map[string]*InterfaceConfig{}
|
||||
@@ -203,6 +242,12 @@ func EnsureDefaults(cfg *AppConfig) {
|
||||
if cfg.KnownDevices == nil {
|
||||
cfg.KnownDevices = []KnownDevice{}
|
||||
}
|
||||
if cfg.ClientPolicy.Default == "" {
|
||||
cfg.ClientPolicy.Default = "direct"
|
||||
}
|
||||
if len(cfg.Connectivity.Direct) == 0 {
|
||||
cfg.Connectivity = DefaultConnectivity()
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateKnownDevices(seen []KnownDevice) error {
|
||||
@@ -238,6 +283,7 @@ func UpdateKnownDevices(seen []KnownDevice) error {
|
||||
if d.StaticIP != "" {
|
||||
existingDev.StaticIP = d.StaticIP
|
||||
}
|
||||
// Policy is always preserved from existingDev; never overwritten by discovery
|
||||
existing[key] = existingDev
|
||||
} else {
|
||||
existing[key] = d
|
||||
|
||||
Reference in New Issue
Block a user