chore(settings): refactor settings processing (#756)

- Better settings tree structure logged using `qdm12/gotree`
- Read settings from environment variables, then files, then secret files
- Settings methods to default them, merge them and override them
- `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else.
- `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
This commit is contained in:
Quentin McGaw
2022-01-06 06:40:23 -05:00
committed by GitHub
parent 46738b2934
commit 7d824a5179
275 changed files with 7167 additions and 6328 deletions

View File

@@ -1,16 +1,16 @@
package privateinternetaccess
import (
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
func (p *PIA) GetConnection(selection configuration.ServerSelection) (
func (p *PIA) GetConnection(selection settings.ServerSelection) (
connection models.Connection, err error) {
protocol := constants.UDP
if selection.OpenVPN.TCP {
if *selection.OpenVPN.TCP {
protocol = constants.TCP
}

View File

@@ -1,12 +1,12 @@
package privateinternetaccess
import (
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
func (p *PIA) filterServers(selection configuration.ServerSelection) (
func (p *PIA) filterServers(selection settings.ServerSelection) (
servers []models.PIAServer, err error) {
for _, server := range p.servers {
switch {

View File

@@ -3,16 +3,16 @@ package privateinternetaccess
import (
"strconv"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
func (p *PIA) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string, err error) {
settings settings.OpenVPN) (lines []string, err error) {
var defaultCipher, defaultAuth, X509CRL, certificate string
switch settings.EncPreset {
switch *settings.PIAEncPreset {
case constants.PIAEncryptionPresetNormal:
defaultCipher = constants.AES128cbc
defaultAuth = constants.SHA1
@@ -34,8 +34,9 @@ func (p *PIA) BuildConf(connection models.Connection,
settings.Ciphers = []string{defaultCipher}
}
if settings.Auth == "" {
settings.Auth = defaultAuth
auth := *settings.Auth
if auth == "" {
auth = defaultAuth
}
lines = []string{
@@ -43,12 +44,13 @@ func (p *PIA) BuildConf(connection models.Connection,
"nobind",
"tls-exit",
"dev " + settings.Interface,
"verb " + strconv.Itoa(settings.Verbosity),
"verb " + strconv.Itoa(*settings.Verbosity),
// PIA specific
"remote-cert-tls server",
"reneg-sec 0",
"auth-user-pass " + constants.OpenVPNAuthConf,
"auth " + auth,
// Added constant values
"auth-nocache",
@@ -66,25 +68,21 @@ func (p *PIA) BuildConf(connection models.Connection,
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
}
if settings.Auth != "" {
lines = append(lines, "auth "+settings.Auth)
}
if connection.Protocol == constants.UDP {
lines = append(lines, "explicit-exit-notify")
}
if !settings.Root {
if !*settings.Root {
lines = append(lines, "user "+settings.ProcUser)
lines = append(lines, "persist-tun")
lines = append(lines, "persist-key")
}
if settings.MSSFix > 0 {
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
if *settings.MSSFix > 0 {
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
}
if !settings.IPv6 {
if !*settings.IPv6 {
lines = append(lines, `pull-filter ignore "route-ipv6"`)
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
}

View File

@@ -4,21 +4,23 @@ import (
"errors"
"fmt"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
)
func getPort(openvpnSelection configuration.OpenVPNSelection) (
func getPort(openvpnSelection settings.OpenVPNSelection) (
port uint16, err error) {
if openvpnSelection.CustomPort == 0 {
return getDefaultPort(openvpnSelection.TCP, openvpnSelection.EncPreset), nil
customPort := *openvpnSelection.CustomPort
tcp := *openvpnSelection.TCP
if customPort == 0 {
return getDefaultPort(tcp, *openvpnSelection.PIAEncPreset), nil
}
if err := checkPort(openvpnSelection.CustomPort, openvpnSelection.TCP); err != nil {
if err := checkPort(customPort, tcp); err != nil {
return 0, err
}
return openvpnSelection.CustomPort, nil
return customPort, nil
}
func getDefaultPort(tcp bool, encryptionPreset string) (port uint16) {