Files
gluetun/internal/params/openvpn.go

85 lines
2.8 KiB
Go
Raw Normal View History

package params
import (
"fmt"
"net"
2020-07-26 12:07:06 +00:00
"github.com/qdm12/gluetun/internal/models"
libparams "github.com/qdm12/golibs/params"
)
2020-10-20 02:45:28 +00:00
// GetUser obtains the user to use to connect to the VPN servers.
2020-12-29 20:02:58 +00:00
func (r *reader) GetUser() (user string, err error) {
return r.envParams.GetEnv("OPENVPN_USER",
libparams.CaseSensitiveValue(),
libparams.Compulsory(),
2020-12-29 20:02:58 +00:00
libparams.RetroKeys([]string{"USER"}, r.onRetroActive),
libparams.Unset())
}
2020-10-20 02:45:28 +00:00
// GetPassword obtains the password to use to connect to the VPN servers.
2020-06-18 18:05:51 +00:00
func (r *reader) GetPassword(required bool) (s string, err error) {
options := []libparams.GetEnvSetter{
libparams.CaseSensitiveValue(),
libparams.Unset(),
libparams.RetroKeys([]string{"PASSWORD"}, r.onRetroActive),
}
2020-06-18 18:05:51 +00:00
if required {
options = append(options, libparams.Compulsory())
}
return r.envParams.GetEnv("OPENVPN_PASSWORD", options...)
}
// GetNetworkProtocol obtains the network protocol to use to connect to the
2020-10-20 02:45:28 +00:00
// VPN servers from the environment variable PROTOCOL.
func (r *reader) GetNetworkProtocol() (protocol models.NetworkProtocol, err error) {
s, err := r.envParams.GetValueIfInside("PROTOCOL", []string{"tcp", "udp"}, libparams.Default("udp"))
return models.NetworkProtocol(s), err
}
// GetOpenVPNVerbosity obtains the verbosity level for verbosity between 0 and 6
2020-10-20 02:45:28 +00:00
// from the environment variable OPENVPN_VERBOSITY.
func (r *reader) GetOpenVPNVerbosity() (verbosity int, err error) {
return r.envParams.GetEnvIntRange("OPENVPN_VERBOSITY", 0, 6, libparams.Default("1"))
}
// GetOpenVPNRoot obtains if openvpn should be run as root
2020-10-20 02:45:28 +00:00
// from the environment variable OPENVPN_ROOT.
func (r *reader) GetOpenVPNRoot() (root bool, err error) {
return r.envParams.GetYesNo("OPENVPN_ROOT", libparams.Default("no"))
}
2020-10-12 20:21:26 +00:00
// GetTargetIP obtains the IP address to override over the list of IP addresses filtered
2020-10-20 02:45:28 +00:00
// from the environment variable OPENVPN_TARGET_IP.
func (r *reader) GetTargetIP() (ip net.IP, err error) {
s, err := r.envParams.GetEnv("OPENVPN_TARGET_IP")
if len(s) == 0 {
return nil, nil
} else if err != nil {
return nil, err
}
ip = net.ParseIP(s)
if ip == nil {
return nil, fmt.Errorf("target IP address %q is not valid", s)
}
return ip, nil
}
// GetOpenVPNCipher obtains a custom cipher to use with OpenVPN
2020-10-20 02:45:28 +00:00
// from the environment variable OPENVPN_CIPHER.
func (r *reader) GetOpenVPNCipher() (cipher string, err error) {
return r.envParams.GetEnv("OPENVPN_CIPHER")
}
// GetOpenVPNAuth obtains a custom auth algorithm to use with OpenVPN
2020-10-20 02:45:28 +00:00
// from the environment variable OPENVPN_AUTH.
func (r *reader) GetOpenVPNAuth() (auth string, err error) {
return r.envParams.GetEnv("OPENVPN_AUTH")
}
// GetOpenVPNIPv6 obtains if ipv6 should be tunneled through the
2020-10-20 02:45:28 +00:00
// openvpn tunnel from the environment variable OPENVPN_IPV6.
func (r *reader) GetOpenVPNIPv6() (ipv6 bool, err error) {
return r.envParams.GetOnOff("OPENVPN_IPV6", libparams.Default("off"))
}