8ad4c3576d
- Fixed verifyAssignment being too strict for new clients - Fixed parseRequestedIP string conversion bug - Fixed response sent to 0.0.0.0 instead of broadcast address - Added SO_BROADCAST support for UDP socket - Fixed session persistence after page refresh (localStorage) - Added in-memory session store for auth middleware - Added config reloader so DHCP server picks up web UI changes dynamically
77 라인
2.0 KiB
Go
77 라인
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
DHCP DHCPConfig `json:"dhcp"`
|
|
DNS DNSConfig `json:"dns"`
|
|
Web WebConfig `json:"web"`
|
|
Database DatabaseConfig `json:"database"`
|
|
}
|
|
|
|
type DHCPConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
Interface string `json:"interface"`
|
|
Network string `json:"network"`
|
|
Netmask string `json:"netmask"`
|
|
Gateway string `json:"gateway"`
|
|
DNSServers []string `json:"dns_servers"`
|
|
NTPServers []string `json:"ntp_servers"`
|
|
BroadcastAddress string `json:"broadcast_address"`
|
|
LeaseTime int `json:"lease_time"` // seconds
|
|
IPPoolStart string `json:"ip_pool_start"`
|
|
IPPoolEnd string `json:"ip_pool_end"`
|
|
DomainName string `json:"domain_name"`
|
|
ExcludedIPs []string `json:"excluded_ips"`
|
|
}
|
|
|
|
type DNSConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
ListenAddr string `json:"listen_addr"`
|
|
ListenPort int `json:"listen_port"`
|
|
Upstream []string `json:"upstream"`
|
|
CacheSize int `json:"cache_size"`
|
|
CacheTTL int `json:"cache_ttl"`
|
|
Recursion bool `json:"recursion"`
|
|
AllowQuery []string `json:"allow_query"`
|
|
DNSSECValidation bool `json:"dnssec_validation"`
|
|
}
|
|
|
|
type WebConfig struct {
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
SessionKey string `json:"session_key"`
|
|
EnableHTTPS bool `json:"enable_https"`
|
|
CertFile string `json:"https_cert"`
|
|
KeyFile string `json:"https_key"`
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Path string `json:"path"`
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var cfg Config
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
func (c *Config) Save(path string) error {
|
|
data, err := json.MarshalIndent(c, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(path, data, 0644)
|
|
}
|