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:
@@ -29,7 +29,7 @@ func (c *CLI) OpenvpnConfig(logger logging.Logger) error {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -82,52 +82,56 @@ var (
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var readProvider func(r reader) error
|
||||
switch settings.Name {
|
||||
case constants.Cyberghost:
|
||||
readProvider = settings.readCyberghost
|
||||
err = settings.readCyberghost(r)
|
||||
case constants.Fastestvpn:
|
||||
readProvider = settings.readFastestvpn
|
||||
err = settings.readFastestvpn(r)
|
||||
case constants.HideMyAss:
|
||||
readProvider = settings.readHideMyAss
|
||||
err = settings.readHideMyAss(r)
|
||||
case constants.Ipvanish:
|
||||
readProvider = settings.readIpvanish
|
||||
err = settings.readIpvanish(r)
|
||||
case constants.Ivpn:
|
||||
readProvider = settings.readIvpn
|
||||
err = settings.readIvpn(r)
|
||||
case constants.Mullvad:
|
||||
readProvider = settings.readMullvad
|
||||
err = settings.readMullvad(r)
|
||||
case constants.Nordvpn:
|
||||
readProvider = settings.readNordvpn
|
||||
err = settings.readNordvpn(r)
|
||||
case constants.Privado:
|
||||
readProvider = settings.readPrivado
|
||||
err = settings.readPrivado(r)
|
||||
case constants.PrivateInternetAccess:
|
||||
readProvider = settings.readPrivateInternetAccess
|
||||
err = settings.readPrivateInternetAccess(r)
|
||||
case constants.Privatevpn:
|
||||
readProvider = settings.readPrivatevpn
|
||||
err = settings.readPrivatevpn(r)
|
||||
case constants.Protonvpn:
|
||||
readProvider = settings.readProtonvpn
|
||||
err = settings.readProtonvpn(r)
|
||||
case constants.Purevpn:
|
||||
readProvider = settings.readPurevpn
|
||||
err = settings.readPurevpn(r)
|
||||
case constants.Surfshark:
|
||||
readProvider = settings.readSurfshark
|
||||
err = settings.readSurfshark(r)
|
||||
case constants.Torguard:
|
||||
readProvider = settings.readTorguard
|
||||
err = settings.readTorguard(r)
|
||||
case constants.VPNUnlimited:
|
||||
readProvider = settings.readVPNUnlimited
|
||||
err = settings.readVPNUnlimited(r)
|
||||
case constants.Vyprvpn:
|
||||
readProvider = settings.readVyprvpn
|
||||
err = settings.readVyprvpn(r)
|
||||
case constants.Windscribe:
|
||||
readProvider = settings.readWindscribe
|
||||
err = settings.readWindscribe(r)
|
||||
default:
|
||||
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) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
type ServerSelection struct { //nolint:maligned
|
||||
// Common
|
||||
VPN string `json:"vpn"`
|
||||
TargetIP net.IP `json:"target_ip,omitempty"`
|
||||
// TODO comments
|
||||
// Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN
|
||||
|
||||
@@ -49,7 +49,7 @@ func (settings *VPN) read(r reader) (err error) {
|
||||
settings.Type = vpnType
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ type Config struct { //nolint:maligned
|
||||
|
||||
// State
|
||||
enabled bool
|
||||
vpnConnection models.OpenVPNConnection
|
||||
vpnConnection models.Connection
|
||||
outboundSubnets []net.IPNet
|
||||
allowedInputPorts map[uint16]string // port to interface mapping
|
||||
stateMutex sync.Mutex
|
||||
|
||||
@@ -150,7 +150,7 @@ func (c *Config) acceptEstablishedRelatedTraffic(ctx context.Context, remove boo
|
||||
}
|
||||
|
||||
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",
|
||||
appendOrDelete(remove), connection.IP, defaultInterface, connection.Protocol,
|
||||
connection.Protocol, connection.Port)
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
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()
|
||||
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.vpnConnection = models.OpenVPNConnection{}
|
||||
c.vpnConnection = models.Connection{}
|
||||
remove = false
|
||||
if err := c.acceptOutputTrafficToVPN(ctx, c.defaultInterface, connection, remove); err != nil {
|
||||
return fmt.Errorf("cannot set VPN connection through firewall: %w", err)
|
||||
|
||||
50
internal/models/connection.go
Normal file
50
internal/models/connection.go
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ var (
|
||||
)
|
||||
|
||||
func BuildConfig(settings configuration.OpenVPN) (
|
||||
lines []string, connection models.OpenVPNConnection, err error) {
|
||||
lines []string, connection models.Connection, err error) {
|
||||
lines, err = readCustomConfigLines(settings.Config)
|
||||
if err != nil {
|
||||
return nil, connection, fmt.Errorf("%w: %s", ErrReadCustomConfig, err)
|
||||
|
||||
@@ -54,7 +54,7 @@ func Test_BuildConfig(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, expectedLines, lines)
|
||||
|
||||
expectedConnection := models.OpenVPNConnection{
|
||||
expectedConnection := models.Connection{
|
||||
IP: net.IPv4(1, 9, 8, 7),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -17,7 +17,7 @@ var (
|
||||
|
||||
// extractConnectionFromLines always takes the first remote line only.
|
||||
func extractConnectionFromLines(lines []string) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
connection models.Connection, err error) {
|
||||
for i, line := range lines {
|
||||
newConnectionData, err := extractConnectionFromLine(line)
|
||||
if err != nil {
|
||||
@@ -54,7 +54,7 @@ var (
|
||||
)
|
||||
|
||||
func extractConnectionFromLine(line string) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
connection models.Connection, err error) {
|
||||
switch {
|
||||
case strings.HasPrefix(line, "proto "):
|
||||
connection.Protocol, err = extractProto(line)
|
||||
|
||||
@@ -16,12 +16,12 @@ func Test_extractConnectionFromLines(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
lines []string
|
||||
connection models.OpenVPNConnection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"success": {
|
||||
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),
|
||||
Port: 1194,
|
||||
Protocol: constants.TCP,
|
||||
@@ -33,7 +33,7 @@ func Test_extractConnectionFromLines(t *testing.T) {
|
||||
},
|
||||
"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"},
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 2, 3, 4),
|
||||
Port: 443,
|
||||
Protocol: constants.UDP,
|
||||
@@ -41,14 +41,14 @@ func Test_extractConnectionFromLines(t *testing.T) {
|
||||
},
|
||||
"no IP found": {
|
||||
lines: []string{"proto tcp"},
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
err: errRemoteLineNotFound,
|
||||
},
|
||||
"default TCP port": {
|
||||
lines: []string{"remote 1.2.3.4", "proto tcp"},
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 2, 3, 4),
|
||||
Port: 443,
|
||||
Protocol: constants.TCP,
|
||||
@@ -56,7 +56,7 @@ func Test_extractConnectionFromLines(t *testing.T) {
|
||||
},
|
||||
"default UDP port": {
|
||||
lines: []string{"remote 1.2.3.4", "proto udp"},
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 2, 3, 4),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
@@ -88,7 +88,7 @@ func Test_extractConnectionFromLine(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
line string
|
||||
connection models.OpenVPNConnection
|
||||
connection models.Connection
|
||||
isErr error
|
||||
}{
|
||||
"irrelevant line": {
|
||||
@@ -100,7 +100,7 @@ func Test_extractConnectionFromLine(t *testing.T) {
|
||||
},
|
||||
"extract proto success": {
|
||||
line: "proto tcp",
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
@@ -110,7 +110,7 @@ func Test_extractConnectionFromLine(t *testing.T) {
|
||||
},
|
||||
"extract remote success": {
|
||||
line: "remote 1.2.3.4 1194 udp",
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 2, 3, 4),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func modifyCustomConfig(lines []string, settings configuration.OpenVPN,
|
||||
connection models.OpenVPNConnection) (modified []string) {
|
||||
connection models.Connection) (modified []string) {
|
||||
// Remove some lines
|
||||
for _, line := range lines {
|
||||
switch {
|
||||
@@ -33,8 +33,8 @@ func modifyCustomConfig(lines []string, settings configuration.OpenVPN,
|
||||
}
|
||||
|
||||
// Add values
|
||||
modified = append(modified, connection.ProtoLine())
|
||||
modified = append(modified, connection.RemoteLine())
|
||||
modified = append(modified, connection.OpenVPNProtoLine())
|
||||
modified = append(modified, connection.OpenVPNRemoteLine())
|
||||
modified = append(modified, "mute-replay-warnings")
|
||||
modified = append(modified, "auth-nocache")
|
||||
modified = append(modified, "pull-filter ignore \"auth-token\"") // prevent auth failed loop
|
||||
|
||||
@@ -16,7 +16,7 @@ func Test_modifyCustomConfig(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
lines []string
|
||||
settings configuration.OpenVPN
|
||||
connection models.OpenVPNConnection
|
||||
connection models.Connection
|
||||
modified []string
|
||||
}{
|
||||
"mixed": {
|
||||
@@ -36,7 +36,7 @@ func Test_modifyCustomConfig(t *testing.T) {
|
||||
MSSFix: 1000,
|
||||
ProcUser: "procuser",
|
||||
},
|
||||
connection: models.OpenVPNConnection{
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 2, 3, 4),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (c *Cyberghost) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 443
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -20,10 +20,11 @@ func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -33,8 +34,8 @@ func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -48,8 +48,8 @@ func (c *Cyberghost) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (f *Fastestvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 4443
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -20,10 +20,11 @@ func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -33,8 +34,8 @@ func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -51,8 +51,8 @@ func (f *Fastestvpn) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (h *HideMyAss) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
var port uint16 = 553
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -25,10 +25,11 @@ func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -38,8 +39,8 @@ func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -42,7 +42,7 @@ func (h *HideMyAss) BuildConf(connection models.OpenVPNConnection,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"proto " + connection.Protocol,
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
}
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (i *Ipvanish) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 443
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -24,10 +24,11 @@ func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -38,8 +39,8 @@ func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -42,7 +42,7 @@ func (i *Ipvanish) BuildConf(connection models.OpenVPNConnection,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"proto " + connection.Protocol,
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"verify-x509-name " + connection.Hostname + " name",
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (i *Ivpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 2049
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -24,10 +24,11 @@ func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -38,8 +39,8 @@ func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -45,7 +45,7 @@ func (i *Ivpn) BuildConf(connection models.OpenVPNConnection,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"proto " + connection.Protocol,
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"verify-x509-name " + namePrefix + " name-prefix",
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (m *Mullvad) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
var port uint16 = 1194
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -25,10 +25,11 @@ func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -38,8 +39,8 @@ func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -42,8 +42,8 @@ func (m *Mullvad) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
}
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (n *Nordvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
var port uint16 = 1194
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -21,9 +21,10 @@ func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
connections := make([]models.OpenVPNConnection, len(servers))
|
||||
connections := make([]models.Connection, len(servers))
|
||||
for i := range servers {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: servers[i].IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -32,8 +33,8 @@ func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -52,8 +52,8 @@ func (n *Nordvpn) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (p *Privado) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 1194
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -25,9 +25,10 @@ func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
connections := make([]models.OpenVPNConnection, len(servers))
|
||||
connections := make([]models.Connection, len(servers))
|
||||
for i := range servers {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: servers[i].IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -37,8 +38,8 @@ func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -43,8 +43,8 @@ func (p *Privado) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (p *PIA) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
@@ -24,10 +24,11 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -38,9 +39,9 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
}
|
||||
|
||||
if selection.TargetIP != nil {
|
||||
connection, err = utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP)
|
||||
connection, err = utils.GetTargetIPConnection(connections, selection.TargetIP)
|
||||
} else {
|
||||
connection, err = utils.PickRandomOpenVPNConnection(connections, p.randSource), nil
|
||||
connection, err = utils.PickRandomConnection(connections, p.randSource), nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
var defaultCipher, defaultAuth, X509CRL, certificate string
|
||||
switch settings.EncPreset {
|
||||
@@ -61,8 +61,8 @@ func (p *PIA) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
}
|
||||
|
||||
if settings.Cipher != "" {
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (p *Privatevpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 1194
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -21,10 +21,11 @@ func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, ip := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: ip,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -34,8 +35,8 @@ func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES128gcm
|
||||
@@ -40,8 +40,8 @@ func (p *Privatevpn) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (p *Protonvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
@@ -24,9 +24,10 @@ func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection
|
||||
return connection, err
|
||||
}
|
||||
|
||||
connections := make([]models.OpenVPNConnection, len(servers))
|
||||
connections := make([]models.Connection, len(servers))
|
||||
for i := range servers {
|
||||
connections[i] = models.OpenVPNConnection{
|
||||
connections[i] = models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: servers[i].EntryIP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -34,8 +35,8 @@ func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -51,8 +51,8 @@ func (p *Protonvpn) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ import (
|
||||
|
||||
// Provider contains methods to read and modify the openvpn configuration to connect as a client.
|
||||
type Provider interface {
|
||||
GetOpenVPNConnection(selection configuration.ServerSelection) (connection models.OpenVPNConnection, err error)
|
||||
BuildConf(connection models.OpenVPNConnection, settings configuration.OpenVPN) (lines []string)
|
||||
GetConnection(selection configuration.ServerSelection) (connection models.Connection, err error)
|
||||
BuildConf(connection models.Connection, settings configuration.OpenVPN) (lines []string)
|
||||
PortForwarder
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (p *Purevpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 53
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -21,10 +21,11 @@ func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -34,8 +35,8 @@ func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256gcm
|
||||
@@ -44,8 +44,8 @@ func (p *Purevpn) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
}
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (s *Surfshark) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 1194
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -21,10 +21,11 @@ func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -34,8 +35,8 @@ func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256gcm
|
||||
@@ -53,8 +53,8 @@ func (s *Surfshark) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (t *Torguard) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
@@ -24,10 +24,11 @@ func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -37,8 +38,8 @@ func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256gcm
|
||||
@@ -55,8 +55,8 @@ func (t *Torguard) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func PickRandomOpenVPNConnection(connections []models.OpenVPNConnection,
|
||||
source rand.Source) models.OpenVPNConnection {
|
||||
func PickRandomConnection(connections []models.Connection,
|
||||
source rand.Source) models.Connection {
|
||||
return connections[rand.New(source).Intn(len(connections))] //nolint:gosec
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_PickRandomOpenVPNConnection(t *testing.T) {
|
||||
func Test_PickRandomConnection(t *testing.T) {
|
||||
t.Parallel()
|
||||
connections := []models.OpenVPNConnection{
|
||||
connections := []models.Connection{
|
||||
{Port: 1}, {Port: 2}, {Port: 3}, {Port: 4},
|
||||
}
|
||||
source := rand.NewSource(0)
|
||||
|
||||
connection := PickRandomOpenVPNConnection(connections, source)
|
||||
assert.Equal(t, models.OpenVPNConnection{Port: 3}, connection)
|
||||
connection := PickRandomConnection(connections, source)
|
||||
assert.Equal(t, models.Connection{Port: 3}, connection)
|
||||
|
||||
connection = PickRandomOpenVPNConnection(connections, source)
|
||||
assert.Equal(t, models.OpenVPNConnection{Port: 3}, connection)
|
||||
connection = PickRandomConnection(connections, source)
|
||||
assert.Equal(t, models.Connection{Port: 3}, connection)
|
||||
|
||||
connection = PickRandomOpenVPNConnection(connections, source)
|
||||
assert.Equal(t, models.OpenVPNConnection{Port: 2}, connection)
|
||||
connection = PickRandomConnection(connections, source)
|
||||
assert.Equal(t, models.Connection{Port: 2}, connection)
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
|
||||
var ErrTargetIPNotFound = errors.New("target IP address not found")
|
||||
|
||||
func GetTargetIPOpenVPNConnection(connections []models.OpenVPNConnection,
|
||||
targetIP net.IP) (connection models.OpenVPNConnection, err error) {
|
||||
func GetTargetIPConnection(connections []models.Connection,
|
||||
targetIP net.IP) (connection models.Connection, err error) {
|
||||
for _, connection := range connections {
|
||||
if targetIP.Equal(connection.IP) {
|
||||
return connection, nil
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 1194
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -24,10 +24,11 @@ func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -37,8 +38,8 @@ func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
lines = []string{
|
||||
"client",
|
||||
@@ -35,8 +35,8 @@ func (p *Provider) BuildConf(connection models.OpenVPNConnection,
|
||||
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
}
|
||||
|
||||
if settings.Cipher != "" {
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (v *Vyprvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 443
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -25,10 +25,11 @@ func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -38,8 +39,8 @@ func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -45,8 +45,8 @@ func (v *Vyprvpn) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
func (w *Windscribe) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 443
|
||||
if selection.OpenVPN.TCP {
|
||||
@@ -25,10 +25,11 @@ func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
@@ -39,8 +40,8 @@ func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelectio
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"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) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
@@ -47,8 +47,8 @@ func (w *Windscribe) BuildConf(connection models.OpenVPNConnection,
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
"auth " + settings.Auth,
|
||||
"verify-x509-name " + connection.Hostname + " name",
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ func setupOpenVPN(ctx context.Context, fw firewall.VPNConnectionSetter,
|
||||
openvpnConf openvpn.Interface, providerConf provider.Provider,
|
||||
openVPNSettings configuration.OpenVPN, providerSettings configuration.Provider) (
|
||||
serverName string, err error) {
|
||||
var connection models.OpenVPNConnection
|
||||
var connection models.Connection
|
||||
var lines []string
|
||||
if openVPNSettings.Config == "" {
|
||||
connection, err = providerConf.GetOpenVPNConnection(providerSettings.ServerSelection)
|
||||
connection, err = providerConf.GetConnection(providerSettings.ServerSelection)
|
||||
if err == nil {
|
||||
lines = providerConf.BuildConf(connection, openVPNSettings)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user