From 2c30984a10bd0667a715fbd5f77b268a58a0af42 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 30 May 2023 12:46:10 +0000 Subject: [PATCH] hotfix(env): read some settings with case sensitivity --- internal/configuration/sources/env/dns.go | 2 +- .../configuration/sources/env/dnsblacklist.go | 2 +- .../configuration/sources/env/firewall.go | 2 +- internal/configuration/sources/env/health.go | 4 +-- internal/configuration/sources/env/helpers.go | 4 +-- .../configuration/sources/env/httproxy.go | 16 ++++++++---- internal/configuration/sources/env/openvpn.go | 26 +++++++++++-------- .../sources/env/openvpnselection.go | 6 ++--- .../configuration/sources/env/portforward.go | 19 ++++++++------ .../configuration/sources/env/provider.go | 2 +- .../configuration/sources/env/publicip.go | 3 ++- internal/configuration/sources/env/reader.go | 6 ++--- internal/configuration/sources/env/server.go | 3 ++- .../sources/env/serverselection.go | 14 +++++----- .../configuration/sources/env/shadowsocks.go | 9 ++++--- internal/configuration/sources/env/system.go | 2 +- .../configuration/sources/env/wireguard.go | 10 ++++--- .../sources/env/wireguardselection.go | 6 ++--- 18 files changed, 78 insertions(+), 58 deletions(-) diff --git a/internal/configuration/sources/env/dns.go b/internal/configuration/sources/env/dns.go index 745d6814..a6c2f987 100644 --- a/internal/configuration/sources/env/dns.go +++ b/internal/configuration/sources/env/dns.go @@ -27,7 +27,7 @@ func (s *Source) readDNS() (dns settings.DNS, err error) { } func (s *Source) readDNSServerAddress() (address netip.Addr, err error) { - key, value := s.getEnvWithRetro("DNS_ADDRESS", "DNS_PLAINTEXT_ADDRESS") + key, value := s.getEnvWithRetro("DNS_ADDRESS", []string{"DNS_PLAINTEXT_ADDRESS"}) if value == "" { return address, nil } diff --git a/internal/configuration/sources/env/dnsblacklist.go b/internal/configuration/sources/env/dnsblacklist.go index da83d6af..573026c3 100644 --- a/internal/configuration/sources/env/dnsblacklist.go +++ b/internal/configuration/sources/env/dnsblacklist.go @@ -37,7 +37,7 @@ func (s *Source) readDNSBlacklist() (blacklist settings.DNSBlacklist, err error) } func (s *Source) readBlockSurveillance() (blocked *bool, err error) { - key, value := s.getEnvWithRetro("BLOCK_SURVEILLANCE", "BLOCK_NSA") + key, value := s.getEnvWithRetro("BLOCK_SURVEILLANCE", []string{"BLOCK_NSA"}) blocked, err = binary.Validate(value) if err != nil { return nil, fmt.Errorf("environment variable %s: %w", key, err) diff --git a/internal/configuration/sources/env/firewall.go b/internal/configuration/sources/env/firewall.go index 5c9e625a..60a775a0 100644 --- a/internal/configuration/sources/env/firewall.go +++ b/internal/configuration/sources/env/firewall.go @@ -22,7 +22,7 @@ func (s *Source) readFirewall() (firewall settings.Firewall, err error) { return firewall, fmt.Errorf("environment variable FIREWALL_INPUT_PORTS: %w", err) } - outboundSubnetsKey, _ := s.getEnvWithRetro("FIREWALL_OUTBOUND_SUBNETS", "EXTRA_SUBNETS") + outboundSubnetsKey, _ := s.getEnvWithRetro("FIREWALL_OUTBOUND_SUBNETS", []string{"EXTRA_SUBNETS"}) outboundSubnetStrings := envToCSV(outboundSubnetsKey) firewall.OutboundSubnets, err = stringsToNetipPrefixes(outboundSubnetStrings) if err != nil { diff --git a/internal/configuration/sources/env/health.go b/internal/configuration/sources/env/health.go index bcae65df..4e8f4ac1 100644 --- a/internal/configuration/sources/env/health.go +++ b/internal/configuration/sources/env/health.go @@ -10,7 +10,7 @@ import ( func (s *Source) ReadHealth() (health settings.Health, err error) { health.ServerAddress = env.Get("HEALTH_SERVER_ADDRESS") - _, health.TargetAddress = s.getEnvWithRetro("HEALTH_TARGET_ADDRESS", "HEALTH_ADDRESS_TO_PING") + _, health.TargetAddress = s.getEnvWithRetro("HEALTH_TARGET_ADDRESS", []string{"HEALTH_ADDRESS_TO_PING"}) successWaitPtr, err := envToDurationPtr("HEALTH_SUCCESS_WAIT_DURATION") if err != nil { @@ -37,7 +37,7 @@ func (s *Source) ReadHealth() (health settings.Health, err error) { } func (s *Source) readDurationWithRetro(envKey, retroEnvKey string) (d *time.Duration, err error) { - envKey, value := s.getEnvWithRetro(envKey, retroEnvKey) + envKey, value := s.getEnvWithRetro(envKey, []string{retroEnvKey}) if value == "" { return nil, nil //nolint:nilnil } diff --git a/internal/configuration/sources/env/helpers.go b/internal/configuration/sources/env/helpers.go index 8c0d18f0..9761ef5c 100644 --- a/internal/configuration/sources/env/helpers.go +++ b/internal/configuration/sources/env/helpers.go @@ -29,8 +29,8 @@ func envToFloat64(envKey string) (f float64, err error) { return strconv.ParseFloat(s, bits) } -func envToStringPtr(envKey string) (stringPtr *string) { - s := env.Get(envKey) +func envToStringPtr(envKey string, options ...env.Option) (stringPtr *string) { + s := env.Get(envKey, options...) if s == "" { return nil } diff --git a/internal/configuration/sources/env/httproxy.go b/internal/configuration/sources/env/httproxy.go index bb6fa8fd..e4482fd3 100644 --- a/internal/configuration/sources/env/httproxy.go +++ b/internal/configuration/sources/env/httproxy.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/qdm12/gluetun/internal/configuration/settings" + "github.com/qdm12/gosettings/sources/env" "github.com/qdm12/govalid/binary" ) @@ -31,7 +32,8 @@ func (s *Source) readHTTPProxy() (httpProxy settings.HTTPProxy, err error) { } func (s *Source) readHTTProxyUser() (user *string) { - _, value := s.getEnvWithRetro("HTTPPROXY_USER", "PROXY_USER", "TINYPROXY_USER") + _, value := s.getEnvWithRetro("HTTPPROXY_USER", + []string{"PROXY_USER", "TINYPROXY_USER"}, env.ForceLowercase(false)) if value != "" { return &value } @@ -39,7 +41,8 @@ func (s *Source) readHTTProxyUser() (user *string) { } func (s *Source) readHTTProxyPassword() (user *string) { - _, value := s.getEnvWithRetro("HTTPPROXY_PASSWORD", "PROXY_PASSWORD", "TINYPROXY_PASSWORD") + _, value := s.getEnvWithRetro("HTTPPROXY_PASSWORD", + []string{"PROXY_PASSWORD", "TINYPROXY_PASSWORD"}, env.ForceLowercase(false)) if value != "" { return &value } @@ -47,7 +50,8 @@ func (s *Source) readHTTProxyPassword() (user *string) { } func (s *Source) readHTTProxyListeningAddress() (listeningAddress string) { - key, value := s.getEnvWithRetro("HTTPPROXY_LISTENING_ADDRESS", "PROXY_PORT", "TINYPROXY_PORT", "HTTPPROXY_PORT") + key, value := s.getEnvWithRetro("HTTPPROXY_LISTENING_ADDRESS", + []string{"PROXY_PORT", "TINYPROXY_PORT", "HTTPPROXY_PORT"}) if key == "HTTPPROXY_LISTENING_ADDRESS" { return value } @@ -55,7 +59,8 @@ func (s *Source) readHTTProxyListeningAddress() (listeningAddress string) { } func (s *Source) readHTTProxyEnabled() (enabled *bool, err error) { - key, value := s.getEnvWithRetro("HTTPPROXY", "PROXY", "TINYPROXY") + key, value := s.getEnvWithRetro("HTTPPROXY", + []string{"PROXY", "TINYPROXY"}) enabled, err = binary.Validate(value) if err != nil { return nil, fmt.Errorf("environment variable %s: %w", key, err) @@ -65,7 +70,8 @@ func (s *Source) readHTTProxyEnabled() (enabled *bool, err error) { } func (s *Source) readHTTProxyLog() (enabled *bool, err error) { - key, value := s.getEnvWithRetro("HTTPPROXY_LOG", "PROXY_LOG_LEVEL", "TINYPROXY_LOG") + key, value := s.getEnvWithRetro("HTTPPROXY_LOG", + []string{"PROXY_LOG_LEVEL", "TINYPROXY_LOG"}) var binaryOptions []binary.Option if key != "HTTPROXY_LOG" { diff --git a/internal/configuration/sources/env/openvpn.go b/internal/configuration/sources/env/openvpn.go index 99d4262d..724678f9 100644 --- a/internal/configuration/sources/env/openvpn.go +++ b/internal/configuration/sources/env/openvpn.go @@ -24,7 +24,7 @@ func (s *Source) readOpenVPN() ( openVPN.ConfFile = &confFile } - ciphersKey, _ := s.getEnvWithRetro("OPENVPN_CIPHERS", "OPENVPN_CIPHER") + ciphersKey, _ := s.getEnvWithRetro("OPENVPN_CIPHERS", []string{"OPENVPN_CIPHER"}) openVPN.Ciphers = envToCSV(ciphersKey) auth := env.Get("OPENVPN_AUTH") @@ -32,9 +32,9 @@ func (s *Source) readOpenVPN() ( openVPN.Auth = &auth } - openVPN.Cert = envToStringPtr("OPENVPN_CERT") - openVPN.Key = envToStringPtr("OPENVPN_KEY") - openVPN.EncryptedKey = envToStringPtr("OPENVPN_ENCRYPTED_KEY") + openVPN.Cert = envToStringPtr("OPENVPN_CERT", env.ForceLowercase(false)) + openVPN.Key = envToStringPtr("OPENVPN_KEY", env.ForceLowercase(false)) + openVPN.EncryptedKey = envToStringPtr("OPENVPN_ENCRYPTED_KEY", env.ForceLowercase(false)) openVPN.KeyPassphrase = s.readOpenVPNKeyPassphrase() @@ -45,7 +45,8 @@ func (s *Source) readOpenVPN() ( return openVPN, fmt.Errorf("environment variable OPENVPN_MSSFIX: %w", err) } - _, openVPN.Interface = s.getEnvWithRetro("VPN_INTERFACE", "OPENVPN_INTERFACE") + _, openVPN.Interface = s.getEnvWithRetro("VPN_INTERFACE", + []string{"OPENVPN_INTERFACE"}, env.ForceLowercase(false)) openVPN.ProcessUser, err = s.readOpenVPNProcessUser() if err != nil { @@ -57,7 +58,7 @@ func (s *Source) readOpenVPN() ( return openVPN, fmt.Errorf("environment variable OPENVPN_VERBOSITY: %w", err) } - flagsStr := env.Get("OPENVPN_FLAGS") + flagsStr := env.Get("OPENVPN_FLAGS", env.ForceLowercase(false)) if flagsStr != "" { openVPN.Flags = strings.Fields(flagsStr) } @@ -67,7 +68,8 @@ func (s *Source) readOpenVPN() ( func (s *Source) readOpenVPNUser() (user *string) { user = new(string) - _, *user = s.getEnvWithRetro("OPENVPN_USER", "USER") + _, *user = s.getEnvWithRetro("OPENVPN_USER", + []string{"USER"}, env.ForceLowercase(false)) if *user == "" { return nil } @@ -79,7 +81,8 @@ func (s *Source) readOpenVPNUser() (user *string) { func (s *Source) readOpenVPNPassword() (password *string) { password = new(string) - _, *password = s.getEnvWithRetro("OPENVPN_PASSWORD", "PASSWORD") + _, *password = s.getEnvWithRetro("OPENVPN_PASSWORD", + []string{"PASSWORD"}, env.ForceLowercase(false)) if *password == "" { return nil } @@ -89,7 +92,7 @@ func (s *Source) readOpenVPNPassword() (password *string) { func (s *Source) readOpenVPNKeyPassphrase() (passphrase *string) { passphrase = new(string) - *passphrase = env.Get("OPENVPN_KEY_PASSPHRASE") + *passphrase = env.Get("OPENVPN_KEY_PASSPHRASE", env.ForceLowercase(false)) if *passphrase == "" { return nil } @@ -99,7 +102,7 @@ func (s *Source) readOpenVPNKeyPassphrase() (passphrase *string) { func (s *Source) readPIAEncryptionPreset() (presetPtr *string) { _, preset := s.getEnvWithRetro( "PRIVATE_INTERNET_ACCESS_OPENVPN_ENCRYPTION_PRESET", - "PIA_ENCRYPTION", "ENCRYPTION") + []string{"PIA_ENCRYPTION", "ENCRYPTION"}) if preset != "" { return &preset } @@ -107,7 +110,8 @@ func (s *Source) readPIAEncryptionPreset() (presetPtr *string) { } func (s *Source) readOpenVPNProcessUser() (processUser string, err error) { - key, value := s.getEnvWithRetro("OPENVPN_PROCESS_USER", "OPENVPN_ROOT") + key, value := s.getEnvWithRetro("OPENVPN_PROCESS_USER", + []string{"OPENVPN_ROOT"}) if key == "OPENVPN_PROCESS_USER" { return value, nil } diff --git a/internal/configuration/sources/env/openvpnselection.go b/internal/configuration/sources/env/openvpnselection.go index e606ec6a..5a6e84e7 100644 --- a/internal/configuration/sources/env/openvpnselection.go +++ b/internal/configuration/sources/env/openvpnselection.go @@ -13,7 +13,7 @@ import ( func (s *Source) readOpenVPNSelection() ( selection settings.OpenVPNSelection, err error) { - confFile := env.Get("OPENVPN_CUSTOM_CONFIG") + confFile := env.Get("OPENVPN_CUSTOM_CONFIG", env.ForceLowercase(false)) if confFile != "" { selection.ConfFile = &confFile } @@ -36,7 +36,7 @@ func (s *Source) readOpenVPNSelection() ( var ErrOpenVPNProtocolNotValid = errors.New("OpenVPN protocol is not valid") func (s *Source) readOpenVPNProtocol() (tcp *bool, err error) { - envKey, protocol := s.getEnvWithRetro("OPENVPN_PROTOCOL", "PROTOCOL") + envKey, protocol := s.getEnvWithRetro("OPENVPN_PROTOCOL", []string{"PROTOCOL"}) switch strings.ToLower(protocol) { case "": @@ -52,7 +52,7 @@ func (s *Source) readOpenVPNProtocol() (tcp *bool, err error) { } func (s *Source) readOpenVPNCustomPort() (customPort *uint16, err error) { - key, value := s.getEnvWithRetro("VPN_ENDPOINT_PORT", "PORT", "OPENVPN_PORT") + key, value := s.getEnvWithRetro("VPN_ENDPOINT_PORT", []string{"PORT", "OPENVPN_PORT"}) if value == "" { return nil, nil //nolint:nilnil } diff --git a/internal/configuration/sources/env/portforward.go b/internal/configuration/sources/env/portforward.go index 203e156d..b81d611e 100644 --- a/internal/configuration/sources/env/portforward.go +++ b/internal/configuration/sources/env/portforward.go @@ -4,23 +4,26 @@ import ( "fmt" "github.com/qdm12/gluetun/internal/configuration/settings" + "github.com/qdm12/gosettings/sources/env" ) func (s *Source) readPortForward() ( portForwarding settings.PortForwarding, err error) { - key, _ := s.getEnvWithRetro( - "VPN_PORT_FORWARDING", - "PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING", - "PORT_FORWARDING") + key, _ := s.getEnvWithRetro("VPN_PORT_FORWARDING", + []string{ + "PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING", + "PORT_FORWARDING", + }) portForwarding.Enabled, err = envToBoolPtr(key) if err != nil { return portForwarding, fmt.Errorf("environment variable %s: %w", key, err) } - _, value := s.getEnvWithRetro( - "VPN_PORT_FORWARDING_STATUS_FILE", - "PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING_STATUS_FILE", - "PORT_FORWARDING_STATUS_FILE") + _, value := s.getEnvWithRetro("VPN_PORT_FORWARDING_STATUS_FILE", + []string{ + "PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING_STATUS_FILE", + "PORT_FORWARDING_STATUS_FILE", + }, env.ForceLowercase(false)) if value != "" { portForwarding.Filepath = stringPtr(value) } diff --git a/internal/configuration/sources/env/provider.go b/internal/configuration/sources/env/provider.go index 7ab44b16..bdf22c99 100644 --- a/internal/configuration/sources/env/provider.go +++ b/internal/configuration/sources/env/provider.go @@ -31,7 +31,7 @@ func (s *Source) readProvider(vpnType string) (provider settings.Provider, err e } func (s *Source) readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) { - _, value := s.getEnvWithRetro("VPN_SERVICE_PROVIDER", "VPNSP") + _, value := s.getEnvWithRetro("VPN_SERVICE_PROVIDER", []string{"VPNSP"}) if value == "" { if vpnType != vpn.Wireguard && env.Get("OPENVPN_CUSTOM_CONFIG") != "" { // retro compatibility diff --git a/internal/configuration/sources/env/publicip.go b/internal/configuration/sources/env/publicip.go index a9f93d48..4a61e697 100644 --- a/internal/configuration/sources/env/publicip.go +++ b/internal/configuration/sources/env/publicip.go @@ -35,7 +35,8 @@ func readPublicIPPeriod() (period *time.Duration, err error) { } func (s *Source) readPublicIPFilepath() (filepath *string) { - _, value := s.getEnvWithRetro("PUBLICIP_FILE", "IP_STATUS_FILE") + _, value := s.getEnvWithRetro("PUBLICIP_FILE", + []string{"IP_STATUS_FILE"}, env.ForceLowercase(false)) if value != "" { return &value } diff --git a/internal/configuration/sources/env/reader.go b/internal/configuration/sources/env/reader.go index 0fde429e..6a72e4b6 100644 --- a/internal/configuration/sources/env/reader.go +++ b/internal/configuration/sources/env/reader.go @@ -103,16 +103,16 @@ func (s *Source) onRetroActive(oldKey, newKey string) { // Note retroKeys should be in order from oldest to most // recent retro-compatibility key. func (s *Source) getEnvWithRetro(currentKey string, - retroKeys ...string) (key, value string) { + retroKeys []string, options ...env.Option) (key, value string) { // We check retro-compatibility keys first since // the current key might be set in the Dockerfile. for _, key = range retroKeys { - value = env.Get(key) + value = env.Get(key, options...) if value != "" { s.onRetroActive(key, currentKey) return key, value } } - return currentKey, env.Get(currentKey) + return currentKey, env.Get(currentKey, options...) } diff --git a/internal/configuration/sources/env/server.go b/internal/configuration/sources/env/server.go index d3ef2188..c27d64d2 100644 --- a/internal/configuration/sources/env/server.go +++ b/internal/configuration/sources/env/server.go @@ -29,7 +29,8 @@ func readControlServerLog() (enabled *bool, err error) { } func (s *Source) readControlServerAddress() (address *string) { - key, value := s.getEnvWithRetro("HTTP_CONTROL_SERVER_ADDRESS", "HTTP_CONTROL_SERVER_PORT") + key, value := s.getEnvWithRetro("HTTP_CONTROL_SERVER_ADDRESS", + []string{"CONTROL_SERVER_ADDRESS"}) if value == "" { return nil } diff --git a/internal/configuration/sources/env/serverselection.go b/internal/configuration/sources/env/serverselection.go index 680c4cb8..48c788e3 100644 --- a/internal/configuration/sources/env/serverselection.go +++ b/internal/configuration/sources/env/serverselection.go @@ -25,7 +25,7 @@ func (s *Source) readServerSelection(vpnProvider, vpnType string) ( return ss, err } - countriesKey, _ := s.getEnvWithRetro("SERVER_COUNTRIES", "COUNTRY") + countriesKey, _ := s.getEnvWithRetro("SERVER_COUNTRIES", []string{"COUNTRY"}) ss.Countries = envToCSV(countriesKey) if vpnProvider == providers.Cyberghost && len(ss.Countries) == 0 { // Retro-compatibility for Cyberghost using the REGION variable @@ -35,18 +35,18 @@ func (s *Source) readServerSelection(vpnProvider, vpnType string) ( } } - regionsKey, _ := s.getEnvWithRetro("SERVER_REGIONS", "REGION") + regionsKey, _ := s.getEnvWithRetro("SERVER_REGIONS", []string{"REGION"}) ss.Regions = envToCSV(regionsKey) - citiesKey, _ := s.getEnvWithRetro("SERVER_CITIES", "CITY") + citiesKey, _ := s.getEnvWithRetro("SERVER_CITIES", []string{"CITY"}) ss.Cities = envToCSV(citiesKey) ss.ISPs = envToCSV("ISP") - hostnamesKey, _ := s.getEnvWithRetro("SERVER_HOSTNAMES", "SERVER_HOSTNAME") + hostnamesKey, _ := s.getEnvWithRetro("SERVER_HOSTNAMES", []string{"SERVER_HOSTNAME"}) ss.Hostnames = envToCSV(hostnamesKey) - serverNamesKey, _ := s.getEnvWithRetro("SERVER_NAMES", "SERVER_NAME") + serverNamesKey, _ := s.getEnvWithRetro("SERVER_NAMES", []string{"SERVER_NAME"}) ss.Names = envToCSV(serverNamesKey) if csv := env.Get("SERVER_NUMBER"); csv != "" { @@ -115,7 +115,7 @@ var ( ) func (s *Source) readOpenVPNTargetIP() (ip netip.Addr, err error) { - envKey, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", "OPENVPN_TARGET_IP") + envKey, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", []string{"OPENVPN_TARGET_IP"}) if value == "" { return ip, nil } @@ -129,7 +129,7 @@ func (s *Source) readOpenVPNTargetIP() (ip netip.Addr, err error) { } func (s *Source) readOwnedOnly() (ownedOnly *bool, err error) { - envKey, _ := s.getEnvWithRetro("OWNED_ONLY", "OWNED") + envKey, _ := s.getEnvWithRetro("OWNED_ONLY", []string{"OWNED"}) ownedOnly, err = envToBoolPtr(envKey) if err != nil { return nil, fmt.Errorf("environment variable %s: %w", envKey, err) diff --git a/internal/configuration/sources/env/shadowsocks.go b/internal/configuration/sources/env/shadowsocks.go index a9bace58..713191fa 100644 --- a/internal/configuration/sources/env/shadowsocks.go +++ b/internal/configuration/sources/env/shadowsocks.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/qdm12/gluetun/internal/configuration/settings" + "github.com/qdm12/gosettings/sources/env" ) func (s *Source) readShadowsocks() (shadowsocks settings.Shadowsocks, err error) { @@ -19,13 +20,14 @@ func (s *Source) readShadowsocks() (shadowsocks settings.Shadowsocks, err error) return shadowsocks, fmt.Errorf("environment variable SHADOWSOCKS_LOG: %w", err) } shadowsocks.CipherName = s.readShadowsocksCipher() - shadowsocks.Password = envToStringPtr("SHADOWSOCKS_PASSWORD") + shadowsocks.Password = envToStringPtr("SHADOWSOCKS_PASSWORD", env.ForceLowercase(false)) return shadowsocks, nil } func (s *Source) readShadowsocksAddress() (address string) { - key, value := s.getEnvWithRetro("SHADOWSOCKS_LISTENING_ADDRESS", "SHADOWSOCKS_PORT") + key, value := s.getEnvWithRetro("SHADOWSOCKS_LISTENING_ADDRESS", + []string{"SHADOWSOCKS_PORT"}) if value == "" { return "" } @@ -39,6 +41,7 @@ func (s *Source) readShadowsocksAddress() (address string) { } func (s *Source) readShadowsocksCipher() (cipher string) { - _, cipher = s.getEnvWithRetro("SHADOWSOCKS_CIPHER", "SHADOWSOCKS_METHOD") + _, cipher = s.getEnvWithRetro("SHADOWSOCKS_CIPHER", + []string{"SHADOWSOCKS_METHOD"}) return strings.ToLower(cipher) } diff --git a/internal/configuration/sources/env/system.go b/internal/configuration/sources/env/system.go index b4adf3d5..0fc05d23 100644 --- a/internal/configuration/sources/env/system.go +++ b/internal/configuration/sources/env/system.go @@ -35,7 +35,7 @@ var ErrSystemIDNotValid = errors.New("system ID is not valid") func (s *Source) readID(key, retroKey string) ( id *uint32, err error) { - idEnvKey, idString := s.getEnvWithRetro(key, retroKey) + idEnvKey, idString := s.getEnvWithRetro(key, []string{retroKey}) if idString == "" { return nil, nil //nolint:nilnil } diff --git a/internal/configuration/sources/env/wireguard.go b/internal/configuration/sources/env/wireguard.go index 6bfe821c..7592dd23 100644 --- a/internal/configuration/sources/env/wireguard.go +++ b/internal/configuration/sources/env/wireguard.go @@ -13,9 +13,10 @@ func (s *Source) readWireguard() (wireguard settings.Wireguard, err error) { defer func() { err = unsetEnvKeys([]string{"WIREGUARD_PRIVATE_KEY", "WIREGUARD_PRESHARED_KEY"}, err) }() - wireguard.PrivateKey = envToStringPtr("WIREGUARD_PRIVATE_KEY") - wireguard.PreSharedKey = envToStringPtr("WIREGUARD_PRESHARED_KEY") - _, wireguard.Interface = s.getEnvWithRetro("VPN_INTERFACE", "WIREGUARD_INTERFACE") + wireguard.PrivateKey = envToStringPtr("WIREGUARD_PRIVATE_KEY", env.ForceLowercase(false)) + wireguard.PreSharedKey = envToStringPtr("WIREGUARD_PRESHARED_KEY", env.ForceLowercase(false)) + _, wireguard.Interface = s.getEnvWithRetro("VPN_INTERFACE", + []string{"WIREGUARD_INTERFACE"}, env.ForceLowercase(false)) wireguard.Implementation = env.Get("WIREGUARD_IMPLEMENTATION") wireguard.Addresses, err = s.readWireguardAddresses() if err != nil { @@ -31,7 +32,8 @@ func (s *Source) readWireguard() (wireguard settings.Wireguard, err error) { } func (s *Source) readWireguardAddresses() (addresses []netip.Prefix, err error) { - key, addressesCSV := s.getEnvWithRetro("WIREGUARD_ADDRESSES", "WIREGUARD_ADDRESS") + key, addressesCSV := s.getEnvWithRetro("WIREGUARD_ADDRESSES", + []string{"WIREGUARD_ADDRESS"}) if addressesCSV == "" { return nil, nil } diff --git a/internal/configuration/sources/env/wireguardselection.go b/internal/configuration/sources/env/wireguardselection.go index 952cc854..a7fd1520 100644 --- a/internal/configuration/sources/env/wireguardselection.go +++ b/internal/configuration/sources/env/wireguardselection.go @@ -21,13 +21,13 @@ func (s *Source) readWireguardSelection() ( return selection, err } - selection.PublicKey = env.Get("WIREGUARD_PUBLIC_KEY") + selection.PublicKey = env.Get("WIREGUARD_PUBLIC_KEY", env.ForceLowercase(false)) return selection, nil } func (s *Source) readWireguardEndpointIP() (endpointIP netip.Addr, err error) { - key, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", "WIREGUARD_ENDPOINT_IP") + key, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", []string{"WIREGUARD_ENDPOINT_IP"}) if value == "" { return endpointIP, nil } @@ -41,7 +41,7 @@ func (s *Source) readWireguardEndpointIP() (endpointIP netip.Addr, err error) { } func (s *Source) readWireguardCustomPort() (customPort *uint16, err error) { - key, value := s.getEnvWithRetro("VPN_ENDPOINT_PORT", "WIREGUARD_ENDPOINT_PORT") + key, value := s.getEnvWithRetro("VPN_ENDPOINT_PORT", []string{"WIREGUARD_ENDPOINT_PORT"}) if value == "" { return nil, nil //nolint:nilnil }