Maint: make VPN connection not specific to OpenVPN

- Add VPN field to ServerSelection struct
- Set VPN type to server selection at start using VPN_TYPE
- Change OpenVPNConnection to Connection with Type field
- Rename Provider GetOpenVPNConnection to GetConnection
- Rename GetTargetIPOpenVPNConnection to GetTargetIPConnection
- Rename PickRandomOpenVPNConnection to PickRandomConnection
- Add 'OpenVPN' prefix to OpenVPN specific methods on connection
This commit is contained in:
Quentin McGaw (desktop)
2021-08-19 14:09:41 +00:00
parent 105d81c018
commit 3d8e61900b
54 changed files with 283 additions and 255 deletions

View File

@@ -29,7 +29,7 @@ func (c *CLI) OpenvpnConfig(logger logging.Logger) error {
return err return err
} }
providerConf := provider.New(allSettings.VPN.Provider.Name, allServers, time.Now) providerConf := provider.New(allSettings.VPN.Provider.Name, allServers, time.Now)
connection, err := providerConf.GetOpenVPNConnection(allSettings.VPN.Provider.ServerSelection) connection, err := providerConf.GetConnection(allSettings.VPN.Provider.ServerSelection)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -82,52 +82,56 @@ var (
ErrInvalidVPNProvider = errors.New("invalid VPN provider") ErrInvalidVPNProvider = errors.New("invalid VPN provider")
) )
func (settings *Provider) read(r reader) error { func (settings *Provider) read(r reader, vpnType string) error {
err := settings.readVPNServiceProvider(r) err := settings.readVPNServiceProvider(r)
if err != nil { if err != nil {
return err return err
} }
var readProvider func(r reader) error
switch settings.Name { switch settings.Name {
case constants.Cyberghost: case constants.Cyberghost:
readProvider = settings.readCyberghost err = settings.readCyberghost(r)
case constants.Fastestvpn: case constants.Fastestvpn:
readProvider = settings.readFastestvpn err = settings.readFastestvpn(r)
case constants.HideMyAss: case constants.HideMyAss:
readProvider = settings.readHideMyAss err = settings.readHideMyAss(r)
case constants.Ipvanish: case constants.Ipvanish:
readProvider = settings.readIpvanish err = settings.readIpvanish(r)
case constants.Ivpn: case constants.Ivpn:
readProvider = settings.readIvpn err = settings.readIvpn(r)
case constants.Mullvad: case constants.Mullvad:
readProvider = settings.readMullvad err = settings.readMullvad(r)
case constants.Nordvpn: case constants.Nordvpn:
readProvider = settings.readNordvpn err = settings.readNordvpn(r)
case constants.Privado: case constants.Privado:
readProvider = settings.readPrivado err = settings.readPrivado(r)
case constants.PrivateInternetAccess: case constants.PrivateInternetAccess:
readProvider = settings.readPrivateInternetAccess err = settings.readPrivateInternetAccess(r)
case constants.Privatevpn: case constants.Privatevpn:
readProvider = settings.readPrivatevpn err = settings.readPrivatevpn(r)
case constants.Protonvpn: case constants.Protonvpn:
readProvider = settings.readProtonvpn err = settings.readProtonvpn(r)
case constants.Purevpn: case constants.Purevpn:
readProvider = settings.readPurevpn err = settings.readPurevpn(r)
case constants.Surfshark: case constants.Surfshark:
readProvider = settings.readSurfshark err = settings.readSurfshark(r)
case constants.Torguard: case constants.Torguard:
readProvider = settings.readTorguard err = settings.readTorguard(r)
case constants.VPNUnlimited: case constants.VPNUnlimited:
readProvider = settings.readVPNUnlimited err = settings.readVPNUnlimited(r)
case constants.Vyprvpn: case constants.Vyprvpn:
readProvider = settings.readVyprvpn err = settings.readVyprvpn(r)
case constants.Windscribe: case constants.Windscribe:
readProvider = settings.readWindscribe err = settings.readWindscribe(r)
default: default:
return fmt.Errorf("%w: %s", ErrInvalidVPNProvider, settings.Name) return fmt.Errorf("%w: %s", ErrInvalidVPNProvider, settings.Name)
} }
return readProvider(r) if err != nil {
return err
}
settings.ServerSelection.VPN = vpnType
return nil
} }
func (settings *Provider) readVPNServiceProvider(r reader) (err error) { func (settings *Provider) readVPNServiceProvider(r reader) (err error) {

View File

@@ -9,6 +9,7 @@ import (
type ServerSelection struct { //nolint:maligned type ServerSelection struct { //nolint:maligned
// Common // Common
VPN string `json:"vpn"`
TargetIP net.IP `json:"target_ip,omitempty"` TargetIP net.IP `json:"target_ip,omitempty"`
// TODO comments // TODO comments
// Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN // Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN

View File

@@ -49,7 +49,7 @@ func (settings *VPN) read(r reader) (err error) {
settings.Type = vpnType settings.Type = vpnType
if !settings.isOpenVPNCustomConfig(r.env) { if !settings.isOpenVPNCustomConfig(r.env) {
if err := settings.Provider.read(r); err != nil { if err := settings.Provider.read(r, vpnType); err != nil {
return fmt.Errorf("%w: %s", errReadProviderSettings, err) return fmt.Errorf("%w: %s", errReadProviderSettings, err)
} }
} }

View File

@@ -39,7 +39,7 @@ type Config struct { //nolint:maligned
// State // State
enabled bool enabled bool
vpnConnection models.OpenVPNConnection vpnConnection models.Connection
outboundSubnets []net.IPNet outboundSubnets []net.IPNet
allowedInputPorts map[uint16]string // port to interface mapping allowedInputPorts map[uint16]string // port to interface mapping
stateMutex sync.Mutex stateMutex sync.Mutex

View File

@@ -150,7 +150,7 @@ func (c *Config) acceptEstablishedRelatedTraffic(ctx context.Context, remove boo
} }
func (c *Config) acceptOutputTrafficToVPN(ctx context.Context, func (c *Config) acceptOutputTrafficToVPN(ctx context.Context,
defaultInterface string, connection models.OpenVPNConnection, remove bool) error { defaultInterface string, connection models.Connection, remove bool) error {
instruction := fmt.Sprintf("%s OUTPUT -d %s -o %s -p %s -m %s --dport %d -j ACCEPT", instruction := fmt.Sprintf("%s OUTPUT -d %s -o %s -p %s -m %s --dport %d -j ACCEPT",
appendOrDelete(remove), connection.IP, defaultInterface, connection.Protocol, appendOrDelete(remove), connection.IP, defaultInterface, connection.Protocol,
connection.Protocol, connection.Port) connection.Protocol, connection.Port)

View File

@@ -8,10 +8,10 @@ import (
) )
type VPNConnectionSetter interface { type VPNConnectionSetter interface {
SetVPNConnection(ctx context.Context, connection models.OpenVPNConnection) error SetVPNConnection(ctx context.Context, connection models.Connection) error
} }
func (c *Config) SetVPNConnection(ctx context.Context, connection models.OpenVPNConnection) (err error) { func (c *Config) SetVPNConnection(ctx context.Context, connection models.Connection) (err error) {
c.stateMutex.Lock() c.stateMutex.Lock()
defer c.stateMutex.Unlock() defer c.stateMutex.Unlock()
@@ -33,7 +33,7 @@ func (c *Config) SetVPNConnection(ctx context.Context, connection models.OpenVPN
c.logger.Error("cannot remove outdated VPN connection through firewall: " + err.Error()) c.logger.Error("cannot remove outdated VPN connection through firewall: " + err.Error())
} }
} }
c.vpnConnection = models.OpenVPNConnection{} c.vpnConnection = models.Connection{}
remove = false remove = false
if err := c.acceptOutputTrafficToVPN(ctx, c.defaultInterface, connection, remove); err != nil { if err := c.acceptOutputTrafficToVPN(ctx, c.defaultInterface, connection, remove); err != nil {
return fmt.Errorf("cannot set VPN connection through firewall: %w", err) return fmt.Errorf("cannot set VPN connection through firewall: %w", err)

View File

@@ -0,0 +1,50 @@
package models
import (
"fmt"
"net"
)
type Connection struct {
// Type is the connection type and can be "openvpn"
Type string `json:"type"`
// IP is the VPN server IP address.
IP net.IP `json:"ip"`
// Port is the VPN server port.
Port uint16 `json:"port"`
// Protocol can be "tcp" or "udp".
Protocol string `json:"protocol"`
// Hostname is used for IPVanish, IVPN, Privado
// and Windscribe for TLS verification
Hostname string `json:"hostname"`
}
func (c *Connection) Equal(other Connection) bool {
return c.IP.Equal(other.IP) && c.Port == other.Port &&
c.Protocol == other.Protocol && c.Hostname == other.Hostname
}
func (c Connection) OpenVPNRemoteLine() (line string) {
return "remote " + c.IP.String() + " " + fmt.Sprint(c.Port)
}
func (c Connection) OpenVPNProtoLine() (line string) {
return "proto " + c.Protocol
}
// UpdateEmptyWith updates each field of the connection where the
// value is not set using the value from the other connection.
func (c *Connection) UpdateEmptyWith(connection Connection) {
if c.IP == nil {
c.IP = connection.IP
}
if c.Port == 0 {
c.Port = connection.Port
}
if c.Protocol == "" {
c.Protocol = connection.Protocol
}
if c.Hostname == "" {
c.Hostname = connection.Hostname
}
}

View File

@@ -1,44 +0,0 @@
package models
import (
"net"
"strconv"
)
type OpenVPNConnection struct {
IP net.IP `json:"ip"`
Port uint16 `json:"port"`
Protocol string `json:"protocol"`
// Hostname is used for IPVanish, IVPN, Privado
// and Windscribe for TLS verification
Hostname string `json:"hostname"`
}
func (o *OpenVPNConnection) Equal(other OpenVPNConnection) bool {
return o.IP.Equal(other.IP) && o.Port == other.Port && o.Protocol == other.Protocol &&
o.Hostname == other.Hostname
}
func (o OpenVPNConnection) RemoteLine() (line string) {
return "remote " + o.IP.String() + " " + strconv.Itoa(int(o.Port))
}
func (o OpenVPNConnection) ProtoLine() (line string) {
return "proto " + o.Protocol
}
// UpdateEmptyWith updates each field of the connection where the value is not set.
func (o *OpenVPNConnection) UpdateEmptyWith(connection OpenVPNConnection) {
if o.IP == nil {
o.IP = connection.IP
}
if o.Port == 0 {
o.Port = connection.Port
}
if o.Protocol == "" {
o.Protocol = connection.Protocol
}
if o.Hostname == "" {
o.Hostname = connection.Hostname
}
}

View File

@@ -14,7 +14,7 @@ var (
) )
func BuildConfig(settings configuration.OpenVPN) ( func BuildConfig(settings configuration.OpenVPN) (
lines []string, connection models.OpenVPNConnection, err error) { lines []string, connection models.Connection, err error) {
lines, err = readCustomConfigLines(settings.Config) lines, err = readCustomConfigLines(settings.Config)
if err != nil { if err != nil {
return nil, connection, fmt.Errorf("%w: %s", ErrReadCustomConfig, err) return nil, connection, fmt.Errorf("%w: %s", ErrReadCustomConfig, err)

View File

@@ -54,7 +54,7 @@ func Test_BuildConfig(t *testing.T) {
} }
assert.Equal(t, expectedLines, lines) assert.Equal(t, expectedLines, lines)
expectedConnection := models.OpenVPNConnection{ expectedConnection := models.Connection{
IP: net.IPv4(1, 9, 8, 7), IP: net.IPv4(1, 9, 8, 7),
Port: 1194, Port: 1194,
Protocol: constants.UDP, Protocol: constants.UDP,

View File

@@ -17,7 +17,7 @@ var (
// extractConnectionFromLines always takes the first remote line only. // extractConnectionFromLines always takes the first remote line only.
func extractConnectionFromLines(lines []string) ( func extractConnectionFromLines(lines []string) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
for i, line := range lines { for i, line := range lines {
newConnectionData, err := extractConnectionFromLine(line) newConnectionData, err := extractConnectionFromLine(line)
if err != nil { if err != nil {
@@ -54,7 +54,7 @@ var (
) )
func extractConnectionFromLine(line string) ( func extractConnectionFromLine(line string) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
switch { switch {
case strings.HasPrefix(line, "proto "): case strings.HasPrefix(line, "proto "):
connection.Protocol, err = extractProto(line) connection.Protocol, err = extractProto(line)

View File

@@ -16,12 +16,12 @@ func Test_extractConnectionFromLines(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
lines []string lines []string
connection models.OpenVPNConnection connection models.Connection
err error err error
}{ }{
"success": { "success": {
lines: []string{"bla bla", "proto tcp", "remote 1.2.3.4 1194 tcp"}, lines: []string{"bla bla", "proto tcp", "remote 1.2.3.4 1194 tcp"},
connection: models.OpenVPNConnection{ connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4), IP: net.IPv4(1, 2, 3, 4),
Port: 1194, Port: 1194,
Protocol: constants.TCP, Protocol: constants.TCP,
@@ -33,7 +33,7 @@ func Test_extractConnectionFromLines(t *testing.T) {
}, },
"only use first values found": { "only use first values found": {
lines: []string{"proto udp", "proto tcp", "remote 1.2.3.4 443 tcp", "remote 5.2.3.4 1194 udp"}, lines: []string{"proto udp", "proto tcp", "remote 1.2.3.4 443 tcp", "remote 5.2.3.4 1194 udp"},
connection: models.OpenVPNConnection{ connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4), IP: net.IPv4(1, 2, 3, 4),
Port: 443, Port: 443,
Protocol: constants.UDP, Protocol: constants.UDP,
@@ -41,14 +41,14 @@ func Test_extractConnectionFromLines(t *testing.T) {
}, },
"no IP found": { "no IP found": {
lines: []string{"proto tcp"}, lines: []string{"proto tcp"},
connection: models.OpenVPNConnection{ connection: models.Connection{
Protocol: constants.TCP, Protocol: constants.TCP,
}, },
err: errRemoteLineNotFound, err: errRemoteLineNotFound,
}, },
"default TCP port": { "default TCP port": {
lines: []string{"remote 1.2.3.4", "proto tcp"}, lines: []string{"remote 1.2.3.4", "proto tcp"},
connection: models.OpenVPNConnection{ connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4), IP: net.IPv4(1, 2, 3, 4),
Port: 443, Port: 443,
Protocol: constants.TCP, Protocol: constants.TCP,
@@ -56,7 +56,7 @@ func Test_extractConnectionFromLines(t *testing.T) {
}, },
"default UDP port": { "default UDP port": {
lines: []string{"remote 1.2.3.4", "proto udp"}, lines: []string{"remote 1.2.3.4", "proto udp"},
connection: models.OpenVPNConnection{ connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4), IP: net.IPv4(1, 2, 3, 4),
Port: 1194, Port: 1194,
Protocol: constants.UDP, Protocol: constants.UDP,
@@ -88,7 +88,7 @@ func Test_extractConnectionFromLine(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
line string line string
connection models.OpenVPNConnection connection models.Connection
isErr error isErr error
}{ }{
"irrelevant line": { "irrelevant line": {
@@ -100,7 +100,7 @@ func Test_extractConnectionFromLine(t *testing.T) {
}, },
"extract proto success": { "extract proto success": {
line: "proto tcp", line: "proto tcp",
connection: models.OpenVPNConnection{ connection: models.Connection{
Protocol: constants.TCP, Protocol: constants.TCP,
}, },
}, },
@@ -110,7 +110,7 @@ func Test_extractConnectionFromLine(t *testing.T) {
}, },
"extract remote success": { "extract remote success": {
line: "remote 1.2.3.4 1194 udp", line: "remote 1.2.3.4 1194 udp",
connection: models.OpenVPNConnection{ connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4), IP: net.IPv4(1, 2, 3, 4),
Port: 1194, Port: 1194,
Protocol: constants.UDP, Protocol: constants.UDP,

View File

@@ -11,7 +11,7 @@ import (
) )
func modifyCustomConfig(lines []string, settings configuration.OpenVPN, func modifyCustomConfig(lines []string, settings configuration.OpenVPN,
connection models.OpenVPNConnection) (modified []string) { connection models.Connection) (modified []string) {
// Remove some lines // Remove some lines
for _, line := range lines { for _, line := range lines {
switch { switch {
@@ -33,8 +33,8 @@ func modifyCustomConfig(lines []string, settings configuration.OpenVPN,
} }
// Add values // Add values
modified = append(modified, connection.ProtoLine()) modified = append(modified, connection.OpenVPNProtoLine())
modified = append(modified, connection.RemoteLine()) modified = append(modified, connection.OpenVPNRemoteLine())
modified = append(modified, "mute-replay-warnings") modified = append(modified, "mute-replay-warnings")
modified = append(modified, "auth-nocache") modified = append(modified, "auth-nocache")
modified = append(modified, "pull-filter ignore \"auth-token\"") // prevent auth failed loop modified = append(modified, "pull-filter ignore \"auth-token\"") // prevent auth failed loop

View File

@@ -16,7 +16,7 @@ func Test_modifyCustomConfig(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
lines []string lines []string
settings configuration.OpenVPN settings configuration.OpenVPN
connection models.OpenVPNConnection connection models.Connection
modified []string modified []string
}{ }{
"mixed": { "mixed": {
@@ -36,7 +36,7 @@ func Test_modifyCustomConfig(t *testing.T) {
MSSFix: 1000, MSSFix: 1000,
ProcUser: "procuser", ProcUser: "procuser",
}, },
connection: models.OpenVPNConnection{ connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4), IP: net.IPv4(1, 2, 3, 4),
Port: 1194, Port: 1194,
Protocol: constants.UDP, Protocol: constants.UDP,

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (c *Cyberghost) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 443 const port = 443
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -20,10 +20,11 @@ func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelectio
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -33,8 +34,8 @@ func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelectio
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, c.randSource), nil return utils.PickRandomConnection(connections, c.randSource), nil
} }

View File

@@ -10,7 +10,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (c *Cyberghost) BuildConf(connection models.OpenVPNConnection, func (c *Cyberghost) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -48,8 +48,8 @@ func (c *Cyberghost) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (f *Fastestvpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 4443 const port = 4443
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -20,10 +20,11 @@ func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelectio
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -33,8 +34,8 @@ func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelectio
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, f.randSource), nil return utils.PickRandomConnection(connections, f.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (f *Fastestvpn) BuildConf(connection models.OpenVPNConnection, func (f *Fastestvpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -51,8 +51,8 @@ func (f *Fastestvpn) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (h *HideMyAss) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
var port uint16 = 553 var port uint16 = 553
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -25,10 +25,11 @@ func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -38,8 +39,8 @@ func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, h.randSource), nil return utils.PickRandomConnection(connections, h.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (h *HideMyAss) BuildConf(connection models.OpenVPNConnection, func (h *HideMyAss) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -42,7 +42,7 @@ func (h *HideMyAss) BuildConf(connection models.OpenVPNConnection,
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
"proto " + connection.Protocol, "proto " + connection.Protocol,
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
} }
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...) lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)

View File

@@ -11,8 +11,8 @@ import (
var ErrProtocolUnsupported = errors.New("network protocol is not supported") var ErrProtocolUnsupported = errors.New("network protocol is not supported")
func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (i *Ipvanish) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 443 const port = 443
const protocol = constants.UDP const protocol = constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -24,10 +24,11 @@ func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -38,8 +39,8 @@ func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, i.randSource), nil return utils.PickRandomConnection(connections, i.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (i *Ipvanish) BuildConf(connection models.OpenVPNConnection, func (i *Ipvanish) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -42,7 +42,7 @@ func (i *Ipvanish) BuildConf(connection models.OpenVPNConnection,
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
"proto " + connection.Protocol, "proto " + connection.Protocol,
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"verify-x509-name " + connection.Hostname + " name", "verify-x509-name " + connection.Hostname + " name",
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -11,8 +11,8 @@ import (
var ErrProtocolUnsupported = errors.New("network protocol is not supported") var ErrProtocolUnsupported = errors.New("network protocol is not supported")
func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (i *Ivpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 2049 const port = 2049
const protocol = constants.UDP const protocol = constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -24,10 +24,11 @@ func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -38,8 +39,8 @@ func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, i.randSource), nil return utils.PickRandomConnection(connections, i.randSource), nil
} }

View File

@@ -10,7 +10,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (i *Ivpn) BuildConf(connection models.OpenVPNConnection, func (i *Ivpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -45,7 +45,7 @@ func (i *Ivpn) BuildConf(connection models.OpenVPNConnection,
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
"proto " + connection.Protocol, "proto " + connection.Protocol,
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"verify-x509-name " + namePrefix + " name-prefix", "verify-x509-name " + namePrefix + " name-prefix",
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (m *Mullvad) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
var port uint16 = 1194 var port uint16 = 1194
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -25,10 +25,11 @@ func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -38,8 +39,8 @@ func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, m.randSource), nil return utils.PickRandomConnection(connections, m.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (m *Mullvad) BuildConf(connection models.OpenVPNConnection, func (m *Mullvad) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -42,8 +42,8 @@ func (m *Mullvad) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
} }
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...) lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (n *Nordvpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
var port uint16 = 1194 var port uint16 = 1194
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -21,9 +21,10 @@ func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
connections := make([]models.OpenVPNConnection, len(servers)) connections := make([]models.Connection, len(servers))
for i := range servers { for i := range servers {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: servers[i].IP, IP: servers[i].IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -32,8 +33,8 @@ func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, n.randSource), nil return utils.PickRandomConnection(connections, n.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (n *Nordvpn) BuildConf(connection models.OpenVPNConnection, func (n *Nordvpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -52,8 +52,8 @@ func (n *Nordvpn) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -12,8 +12,8 @@ import (
var ErrProtocolUnsupported = errors.New("network protocol is not supported") var ErrProtocolUnsupported = errors.New("network protocol is not supported")
func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *Privado) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 1194 const port = 1194
const protocol = constants.UDP const protocol = constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -25,9 +25,10 @@ func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
connections := make([]models.OpenVPNConnection, len(servers)) connections := make([]models.Connection, len(servers))
for i := range servers { for i := range servers {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: servers[i].IP, IP: servers[i].IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -37,8 +38,8 @@ func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, p.randSource), nil return utils.PickRandomConnection(connections, p.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Privado) BuildConf(connection models.OpenVPNConnection, func (p *Privado) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -43,8 +43,8 @@ func (p *Privado) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *PIA) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
@@ -24,10 +24,11 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -38,9 +39,9 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
connection, err = utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) connection, err = utils.GetTargetIPConnection(connections, selection.TargetIP)
} else { } else {
connection, err = utils.PickRandomOpenVPNConnection(connections, p.randSource), nil connection, err = utils.PickRandomConnection(connections, p.randSource), nil
} }
if err != nil { if err != nil {

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *PIA) BuildConf(connection models.OpenVPNConnection, func (p *PIA) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
var defaultCipher, defaultAuth, X509CRL, certificate string var defaultCipher, defaultAuth, X509CRL, certificate string
switch settings.EncPreset { switch settings.EncPreset {
@@ -61,8 +61,8 @@ func (p *PIA) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
} }
if settings.Cipher != "" { if settings.Cipher != "" {

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *Privatevpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 1194 var port uint16 = 1194
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -21,10 +21,11 @@ func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelectio
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, ip := range server.IPs { for _, ip := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: ip, IP: ip,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -34,8 +35,8 @@ func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelectio
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, p.randSource), nil return utils.PickRandomConnection(connections, p.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Privatevpn) BuildConf(connection models.OpenVPNConnection, func (p *Privatevpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES128gcm settings.Cipher = constants.AES128gcm
@@ -40,8 +40,8 @@ func (p *Privatevpn) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *Protonvpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
@@ -24,9 +24,10 @@ func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection
return connection, err return connection, err
} }
connections := make([]models.OpenVPNConnection, len(servers)) connections := make([]models.Connection, len(servers))
for i := range servers { for i := range servers {
connections[i] = models.OpenVPNConnection{ connections[i] = models.Connection{
Type: selection.VPN,
IP: servers[i].EntryIP, IP: servers[i].EntryIP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -34,8 +35,8 @@ func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, p.randSource), nil return utils.PickRandomConnection(connections, p.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Protonvpn) BuildConf(connection models.OpenVPNConnection, func (p *Protonvpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -51,8 +51,8 @@ func (p *Protonvpn) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -33,8 +33,8 @@ import (
// Provider contains methods to read and modify the openvpn configuration to connect as a client. // Provider contains methods to read and modify the openvpn configuration to connect as a client.
type Provider interface { type Provider interface {
GetOpenVPNConnection(selection configuration.ServerSelection) (connection models.OpenVPNConnection, err error) GetConnection(selection configuration.ServerSelection) (connection models.Connection, err error)
BuildConf(connection models.OpenVPNConnection, settings configuration.OpenVPN) (lines []string) BuildConf(connection models.Connection, settings configuration.OpenVPN) (lines []string)
PortForwarder PortForwarder
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *Purevpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 53 var port uint16 = 53
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -21,10 +21,11 @@ func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -34,8 +35,8 @@ func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, p.randSource), nil return utils.PickRandomConnection(connections, p.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Purevpn) BuildConf(connection models.OpenVPNConnection, func (p *Purevpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256gcm settings.Cipher = constants.AES256gcm
@@ -44,8 +44,8 @@ func (p *Purevpn) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
} }
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...) lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (s *Surfshark) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 1194 var port uint16 = 1194
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -21,10 +21,11 @@ func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -34,8 +35,8 @@ func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, s.randSource), nil return utils.PickRandomConnection(connections, s.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (s *Surfshark) BuildConf(connection models.OpenVPNConnection, func (s *Surfshark) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256gcm settings.Cipher = constants.AES256gcm
@@ -53,8 +53,8 @@ func (s *Surfshark) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (t *Torguard) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
@@ -24,10 +24,11 @@ func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -37,8 +38,8 @@ func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, t.randSource), nil return utils.PickRandomConnection(connections, t.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (t *Torguard) BuildConf(connection models.OpenVPNConnection, func (t *Torguard) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256gcm settings.Cipher = constants.AES256gcm
@@ -55,8 +55,8 @@ func (t *Torguard) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -6,7 +6,7 @@ import (
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
) )
func PickRandomOpenVPNConnection(connections []models.OpenVPNConnection, func PickRandomConnection(connections []models.Connection,
source rand.Source) models.OpenVPNConnection { source rand.Source) models.Connection {
return connections[rand.New(source).Intn(len(connections))] //nolint:gosec return connections[rand.New(source).Intn(len(connections))] //nolint:gosec
} }

View File

@@ -8,19 +8,19 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func Test_PickRandomOpenVPNConnection(t *testing.T) { func Test_PickRandomConnection(t *testing.T) {
t.Parallel() t.Parallel()
connections := []models.OpenVPNConnection{ connections := []models.Connection{
{Port: 1}, {Port: 2}, {Port: 3}, {Port: 4}, {Port: 1}, {Port: 2}, {Port: 3}, {Port: 4},
} }
source := rand.NewSource(0) source := rand.NewSource(0)
connection := PickRandomOpenVPNConnection(connections, source) connection := PickRandomConnection(connections, source)
assert.Equal(t, models.OpenVPNConnection{Port: 3}, connection) assert.Equal(t, models.Connection{Port: 3}, connection)
connection = PickRandomOpenVPNConnection(connections, source) connection = PickRandomConnection(connections, source)
assert.Equal(t, models.OpenVPNConnection{Port: 3}, connection) assert.Equal(t, models.Connection{Port: 3}, connection)
connection = PickRandomOpenVPNConnection(connections, source) connection = PickRandomConnection(connections, source)
assert.Equal(t, models.OpenVPNConnection{Port: 2}, connection) assert.Equal(t, models.Connection{Port: 2}, connection)
} }

View File

@@ -10,8 +10,8 @@ import (
var ErrTargetIPNotFound = errors.New("target IP address not found") var ErrTargetIPNotFound = errors.New("target IP address not found")
func GetTargetIPOpenVPNConnection(connections []models.OpenVPNConnection, func GetTargetIPConnection(connections []models.Connection,
targetIP net.IP) (connection models.OpenVPNConnection, err error) { targetIP net.IP) (connection models.Connection, err error) {
for _, connection := range connections { for _, connection := range connections {
if targetIP.Equal(connection.IP) { if targetIP.Equal(connection.IP) {
return connection, nil return connection, nil

View File

@@ -11,8 +11,8 @@ import (
var ErrProtocolUnsupported = errors.New("network protocol is not supported") var ErrProtocolUnsupported = errors.New("network protocol is not supported")
func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *Provider) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 1194 const port = 1194
const protocol = constants.UDP const protocol = constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -24,10 +24,11 @@ func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -37,8 +38,8 @@ func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, p.randSource), nil return utils.PickRandomConnection(connections, p.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (p *Provider) BuildConf(connection models.OpenVPNConnection, func (p *Provider) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
lines = []string{ lines = []string{
"client", "client",
@@ -35,8 +35,8 @@ func (p *Provider) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
} }
if settings.Cipher != "" { if settings.Cipher != "" {

View File

@@ -12,8 +12,8 @@ import (
var ErrProtocolUnsupported = errors.New("network protocol is not supported") var ErrProtocolUnsupported = errors.New("network protocol is not supported")
func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (v *Vyprvpn) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
const port = 443 const port = 443
const protocol = constants.UDP const protocol = constants.UDP
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -25,10 +25,11 @@ func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -38,8 +39,8 @@ func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, v.randSource), nil return utils.PickRandomConnection(connections, v.randSource), nil
} }

View File

@@ -9,7 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (v *Vyprvpn) BuildConf(connection models.OpenVPNConnection, func (v *Vyprvpn) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -45,8 +45,8 @@ func (v *Vyprvpn) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
} }

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (w *Windscribe) GetConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.Connection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 443 var port uint16 = 443
if selection.OpenVPN.TCP { if selection.OpenVPN.TCP {
@@ -25,10 +25,11 @@ func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelectio
return connection, err return connection, err
} }
var connections []models.OpenVPNConnection var connections []models.Connection
for _, server := range servers { for _, server := range servers {
for _, IP := range server.IPs { for _, IP := range server.IPs {
connection := models.OpenVPNConnection{ connection := models.Connection{
Type: selection.VPN,
IP: IP, IP: IP,
Port: port, Port: port,
Protocol: protocol, Protocol: protocol,
@@ -39,8 +40,8 @@ func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelectio
} }
if selection.TargetIP != nil { if selection.TargetIP != nil {
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP) return utils.GetTargetIPConnection(connections, selection.TargetIP)
} }
return utils.PickRandomOpenVPNConnection(connections, w.randSource), nil return utils.PickRandomConnection(connections, w.randSource), nil
} }

View File

@@ -10,7 +10,7 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
func (w *Windscribe) BuildConf(connection models.OpenVPNConnection, func (w *Windscribe) BuildConf(connection models.Connection,
settings configuration.OpenVPN) (lines []string) { settings configuration.OpenVPN) (lines []string) {
if settings.Cipher == "" { if settings.Cipher == "" {
settings.Cipher = constants.AES256cbc settings.Cipher = constants.AES256cbc
@@ -47,8 +47,8 @@ func (w *Windscribe) BuildConf(connection models.OpenVPNConnection,
// Modified variables // Modified variables
"verb " + strconv.Itoa(settings.Verbosity), "verb " + strconv.Itoa(settings.Verbosity),
"auth-user-pass " + constants.OpenVPNAuthConf, "auth-user-pass " + constants.OpenVPNAuthConf,
connection.ProtoLine(), connection.OpenVPNProtoLine(),
connection.RemoteLine(), connection.OpenVPNRemoteLine(),
"auth " + settings.Auth, "auth " + settings.Auth,
"verify-x509-name " + connection.Hostname + " name", "verify-x509-name " + connection.Hostname + " name",
} }

View File

@@ -26,10 +26,10 @@ func setupOpenVPN(ctx context.Context, fw firewall.VPNConnectionSetter,
openvpnConf openvpn.Interface, providerConf provider.Provider, openvpnConf openvpn.Interface, providerConf provider.Provider,
openVPNSettings configuration.OpenVPN, providerSettings configuration.Provider) ( openVPNSettings configuration.OpenVPN, providerSettings configuration.Provider) (
serverName string, err error) { serverName string, err error) {
var connection models.OpenVPNConnection var connection models.Connection
var lines []string var lines []string
if openVPNSettings.Config == "" { if openVPNSettings.Config == "" {
connection, err = providerConf.GetOpenVPNConnection(providerSettings.ServerSelection) connection, err = providerConf.GetConnection(providerSettings.ServerSelection)
if err == nil { if err == nil {
lines = providerConf.BuildConf(connection, openVPNSettings) lines = providerConf.BuildConf(connection, openVPNSettings)
} }