2020-04-12 20:05:28 +00:00
|
|
|
package params
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net"
|
2020-05-05 18:00:56 +00:00
|
|
|
"time"
|
2020-04-12 20:05:28 +00:00
|
|
|
|
2020-07-26 12:07:06 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
2020-12-29 00:55:31 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/os"
|
2020-04-12 20:05:28 +00:00
|
|
|
"github.com/qdm12/golibs/logging"
|
|
|
|
|
libparams "github.com/qdm12/golibs/params"
|
|
|
|
|
"github.com/qdm12/golibs/verification"
|
|
|
|
|
)
|
|
|
|
|
|
2020-10-20 02:45:28 +00:00
|
|
|
// Reader contains methods to obtain parameters.
|
2020-04-12 20:05:28 +00:00
|
|
|
type Reader interface {
|
|
|
|
|
GetVPNSP() (vpnServiceProvider models.VPNProvider, err error)
|
|
|
|
|
|
|
|
|
|
// DNS over TLS getters
|
|
|
|
|
GetDNSOverTLS() (DNSOverTLS bool, err error)
|
|
|
|
|
GetDNSOverTLSProviders() (providers []models.DNSProvider, err error)
|
|
|
|
|
GetDNSOverTLSCaching() (caching bool, err error)
|
|
|
|
|
GetDNSOverTLSVerbosity() (verbosityLevel uint8, err error)
|
|
|
|
|
GetDNSOverTLSVerbosityDetails() (verbosityDetailsLevel uint8, err error)
|
|
|
|
|
GetDNSOverTLSValidationLogLevel() (validationLogLevel uint8, err error)
|
|
|
|
|
GetDNSMaliciousBlocking() (blocking bool, err error)
|
|
|
|
|
GetDNSSurveillanceBlocking() (blocking bool, err error)
|
|
|
|
|
GetDNSAdsBlocking() (blocking bool, err error)
|
|
|
|
|
GetDNSUnblockedHostnames() (hostnames []string, err error)
|
2020-04-26 13:28:14 +00:00
|
|
|
GetDNSOverTLSPrivateAddresses() (privateAddresses []string, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
GetDNSOverTLSIPv6() (ipv6 bool, err error)
|
2020-05-05 18:00:56 +00:00
|
|
|
GetDNSUpdatePeriod() (period time.Duration, err error)
|
2020-06-26 14:40:46 +00:00
|
|
|
GetDNSPlaintext() (ip net.IP, err error)
|
2020-07-11 23:51:53 +00:00
|
|
|
GetDNSKeepNameserver() (on bool, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
|
|
|
|
// System
|
2020-12-29 16:44:35 +00:00
|
|
|
GetPUID() (puid int, err error)
|
|
|
|
|
GetPGID() (pgid int, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
GetTimezone() (timezone string, err error)
|
2020-12-28 01:51:55 +00:00
|
|
|
GetPublicIPFilepath() (filepath models.Filepath, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
|
|
|
|
// Firewall getters
|
2020-06-12 17:11:21 +00:00
|
|
|
GetFirewall() (enabled bool, err error)
|
2020-07-20 02:07:13 +00:00
|
|
|
GetVPNInputPorts() (ports []uint16, err error)
|
2020-10-18 09:22:28 -04:00
|
|
|
GetInputPorts() (ports []uint16, err error)
|
2020-10-29 19:23:44 -04:00
|
|
|
GetOutboundSubnets() (outboundSubnets []net.IPNet, err error)
|
2020-07-13 02:14:56 +00:00
|
|
|
GetFirewallDebug() (debug bool, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
|
|
|
|
// VPN getters
|
|
|
|
|
GetUser() (s string, err error)
|
2020-12-29 20:06:24 +00:00
|
|
|
GetPassword() (s string, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
GetNetworkProtocol() (protocol models.NetworkProtocol, err error)
|
|
|
|
|
GetOpenVPNVerbosity() (verbosity int, err error)
|
|
|
|
|
GetOpenVPNRoot() (root bool, err error)
|
|
|
|
|
GetTargetIP() (ip net.IP, err error)
|
|
|
|
|
GetOpenVPNCipher() (cipher string, err error)
|
|
|
|
|
GetOpenVPNAuth() (auth string, err error)
|
2020-09-26 09:33:24 -04:00
|
|
|
GetOpenVPNIPv6() (tunnel bool, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
|
|
|
|
// PIA getters
|
|
|
|
|
GetPortForwarding() (activated bool, err error)
|
|
|
|
|
GetPortForwardingStatusFilepath() (filepath models.Filepath, err error)
|
2020-06-13 14:08:29 -04:00
|
|
|
GetPIAEncryptionPreset() (preset string, err error)
|
2020-10-18 17:15:42 -04:00
|
|
|
GetPIARegions() (regions []string, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
|
|
|
|
// Mullvad getters
|
2020-10-18 17:15:42 -04:00
|
|
|
GetMullvadCountries() (countries []string, err error)
|
|
|
|
|
GetMullvadCities() (cities []string, err error)
|
|
|
|
|
GetMullvadISPs() (ips []string, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
GetMullvadPort() (port uint16, err error)
|
2020-10-18 17:15:42 -04:00
|
|
|
GetMullvadOwned() (owned bool, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
|
|
|
|
// Windscribe getters
|
2020-10-18 17:15:42 -04:00
|
|
|
GetWindscribeRegions() (countries []string, err error)
|
2020-11-04 20:38:35 -05:00
|
|
|
GetWindscribeCities() (cities []string, err error)
|
|
|
|
|
GetWindscribeHostnames() (hostnames []string, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
GetWindscribePort(protocol models.NetworkProtocol) (port uint16, err error)
|
|
|
|
|
|
2020-05-29 07:24:27 -04:00
|
|
|
// Surfshark getters
|
2020-10-18 17:15:42 -04:00
|
|
|
GetSurfsharkRegions() (countries []string, err error)
|
2020-05-29 07:24:27 -04:00
|
|
|
|
2020-06-13 10:43:47 -04:00
|
|
|
// Cyberghost getters
|
2020-06-13 14:08:29 -04:00
|
|
|
GetCyberghostGroup() (group string, err error)
|
2020-10-18 17:15:42 -04:00
|
|
|
GetCyberghostRegions() (regions []string, err error)
|
2020-06-13 10:43:47 -04:00
|
|
|
GetCyberghostClientKey() (clientKey string, err error)
|
2020-11-19 08:50:55 -05:00
|
|
|
GetCyberghostClientCertificate() (clientCertificate string, err error)
|
2020-06-13 10:43:47 -04:00
|
|
|
|
2020-07-13 08:04:35 -04:00
|
|
|
// Vyprvpn getters
|
2020-10-18 17:15:42 -04:00
|
|
|
GetVyprvpnRegions() (regions []string, err error)
|
2020-07-13 08:04:35 -04:00
|
|
|
|
2020-07-15 18:14:45 -04:00
|
|
|
// NordVPN getters
|
2020-10-18 17:15:42 -04:00
|
|
|
GetNordvpnRegions() (regions []string, err error)
|
|
|
|
|
GetNordvpnNumbers() (numbers []uint16, err error)
|
2020-07-15 18:14:45 -04:00
|
|
|
|
2020-11-08 20:56:49 -05:00
|
|
|
// Privado getters
|
2020-11-09 23:17:22 +00:00
|
|
|
GetPrivadoHostnames() (hostnames []string, err error)
|
2020-11-08 20:56:49 -05:00
|
|
|
|
2020-07-25 11:19:45 -04:00
|
|
|
// PureVPN getters
|
2020-10-18 17:15:42 -04:00
|
|
|
GetPurevpnRegions() (regions []string, err error)
|
|
|
|
|
GetPurevpnCountries() (countries []string, err error)
|
|
|
|
|
GetPurevpnCities() (cities []string, err error)
|
2020-07-25 11:19:45 -04:00
|
|
|
|
2020-04-12 20:05:28 +00:00
|
|
|
// Shadowsocks getters
|
|
|
|
|
GetShadowSocks() (activated bool, err error)
|
|
|
|
|
GetShadowSocksLog() (activated bool, err error)
|
|
|
|
|
GetShadowSocksPort() (port uint16, err error)
|
|
|
|
|
GetShadowSocksPassword() (password string, err error)
|
|
|
|
|
GetShadowSocksMethod() (method string, err error)
|
|
|
|
|
|
2020-10-31 21:50:31 -04:00
|
|
|
// HTTP proxy getters
|
|
|
|
|
GetHTTPProxy() (activated bool, err error)
|
|
|
|
|
GetHTTPProxyLog() (log bool, err error)
|
|
|
|
|
GetHTTPProxyPort() (port uint16, err error)
|
|
|
|
|
GetHTTPProxyUser() (user string, err error)
|
|
|
|
|
GetHTTPProxyPassword() (password string, err error)
|
|
|
|
|
GetHTTPProxyStealth() (stealth bool, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
|
2020-07-16 01:12:54 +00:00
|
|
|
// Public IP getters
|
|
|
|
|
GetPublicIPPeriod() (period time.Duration, err error)
|
2020-08-30 14:48:57 +00:00
|
|
|
|
2020-10-17 22:07:15 +00:00
|
|
|
// Control server
|
|
|
|
|
GetControlServerPort() (port uint16, err error)
|
2020-10-17 22:21:20 +00:00
|
|
|
GetControlServerLog() (enabled bool, err error)
|
2020-10-17 22:07:15 +00:00
|
|
|
|
2020-08-30 14:48:57 +00:00
|
|
|
GetVersionInformation() (enabled bool, err error)
|
2020-09-12 14:04:54 -04:00
|
|
|
|
|
|
|
|
GetUpdaterPeriod() (period time.Duration, err error)
|
2020-04-12 20:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type reader struct {
|
2020-12-29 00:55:31 +00:00
|
|
|
envParams libparams.EnvParams
|
|
|
|
|
logger logging.Logger
|
|
|
|
|
verifier verification.Verifier
|
|
|
|
|
os os.OS
|
2020-04-12 20:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Newreader returns a paramsReadeer object to read parameters from
|
2020-10-20 02:45:28 +00:00
|
|
|
// environment variables.
|
2020-12-29 00:55:31 +00:00
|
|
|
func NewReader(logger logging.Logger, os os.OS) Reader {
|
2020-04-12 20:05:28 +00:00
|
|
|
return &reader{
|
2020-12-29 00:55:31 +00:00
|
|
|
envParams: libparams.NewEnvParams(),
|
|
|
|
|
logger: logger,
|
|
|
|
|
verifier: verification.NewVerifier(),
|
|
|
|
|
os: os,
|
2020-04-12 20:05:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 02:45:28 +00:00
|
|
|
// GetVPNSP obtains the VPN service provider to use from the environment variable VPNSP.
|
2020-06-12 17:07:32 +00:00
|
|
|
func (r *reader) GetVPNSP() (vpnServiceProvider models.VPNProvider, err error) {
|
2020-10-20 02:45:28 +00:00
|
|
|
s, err := r.envParams.GetValueIfInside(
|
|
|
|
|
"VPNSP",
|
|
|
|
|
[]string{
|
2020-11-08 20:56:49 -05:00
|
|
|
"pia", "private internet access",
|
2020-10-20 02:45:28 +00:00
|
|
|
"mullvad", "windscribe", "surfshark", "cyberghost",
|
2020-11-08 20:56:49 -05:00
|
|
|
"vyprvpn", "nordvpn", "purevpn", "privado",
|
2020-10-24 19:09:54 +00:00
|
|
|
}, libparams.Default("private internet access"))
|
2020-04-12 20:05:28 +00:00
|
|
|
if s == "pia" {
|
|
|
|
|
s = "private internet access"
|
|
|
|
|
}
|
|
|
|
|
return models.VPNProvider(s), err
|
|
|
|
|
}
|
2020-08-30 14:48:57 +00:00
|
|
|
|
|
|
|
|
func (r *reader) GetVersionInformation() (enabled bool, err error) {
|
|
|
|
|
return r.envParams.GetOnOff("VERSION_INFORMATION", libparams.Default("on"))
|
|
|
|
|
}
|
2020-10-29 23:32:15 +00:00
|
|
|
|
|
|
|
|
func (r *reader) onRetroActive(oldKey, newKey string) {
|
|
|
|
|
r.logger.Warn(
|
|
|
|
|
"You are using the old environment variable %s, please consider changing it to %s",
|
|
|
|
|
oldKey, newKey,
|
|
|
|
|
)
|
|
|
|
|
}
|