Maint: configuration Openvpn selection structure

- Move network protocol from ServerSelection to OpenVPNSelection child
- Move PIA encryption preset from ServerSelection to OpenVPNSelection child
- Move custom port from ServerSelection to OpenVPNSelection child
This commit is contained in:
Quentin McGaw (desktop)
2021-08-17 16:54:22 +00:00
parent cc2235653a
commit 9105b33e9f
57 changed files with 321 additions and 282 deletions

View File

@@ -17,17 +17,14 @@ func (settings *Provider) cyberghostLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readCyberghost(r reader) (err error) { func (settings *Provider) readCyberghost(r reader) (err error) {
settings.Name = constants.Cyberghost settings.Name = constants.Cyberghost
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -49,7 +46,7 @@ func (settings *Provider) readCyberghost(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolAndPort(r.env)
} }
func (settings *OpenVPN) readCyberghost(r reader) (err error) { func (settings *OpenVPN) readCyberghost(r reader) (err error) {

View File

@@ -15,17 +15,14 @@ func (settings *Provider) fastestvpnLines() (lines []string) {
lines = append(lines, lastIndent+"Countries: "+commaJoin(settings.ServerSelection.Countries)) lines = append(lines, lastIndent+"Countries: "+commaJoin(settings.ServerSelection.Countries))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readFastestvpn(r reader) (err error) { func (settings *Provider) readFastestvpn(r reader) (err error) {
settings.Name = constants.Fastestvpn settings.Name = constants.Fastestvpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -41,5 +38,5 @@ func (settings *Provider) readFastestvpn(r reader) (err error) {
return fmt.Errorf("environment variable COUNTRY: %w", err) return fmt.Errorf("environment variable COUNTRY: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }

View File

@@ -23,17 +23,14 @@ func (settings *Provider) hideMyAssLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readHideMyAss(r reader) (err error) { func (settings *Provider) readHideMyAss(r reader) (err error) {
settings.Name = constants.HideMyAss settings.Name = constants.HideMyAss
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -59,5 +56,5 @@ func (settings *Provider) readHideMyAss(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolAndPort(r.env)
} }

View File

@@ -19,17 +19,14 @@ func (settings *Provider) ipvanishLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readIpvanish(r reader) (err error) { func (settings *Provider) readIpvanish(r reader) (err error) {
settings.Name = constants.Ipvanish settings.Name = constants.Ipvanish
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -50,5 +47,5 @@ func (settings *Provider) readIpvanish(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }

View File

@@ -19,7 +19,12 @@ func Test_Provider_ipvanishLines(t *testing.T) {
settings Provider settings Provider
lines []string lines []string
}{ }{
"empty settings": {}, "empty settings": {
lines: []string{
"|--OpenVPN selection:",
" |--Protocol: udp",
},
},
"full settings": { "full settings": {
settings: Provider{ settings: Provider{
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
@@ -32,6 +37,8 @@ func Test_Provider_ipvanishLines(t *testing.T) {
"|--Countries: A, B", "|--Countries: A, B",
"|--Cities: C, D", "|--Cities: C, D",
"|--Hostnames: E, F", "|--Hostnames: E, F",
"|--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
} }
@@ -65,23 +72,15 @@ func Test_Provider_readIpvanish(t *testing.T) {
} }
testCases := map[string]struct { testCases := map[string]struct {
protocol singleStringCall
targetIP singleStringCall targetIP singleStringCall
countries sliceStringCall countries sliceStringCall
cities sliceStringCall cities sliceStringCall
hostnames sliceStringCall hostnames sliceStringCall
protocol singleStringCall
settings Provider settings Provider
err error err error
}{ }{
"protocol error": {
protocol: singleStringCall{call: true, err: errDummy},
settings: Provider{
Name: constants.Ipvanish,
},
err: errors.New("environment variable PROTOCOL: dummy test error"),
},
"target IP error": { "target IP error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true, value: "something", err: errDummy}, targetIP: singleStringCall{call: true, value: "something", err: errDummy},
settings: Provider{ settings: Provider{
Name: constants.Ipvanish, Name: constants.Ipvanish,
@@ -89,7 +88,6 @@ func Test_Provider_readIpvanish(t *testing.T) {
err: errors.New("environment variable OPENVPN_TARGET_IP: dummy test error"), err: errors.New("environment variable OPENVPN_TARGET_IP: dummy test error"),
}, },
"countries error": { "countries error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true, err: errDummy}, countries: sliceStringCall{call: true, err: errDummy},
settings: Provider{ settings: Provider{
@@ -98,7 +96,6 @@ func Test_Provider_readIpvanish(t *testing.T) {
err: errors.New("environment variable COUNTRY: dummy test error"), err: errors.New("environment variable COUNTRY: dummy test error"),
}, },
"cities error": { "cities error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true}, countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true, err: errDummy}, cities: sliceStringCall{call: true, err: errDummy},
@@ -108,7 +105,6 @@ func Test_Provider_readIpvanish(t *testing.T) {
err: errors.New("environment variable CITY: dummy test error"), err: errors.New("environment variable CITY: dummy test error"),
}, },
"hostnames error": { "hostnames error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true}, countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true}, cities: sliceStringCall{call: true},
@@ -118,26 +114,39 @@ func Test_Provider_readIpvanish(t *testing.T) {
}, },
err: errors.New("environment variable SERVER_HOSTNAME: dummy test error"), err: errors.New("environment variable SERVER_HOSTNAME: dummy test error"),
}, },
"default settings": { "protocol error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true}, countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true}, cities: sliceStringCall{call: true},
hostnames: sliceStringCall{call: true}, hostnames: sliceStringCall{call: true},
protocol: singleStringCall{call: true, err: errDummy},
settings: Provider{
Name: constants.Ipvanish,
},
err: errors.New("environment variable PROTOCOL: dummy test error"),
},
"default settings": {
targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true},
hostnames: sliceStringCall{call: true},
protocol: singleStringCall{call: true},
settings: Provider{ settings: Provider{
Name: constants.Ipvanish, Name: constants.Ipvanish,
}, },
}, },
"set settings": { "set settings": {
protocol: singleStringCall{call: true, value: constants.TCP},
targetIP: singleStringCall{call: true, value: "1.2.3.4"}, targetIP: singleStringCall{call: true, value: "1.2.3.4"},
countries: sliceStringCall{call: true, values: []string{"A", "B"}}, countries: sliceStringCall{call: true, values: []string{"A", "B"}},
cities: sliceStringCall{call: true, values: []string{"C", "D"}}, cities: sliceStringCall{call: true, values: []string{"C", "D"}},
hostnames: sliceStringCall{call: true, values: []string{"E", "F"}}, hostnames: sliceStringCall{call: true, values: []string{"E", "F"}},
protocol: singleStringCall{call: true, value: constants.TCP},
settings: Provider{ settings: Provider{
Name: constants.Ipvanish, Name: constants.Ipvanish,
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
OpenVPN: OpenVPNSelection{
TCP: true, TCP: true,
},
TargetIP: net.IPv4(1, 2, 3, 4), TargetIP: net.IPv4(1, 2, 3, 4),
Countries: []string{"A", "B"}, Countries: []string{"A", "B"},
Cities: []string{"C", "D"}, Cities: []string{"C", "D"},
@@ -153,10 +162,6 @@ func Test_Provider_readIpvanish(t *testing.T) {
ctrl := gomock.NewController(t) ctrl := gomock.NewController(t)
env := mock_params.NewMockEnv(ctrl) env := mock_params.NewMockEnv(ctrl)
if testCase.protocol.call {
env.EXPECT().Inside("PROTOCOL", []string{constants.TCP, constants.UDP}, gomock.Any()).
Return(testCase.protocol.value, testCase.protocol.err)
}
if testCase.targetIP.call { if testCase.targetIP.call {
env.EXPECT().Get("OPENVPN_TARGET_IP"). env.EXPECT().Get("OPENVPN_TARGET_IP").
Return(testCase.targetIP.value, testCase.targetIP.err) Return(testCase.targetIP.value, testCase.targetIP.err)
@@ -173,6 +178,10 @@ func Test_Provider_readIpvanish(t *testing.T) {
env.EXPECT().CSVInside("SERVER_HOSTNAME", constants.IpvanishHostnameChoices()). env.EXPECT().CSVInside("SERVER_HOSTNAME", constants.IpvanishHostnameChoices()).
Return(testCase.hostnames.values, testCase.hostnames.err) Return(testCase.hostnames.values, testCase.hostnames.err)
} }
if testCase.protocol.call {
env.EXPECT().Inside("PROTOCOL", []string{constants.TCP, constants.UDP}, gomock.Any()).
Return(testCase.protocol.value, testCase.protocol.err)
}
r := reader{env: env} r := reader{env: env}

View File

@@ -19,17 +19,14 @@ func (settings *Provider) ivpnLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readIvpn(r reader) (err error) { func (settings *Provider) readIvpn(r reader) (err error) {
settings.Name = constants.Ivpn settings.Name = constants.Ivpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -50,5 +47,5 @@ func (settings *Provider) readIvpn(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }

View File

@@ -19,7 +19,12 @@ func Test_Provider_ivpnLines(t *testing.T) {
settings Provider settings Provider
lines []string lines []string
}{ }{
"empty settings": {}, "empty settings": {
lines: []string{
"|--OpenVPN selection:",
" |--Protocol: udp",
},
},
"full settings": { "full settings": {
settings: Provider{ settings: Provider{
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
@@ -32,6 +37,8 @@ func Test_Provider_ivpnLines(t *testing.T) {
"|--Countries: A, B", "|--Countries: A, B",
"|--Cities: C, D", "|--Cities: C, D",
"|--Hostnames: E, F", "|--Hostnames: E, F",
"|--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
} }
@@ -73,15 +80,7 @@ func Test_Provider_readIvpn(t *testing.T) {
settings Provider settings Provider
err error err error
}{ }{
"protocol error": {
protocol: singleStringCall{call: true, err: errDummy},
settings: Provider{
Name: constants.Ivpn,
},
err: errors.New("environment variable PROTOCOL: dummy test error"),
},
"target IP error": { "target IP error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true, value: "something", err: errDummy}, targetIP: singleStringCall{call: true, value: "something", err: errDummy},
settings: Provider{ settings: Provider{
Name: constants.Ivpn, Name: constants.Ivpn,
@@ -89,7 +88,6 @@ func Test_Provider_readIvpn(t *testing.T) {
err: errors.New("environment variable OPENVPN_TARGET_IP: dummy test error"), err: errors.New("environment variable OPENVPN_TARGET_IP: dummy test error"),
}, },
"countries error": { "countries error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true, err: errDummy}, countries: sliceStringCall{call: true, err: errDummy},
settings: Provider{ settings: Provider{
@@ -98,7 +96,6 @@ func Test_Provider_readIvpn(t *testing.T) {
err: errors.New("environment variable COUNTRY: dummy test error"), err: errors.New("environment variable COUNTRY: dummy test error"),
}, },
"cities error": { "cities error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true}, countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true, err: errDummy}, cities: sliceStringCall{call: true, err: errDummy},
@@ -108,7 +105,6 @@ func Test_Provider_readIvpn(t *testing.T) {
err: errors.New("environment variable CITY: dummy test error"), err: errors.New("environment variable CITY: dummy test error"),
}, },
"hostnames error": { "hostnames error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true}, countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true}, cities: sliceStringCall{call: true},
@@ -118,26 +114,39 @@ func Test_Provider_readIvpn(t *testing.T) {
}, },
err: errors.New("environment variable SERVER_HOSTNAME: dummy test error"), err: errors.New("environment variable SERVER_HOSTNAME: dummy test error"),
}, },
"default settings": { "protocol error": {
protocol: singleStringCall{call: true},
targetIP: singleStringCall{call: true}, targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true}, countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true}, cities: sliceStringCall{call: true},
hostnames: sliceStringCall{call: true}, hostnames: sliceStringCall{call: true},
protocol: singleStringCall{call: true, err: errDummy},
settings: Provider{
Name: constants.Ivpn,
},
err: errors.New("environment variable PROTOCOL: dummy test error"),
},
"default settings": {
targetIP: singleStringCall{call: true},
countries: sliceStringCall{call: true},
cities: sliceStringCall{call: true},
hostnames: sliceStringCall{call: true},
protocol: singleStringCall{call: true},
settings: Provider{ settings: Provider{
Name: constants.Ivpn, Name: constants.Ivpn,
}, },
}, },
"set settings": { "set settings": {
protocol: singleStringCall{call: true, value: constants.TCP},
targetIP: singleStringCall{call: true, value: "1.2.3.4"}, targetIP: singleStringCall{call: true, value: "1.2.3.4"},
countries: sliceStringCall{call: true, values: []string{"A", "B"}}, countries: sliceStringCall{call: true, values: []string{"A", "B"}},
cities: sliceStringCall{call: true, values: []string{"C", "D"}}, cities: sliceStringCall{call: true, values: []string{"C", "D"}},
hostnames: sliceStringCall{call: true, values: []string{"E", "F"}}, hostnames: sliceStringCall{call: true, values: []string{"E", "F"}},
protocol: singleStringCall{call: true, value: constants.TCP},
settings: Provider{ settings: Provider{
Name: constants.Ivpn, Name: constants.Ivpn,
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
OpenVPN: OpenVPNSelection{
TCP: true, TCP: true,
},
TargetIP: net.IPv4(1, 2, 3, 4), TargetIP: net.IPv4(1, 2, 3, 4),
Countries: []string{"A", "B"}, Countries: []string{"A", "B"},
Cities: []string{"C", "D"}, Cities: []string{"C", "D"},

View File

@@ -2,7 +2,6 @@ package configuration
import ( import (
"fmt" "fmt"
"strconv"
"github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/golibs/params" "github.com/qdm12/golibs/params"
@@ -25,9 +24,7 @@ func (settings *Provider) mullvadLines() (lines []string) {
lines = append(lines, lastIndent+"ISPs: "+commaJoin(settings.ServerSelection.ISPs)) lines = append(lines, lastIndent+"ISPs: "+commaJoin(settings.ServerSelection.ISPs))
} }
if settings.ServerSelection.CustomPort > 0 { lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
lines = append(lines, lastIndent+"Custom port: "+strconv.Itoa(int(settings.ServerSelection.CustomPort)))
}
return lines return lines
} }
@@ -35,11 +32,6 @@ func (settings *Provider) mullvadLines() (lines []string) {
func (settings *Provider) readMullvad(r reader) (err error) { func (settings *Provider) readMullvad(r reader) (err error) {
settings.Name = constants.Mullvad settings.Name = constants.Mullvad
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -65,16 +57,25 @@ func (settings *Provider) readMullvad(r reader) (err error) {
return fmt.Errorf("environment variable ISP: %w", err) return fmt.Errorf("environment variable ISP: %w", err)
} }
settings.ServerSelection.CustomPort, err = readCustomPort(r.env, settings.ServerSelection.TCP,
[]uint16{80, 443, 1401}, []uint16{53, 1194, 1195, 1196, 1197, 1300, 1301, 1302, 1303, 1400})
if err != nil {
return err
}
settings.ServerSelection.Owned, err = r.env.YesNo("OWNED", params.Default("no")) settings.ServerSelection.Owned, err = r.env.YesNo("OWNED", params.Default("no"))
if err != nil { if err != nil {
return fmt.Errorf("environment variable OWNED: %w", err) return fmt.Errorf("environment variable OWNED: %w", err)
} }
return settings.ServerSelection.OpenVPN.readMullvad(r.env)
}
func (settings *OpenVPNSelection) readMullvad(env params.Env) (err error) {
settings.TCP, err = readProtocol(env)
if err != nil {
return err
}
settings.CustomPort, err = readCustomPort(env, settings.TCP,
[]uint16{80, 443, 1401}, []uint16{53, 1194, 1195, 1196, 1197, 1300, 1301, 1302, 1303, 1400})
if err != nil {
return err
}
return nil return nil
} }

View File

@@ -29,17 +29,14 @@ func (settings *Provider) nordvpnLines() (lines []string) {
lines = append(lines, lastIndent+"Numbers: "+commaJoin(numbersString)) lines = append(lines, lastIndent+"Numbers: "+commaJoin(numbersString))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readNordvpn(r reader) (err error) { func (settings *Provider) readNordvpn(r reader) (err error) {
settings.Name = constants.Nordvpn settings.Name = constants.Nordvpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -65,7 +62,7 @@ func (settings *Provider) readNordvpn(r reader) (err error) {
return err return err
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }
func readNordVPNServerNumbers(env params.Env) (numbers []uint16, err error) { func readNordVPNServerNumbers(env params.Env) (numbers []uint16, err error) {

View File

@@ -150,8 +150,6 @@ func (settings *OpenVPN) read(r reader, serviceProvider string) (err error) {
switch serviceProvider { switch serviceProvider {
case constants.Cyberghost: case constants.Cyberghost:
err = settings.readCyberghost(r) err = settings.readCyberghost(r)
case constants.PrivateInternetAccess:
err = settings.readPrivateInternetAccess(r)
case constants.VPNUnlimited: case constants.VPNUnlimited:
err = settings.readVPNUnlimited(r) err = settings.readVPNUnlimited(r)
} }
@@ -161,3 +159,11 @@ func (settings *OpenVPN) read(r reader, serviceProvider string) (err error) {
return nil return nil
} }
func readProtocol(env params.Env) (tcp bool, err error) {
protocol, err := env.Inside("PROTOCOL", []string{constants.TCP, constants.UDP}, params.Default(constants.UDP))
if err != nil {
return false, fmt.Errorf("environment variable PROTOCOL: %w", err)
}
return protocol == constants.TCP, nil
}

View File

@@ -23,17 +23,14 @@ func (settings *Provider) privadoLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readPrivado(r reader) (err error) { func (settings *Provider) readPrivado(r reader) (err error) {
settings.Name = constants.Privado settings.Name = constants.Privado
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err

View File

@@ -2,7 +2,6 @@ package configuration
import ( import (
"fmt" "fmt"
"strconv"
"github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/golibs/params" "github.com/qdm12/golibs/params"
@@ -21,9 +20,7 @@ func (settings *Provider) privateinternetaccessLines() (lines []string) {
lines = append(lines, lastIndent+"Names: "+commaJoin(settings.ServerSelection.Names)) lines = append(lines, lastIndent+"Names: "+commaJoin(settings.ServerSelection.Names))
} }
if settings.ServerSelection.CustomPort > 0 { lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
lines = append(lines, lastIndent+"Custom port: "+strconv.Itoa(int(settings.ServerSelection.CustomPort)))
}
if settings.PortForwarding.Enabled { if settings.PortForwarding.Enabled {
lines = append(lines, lastIndent+"Port forwarding:") lines = append(lines, lastIndent+"Port forwarding:")
@@ -38,11 +35,6 @@ func (settings *Provider) privateinternetaccessLines() (lines []string) {
func (settings *Provider) readPrivateInternetAccess(r reader) (err error) { func (settings *Provider) readPrivateInternetAccess(r reader) (err error) {
settings.Name = constants.PrivateInternetAccess settings.Name = constants.PrivateInternetAccess
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -63,16 +55,6 @@ func (settings *Provider) readPrivateInternetAccess(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_NAME: %w", err) return fmt.Errorf("environment variable SERVER_NAME: %w", err)
} }
settings.ServerSelection.CustomPort, err = readPortOrZero(r.env, "PORT")
if err != nil {
return fmt.Errorf("environment variable PORT: %w", err)
}
settings.ServerSelection.EncryptionPreset, err = getPIAEncryptionPreset(r)
if err != nil {
return err
}
settings.PortForwarding.Enabled, err = r.env.OnOff("PORT_FORWARDING", params.Default("off")) settings.PortForwarding.Enabled, err = r.env.OnOff("PORT_FORWARDING", params.Default("off"))
if err != nil { if err != nil {
return fmt.Errorf("environment variable PORT_FORWARDING: %w", err) return fmt.Errorf("environment variable PORT_FORWARDING: %w", err)
@@ -86,14 +68,23 @@ func (settings *Provider) readPrivateInternetAccess(r reader) (err error) {
} }
} }
return nil return settings.ServerSelection.OpenVPN.readPrivateInternetAccess(r)
} }
func (settings *OpenVPN) readPrivateInternetAccess(r reader) (err error) { func (settings *OpenVPNSelection) readPrivateInternetAccess(r reader) (err error) {
settings.EncPreset, err = getPIAEncryptionPreset(r) settings.EncPreset, err = getPIAEncryptionPreset(r)
if err != nil {
return err return err
} }
settings.CustomPort, err = readPortOrZero(r.env, "PORT")
if err != nil {
return fmt.Errorf("environment variable PORT: %w", err)
}
return nil
}
func getPIAEncryptionPreset(r reader) (encryptionPreset string, err error) { func getPIAEncryptionPreset(r reader) (encryptionPreset string, err error) {
encryptionPreset, err = r.env.Inside("PIA_ENCRYPTION", encryptionPreset, err = r.env.Inside("PIA_ENCRYPTION",
[]string{constants.PIAEncryptionPresetNone, constants.PIAEncryptionPresetNormal, constants.PIAEncryptionPresetStrong}, []string{constants.PIAEncryptionPresetNone, constants.PIAEncryptionPresetNormal, constants.PIAEncryptionPresetStrong},
@@ -103,5 +94,6 @@ func getPIAEncryptionPreset(r reader) (encryptionPreset string, err error) {
if err != nil { if err != nil {
return "", fmt.Errorf("environment variable PIA_ENCRYPTION: %w", err) return "", fmt.Errorf("environment variable PIA_ENCRYPTION: %w", err)
} }
return encryptionPreset, nil return encryptionPreset, nil
} }

View File

@@ -19,17 +19,14 @@ func (settings *Provider) privatevpnLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readPrivatevpn(r reader) (err error) { func (settings *Provider) readPrivatevpn(r reader) (err error) {
settings.Name = constants.Privatevpn settings.Name = constants.Privatevpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -50,5 +47,5 @@ func (settings *Provider) readPrivatevpn(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolAndPort(r.env)
} }

View File

@@ -32,27 +32,19 @@ func (settings *Provider) protonvpnLines() (lines []string) {
lines = append(lines, lastIndent+"Free only: yes") lines = append(lines, lastIndent+"Free only: yes")
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readProtonvpn(r reader) (err error) { func (settings *Provider) readProtonvpn(r reader) (err error) {
settings.Name = constants.Protonvpn settings.Name = constants.Protonvpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
} }
settings.ServerSelection.CustomPort, err = readPortOrZero(r.env, "PORT")
if err != nil {
return fmt.Errorf("environment variable PORT: %w", err)
}
settings.ServerSelection.Countries, err = r.env.CSVInside("COUNTRY", constants.ProtonvpnCountryChoices()) settings.ServerSelection.Countries, err = r.env.CSVInside("COUNTRY", constants.ProtonvpnCountryChoices())
if err != nil { if err != nil {
return fmt.Errorf("environment variable COUNTRY: %w", err) return fmt.Errorf("environment variable COUNTRY: %w", err)
@@ -83,5 +75,5 @@ func (settings *Provider) readProtonvpn(r reader) (err error) {
return fmt.Errorf("environment variable FREE_ONLY: %w", err) return fmt.Errorf("environment variable FREE_ONLY: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolAndPort(r.env)
} }

View File

@@ -18,12 +18,14 @@ type Provider struct {
} }
func (settings *Provider) lines() (lines []string) { func (settings *Provider) lines() (lines []string) {
if settings.Name == "" { // custom OpenVPN configuration
return nil
}
lines = append(lines, lastIndent+strings.Title(settings.Name)+" settings:") lines = append(lines, lastIndent+strings.Title(settings.Name)+" settings:")
selection := settings.ServerSelection selection := settings.ServerSelection
lines = append(lines, indent+lastIndent+"Network protocol: "+protoToString(selection.TCP))
if selection.TargetIP != nil { if selection.TargetIP != nil {
lines = append(lines, indent+lastIndent+"Target IP address: "+selection.TargetIP.String()) lines = append(lines, indent+lastIndent+"Target IP address: "+selection.TargetIP.String())
} }
@@ -153,14 +155,6 @@ func commaJoin(slice []string) string {
return strings.Join(slice, ", ") return strings.Join(slice, ", ")
} }
func readProtocol(env params.Env) (tcp bool, err error) {
protocol, err := env.Inside("PROTOCOL", []string{constants.TCP, constants.UDP}, params.Default(constants.UDP))
if err != nil {
return false, fmt.Errorf("environment variable PROTOCOL: %w", err)
}
return protocol == constants.TCP, nil
}
func protoToString(tcp bool) string { func protoToString(tcp bool) string {
if tcp { if tcp {
return constants.TCP return constants.TCP

View File

@@ -30,9 +30,10 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Cyberghost settings:", "|--Cyberghost settings:",
" |--Network protocol: udp",
" |--Server groups: group", " |--Server groups: group",
" |--Regions: a, El country", " |--Regions: a, El country",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"fastestvpn": { "fastestvpn": {
@@ -45,9 +46,10 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Fastestvpn settings:", "|--Fastestvpn settings:",
" |--Network protocol: udp",
" |--Hostnames: a, b", " |--Hostnames: a, b",
" |--Countries: c, d", " |--Countries: c, d",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"hidemyass": { "hidemyass": {
@@ -61,10 +63,11 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Hidemyass settings:", "|--Hidemyass settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--Hostnames: e, f", " |--Hostnames: e, f",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"ipvanish": { "ipvanish": {
@@ -78,10 +81,11 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Ipvanish settings:", "|--Ipvanish settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--Hostnames: e, f", " |--Hostnames: e, f",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"ivpn": { "ivpn": {
@@ -95,10 +99,11 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Ivpn settings:", "|--Ivpn settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--Hostnames: e, f", " |--Hostnames: e, f",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"mullvad": { "mullvad": {
@@ -108,15 +113,18 @@ func Test_Provider_lines(t *testing.T) {
Countries: []string{"a", "b"}, Countries: []string{"a", "b"},
Cities: []string{"c", "d"}, Cities: []string{"c", "d"},
ISPs: []string{"e", "f"}, ISPs: []string{"e", "f"},
OpenVPN: OpenVPNSelection{
CustomPort: 1, CustomPort: 1,
}, },
}, },
},
lines: []string{ lines: []string{
"|--Mullvad settings:", "|--Mullvad settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--ISPs: e, f", " |--ISPs: e, f",
" |--OpenVPN selection:",
" |--Protocol: udp",
" |--Custom port: 1", " |--Custom port: 1",
}, },
}, },
@@ -130,9 +138,10 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Nordvpn settings:", "|--Nordvpn settings:",
" |--Network protocol: udp",
" |--Regions: a, b", " |--Regions: a, b",
" |--Numbers: 1, 2", " |--Numbers: 1, 2",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"privado": { "privado": {
@@ -144,8 +153,9 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Privado settings:", "|--Privado settings:",
" |--Network protocol: udp",
" |--Hostnames: a, b", " |--Hostnames: a, b",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"privatevpn": { "privatevpn": {
@@ -159,10 +169,11 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Privatevpn settings:", "|--Privatevpn settings:",
" |--Network protocol: udp",
" |--Countries: c, d", " |--Countries: c, d",
" |--Cities: e, f", " |--Cities: e, f",
" |--Hostnames: a, b", " |--Hostnames: a, b",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"protonvpn": { "protonvpn": {
@@ -178,12 +189,13 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Protonvpn settings:", "|--Protonvpn settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Regions: c, d", " |--Regions: c, d",
" |--Cities: e, f", " |--Cities: e, f",
" |--Names: g, h", " |--Names: g, h",
" |--Hostnames: i, j", " |--Hostnames: i, j",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"private internet access": { "private internet access": {
@@ -191,8 +203,10 @@ func Test_Provider_lines(t *testing.T) {
Name: constants.PrivateInternetAccess, Name: constants.PrivateInternetAccess,
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
Regions: []string{"a", "b"}, Regions: []string{"a", "b"},
OpenVPN: OpenVPNSelection{
CustomPort: 1, CustomPort: 1,
}, },
},
PortForwarding: PortForwarding{ PortForwarding: PortForwarding{
Enabled: true, Enabled: true,
Filepath: string("/here"), Filepath: string("/here"),
@@ -200,8 +214,9 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Private Internet Access settings:", "|--Private Internet Access settings:",
" |--Network protocol: udp",
" |--Regions: a, b", " |--Regions: a, b",
" |--OpenVPN selection:",
" |--Protocol: udp",
" |--Custom port: 1", " |--Custom port: 1",
" |--Port forwarding:", " |--Port forwarding:",
" |--File path: /here", " |--File path: /here",
@@ -218,10 +233,11 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Purevpn settings:", "|--Purevpn settings:",
" |--Network protocol: udp",
" |--Regions: a, b", " |--Regions: a, b",
" |--Countries: c, d", " |--Countries: c, d",
" |--Cities: e, f", " |--Cities: e, f",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"surfshark": { "surfshark": {
@@ -233,8 +249,9 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Surfshark settings:", "|--Surfshark settings:",
" |--Network protocol: udp",
" |--Regions: a, b", " |--Regions: a, b",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"torguard": { "torguard": {
@@ -248,10 +265,11 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Torguard settings:", "|--Torguard settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--Hostnames: e", " |--Hostnames: e",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
constants.VPNUnlimited: { constants.VPNUnlimited: {
@@ -267,12 +285,13 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Vpn Unlimited settings:", "|--Vpn Unlimited settings:",
" |--Network protocol: udp",
" |--Countries: a, b", " |--Countries: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--Hostnames: e, f", " |--Hostnames: e, f",
" |--Free servers only", " |--Free servers only",
" |--Stream servers only", " |--Stream servers only",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"vyprvpn": { "vyprvpn": {
@@ -284,8 +303,9 @@ func Test_Provider_lines(t *testing.T) {
}, },
lines: []string{ lines: []string{
"|--Vyprvpn settings:", "|--Vyprvpn settings:",
" |--Network protocol: udp",
" |--Regions: a, b", " |--Regions: a, b",
" |--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
"windscribe": { "windscribe": {
@@ -295,15 +315,18 @@ func Test_Provider_lines(t *testing.T) {
Regions: []string{"a", "b"}, Regions: []string{"a", "b"},
Cities: []string{"c", "d"}, Cities: []string{"c", "d"},
Hostnames: []string{"e", "f"}, Hostnames: []string{"e", "f"},
OpenVPN: OpenVPNSelection{
CustomPort: 1, CustomPort: 1,
}, },
}, },
},
lines: []string{ lines: []string{
"|--Windscribe settings:", "|--Windscribe settings:",
" |--Network protocol: udp",
" |--Regions: a, b", " |--Regions: a, b",
" |--Cities: c, d", " |--Cities: c, d",
" |--Hostnames: e, f", " |--Hostnames: e, f",
" |--OpenVPN selection:",
" |--Protocol: udp",
" |--Custom port: 1", " |--Custom port: 1",
}, },
}, },

View File

@@ -23,17 +23,14 @@ func (settings *Provider) purevpnLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readPurevpn(r reader) (err error) { func (settings *Provider) readPurevpn(r reader) (err error) {
settings.Name = constants.Purevpn settings.Name = constants.Purevpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -59,5 +56,5 @@ func (settings *Provider) readPurevpn(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }

View File

@@ -1,12 +1,14 @@
package configuration package configuration
import ( import (
"fmt"
"net" "net"
"github.com/qdm12/golibs/params"
) )
type ServerSelection struct { //nolint:maligned type ServerSelection struct { //nolint:maligned
// Common // Common
TCP bool `json:"tcp"` // UDP if TCP is false
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
@@ -27,20 +29,57 @@ type ServerSelection struct { //nolint:maligned
ISPs []string `json:"isps"` ISPs []string `json:"isps"`
Owned bool `json:"owned"` Owned bool `json:"owned"`
// Mullvad, Windscribe, PIA
CustomPort uint16 `json:"custom_port"`
// NordVPN // NordVPN
Numbers []uint16 `json:"numbers"` Numbers []uint16 `json:"numbers"`
// PIA - needed to get the port number
EncryptionPreset string `json:"encryption_preset"`
// ProtonVPN // ProtonVPN
FreeOnly bool `json:"free_only"` FreeOnly bool `json:"free_only"`
// VPNUnlimited // VPNUnlimited
StreamOnly bool `json:"stream_only"` StreamOnly bool `json:"stream_only"`
OpenVPN OpenVPNSelection `json:"openvpn"`
}
type OpenVPNSelection struct {
TCP bool `json:"tcp"` // UDP if TCP is false
CustomPort uint16 `json:"custom_port"` // HideMyAss, Mullvad, PIA, ProtonVPN, Windscribe
EncPreset string `json:"encryption_preset"` // PIA - needed to get the port number
}
func (settings *OpenVPNSelection) lines() (lines []string) {
lines = append(lines, lastIndent+"OpenVPN selection:")
lines = append(lines, indent+lastIndent+"Protocol: "+protoToString(settings.TCP))
if settings.CustomPort != 0 {
lines = append(lines, indent+lastIndent+"Custom port: "+fmt.Sprint(settings.CustomPort))
}
if settings.EncPreset != "" {
lines = append(lines, indent+lastIndent+"PIA encryption preset: "+settings.EncPreset)
}
return lines
}
func (settings *OpenVPNSelection) readProtocolOnly(env params.Env) (err error) {
settings.TCP, err = readProtocol(env)
return err
}
func (settings *OpenVPNSelection) readProtocolAndPort(env params.Env) (err error) {
settings.TCP, err = readProtocol(env)
if err != nil {
return err
}
settings.CustomPort, err = readPortOrZero(env, "PORT")
if err != nil {
return fmt.Errorf("environment variable PORT: %w", err)
}
return nil
} }
// PortForwarding contains settings for port forwarding. // PortForwarding contains settings for port forwarding.

View File

@@ -34,7 +34,8 @@ func Test_Settings_lines(t *testing.T) {
" |--Version: 2.5", " |--Version: 2.5",
" |--Verbosity level: 0", " |--Verbosity level: 0",
" |--Mullvad settings:", " |--Mullvad settings:",
" |--Network protocol: udp", " |--OpenVPN selection:",
" |--Protocol: udp",
"|--DNS:", "|--DNS:",
"|--Firewall: disabled ⚠️", "|--Firewall: disabled ⚠️",
"|--System:", "|--System:",

View File

@@ -15,17 +15,14 @@ func (settings *Provider) surfsharkLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readSurfshark(r reader) (err error) { func (settings *Provider) readSurfshark(r reader) (err error) {
settings.Name = constants.Surfshark settings.Name = constants.Surfshark
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -41,5 +38,5 @@ func (settings *Provider) readSurfshark(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }

View File

@@ -19,17 +19,14 @@ func (settings *Provider) torguardLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readTorguard(r reader) (err error) { func (settings *Provider) readTorguard(r reader) (err error) {
settings.Name = constants.Torguard settings.Name = constants.Torguard
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -50,5 +47,5 @@ func (settings *Provider) readTorguard(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolAndPort(r.env)
} }

View File

@@ -28,17 +28,14 @@ func (settings *Provider) vpnUnlimitedLines() (lines []string) {
lines = append(lines, lastIndent+"Stream servers only") lines = append(lines, lastIndent+"Stream servers only")
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readVPNUnlimited(r reader) (err error) { func (settings *Provider) readVPNUnlimited(r reader) (err error) {
settings.Name = constants.VPNUnlimited settings.Name = constants.VPNUnlimited
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -69,7 +66,7 @@ func (settings *Provider) readVPNUnlimited(r reader) (err error) {
return fmt.Errorf("environment variable STREAM_ONLY: %w", err) return fmt.Errorf("environment variable STREAM_ONLY: %w", err)
} }
return nil return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
} }
func (settings *OpenVPN) readVPNUnlimited(r reader) (err error) { func (settings *OpenVPN) readVPNUnlimited(r reader) (err error) {

View File

@@ -13,7 +13,12 @@ func Test_Provider_vpnUnlimitedLines(t *testing.T) {
settings Provider settings Provider
lines []string lines []string
}{ }{
"empty settings": {}, "empty settings": {
lines: []string{
"|--OpenVPN selection:",
" |--Protocol: udp",
},
},
"full settings": { "full settings": {
settings: Provider{ settings: Provider{
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
@@ -26,6 +31,8 @@ func Test_Provider_vpnUnlimitedLines(t *testing.T) {
"|--Countries: A, B", "|--Countries: A, B",
"|--Cities: C, D", "|--Cities: C, D",
"|--Hostnames: E, F", "|--Hostnames: E, F",
"|--OpenVPN selection:",
" |--Protocol: udp",
}, },
}, },
} }

View File

@@ -11,17 +11,14 @@ func (settings *Provider) vyprvpnLines() (lines []string) {
lines = append(lines, lastIndent+"Regions: "+commaJoin(settings.ServerSelection.Regions)) lines = append(lines, lastIndent+"Regions: "+commaJoin(settings.ServerSelection.Regions))
} }
lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
return lines return lines
} }
func (settings *Provider) readVyprvpn(r reader) (err error) { func (settings *Provider) readVyprvpn(r reader) (err error) {
settings.Name = constants.Vyprvpn settings.Name = constants.Vyprvpn
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err

View File

@@ -2,9 +2,9 @@ package configuration
import ( import (
"fmt" "fmt"
"strconv"
"github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/golibs/params"
) )
func (settings *Provider) windscribeLines() (lines []string) { func (settings *Provider) windscribeLines() (lines []string) {
@@ -20,9 +20,7 @@ func (settings *Provider) windscribeLines() (lines []string) {
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames)) lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
} }
if settings.ServerSelection.CustomPort > 0 { lines = append(lines, settings.ServerSelection.OpenVPN.lines()...)
lines = append(lines, lastIndent+"Custom port: "+strconv.Itoa(int(settings.ServerSelection.CustomPort)))
}
return lines return lines
} }
@@ -30,11 +28,6 @@ func (settings *Provider) windscribeLines() (lines []string) {
func (settings *Provider) readWindscribe(r reader) (err error) { func (settings *Provider) readWindscribe(r reader) (err error) {
settings.Name = constants.Windscribe settings.Name = constants.Windscribe
settings.ServerSelection.TCP, err = readProtocol(r.env)
if err != nil {
return err
}
settings.ServerSelection.TargetIP, err = readTargetIP(r.env) settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
if err != nil { if err != nil {
return err return err
@@ -55,7 +48,16 @@ func (settings *Provider) readWindscribe(r reader) (err error) {
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err) return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
} }
settings.ServerSelection.CustomPort, err = readCustomPort(r.env, settings.ServerSelection.TCP, return settings.ServerSelection.OpenVPN.readWindscribe(r.env)
}
func (settings *OpenVPNSelection) readWindscribe(env params.Env) (err error) {
settings.TCP, err = readProtocol(env)
if err != nil {
return err
}
settings.CustomPort, err = readCustomPort(env, settings.TCP,
[]uint16{21, 22, 80, 123, 143, 443, 587, 1194, 3306, 8080, 54783}, []uint16{21, 22, 80, 123, 143, 443, 587, 1194, 3306, 8080, 54783},
[]uint16{53, 80, 123, 443, 1194, 54783}) []uint16{53, 80, 123, 443, 1194, 54783})
if err != nil { if err != nil {

View File

@@ -11,7 +11,7 @@ func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelectio
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 443 const port = 443
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
} }

View File

@@ -16,7 +16,7 @@ var ErrGroupMismatchesProtocol = errors.New("server group does not match protoco
func (c *Cyberghost) filterServers(selection configuration.ServerSelection) ( func (c *Cyberghost) filterServers(selection configuration.ServerSelection) (
servers []models.CyberghostServer, err error) { servers []models.CyberghostServer, err error) {
if len(selection.Groups) == 0 { if len(selection.Groups) == 0 {
if selection.TCP { if selection.OpenVPN.TCP {
selection.Groups = tcpGroupChoices() selection.Groups = tcpGroupChoices()
} else { } else {
selection.Groups = udpGroupChoices() selection.Groups = udpGroupChoices()
@@ -25,7 +25,7 @@ func (c *Cyberghost) filterServers(selection configuration.ServerSelection) (
// Check each group match the protocol // Check each group match the protocol
groupsCheckFn := groupsAreAllUDP groupsCheckFn := groupsAreAllUDP
if selection.TCP { if selection.OpenVPN.TCP {
groupsCheckFn = groupsAreAllTCP groupsCheckFn = groupsAreAllTCP
} }
if err := groupsCheckFn(selection.Groups); err != nil { if err := groupsCheckFn(selection.Groups); err != nil {

View File

@@ -41,8 +41,10 @@ func Test_Cyberghost_filterServers(t *testing.T) {
{Region: "d", Group: "Premium UDP Europe"}, {Region: "d", Group: "Premium UDP Europe"},
}, },
selection: configuration.ServerSelection{ selection: configuration.ServerSelection{
OpenVPN: configuration.OpenVPNSelection{
TCP: true, TCP: true,
}, },
},
filteredServers: []models.CyberghostServer{ filteredServers: []models.CyberghostServer{
{Region: "a", Group: "Premium TCP Asia"}, {Region: "a", Group: "Premium TCP Asia"},
{Region: "b", Group: "Premium TCP Europe"}, {Region: "b", Group: "Premium TCP Europe"},

View File

@@ -11,7 +11,7 @@ func (f *Fastestvpn) GetOpenVPNConnection(selection configuration.ServerSelectio
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 4443 const port = 4443
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
} }

View File

@@ -13,8 +13,8 @@ func (f *Fastestvpn) filterServers(selection configuration.ServerSelection) (
case case
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -11,13 +11,13 @@ func (h *HideMyAss) GetOpenVPNConnection(selection configuration.ServerSelection
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
var port uint16 = 553 var port uint16 = 553
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
port = 8080 port = 8080
} }
if selection.CustomPort > 0 { if selection.OpenVPN.CustomPort > 0 {
port = selection.CustomPort port = selection.OpenVPN.CustomPort
} }
servers, err := h.filterServers(selection) servers, err := h.filterServers(selection)

View File

@@ -14,8 +14,8 @@ func (h *HideMyAss) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.City, selection.Cities), utils.FilterByPossibilities(server.City, selection.Cities),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -15,7 +15,7 @@ func (i *Ipvanish) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 443 const port = 443
const protocol = constants.UDP const protocol = constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
return connection, ErrProtocolUnsupported return connection, ErrProtocolUnsupported
} }

View File

@@ -14,8 +14,8 @@ func (i *Ipvanish) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.City, selection.Cities), utils.FilterByPossibilities(server.City, selection.Cities),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -15,7 +15,7 @@ func (i *Ivpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 2049 const port = 2049
const protocol = constants.UDP const protocol = constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
return connection, ErrProtocolUnsupported return connection, ErrProtocolUnsupported
} }

View File

@@ -14,8 +14,8 @@ func (i *Ivpn) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.City, selection.Cities), utils.FilterByPossibilities(server.City, selection.Cities),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -11,13 +11,13 @@ func (m *Mullvad) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
var port uint16 = 1194 var port uint16 = 1194
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
port = 443 port = 443
protocol = constants.TCP protocol = constants.TCP
} }
if selection.CustomPort > 0 { if selection.OpenVPN.CustomPort > 0 {
port = selection.CustomPort port = selection.OpenVPN.CustomPort
} }
servers, err := m.filterServers(selection) servers, err := m.filterServers(selection)

View File

@@ -11,7 +11,7 @@ func (n *Nordvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
var port uint16 = 1194 var port uint16 = 1194
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
port = 443 port = 443
protocol = constants.TCP protocol = constants.TCP
} }

View File

@@ -23,8 +23,8 @@ func (n *Nordvpn) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
utils.FilterByPossibilities(server.Name, selection.Names), utils.FilterByPossibilities(server.Name, selection.Names),
utils.FilterByPossibilities(serverNumber, selectedNumbers), utils.FilterByPossibilities(serverNumber, selectedNumbers),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -16,7 +16,7 @@ func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 1194 const port = 1194
const protocol = constants.UDP const protocol = constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
return connection, fmt.Errorf("%w: TCP for provider Privado", ErrProtocolUnsupported) return connection, fmt.Errorf("%w: TCP for provider Privado", ErrProtocolUnsupported)
} }

View File

@@ -10,11 +10,11 @@ import (
func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
} }
port, err := getPort(selection.TCP, selection.EncryptionPreset, selection.CustomPort) port, err := getPort(selection.OpenVPN)
if err != nil { if err != nil {
return connection, err return connection, err
} }

View File

@@ -14,8 +14,8 @@ func (p *PIA) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Region, selection.Regions), utils.FilterByPossibilities(server.Region, selection.Regions),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
utils.FilterByPossibilities(server.ServerName, selection.Names), utils.FilterByPossibilities(server.ServerName, selection.Names),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -4,20 +4,21 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants"
) )
func getPort(tcp bool, encryptionPreset string, customPort uint16) ( func getPort(openvpnSelection configuration.OpenVPNSelection) (
port uint16, err error) { port uint16, err error) {
if customPort == 0 { if openvpnSelection.CustomPort == 0 {
return getDefaultPort(tcp, encryptionPreset), nil return getDefaultPort(openvpnSelection.TCP, openvpnSelection.EncPreset), nil
} }
if err := checkPort(customPort, tcp); err != nil { if err := checkPort(openvpnSelection.CustomPort, openvpnSelection.TCP); err != nil {
return 0, err return 0, err
} }
return customPort, nil return openvpnSelection.CustomPort, nil
} }
func getDefaultPort(tcp bool, encryptionPreset string) (port uint16) { func getDefaultPort(tcp bool, encryptionPreset string) (port uint16) {

View File

@@ -11,7 +11,7 @@ func (p *Privatevpn) GetOpenVPNConnection(selection configuration.ServerSelectio
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 1194 var port uint16 = 1194
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
port = 443 port = 443
} }

View File

@@ -10,11 +10,11 @@ import (
func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
} }
port, err := getPort(selection.TCP, selection.CustomPort) port, err := getPort(selection.OpenVPN.TCP, selection.OpenVPN.CustomPort)
if err != nil { if err != nil {
return connection, err return connection, err
} }

View File

@@ -11,7 +11,7 @@ func (p *Purevpn) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 53 var port uint16 = 53
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
port = 80 port = 80
} }

View File

@@ -15,8 +15,8 @@ func (p *Purevpn) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.City, selection.Cities), utils.FilterByPossibilities(server.City, selection.Cities),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -11,7 +11,7 @@ func (s *Surfshark) GetOpenVPNConnection(selection configuration.ServerSelection
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 1194 var port uint16 = 1194
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
port = 1443 port = 1443
} }

View File

@@ -13,8 +13,8 @@ func (s *Surfshark) filterServers(selection configuration.ServerSelection) (
case case
utils.FilterByPossibilities(server.Region, selection.Regions), utils.FilterByPossibilities(server.Region, selection.Regions),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -10,13 +10,13 @@ import (
func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection) ( func (t *Torguard) GetOpenVPNConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
} }
var port uint16 = 1912 var port uint16 = 1912
if selection.CustomPort > 0 { if selection.OpenVPN.CustomPort > 0 {
port = selection.CustomPort port = selection.OpenVPN.CustomPort
} }
servers, err := t.filterServers(selection) servers, err := t.filterServers(selection)

View File

@@ -14,8 +14,8 @@ func (t *Torguard) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.City, selection.Cities), utils.FilterByPossibilities(server.City, selection.Cities),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -20,7 +20,7 @@ func NoServerFoundError(selection configuration.ServerSelection) (err error) {
var messageParts []string var messageParts []string
protocol := constants.UDP protocol := constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
} }
messageParts = append(messageParts, "protocol "+protocol) messageParts = append(messageParts, "protocol "+protocol)
@@ -113,8 +113,8 @@ func NoServerFoundError(selection configuration.ServerSelection) (err error) {
messageParts = append(messageParts, part) messageParts = append(messageParts, part)
} }
if selection.EncryptionPreset != "" { if selection.OpenVPN.EncPreset != "" {
part := "encryption preset " + selection.EncryptionPreset part := "encryption preset " + selection.OpenVPN.EncPreset
messageParts = append(messageParts, part) messageParts = append(messageParts, part)
} }

View File

@@ -15,7 +15,7 @@ func (p *Provider) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 1194 const port = 1194
const protocol = constants.UDP const protocol = constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
return connection, ErrProtocolUnsupported return connection, ErrProtocolUnsupported
} }

View File

@@ -16,8 +16,8 @@ func (p *Provider) filterServers(selection configuration.ServerSelection) (
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.FreeOnly && !server.Free, selection.FreeOnly && !server.Free,
selection.StreamOnly && !server.Stream, selection.StreamOnly && !server.Stream,
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -16,7 +16,7 @@ func (v *Vyprvpn) GetOpenVPNConnection(selection configuration.ServerSelection)
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
const port = 443 const port = 443
const protocol = constants.UDP const protocol = constants.UDP
if selection.TCP { if selection.OpenVPN.TCP {
return connection, fmt.Errorf("%w: TCP for provider VyprVPN", ErrProtocolUnsupported) return connection, fmt.Errorf("%w: TCP for provider VyprVPN", ErrProtocolUnsupported)
} }

View File

@@ -13,8 +13,8 @@ func (v *Vyprvpn) filterServers(selection configuration.ServerSelection) (
case case
utils.FilterByPossibilities(server.Region, selection.Regions), utils.FilterByPossibilities(server.Region, selection.Regions),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames), utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
selection.TCP && !server.TCP, selection.OpenVPN.TCP && !server.TCP,
!selection.TCP && !server.UDP: !selection.OpenVPN.TCP && !server.UDP:
default: default:
servers = append(servers, server) servers = append(servers, server)
} }

View File

@@ -11,13 +11,13 @@ func (w *Windscribe) GetOpenVPNConnection(selection configuration.ServerSelectio
connection models.OpenVPNConnection, err error) { connection models.OpenVPNConnection, err error) {
protocol := constants.UDP protocol := constants.UDP
var port uint16 = 443 var port uint16 = 443
if selection.TCP { if selection.OpenVPN.TCP {
protocol = constants.TCP protocol = constants.TCP
port = 1194 port = 1194
} }
if selection.CustomPort > 0 { if selection.OpenVPN.CustomPort > 0 {
port = selection.CustomPort port = selection.OpenVPN.CustomPort
} }
servers, err := w.filterServers(selection) servers, err := w.filterServers(selection)