2020-04-12 20:05:28 +00:00
package params
import (
"net"
"os"
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-07-14 00:17:31 +00:00
"github.com/qdm12/golibs/files"
2020-04-12 20:05:28 +00:00
"github.com/qdm12/golibs/logging"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/golibs/verification"
)
// Reader contains methods to obtain parameters
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
GetUID ( ) ( uid int , err error )
GetGID ( ) ( gid int , err error )
GetTimezone ( ) ( timezone string , err error )
GetIPStatusFilepath ( ) ( filepath models . Filepath , err error )
// Firewall getters
2020-06-12 17:11:21 +00:00
GetFirewall ( ) ( enabled bool , err error )
2020-04-12 20:05:28 +00:00
GetExtraSubnets ( ) ( extraSubnets [ ] net . IPNet , err error )
2020-07-20 02:07:13 +00:00
GetVPNInputPorts ( ) ( ports [ ] uint16 , 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-06-18 18:05:51 +00:00
GetPassword ( required bool ) ( 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 )
GetPIARegion ( ) ( region string , err error )
2020-08-28 08:17:04 -04:00
GetPIAOldRegion ( ) ( region string , err error )
2020-04-12 20:05:28 +00:00
// Mullvad getters
2020-06-13 14:08:29 -04:00
GetMullvadCountry ( ) ( country string , err error )
GetMullvadCity ( ) ( country string , err error )
GetMullvadISP ( ) ( country string , err error )
2020-04-12 20:05:28 +00:00
GetMullvadPort ( ) ( port uint16 , err error )
// Windscribe getters
2020-06-13 14:08:29 -04:00
GetWindscribeRegion ( ) ( country 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-06-13 14:08:29 -04:00
GetSurfsharkRegion ( ) ( country 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 )
GetCyberghostRegion ( ) ( region string , err error )
2020-06-13 10:43:47 -04:00
GetCyberghostClientKey ( ) ( clientKey string , err error )
2020-07-13 08:04:35 -04:00
// Vyprvpn getters
GetVyprvpnRegion ( ) ( region string , err error )
2020-07-15 18:14:45 -04:00
// NordVPN getters
GetNordvpnRegion ( ) ( region string , err error )
GetNordvpnNumber ( ) ( number uint16 , err error )
2020-07-25 11:19:45 -04:00
// PureVPN getters
GetPurevpnRegion ( ) ( region string , err error )
GetPurevpnCountry ( ) ( country string , err error )
GetPurevpnCity ( ) ( city string , err error )
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 )
// Tinyproxy getters
GetTinyProxy ( ) ( activated bool , err error )
GetTinyProxyLog ( ) ( models . TinyProxyLogLevel , error )
GetTinyProxyPort ( ) ( port uint16 , err error )
GetTinyProxyUser ( ) ( user string , err error )
GetTinyProxyPassword ( ) ( password string , err error )
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
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-07-14 00:17:31 +00:00
envParams libparams . EnvParams
logger logging . Logger
verifier verification . Verifier
unsetEnv func ( key string ) error
fileManager files . FileManager
2020-04-12 20:05:28 +00:00
}
// Newreader returns a paramsReadeer object to read parameters from
// environment variables
2020-07-14 00:17:31 +00:00
func NewReader ( logger logging . Logger , fileManager files . FileManager ) Reader {
2020-04-12 20:05:28 +00:00
return & reader {
2020-07-14 00:17:31 +00:00
envParams : libparams . NewEnvParams ( ) ,
logger : logger ,
verifier : verification . NewVerifier ( ) ,
unsetEnv : os . Unsetenv ,
fileManager : fileManager ,
2020-04-12 20:05: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-08-28 08:17:04 -04:00
s , err := r . envParams . GetValueIfInside ( "VPNSP" , [ ] string { "pia" , "private internet access" , "private internet access old" , "mullvad" , "windscribe" , "surfshark" , "cyberghost" , "vyprvpn" , "nordvpn" , "purevpn" } )
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" ) )
}