2019-06-10 11:33:19 +03:00
|
|
|
package home
|
2018-08-30 17:25:33 +03:00
|
|
|
|
|
|
|
import (
|
2022-08-08 15:50:54 +03:00
|
|
|
"bytes"
|
2021-12-28 17:00:52 +03:00
|
|
|
"fmt"
|
2022-10-14 15:29:44 +03:00
|
|
|
"net/netip"
|
2018-08-30 17:25:33 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"sync"
|
2018-10-30 17:16:20 +03:00
|
|
|
|
2022-01-19 20:45:50 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
|
2022-10-14 20:14:07 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtls"
|
2023-12-15 20:27:47 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
|
2020-10-30 13:32:02 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
2021-05-21 16:15:47 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
2020-10-30 13:32:02 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
2023-06-14 15:08:57 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/schedule"
|
2020-10-30 13:32:02 +03:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
2021-08-27 20:16:07 +03:00
|
|
|
"github.com/AdguardTeam/dnsproxy/fastip"
|
2021-05-24 17:28:11 +03:00
|
|
|
"github.com/AdguardTeam/golibs/errors"
|
2019-02-25 16:44:22 +03:00
|
|
|
"github.com/AdguardTeam/golibs/log"
|
2024-01-17 15:06:16 +03:00
|
|
|
"github.com/AdguardTeam/golibs/netutil"
|
2021-09-30 21:17:54 +03:00
|
|
|
"github.com/AdguardTeam/golibs/timeutil"
|
2023-07-25 17:47:24 +03:00
|
|
|
"github.com/google/renameio/v2/maybe"
|
2022-08-08 15:50:54 +03:00
|
|
|
yaml "gopkg.in/yaml.v3"
|
2018-08-30 17:25:33 +03:00
|
|
|
)
|
|
|
|
|
2022-09-23 13:23:35 +03:00
|
|
|
// dataDir is the name of a directory under the working one to store some
|
|
|
|
// persistent data.
|
|
|
|
const dataDir = "data"
|
2018-10-30 17:16:20 +03:00
|
|
|
|
2022-08-08 15:50:54 +03:00
|
|
|
// logSettings are the logging settings part of the configuration file.
|
2019-02-04 13:54:53 +03:00
|
|
|
type logSettings struct {
|
2022-08-08 15:50:54 +03:00
|
|
|
// File is the path to the log file. If empty, logs are written to stdout.
|
|
|
|
// If "syslog", logs are written to syslog.
|
2023-07-06 10:09:04 +03:00
|
|
|
File string `yaml:"file"`
|
2022-08-08 15:50:54 +03:00
|
|
|
|
|
|
|
// MaxBackups is the maximum number of old log files to retain.
|
|
|
|
//
|
|
|
|
// NOTE: MaxAge may still cause them to get deleted.
|
2023-07-06 10:09:04 +03:00
|
|
|
MaxBackups int `yaml:"max_backups"`
|
2022-08-08 15:50:54 +03:00
|
|
|
|
|
|
|
// MaxSize is the maximum size of the log file before it gets rotated, in
|
|
|
|
// megabytes. The default value is 100 MB.
|
2023-07-06 10:09:04 +03:00
|
|
|
MaxSize int `yaml:"max_size"`
|
2022-08-08 15:50:54 +03:00
|
|
|
|
|
|
|
// MaxAge is the maximum duration for retaining old log files, in days.
|
2023-07-06 10:09:04 +03:00
|
|
|
MaxAge int `yaml:"max_age"`
|
2022-08-08 15:50:54 +03:00
|
|
|
|
|
|
|
// Compress determines, if the rotated log files should be compressed using
|
|
|
|
// gzip.
|
2023-07-06 10:09:04 +03:00
|
|
|
Compress bool `yaml:"compress"`
|
2022-08-08 15:50:54 +03:00
|
|
|
|
|
|
|
// LocalTime determines, if the time used for formatting the timestamps in
|
|
|
|
// is the computer's local time.
|
2023-07-06 10:09:04 +03:00
|
|
|
LocalTime bool `yaml:"local_time"`
|
2022-08-08 15:50:54 +03:00
|
|
|
|
|
|
|
// Verbose determines, if verbose (aka debug) logging is enabled.
|
|
|
|
Verbose bool `yaml:"verbose"`
|
2019-02-04 13:54:53 +03:00
|
|
|
}
|
|
|
|
|
2021-06-04 16:35:34 +03:00
|
|
|
// osConfig contains OS-related configuration.
|
|
|
|
type osConfig struct {
|
|
|
|
// Group is the name of the group which AdGuard Home must switch to on
|
|
|
|
// startup. Empty string means no switching.
|
|
|
|
Group string `yaml:"group"`
|
|
|
|
// User is the name of the user which AdGuard Home must switch to on
|
|
|
|
// startup. Empty string means no switching.
|
|
|
|
User string `yaml:"user"`
|
|
|
|
// RlimitNoFile is the maximum number of opened fd's per process. Zero
|
|
|
|
// means use the default value.
|
|
|
|
RlimitNoFile uint64 `yaml:"rlimit_nofile"`
|
|
|
|
}
|
|
|
|
|
2022-04-26 13:04:16 +03:00
|
|
|
type clientsConfig struct {
|
|
|
|
// Sources defines the set of sources to fetch the runtime clients from.
|
2023-03-01 13:27:24 +03:00
|
|
|
Sources *clientSourcesConfig `yaml:"runtime_sources"`
|
2022-04-26 13:04:16 +03:00
|
|
|
// Persistent are the configured clients.
|
|
|
|
Persistent []*clientObject `yaml:"persistent"`
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:27:24 +03:00
|
|
|
// clientSourceConfig is used to configure where the runtime clients will be
|
|
|
|
// obtained from.
|
|
|
|
type clientSourcesConfig struct {
|
|
|
|
WHOIS bool `yaml:"whois"`
|
|
|
|
ARP bool `yaml:"arp"`
|
|
|
|
RDNS bool `yaml:"rdns"`
|
|
|
|
DHCP bool `yaml:"dhcp"`
|
|
|
|
HostsFile bool `yaml:"hosts"`
|
|
|
|
}
|
|
|
|
|
2023-06-29 15:29:52 +03:00
|
|
|
// configuration is loaded from YAML.
|
|
|
|
//
|
|
|
|
// Field ordering is important, YAML fields better not to be reordered, if it's
|
|
|
|
// not absolutely necessary.
|
2018-08-30 17:25:33 +03:00
|
|
|
type configuration struct {
|
2019-04-30 14:38:24 +03:00
|
|
|
// Raw file data to avoid re-reading of configuration file
|
|
|
|
// It's reset after config is parsed
|
|
|
|
fileData []byte
|
|
|
|
|
2023-06-29 15:29:52 +03:00
|
|
|
// HTTPConfig is the block with http conf.
|
|
|
|
HTTPConfig httpConfig `yaml:"http"`
|
2022-10-14 15:29:44 +03:00
|
|
|
// Users are the clients capable for accessing the web interface.
|
|
|
|
Users []webUser `yaml:"users"`
|
2021-04-27 18:56:32 +03:00
|
|
|
// AuthAttempts is the maximum number of failed login attempts a user
|
|
|
|
// can do before being blocked.
|
|
|
|
AuthAttempts uint `yaml:"auth_attempts"`
|
|
|
|
// AuthBlockMin is the duration, in minutes, of the block of new login
|
|
|
|
// attempts after AuthAttempts unsuccessful login attempts.
|
2022-10-14 15:29:44 +03:00
|
|
|
AuthBlockMin uint `yaml:"block_auth_min"`
|
|
|
|
// ProxyURL is the address of proxy server for the internal HTTP client.
|
|
|
|
ProxyURL string `yaml:"http_proxy"`
|
|
|
|
// Language is a two-letter ISO 639-1 language code.
|
|
|
|
Language string `yaml:"language"`
|
2023-01-13 19:24:17 +03:00
|
|
|
// Theme is a UI theme for current user.
|
|
|
|
Theme Theme `yaml:"theme"`
|
2019-03-27 17:09:48 +03:00
|
|
|
|
2023-11-17 16:52:41 +03:00
|
|
|
// TODO(a.garipov): Make DNS and the fields below pointers and validate
|
|
|
|
// and/or reset on explicit nulling.
|
2023-02-07 17:50:39 +03:00
|
|
|
DNS dnsConfig `yaml:"dns"`
|
|
|
|
TLS tlsConfigSettings `yaml:"tls"`
|
|
|
|
QueryLog queryLogConfig `yaml:"querylog"`
|
2023-02-13 18:15:33 +03:00
|
|
|
Stats statsConfig `yaml:"statistics"`
|
2020-02-26 19:58:25 +03:00
|
|
|
|
2022-09-23 13:23:35 +03:00
|
|
|
// Filters reflects the filters from [filtering.Config]. It's cloned to the
|
|
|
|
// config used in the filtering module at the startup. Afterwards it's
|
|
|
|
// cloned from the filtering module back here.
|
|
|
|
//
|
|
|
|
// TODO(e.burkov): Move all the filtering configuration fields into the
|
|
|
|
// only configuration subsection covering the changes with a single
|
2022-10-14 15:29:44 +03:00
|
|
|
// migration. Also keep the blocked services in mind.
|
2022-09-23 13:23:35 +03:00
|
|
|
Filters []filtering.FilterYAML `yaml:"filters"`
|
|
|
|
WhitelistFilters []filtering.FilterYAML `yaml:"whitelist_filters"`
|
|
|
|
UserRules []string `yaml:"user_rules"`
|
2020-02-26 19:58:25 +03:00
|
|
|
|
2023-08-30 18:26:02 +03:00
|
|
|
DHCP *dhcpd.ServerConfig `yaml:"dhcp"`
|
|
|
|
Filtering *filtering.Config `yaml:"filtering"`
|
2018-08-30 17:25:33 +03:00
|
|
|
|
2021-12-13 15:24:35 +03:00
|
|
|
// Clients contains the YAML representations of the persistent clients.
|
|
|
|
// This field is only used for reading and writing persistent client data.
|
|
|
|
// Keep this field sorted to ensure consistent ordering.
|
2022-04-26 13:04:16 +03:00
|
|
|
Clients *clientsConfig `yaml:"clients"`
|
2019-04-26 16:04:22 +03:00
|
|
|
|
2023-07-06 10:09:04 +03:00
|
|
|
// Log is a block with log configuration settings.
|
|
|
|
Log logSettings `yaml:"log"`
|
2019-02-04 13:54:53 +03:00
|
|
|
|
2021-06-04 16:35:34 +03:00
|
|
|
OSConfig *osConfig `yaml:"os"`
|
|
|
|
|
2018-10-07 00:58:59 +03:00
|
|
|
sync.RWMutex `yaml:"-"`
|
2018-11-27 20:51:12 +03:00
|
|
|
|
2023-09-04 20:45:50 +03:00
|
|
|
// SchemaVersion is the version of the configuration schema. See
|
2023-12-15 20:27:47 +03:00
|
|
|
// [configmigrate.LastSchemaVersion].
|
2023-09-04 20:45:50 +03:00
|
|
|
SchemaVersion uint `yaml:"schema_version"`
|
2018-08-30 17:25:33 +03:00
|
|
|
}
|
|
|
|
|
2023-06-29 15:29:52 +03:00
|
|
|
// httpConfig is a block with HTTP configuration params.
|
|
|
|
//
|
|
|
|
// Field ordering is important, YAML fields better not to be reordered, if it's
|
|
|
|
// not absolutely necessary.
|
|
|
|
type httpConfig struct {
|
2023-08-02 17:39:33 +03:00
|
|
|
// Pprof defines the profiling HTTP handler.
|
|
|
|
Pprof *httpPprofConfig `yaml:"pprof"`
|
|
|
|
|
2023-06-29 15:29:52 +03:00
|
|
|
// Address is the address to serve the web UI on.
|
|
|
|
Address netip.AddrPort
|
|
|
|
|
|
|
|
// SessionTTL for a web session.
|
|
|
|
// An active session is automatically refreshed once a day.
|
|
|
|
SessionTTL timeutil.Duration `yaml:"session_ttl"`
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:39:33 +03:00
|
|
|
// httpPprofConfig is the block with pprof HTTP configuration.
|
|
|
|
type httpPprofConfig struct {
|
|
|
|
// Port for the profiling handler.
|
|
|
|
Port uint16 `yaml:"port"`
|
|
|
|
|
|
|
|
// Enabled defines if the profiling handler is enabled.
|
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
}
|
|
|
|
|
2023-06-29 15:29:52 +03:00
|
|
|
// dnsConfig is a block with DNS configuration params.
|
|
|
|
//
|
|
|
|
// Field ordering is important, YAML fields better not to be reordered, if it's
|
|
|
|
// not absolutely necessary.
|
2018-12-05 20:29:00 +03:00
|
|
|
type dnsConfig struct {
|
2022-10-14 15:29:44 +03:00
|
|
|
BindHosts []netip.Addr `yaml:"bind_hosts"`
|
2023-10-05 15:26:19 +03:00
|
|
|
Port uint16 `yaml:"port"`
|
2018-11-28 18:24:04 +03:00
|
|
|
|
2022-10-14 15:29:44 +03:00
|
|
|
// AnonymizeClientIP defines if clients' IP addresses should be anonymized
|
|
|
|
// in query log and statistics.
|
|
|
|
AnonymizeClientIP bool `yaml:"anonymize_client_ip"`
|
2019-10-30 11:52:58 +03:00
|
|
|
|
2023-08-30 18:26:02 +03:00
|
|
|
// Config is the embed configuration with DNS params.
|
|
|
|
//
|
|
|
|
// TODO(a.garipov): Remove embed.
|
|
|
|
dnsforward.Config `yaml:",inline"`
|
2021-03-25 16:00:27 +03:00
|
|
|
|
2021-06-15 17:36:49 +03:00
|
|
|
// UpstreamTimeout is the timeout for querying upstream servers.
|
2021-09-30 21:17:54 +03:00
|
|
|
UpstreamTimeout timeutil.Duration `yaml:"upstream_timeout"`
|
2021-06-15 17:36:49 +03:00
|
|
|
|
2022-03-18 13:37:27 +03:00
|
|
|
// PrivateNets is the set of IP networks for which the private reverse DNS
|
|
|
|
// resolver should be used.
|
2024-01-17 15:06:16 +03:00
|
|
|
PrivateNets []netutil.Prefix `yaml:"private_networks"`
|
2022-03-18 13:37:27 +03:00
|
|
|
|
2024-04-22 19:17:30 +03:00
|
|
|
// UsePrivateRDNS enables resolving requests containing a private IP address
|
|
|
|
// using private reverse DNS resolvers. See PrivateRDNSResolvers.
|
|
|
|
//
|
|
|
|
// TODO(e.burkov): Rename in YAML.
|
2021-05-26 17:55:19 +03:00
|
|
|
UsePrivateRDNS bool `yaml:"use_private_ptr_resolvers"`
|
|
|
|
|
2024-04-22 19:17:30 +03:00
|
|
|
// PrivateRDNSResolvers is the slice of addresses to be used as upstreams
|
|
|
|
// for private requests. It's only used for PTR, SOA, and NS queries,
|
|
|
|
// containing an ARPA subdomain, came from the the client with private
|
|
|
|
// address. The address considered private according to PrivateNets.
|
|
|
|
//
|
|
|
|
// If empty, the OS-provided resolvers are used for private requests.
|
|
|
|
PrivateRDNSResolvers []string `yaml:"local_ptr_upstreams"`
|
2022-10-03 18:08:05 +03:00
|
|
|
|
2024-04-22 19:17:30 +03:00
|
|
|
// UseDNS64 defines if DNS64 should be used for incoming requests. Requests
|
|
|
|
// of type PTR for addresses within the configured prefixes will be resolved
|
|
|
|
// via [PrivateRDNSResolvers], so those should be valid and UsePrivateRDNS
|
|
|
|
// be set to true.
|
2023-01-23 19:10:56 +03:00
|
|
|
UseDNS64 bool `yaml:"use_dns64"`
|
|
|
|
|
|
|
|
// DNS64Prefixes is the list of NAT64 prefixes to be used for DNS64.
|
2023-02-06 17:17:51 +03:00
|
|
|
DNS64Prefixes []netip.Prefix `yaml:"dns64_prefixes"`
|
2023-01-23 19:10:56 +03:00
|
|
|
|
2023-11-17 16:52:41 +03:00
|
|
|
// ServeHTTP3 defines if HTTP/3 is allowed for incoming requests.
|
2022-10-03 18:08:05 +03:00
|
|
|
//
|
|
|
|
// TODO(a.garipov): Add to the UI when HTTP/3 support is no longer
|
|
|
|
// experimental.
|
|
|
|
ServeHTTP3 bool `yaml:"serve_http3"`
|
|
|
|
|
2023-11-17 16:52:41 +03:00
|
|
|
// UseHTTP3Upstreams defines if HTTP/3 is allowed for DNS-over-HTTPS
|
2022-10-03 18:08:05 +03:00
|
|
|
// upstreams.
|
|
|
|
//
|
|
|
|
// TODO(a.garipov): Add to the UI when HTTP/3 support is no longer
|
|
|
|
// experimental.
|
|
|
|
UseHTTP3Upstreams bool `yaml:"use_http3_upstreams"`
|
2023-11-22 13:49:02 +03:00
|
|
|
|
|
|
|
// ServePlainDNS defines if plain DNS is allowed for incoming requests.
|
|
|
|
ServePlainDNS bool `yaml:"serve_plain_dns"`
|
2024-02-21 13:04:58 +03:00
|
|
|
|
|
|
|
// HostsFileEnabled defines whether to use information from the system hosts
|
|
|
|
// file to resolve queries.
|
|
|
|
HostsFileEnabled bool `yaml:"hostsfile_enabled"`
|
2018-08-30 17:25:33 +03:00
|
|
|
}
|
|
|
|
|
2019-02-13 11:08:07 +03:00
|
|
|
type tlsConfigSettings struct {
|
2021-06-18 18:13:36 +03:00
|
|
|
Enabled bool `yaml:"enabled" json:"enabled"` // Enabled is the encryption (DoT/DoH/HTTPS) status
|
2020-08-27 15:03:07 +03:00
|
|
|
ServerName string `yaml:"server_name" json:"server_name,omitempty"` // ServerName is the hostname of your HTTPS/TLS server
|
2021-12-13 13:48:08 +03:00
|
|
|
ForceHTTPS bool `yaml:"force_https" json:"force_https"` // ForceHTTPS: if true, forces HTTP->HTTPS redirect
|
2023-10-05 15:26:19 +03:00
|
|
|
PortHTTPS uint16 `yaml:"port_https" json:"port_https,omitempty"` // HTTPS port. If 0, HTTPS will be disabled
|
|
|
|
PortDNSOverTLS uint16 `yaml:"port_dns_over_tls" json:"port_dns_over_tls,omitempty"` // DNS-over-TLS port. If 0, DoT will be disabled
|
|
|
|
PortDNSOverQUIC uint16 `yaml:"port_dns_over_quic" json:"port_dns_over_quic,omitempty"` // DNS-over-QUIC port. If 0, DoQ will be disabled
|
2019-02-12 17:23:38 +03:00
|
|
|
|
2020-12-07 17:58:33 +03:00
|
|
|
// PortDNSCrypt is the port for DNSCrypt requests. If it's zero,
|
|
|
|
// DNSCrypt is disabled.
|
2023-10-05 15:26:19 +03:00
|
|
|
PortDNSCrypt uint16 `yaml:"port_dnscrypt" json:"port_dnscrypt"`
|
2020-12-07 17:58:33 +03:00
|
|
|
// DNSCryptConfigFile is the path to the DNSCrypt config file. Must be
|
|
|
|
// set if PortDNSCrypt is not zero.
|
|
|
|
//
|
|
|
|
// See https://github.com/AdguardTeam/dnsproxy and
|
|
|
|
// https://github.com/ameshkov/dnscrypt.
|
|
|
|
DNSCryptConfigFile string `yaml:"dnscrypt_config_file" json:"dnscrypt_config_file"`
|
|
|
|
|
2021-06-18 18:13:36 +03:00
|
|
|
// Allow DoH queries via unencrypted HTTP (e.g. for reverse proxying)
|
|
|
|
AllowUnencryptedDoH bool `yaml:"allow_unencrypted_doh" json:"allow_unencrypted_doh"`
|
2019-12-13 15:59:36 +03:00
|
|
|
|
2019-02-12 17:23:38 +03:00
|
|
|
dnsforward.TLSConfig `yaml:",inline" json:",inline"`
|
2019-02-13 11:08:07 +03:00
|
|
|
}
|
|
|
|
|
2023-02-07 17:50:39 +03:00
|
|
|
type queryLogConfig struct {
|
2024-02-12 18:45:51 +03:00
|
|
|
// DirPath is the custom directory for logs. If it's empty the default
|
|
|
|
// directory will be used. See [homeContext.getDataDir].
|
|
|
|
DirPath string `yaml:"dir_path"`
|
|
|
|
|
2023-03-23 13:46:57 +03:00
|
|
|
// Ignored is the list of host names, which should not be written to log.
|
2023-07-11 20:42:40 +03:00
|
|
|
// "." is considered to be the root domain.
|
2023-03-23 13:46:57 +03:00
|
|
|
Ignored []string `yaml:"ignored"`
|
2023-02-07 17:50:39 +03:00
|
|
|
|
|
|
|
// Interval is the interval for query log's files rotation.
|
|
|
|
Interval timeutil.Duration `yaml:"interval"`
|
|
|
|
|
2023-03-23 13:46:57 +03:00
|
|
|
// MemSize is the number of entries kept in memory before they are flushed
|
|
|
|
// to disk.
|
2024-01-11 18:38:30 +03:00
|
|
|
MemSize uint `yaml:"size_memory"`
|
2023-02-07 17:50:39 +03:00
|
|
|
|
2023-03-23 13:46:57 +03:00
|
|
|
// Enabled defines if the query log is enabled.
|
2023-02-13 18:15:33 +03:00
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
|
2023-03-23 13:46:57 +03:00
|
|
|
// FileEnabled defines, if the query log is written to the file.
|
|
|
|
FileEnabled bool `yaml:"file_enabled"`
|
|
|
|
}
|
2023-02-13 18:15:33 +03:00
|
|
|
|
2023-03-23 13:46:57 +03:00
|
|
|
type statsConfig struct {
|
2024-02-12 18:45:51 +03:00
|
|
|
// DirPath is the custom directory for statistics. If it's empty the
|
|
|
|
// default directory is used. See [homeContext.getDataDir].
|
|
|
|
DirPath string `yaml:"dir_path"`
|
|
|
|
|
2023-02-13 18:15:33 +03:00
|
|
|
// Ignored is the list of host names, which should not be counted.
|
2023-02-07 17:50:39 +03:00
|
|
|
Ignored []string `yaml:"ignored"`
|
2023-03-23 13:46:57 +03:00
|
|
|
|
|
|
|
// Interval is the retention interval for statistics.
|
|
|
|
Interval timeutil.Duration `yaml:"interval"`
|
|
|
|
|
|
|
|
// Enabled defines if the statistics are enabled.
|
|
|
|
Enabled bool `yaml:"enabled"`
|
2023-02-07 17:50:39 +03:00
|
|
|
}
|
|
|
|
|
2023-09-08 15:04:25 +03:00
|
|
|
// Default block host constants.
|
|
|
|
const (
|
|
|
|
defaultSafeBrowsingBlockHost = "standard-block.dns.adguard.com"
|
|
|
|
defaultParentalBlockHost = "family-block.dns.adguard.com"
|
|
|
|
)
|
|
|
|
|
2021-09-13 16:00:36 +03:00
|
|
|
// config is the global configuration structure.
|
|
|
|
//
|
2021-12-27 19:40:39 +03:00
|
|
|
// TODO(a.garipov, e.burkov): This global is awful and must be removed.
|
2021-09-13 16:00:36 +03:00
|
|
|
var config = &configuration{
|
2023-06-29 15:29:52 +03:00
|
|
|
AuthAttempts: 5,
|
|
|
|
AuthBlockMin: 15,
|
|
|
|
HTTPConfig: httpConfig{
|
|
|
|
Address: netip.AddrPortFrom(netip.IPv4Unspecified(), 3000),
|
|
|
|
SessionTTL: timeutil.Duration{Duration: 30 * timeutil.Day},
|
2023-08-02 17:39:33 +03:00
|
|
|
Pprof: &httpPprofConfig{
|
|
|
|
Enabled: false,
|
|
|
|
Port: 6060,
|
|
|
|
},
|
2023-06-29 15:29:52 +03:00
|
|
|
},
|
2018-12-05 20:29:00 +03:00
|
|
|
DNS: dnsConfig{
|
2023-02-13 18:15:33 +03:00
|
|
|
BindHosts: []netip.Addr{netip.IPv4Unspecified()},
|
|
|
|
Port: defaultPortDNS,
|
2023-08-30 18:26:02 +03:00
|
|
|
Config: dnsforward.Config{
|
2023-11-09 16:44:28 +03:00
|
|
|
Ratelimit: 20,
|
|
|
|
RatelimitSubnetLenIPv4: 24,
|
|
|
|
RatelimitSubnetLenIPv6: 56,
|
|
|
|
RefuseAny: true,
|
2023-12-25 14:16:48 +03:00
|
|
|
UpstreamMode: dnsforward.UpstreamModeLoadBalance,
|
2023-11-09 16:44:28 +03:00
|
|
|
HandleDDR: true,
|
2021-09-30 21:17:54 +03:00
|
|
|
FastestTimeout: timeutil.Duration{
|
2021-08-27 20:16:07 +03:00
|
|
|
Duration: fastip.DefaultPingWaitTimeout,
|
|
|
|
},
|
2020-11-05 13:26:13 +03:00
|
|
|
|
2024-01-17 15:06:16 +03:00
|
|
|
TrustedProxies: []netutil.Prefix{{
|
|
|
|
Prefix: netip.MustParsePrefix("127.0.0.0/8"),
|
|
|
|
}, {
|
|
|
|
Prefix: netip.MustParsePrefix("::1/128"),
|
|
|
|
}},
|
|
|
|
CacheSize: 4 * 1024 * 1024,
|
2021-07-26 19:30:35 +03:00
|
|
|
|
2023-03-07 14:37:14 +03:00
|
|
|
EDNSClientSubnet: &dnsforward.EDNSClientSubnet{
|
2023-03-22 13:42:20 +03:00
|
|
|
CustomIP: netip.Addr{},
|
2023-03-07 14:37:14 +03:00
|
|
|
Enabled: false,
|
|
|
|
UseCustom: false,
|
|
|
|
},
|
|
|
|
|
2020-11-05 13:26:13 +03:00
|
|
|
// set default maximum concurrent queries to 300
|
|
|
|
// we introduced a default limit due to this:
|
|
|
|
// https://github.com/AdguardTeam/AdGuardHome/issues/2015#issuecomment-674041912
|
|
|
|
// was later increased to 300 due to https://github.com/AdguardTeam/AdGuardHome/issues/2257
|
|
|
|
MaxGoroutines: 300,
|
2018-11-28 18:24:04 +03:00
|
|
|
},
|
2024-02-21 13:04:58 +03:00
|
|
|
UpstreamTimeout: timeutil.Duration{Duration: dnsforward.DefaultTimeout},
|
|
|
|
UsePrivateRDNS: true,
|
|
|
|
ServePlainDNS: true,
|
|
|
|
HostsFileEnabled: true,
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
2020-02-19 15:28:06 +03:00
|
|
|
TLS: tlsConfigSettings{
|
2021-09-17 18:31:07 +03:00
|
|
|
PortHTTPS: defaultPortHTTPS,
|
|
|
|
PortDNSOverTLS: defaultPortTLS, // needs to be passed through to dnsproxy
|
|
|
|
PortDNSOverQUIC: defaultPortQUIC,
|
2019-02-11 21:52:39 +03:00
|
|
|
},
|
2023-02-07 17:50:39 +03:00
|
|
|
QueryLog: queryLogConfig{
|
|
|
|
Enabled: true,
|
|
|
|
FileEnabled: true,
|
|
|
|
Interval: timeutil.Duration{Duration: 90 * timeutil.Day},
|
|
|
|
MemSize: 1000,
|
|
|
|
Ignored: []string{},
|
|
|
|
},
|
2023-02-13 18:15:33 +03:00
|
|
|
Stats: statsConfig{
|
|
|
|
Enabled: true,
|
2023-03-23 13:46:57 +03:00
|
|
|
Interval: timeutil.Duration{Duration: 1 * timeutil.Day},
|
2023-02-13 18:15:33 +03:00
|
|
|
Ignored: []string{},
|
|
|
|
},
|
2022-12-08 16:27:10 +03:00
|
|
|
// NOTE: Keep these parameters in sync with the one put into
|
2024-06-10 18:42:23 +03:00
|
|
|
// client/src/helpers/filters/filters.ts by scripts/vetted-filters.
|
2022-12-08 16:27:10 +03:00
|
|
|
//
|
|
|
|
// TODO(a.garipov): Think of a way to make scripts/vetted-filters update
|
|
|
|
// these as well if necessary.
|
2022-09-23 13:23:35 +03:00
|
|
|
Filters: []filtering.FilterYAML{{
|
|
|
|
Filter: filtering.Filter{ID: 1},
|
|
|
|
Enabled: true,
|
2022-12-08 16:27:10 +03:00
|
|
|
URL: "https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt",
|
2022-09-23 13:23:35 +03:00
|
|
|
Name: "AdGuard DNS filter",
|
|
|
|
}, {
|
|
|
|
Filter: filtering.Filter{ID: 2},
|
|
|
|
Enabled: false,
|
2022-12-08 16:27:10 +03:00
|
|
|
URL: "https://adguardteam.github.io/HostlistsRegistry/assets/filter_2.txt",
|
2022-09-23 13:23:35 +03:00
|
|
|
Name: "AdAway Default Blocklist",
|
|
|
|
}},
|
2023-08-30 18:26:02 +03:00
|
|
|
Filtering: &filtering.Config{
|
|
|
|
ProtectionEnabled: true,
|
|
|
|
BlockingMode: filtering.BlockingModeDefault,
|
|
|
|
BlockedResponseTTL: 10, // in seconds
|
|
|
|
|
|
|
|
FilteringEnabled: true,
|
|
|
|
FiltersUpdateIntervalHours: 24,
|
|
|
|
|
|
|
|
ParentalEnabled: false,
|
|
|
|
SafeBrowsingEnabled: false,
|
|
|
|
|
|
|
|
SafeBrowsingCacheSize: 1 * 1024 * 1024,
|
|
|
|
SafeSearchCacheSize: 1 * 1024 * 1024,
|
|
|
|
ParentalCacheSize: 1 * 1024 * 1024,
|
|
|
|
CacheTime: 30,
|
|
|
|
|
|
|
|
SafeSearchConf: filtering.SafeSearchConfig{
|
|
|
|
Enabled: false,
|
|
|
|
Bing: true,
|
|
|
|
DuckDuckGo: true,
|
|
|
|
Google: true,
|
|
|
|
Pixabay: true,
|
|
|
|
Yandex: true,
|
|
|
|
YouTube: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
BlockedServices: &filtering.BlockedServices{
|
|
|
|
Schedule: schedule.EmptyWeekly(),
|
|
|
|
IDs: []string{},
|
|
|
|
},
|
2023-09-08 15:04:25 +03:00
|
|
|
|
|
|
|
ParentalBlockHost: defaultParentalBlockHost,
|
|
|
|
SafeBrowsingBlockHost: defaultSafeBrowsingBlockHost,
|
2023-08-30 18:26:02 +03:00
|
|
|
},
|
2022-01-25 19:47:02 +03:00
|
|
|
DHCP: &dhcpd.ServerConfig{
|
|
|
|
LocalDomainName: "lan",
|
2022-09-23 13:23:35 +03:00
|
|
|
Conf4: dhcpd.V4ServerConf{
|
|
|
|
LeaseDuration: dhcpd.DefaultDHCPLeaseTTL,
|
|
|
|
ICMPTimeout: dhcpd.DefaultDHCPTimeoutICMP,
|
|
|
|
},
|
|
|
|
Conf6: dhcpd.V6ServerConf{
|
|
|
|
LeaseDuration: dhcpd.DefaultDHCPLeaseTTL,
|
|
|
|
},
|
2022-01-25 19:47:02 +03:00
|
|
|
},
|
2022-04-26 13:04:16 +03:00
|
|
|
Clients: &clientsConfig{
|
2023-03-01 13:27:24 +03:00
|
|
|
Sources: &clientSourcesConfig{
|
2022-04-26 13:04:16 +03:00
|
|
|
WHOIS: true,
|
|
|
|
ARP: true,
|
|
|
|
RDNS: true,
|
|
|
|
DHCP: true,
|
|
|
|
HostsFile: true,
|
|
|
|
},
|
|
|
|
},
|
2023-07-06 10:09:04 +03:00
|
|
|
Log: logSettings{
|
2022-08-08 15:50:54 +03:00
|
|
|
Compress: false,
|
|
|
|
LocalTime: false,
|
|
|
|
MaxBackups: 0,
|
|
|
|
MaxSize: 100,
|
|
|
|
MaxAge: 3,
|
2020-06-02 14:20:12 +03:00
|
|
|
},
|
2021-06-04 16:35:34 +03:00
|
|
|
OSConfig: &osConfig{},
|
2023-12-15 20:27:47 +03:00
|
|
|
SchemaVersion: configmigrate.LastSchemaVersion,
|
2023-01-13 19:24:17 +03:00
|
|
|
Theme: ThemeAuto,
|
2018-08-30 17:25:33 +03:00
|
|
|
}
|
|
|
|
|
2024-02-21 17:01:15 +03:00
|
|
|
// configFilePath returns the absolute path to the symlink-evaluated path to the
|
|
|
|
// current config file.
|
|
|
|
func configFilePath() (confPath string) {
|
|
|
|
confPath, err := filepath.EvalSymlinks(Context.confFilePath)
|
2019-03-14 18:06:53 +03:00
|
|
|
if err != nil {
|
2024-02-21 17:01:15 +03:00
|
|
|
confPath = Context.confFilePath
|
|
|
|
logFunc := log.Error
|
|
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
|
|
logFunc = log.Debug
|
2019-03-14 18:06:53 +03:00
|
|
|
}
|
2024-02-21 17:01:15 +03:00
|
|
|
|
|
|
|
logFunc("evaluating config path: %s; using %q", err, confPath)
|
2019-03-14 18:06:53 +03:00
|
|
|
}
|
2024-02-21 17:01:15 +03:00
|
|
|
|
|
|
|
if !filepath.IsAbs(confPath) {
|
|
|
|
confPath = filepath.Join(Context.workDir, confPath)
|
2019-02-05 20:35:48 +03:00
|
|
|
}
|
2023-08-31 16:34:15 +03:00
|
|
|
|
2024-02-21 17:01:15 +03:00
|
|
|
return confPath
|
2019-02-05 20:35:48 +03:00
|
|
|
}
|
|
|
|
|
2023-04-21 18:57:53 +03:00
|
|
|
// validateBindHosts returns error if any of binding hosts from configuration is
|
|
|
|
// not a valid IP address.
|
|
|
|
func validateBindHosts(conf *configuration) (err error) {
|
2023-06-29 15:29:52 +03:00
|
|
|
if !conf.HTTPConfig.Address.IsValid() {
|
|
|
|
return errors.Error("http.address is not a valid ip address")
|
2023-04-21 18:57:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, addr := range conf.DNS.BindHosts {
|
|
|
|
if !addr.IsValid() {
|
|
|
|
return fmt.Errorf("dns.bind_hosts at index %d is not a valid ip address", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-31 16:34:15 +03:00
|
|
|
// parseConfig loads configuration from the YAML file, upgrading it if
|
|
|
|
// necessary.
|
2021-12-16 20:54:59 +03:00
|
|
|
func parseConfig() (err error) {
|
2023-08-31 16:34:15 +03:00
|
|
|
// Do the upgrade if necessary.
|
|
|
|
config.fileData, err = readConfigFile()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-12-15 20:27:47 +03:00
|
|
|
migrator := configmigrate.New(&configmigrate.Config{
|
2023-08-31 16:34:15 +03:00
|
|
|
WorkingDir: Context.workDir,
|
|
|
|
})
|
|
|
|
|
|
|
|
var upgraded bool
|
2023-09-04 20:45:50 +03:00
|
|
|
config.fileData, upgraded, err = migrator.Migrate(
|
|
|
|
config.fileData,
|
2023-12-15 20:27:47 +03:00
|
|
|
configmigrate.LastSchemaVersion,
|
2023-09-04 20:45:50 +03:00
|
|
|
)
|
2018-08-30 17:25:33 +03:00
|
|
|
if err != nil {
|
2023-08-31 16:34:15 +03:00
|
|
|
// Don't wrap the error, because it's informative enough as is.
|
2018-08-30 17:25:33 +03:00
|
|
|
return err
|
2023-08-31 16:34:15 +03:00
|
|
|
} else if upgraded {
|
2024-02-21 17:01:15 +03:00
|
|
|
confPath := configFilePath()
|
|
|
|
log.Debug("writing config file %q after config upgrade", confPath)
|
|
|
|
|
|
|
|
err = maybe.WriteFile(confPath, config.fileData, 0o644)
|
2023-08-31 16:34:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("writing new config: %w", err)
|
|
|
|
}
|
2018-08-30 17:25:33 +03:00
|
|
|
}
|
2021-12-16 20:54:59 +03:00
|
|
|
|
2023-08-31 16:34:15 +03:00
|
|
|
err = yaml.Unmarshal(config.fileData, &config)
|
2018-08-30 17:25:33 +03:00
|
|
|
if err != nil {
|
2023-04-21 18:57:53 +03:00
|
|
|
// Don't wrap the error since it's informative enough as is.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-31 16:34:15 +03:00
|
|
|
err = validateConfig()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.DNS.UpstreamTimeout.Duration == 0 {
|
|
|
|
config.DNS.UpstreamTimeout = timeutil.Duration{Duration: dnsforward.DefaultTimeout}
|
|
|
|
}
|
|
|
|
|
2024-02-21 17:01:15 +03:00
|
|
|
// Do not wrap the error because it's informative enough as is.
|
|
|
|
return setContextTLSCipherIDs()
|
2023-08-31 16:34:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// validateConfig returns error if the configuration is invalid.
|
|
|
|
func validateConfig() (err error) {
|
2023-04-21 18:57:53 +03:00
|
|
|
err = validateBindHosts(config)
|
|
|
|
if err != nil {
|
|
|
|
// Don't wrap the error since it's informative enough as is.
|
2021-12-16 20:54:59 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-08-03 14:36:18 +03:00
|
|
|
tcpPorts := aghalg.UniqChecker[tcpPort]{}
|
2023-06-29 15:29:52 +03:00
|
|
|
addPorts(tcpPorts, tcpPort(config.HTTPConfig.Address.Port()))
|
2022-08-03 14:36:18 +03:00
|
|
|
|
|
|
|
udpPorts := aghalg.UniqChecker[udpPort]{}
|
|
|
|
addPorts(udpPorts, udpPort(config.DNS.Port))
|
2021-12-28 17:00:52 +03:00
|
|
|
|
2021-12-16 20:54:59 +03:00
|
|
|
if config.TLS.Enabled {
|
2021-12-28 17:00:52 +03:00
|
|
|
addPorts(
|
2022-08-03 14:36:18 +03:00
|
|
|
tcpPorts,
|
2022-03-23 16:00:32 +03:00
|
|
|
tcpPort(config.TLS.PortHTTPS),
|
|
|
|
tcpPort(config.TLS.PortDNSOverTLS),
|
|
|
|
tcpPort(config.TLS.PortDNSCrypt),
|
2021-12-16 20:54:59 +03:00
|
|
|
)
|
2022-08-03 14:36:18 +03:00
|
|
|
|
|
|
|
// TODO(e.burkov): Consider adding a udpPort with the same value when
|
|
|
|
// we add support for HTTP/3 for web admin interface.
|
|
|
|
addPorts(udpPorts, udpPort(config.TLS.PortDNSOverQUIC))
|
2021-12-16 20:54:59 +03:00
|
|
|
}
|
2022-10-14 20:14:07 +03:00
|
|
|
|
2022-08-03 14:36:18 +03:00
|
|
|
if err = tcpPorts.Validate(); err != nil {
|
|
|
|
return fmt.Errorf("validating tcp ports: %w", err)
|
|
|
|
} else if err = udpPorts.Validate(); err != nil {
|
|
|
|
return fmt.Errorf("validating udp ports: %w", err)
|
2018-08-30 17:25:33 +03:00
|
|
|
}
|
|
|
|
|
2023-08-30 18:26:02 +03:00
|
|
|
if !filtering.ValidateUpdateIvl(config.Filtering.FiltersUpdateIntervalHours) {
|
|
|
|
config.Filtering.FiltersUpdateIntervalHours = 24
|
2019-09-04 14:12:00 +03:00
|
|
|
}
|
2019-08-08 12:41:00 +03:00
|
|
|
|
2018-08-30 17:25:33 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-23 16:00:32 +03:00
|
|
|
// udpPort is the port number for UDP protocol.
|
2023-10-05 15:26:19 +03:00
|
|
|
type udpPort uint16
|
2022-03-23 16:00:32 +03:00
|
|
|
|
|
|
|
// tcpPort is the port number for TCP protocol.
|
2023-10-05 15:26:19 +03:00
|
|
|
type tcpPort uint16
|
2022-03-23 16:00:32 +03:00
|
|
|
|
2022-08-03 14:36:18 +03:00
|
|
|
// addPorts is a helper for ports validation that skips zero ports.
|
|
|
|
func addPorts[T tcpPort | udpPort](uc aghalg.UniqChecker[T], ports ...T) {
|
2021-12-28 17:00:52 +03:00
|
|
|
for _, p := range ports {
|
2022-08-03 14:36:18 +03:00
|
|
|
if p != 0 {
|
|
|
|
uc.Add(p)
|
2021-12-28 17:00:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 20:54:59 +03:00
|
|
|
// readConfigFile reads configuration file contents.
|
|
|
|
func readConfigFile() (fileData []byte, err error) {
|
|
|
|
if len(config.fileData) > 0 {
|
2019-04-30 14:38:24 +03:00
|
|
|
return config.fileData, nil
|
|
|
|
}
|
|
|
|
|
2024-02-21 17:01:15 +03:00
|
|
|
confPath := configFilePath()
|
|
|
|
log.Debug("reading config file %q", confPath)
|
2021-12-16 20:54:59 +03:00
|
|
|
|
|
|
|
// Do not wrap the error because it's informative enough as is.
|
2024-02-21 17:01:15 +03:00
|
|
|
return os.ReadFile(confPath)
|
2019-02-04 13:54:53 +03:00
|
|
|
}
|
|
|
|
|
2018-10-30 12:24:59 +03:00
|
|
|
// Saves configuration to the YAML file and also saves the user filter contents to a file
|
2022-08-08 15:50:54 +03:00
|
|
|
func (c *configuration) write() (err error) {
|
2018-11-29 13:31:50 +03:00
|
|
|
c.Lock()
|
|
|
|
defer c.Unlock()
|
2019-04-26 16:04:22 +03:00
|
|
|
|
2020-02-13 18:42:07 +03:00
|
|
|
if Context.auth != nil {
|
2023-11-03 16:07:15 +03:00
|
|
|
config.Users = Context.auth.usersList()
|
2019-08-29 12:34:07 +03:00
|
|
|
}
|
2022-08-08 15:50:54 +03:00
|
|
|
|
2020-02-19 15:28:06 +03:00
|
|
|
if Context.tls != nil {
|
|
|
|
tlsConf := tlsConfigSettings{}
|
|
|
|
Context.tls.WriteDiskConfig(&tlsConf)
|
|
|
|
config.TLS = tlsConf
|
|
|
|
}
|
2019-08-29 12:34:07 +03:00
|
|
|
|
2019-12-11 12:38:58 +03:00
|
|
|
if Context.stats != nil {
|
2023-02-13 18:15:33 +03:00
|
|
|
statsConf := stats.Config{}
|
|
|
|
Context.stats.WriteDiskConfig(&statsConf)
|
2023-03-23 13:46:57 +03:00
|
|
|
config.Stats.Interval = timeutil.Duration{Duration: statsConf.Limit}
|
2023-02-13 18:15:33 +03:00
|
|
|
config.Stats.Enabled = statsConf.Enabled
|
|
|
|
config.Stats.Ignored = statsConf.Ignored.Values()
|
2019-09-25 15:36:09 +03:00
|
|
|
}
|
|
|
|
|
2019-12-11 12:38:58 +03:00
|
|
|
if Context.queryLog != nil {
|
2020-05-28 15:29:36 +03:00
|
|
|
dc := querylog.Config{}
|
2019-12-11 12:38:58 +03:00
|
|
|
Context.queryLog.WriteDiskConfig(&dc)
|
2020-03-03 20:21:53 +03:00
|
|
|
config.DNS.AnonymizeClientIP = dc.AnonymizeClientIP
|
2023-02-07 17:50:39 +03:00
|
|
|
config.QueryLog.Enabled = dc.Enabled
|
|
|
|
config.QueryLog.FileEnabled = dc.FileEnabled
|
|
|
|
config.QueryLog.Interval = timeutil.Duration{Duration: dc.RotationIvl}
|
|
|
|
config.QueryLog.MemSize = dc.MemSize
|
|
|
|
config.QueryLog.Ignored = dc.Ignored.Values()
|
2019-09-27 18:58:57 +03:00
|
|
|
}
|
|
|
|
|
2022-09-23 13:23:35 +03:00
|
|
|
if Context.filters != nil {
|
2023-08-30 18:26:02 +03:00
|
|
|
Context.filters.WriteDiskConfig(config.Filtering)
|
|
|
|
config.Filters = config.Filtering.Filters
|
|
|
|
config.WhitelistFilters = config.Filtering.WhitelistFilters
|
|
|
|
config.UserRules = config.Filtering.UserRules
|
2019-10-09 19:51:26 +03:00
|
|
|
}
|
|
|
|
|
2021-04-07 20:16:06 +03:00
|
|
|
if s := Context.dnsServer; s != nil {
|
2023-08-30 18:26:02 +03:00
|
|
|
c := dnsforward.Config{}
|
2021-04-07 20:16:06 +03:00
|
|
|
s.WriteDiskConfig(&c)
|
2021-05-26 17:55:19 +03:00
|
|
|
dns := &config.DNS
|
2023-08-30 18:26:02 +03:00
|
|
|
dns.Config = c
|
2023-07-18 17:02:07 +03:00
|
|
|
|
2024-04-22 19:17:30 +03:00
|
|
|
dns.PrivateRDNSResolvers = s.LocalPTRResolvers()
|
2023-07-18 17:02:07 +03:00
|
|
|
|
|
|
|
addrProcConf := s.AddrProcConfig()
|
|
|
|
config.Clients.Sources.RDNS = addrProcConf.UseRDNS
|
|
|
|
config.Clients.Sources.WHOIS = addrProcConf.UseWHOIS
|
|
|
|
dns.UsePrivateRDNS = addrProcConf.UsePrivateRDNS
|
2019-10-30 11:52:58 +03:00
|
|
|
}
|
|
|
|
|
2019-12-11 12:38:58 +03:00
|
|
|
if Context.dhcpServer != nil {
|
2022-09-13 23:45:35 +03:00
|
|
|
Context.dhcpServer.WriteDiskConfig(config.DHCP)
|
2019-11-22 14:21:08 +03:00
|
|
|
}
|
|
|
|
|
2022-04-26 13:04:16 +03:00
|
|
|
config.Clients.Persistent = Context.clients.forConfig()
|
2021-12-13 15:18:21 +03:00
|
|
|
|
2024-02-21 17:01:15 +03:00
|
|
|
confPath := configFilePath()
|
|
|
|
log.Debug("writing config file %q", confPath)
|
2021-04-06 20:48:36 +03:00
|
|
|
|
2022-08-08 15:50:54 +03:00
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
enc := yaml.NewEncoder(buf)
|
|
|
|
enc.SetIndent(2)
|
2021-04-06 20:48:36 +03:00
|
|
|
|
2022-08-08 15:50:54 +03:00
|
|
|
err = enc.Encode(config)
|
2018-08-30 17:25:33 +03:00
|
|
|
if err != nil {
|
2022-08-08 15:50:54 +03:00
|
|
|
return fmt.Errorf("generating config file: %w", err)
|
|
|
|
}
|
2021-04-06 20:48:36 +03:00
|
|
|
|
2024-02-21 17:01:15 +03:00
|
|
|
err = maybe.WriteFile(confPath, buf.Bytes(), 0o644)
|
2022-08-08 15:50:54 +03:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("writing config file: %w", err)
|
2018-08-30 17:25:33 +03:00
|
|
|
}
|
2018-10-30 02:17:24 +03:00
|
|
|
|
2018-11-28 20:15:32 +03:00
|
|
|
return nil
|
|
|
|
}
|
2022-10-14 20:14:07 +03:00
|
|
|
|
|
|
|
// setContextTLSCipherIDs sets the TLS cipher suite IDs to use.
|
|
|
|
func setContextTLSCipherIDs() (err error) {
|
|
|
|
if len(config.TLS.OverrideTLSCiphers) == 0 {
|
|
|
|
log.Info("tls: using default ciphers")
|
|
|
|
|
|
|
|
Context.tlsCipherIDs = aghtls.SaferCipherSuites()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("tls: overriding ciphers: %s", config.TLS.OverrideTLSCiphers)
|
|
|
|
|
|
|
|
Context.tlsCipherIDs, err = aghtls.ParseCiphers(config.TLS.OverrideTLSCiphers)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("parsing override ciphers: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|