chore(settings): refactor settings processing (#756)
- Better settings tree structure logged using `qdm12/gotree` - Read settings from environment variables, then files, then secret files - Settings methods to default them, merge them and override them - `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else. - `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
@@ -17,7 +17,7 @@ var (
|
||||
)
|
||||
|
||||
// GetConnection gets the connection from the OpenVPN configuration file.
|
||||
func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Provider) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
switch selection.VPN {
|
||||
case constants.OpenVPN:
|
||||
@@ -30,9 +30,9 @@ func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
}
|
||||
|
||||
func getOpenVPNConnection(extractor extract.Interface,
|
||||
selection configuration.ServerSelection) (
|
||||
selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
_, connection, err = extractor.Data(selection.OpenVPN.ConfFile)
|
||||
_, connection, err = extractor.Data(*selection.OpenVPN.ConfFile)
|
||||
if err != nil {
|
||||
return connection, fmt.Errorf("%w: %s", ErrExtractConnection, err)
|
||||
}
|
||||
@@ -41,9 +41,9 @@ func getOpenVPNConnection(extractor extract.Interface,
|
||||
return connection, nil
|
||||
}
|
||||
|
||||
func getWireguardConnection(selection configuration.ServerSelection) (
|
||||
func getWireguardConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection) {
|
||||
port := getPort(selection.Wireguard.EndpointPort, selection)
|
||||
port := getPort(*selection.Wireguard.EndpointPort, selection)
|
||||
return models.Connection{
|
||||
Type: constants.Wireguard,
|
||||
IP: selection.Wireguard.EndpointIP,
|
||||
@@ -54,6 +54,6 @@ func getWireguardConnection(selection configuration.ServerSelection) (
|
||||
}
|
||||
|
||||
// Port found is overridden by custom port set with `PORT` or `WIREGUARD_ENDPOINT_PORT`.
|
||||
func getPort(foundPort uint16, selection configuration.ServerSelection) (port uint16) {
|
||||
func getPort(foundPort uint16, selection settings.ServerSelection) (port uint16) {
|
||||
return utils.GetPort(selection, foundPort, foundPort, foundPort)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
var ErrExtractData = errors.New("failed extracting information from custom configuration file")
|
||||
|
||||
func (p *Provider) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
lines, _, err = p.extractor.Data(settings.ConfFile)
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
lines, _, err = p.extractor.Data(*settings.ConfFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %s", ErrExtractData, err)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func (p *Provider) BuildConf(connection models.Connection,
|
||||
}
|
||||
|
||||
func modifyConfig(lines []string, connection models.Connection,
|
||||
settings configuration.OpenVPN) (modified []string) {
|
||||
settings settings.OpenVPN) (modified []string) {
|
||||
// Remove some lines
|
||||
for _, line := range lines {
|
||||
switch {
|
||||
@@ -52,9 +52,9 @@ func modifyConfig(lines []string, connection models.Connection,
|
||||
// Remove values eventually modified
|
||||
len(settings.Ciphers) > 0 && hasPrefixOneOf(line,
|
||||
"cipher ", "ncp-ciphers ", "data-ciphers ", "data-ciphers-fallback "),
|
||||
settings.Auth != "" && strings.HasPrefix(line, "auth "),
|
||||
settings.MSSFix > 0 && strings.HasPrefix(line, "mssfix "),
|
||||
!settings.IPv6 && hasPrefixOneOf(line, "tun-ipv6",
|
||||
*settings.Auth != "" && strings.HasPrefix(line, "auth "),
|
||||
*settings.MSSFix > 0 && strings.HasPrefix(line, "mssfix "),
|
||||
!*settings.IPv6 && hasPrefixOneOf(line, "tun-ipv6",
|
||||
`pull-filter ignore "route-ipv6"`,
|
||||
`pull-filter ignore "ifconfig-ipv6"`):
|
||||
default:
|
||||
@@ -74,21 +74,21 @@ func modifyConfig(lines []string, connection models.Connection,
|
||||
if settings.User != "" {
|
||||
modified = append(modified, "auth-user-pass "+constants.OpenVPNAuthConf)
|
||||
}
|
||||
modified = append(modified, "verb "+strconv.Itoa(settings.Verbosity))
|
||||
modified = append(modified, "verb "+strconv.Itoa(*settings.Verbosity))
|
||||
if len(settings.Ciphers) > 0 {
|
||||
modified = append(modified, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
}
|
||||
if settings.Auth != "" {
|
||||
modified = append(modified, "auth "+settings.Auth)
|
||||
if *settings.Auth != "" {
|
||||
modified = append(modified, "auth "+*settings.Auth)
|
||||
}
|
||||
if settings.MSSFix > 0 {
|
||||
modified = append(modified, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
modified = append(modified, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
modified = append(modified, `pull-filter ignore "route-ipv6"`)
|
||||
modified = append(modified, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
modified = append(modified, "user "+settings.ProcUser)
|
||||
modified = append(modified, "persist-tun")
|
||||
modified = append(modified, "persist-key")
|
||||
|
||||
@@ -4,18 +4,23 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
func intPtr(n int) *int { return &n }
|
||||
func uint16Ptr(n uint16) *uint16 { return &n }
|
||||
func stringPtr(s string) *string { return &s }
|
||||
|
||||
func Test_modifyConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
lines []string
|
||||
settings configuration.OpenVPN
|
||||
settings settings.OpenVPN
|
||||
connection models.Connection
|
||||
modified []string
|
||||
}{
|
||||
@@ -30,14 +35,16 @@ func Test_modifyConfig(t *testing.T) {
|
||||
"keep me here",
|
||||
"auth bla",
|
||||
},
|
||||
settings: configuration.OpenVPN{
|
||||
settings: settings.OpenVPN{
|
||||
User: "user",
|
||||
Ciphers: []string{"cipher"},
|
||||
Auth: "auth",
|
||||
MSSFix: 1000,
|
||||
Auth: stringPtr("auth"),
|
||||
MSSFix: uint16Ptr(1000),
|
||||
Root: boolPtr(false),
|
||||
ProcUser: "procuser",
|
||||
Interface: "tun3",
|
||||
},
|
||||
Verbosity: intPtr(0),
|
||||
}.WithDefaults(constants.Custom),
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 2, 3, 4),
|
||||
Port: 1194,
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) GetConnection(selection configuration.ServerSelection) (
|
||||
func (c *Cyberghost) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 443
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@ package cyberghost
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
var ErrGroupMismatchesProtocol = errors.New("server group does not match protocol")
|
||||
|
||||
func (c *Cyberghost) filterServers(selection configuration.ServerSelection) (
|
||||
func (c *Cyberghost) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.CyberghostServer, err error) {
|
||||
for _, server := range c.servers {
|
||||
switch {
|
||||
|
||||
@@ -4,23 +4,25 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func Test_Cyberghost_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := map[string]struct {
|
||||
servers []models.CyberghostServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filteredServers []models.CyberghostServer
|
||||
err error
|
||||
}{
|
||||
"no server": {
|
||||
selection: configuration.ServerSelection{VPN: constants.OpenVPN},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Cyberghost),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"servers without filter defaults to UDP": {
|
||||
@@ -30,6 +32,7 @@ func Test_Cyberghost_filterServers(t *testing.T) {
|
||||
{Country: "c", UDP: true},
|
||||
{Country: "d", UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Cyberghost),
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Country: "c", UDP: true},
|
||||
{Country: "d", UDP: true},
|
||||
@@ -42,11 +45,11 @@ func Test_Cyberghost_filterServers(t *testing.T) {
|
||||
{Country: "c", UDP: true},
|
||||
{Country: "d", UDP: true},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
selection: settings.ServerSelection{
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
}.WithDefaults(constants.Cyberghost),
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Country: "a", TCP: true},
|
||||
{Country: "b", TCP: true},
|
||||
@@ -59,9 +62,9 @@ func Test_Cyberghost_filterServers(t *testing.T) {
|
||||
{Country: "c", UDP: true},
|
||||
{Country: "d", UDP: true},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Countries: []string{"a", "c"},
|
||||
},
|
||||
}.WithDefaults(constants.Cyberghost),
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Country: "a", UDP: true},
|
||||
{Country: "c", UDP: true},
|
||||
@@ -73,9 +76,9 @@ func Test_Cyberghost_filterServers(t *testing.T) {
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"a", "c"},
|
||||
},
|
||||
}.WithDefaults(constants.Cyberghost),
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/parse"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{
|
||||
constants.AES256gcm,
|
||||
@@ -19,8 +21,9 @@ func (c *Cyberghost) BuildConf(connection models.Connection,
|
||||
}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -28,13 +31,13 @@ func (c *Cyberghost) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Cyberghost specific
|
||||
"ping 10",
|
||||
"remote-cert-tls server",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -54,27 +57,35 @@ func (c *Cyberghost) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
constants.CyberghostCertificate)...)
|
||||
lines = append(lines, utils.WrapOpenvpnCert(
|
||||
settings.ClientCrt)...)
|
||||
lines = append(lines, utils.WrapOpenvpnKey(
|
||||
settings.ClientKey)...)
|
||||
|
||||
certData, err := parse.ExtractCert([]byte(*settings.ClientCrt))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client cert is not valid: %w", err)
|
||||
}
|
||||
lines = append(lines, utils.WrapOpenvpnCert(certData)...)
|
||||
|
||||
keyData, err := parse.ExtractPrivateKey([]byte(*settings.ClientKey))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client key is not valid: %w", err)
|
||||
}
|
||||
lines = append(lines, utils.WrapOpenvpnKey(keyData)...)
|
||||
|
||||
lines = append(lines, "")
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Provider) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
@@ -33,7 +33,7 @@ func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
return utils.PickConnection(connections, selection, p.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection configuration.ServerSelection) (port uint16) {
|
||||
func getPort(selection settings.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 0
|
||||
defaultOpenVPNUDP = 1195
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -18,15 +18,13 @@ func Test_Provider_GetConnection(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.ExpressvpnServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Expressvpn),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.ExpressvpnServer{
|
||||
@@ -34,37 +32,41 @@ func Test_Provider_GetConnection(t *testing.T) {
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Expressvpn),
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(1, 1, 1, 1),
|
||||
Port: 1195,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"target IP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||
},
|
||||
}.WithDefaults(constants.Expressvpn),
|
||||
servers: []models.ExpressvpnServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1195,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"with filter": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Expressvpn),
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1195,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Provider) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.ExpressvpnServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
|
||||
@@ -5,27 +5,27 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.ExpressvpnServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filtered []models.ExpressvpnServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Expressvpn),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.ExpressvpnServer{
|
||||
@@ -33,6 +33,7 @@ func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Expressvpn),
|
||||
filtered: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
@@ -40,9 +41,9 @@ func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by country": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Countries: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Expressvpn),
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Country: "a", UDP: true},
|
||||
{Country: "b", UDP: true},
|
||||
@@ -53,9 +54,9 @@ func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Expressvpn),
|
||||
servers: []models.ExpressvpnServer{
|
||||
{City: "a", UDP: true},
|
||||
{City: "b", UDP: true},
|
||||
@@ -66,9 +67,9 @@ func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Expressvpn),
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
@@ -79,11 +80,11 @@ func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by protocol": {
|
||||
selection: configuration.ServerSelection{
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
selection: settings.ServerSelection{
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
}.WithDefaults(constants.Expressvpn),
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true, TCP: true},
|
||||
|
||||
@@ -3,23 +3,26 @@ package expressvpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = 1200
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
const defaultMSSFix = 1200
|
||||
mssFix = defaultMSSFix
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -27,19 +30,19 @@ func (p *Provider) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Expressvpn specific
|
||||
"fast-io",
|
||||
"fragment 1300",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"mssfix " + strconv.Itoa(int(mssFix)),
|
||||
"sndbuf 524288",
|
||||
"rcvbuf 524288",
|
||||
"verify-x509-name Server name-prefix", // security hole I guess?
|
||||
"remote-cert-tls server", // updated name of ns-cert-type
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"mute-replay-warnings",
|
||||
@@ -59,13 +62,13 @@ func (p *Provider) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package fastestvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (f *Fastestvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (f *Fastestvpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 4443
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package fastestvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (f *Fastestvpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (f *Fastestvpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.FastestvpnServer, err error) {
|
||||
for _, server := range f.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,22 +3,25 @@ package fastestvpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (f *Fastestvpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = 1450
|
||||
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
mssFix = 1450
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -26,14 +29,14 @@ func (f *Fastestvpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Fastestvpn specific
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)), // defaults to 1450
|
||||
"mssfix " + strconv.Itoa(int(mssFix)), // defaults to 1450
|
||||
"tls-cipher TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-CAMELLIA-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA", //nolint:lll
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
"comp-lzo",
|
||||
"reneg-sec 0",
|
||||
|
||||
@@ -58,13 +61,13 @@ func (f *Fastestvpn) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "ping 15") // FastestVPN specific
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package hidemyass
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (h *HideMyAss) GetConnection(selection configuration.ServerSelection) (
|
||||
func (h *HideMyAss) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
var port uint16 = 553
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
port = 8080
|
||||
}
|
||||
|
||||
if selection.OpenVPN.CustomPort > 0 {
|
||||
port = selection.OpenVPN.CustomPort
|
||||
if *selection.OpenVPN.CustomPort > 0 {
|
||||
port = *selection.OpenVPN.CustomPort
|
||||
}
|
||||
|
||||
servers, err := h.filterServers(selection)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package hidemyass
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (h *HideMyAss) filterServers(selection configuration.ServerSelection) (
|
||||
func (h *HideMyAss) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.HideMyAssServer, err error) {
|
||||
for _, server := range h.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,14 +3,14 @@ package hidemyass
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (h *HideMyAss) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func (h *HideMyAss) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// HideMyAss specific
|
||||
"ping 5",
|
||||
@@ -41,25 +41,25 @@ func (h *HideMyAss) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if settings.Auth != "" {
|
||||
lines = append(lines, "auth "+settings.Auth)
|
||||
if *settings.Auth != "" {
|
||||
lines = append(lines, "auth "+*settings.Auth)
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package ipvanish
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (i *Ipvanish) GetConnection(selection configuration.ServerSelection) (
|
||||
func (i *Ipvanish) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 443
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
return connection, ErrProtocolUnsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package ipvanish
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (i *Ipvanish) filterServers(selection configuration.ServerSelection) (
|
||||
func (i *Ipvanish) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.IpvanishServer, err error) {
|
||||
for _, server := range i.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,19 +3,20 @@ package ipvanish
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (i *Ipvanish) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -23,13 +24,13 @@ func (i *Ipvanish) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Ipvanish specific
|
||||
"verify-x509-name " + connection.Hostname + " name",
|
||||
"tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"mute-replay-warnings",
|
||||
@@ -45,21 +46,21 @@ func (i *Ipvanish) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package ivpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (i *Ivpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (i *Ivpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
@@ -34,7 +34,7 @@ func (i *Ivpn) GetConnection(selection configuration.ServerSelection) (
|
||||
return utils.PickConnection(connections, selection, i.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection configuration.ServerSelection) (port uint16) {
|
||||
func getPort(selection settings.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 443
|
||||
defaultOpenVPNUDP = 1194
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -18,53 +18,55 @@ func Test_Ivpn_GetConnection(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.IvpnServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Ivpn),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.IvpnServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Ivpn),
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(1, 1, 1, 1),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"target IP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"with filter": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package ivpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (i *Ivpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (i *Ivpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.IvpnServer, err error) {
|
||||
for _, server := range i.servers {
|
||||
switch {
|
||||
|
||||
@@ -5,105 +5,106 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func Test_Ivpn_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.IvpnServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filtered []models.IvpnServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Ivpn),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.IvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Ivpn),
|
||||
filtered: []models.IvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by country": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Countries: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{Country: "a", UDP: true},
|
||||
{Country: "b", UDP: true},
|
||||
{Country: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, Country: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, Country: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, Country: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.IvpnServer{
|
||||
{Country: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, Country: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{City: "a", UDP: true},
|
||||
{City: "b", UDP: true},
|
||||
{City: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, City: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, City: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, City: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.IvpnServer{
|
||||
{City: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, City: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by ISP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
ISPs: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{ISP: "a", UDP: true},
|
||||
{ISP: "b", UDP: true},
|
||||
{ISP: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, ISP: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, ISP: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, ISP: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.IvpnServer{
|
||||
{ISP: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, ISP: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.IvpnServer{
|
||||
{Hostname: "b", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by protocol": {
|
||||
selection: configuration.ServerSelection{
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
selection: settings.ServerSelection{
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
}.WithDefaults(constants.Ivpn),
|
||||
servers: []models.IvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true, TCP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.IvpnServer{
|
||||
{Hostname: "b", UDP: true, TCP: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (i *Ivpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func (i *Ivpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// IVPN specific
|
||||
"ping 5",
|
||||
@@ -47,25 +47,25 @@ func (i *Ivpn) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if settings.Auth != "" {
|
||||
lines = append(lines, "auth "+settings.Auth)
|
||||
if *settings.Auth != "" {
|
||||
lines = append(lines, "auth "+*settings.Auth)
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package mullvad
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (m *Mullvad) GetConnection(selection configuration.ServerSelection) (
|
||||
func (m *Mullvad) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
@@ -33,7 +33,7 @@ func (m *Mullvad) GetConnection(selection configuration.ServerSelection) (
|
||||
return utils.PickConnection(connections, selection, m.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection configuration.ServerSelection) (port uint16) {
|
||||
func getPort(selection settings.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 443
|
||||
defaultOpenVPNUDP = 1194
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -18,53 +18,55 @@ func Test_Mullvad_GetConnection(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.MullvadServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.MullvadServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(1, 1, 1, 1),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"target IP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"with filter": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package mullvad
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (m *Mullvad) filterServers(selection configuration.ServerSelection) (
|
||||
func (m *Mullvad) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.MullvadServer, err error) {
|
||||
for _, server := range m.servers {
|
||||
switch {
|
||||
@@ -16,7 +16,7 @@ func (m *Mullvad) filterServers(selection configuration.ServerSelection) (
|
||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||
utils.FilterByPossibilities(server.ISP, selection.ISPs),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
selection.Owned && !server.Owned:
|
||||
*selection.OwnedOnly && !server.Owned:
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
|
||||
@@ -5,44 +5,45 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func Test_Mullvad_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.MullvadServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filtered []models.MullvadServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.MullvadServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
|
||||
filtered: []models.MullvadServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
},
|
||||
"filter OpenVPN out": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.Wireguard, Hostname: "b"},
|
||||
@@ -53,68 +54,68 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by country": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Countries: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{Country: "a"},
|
||||
{Country: "b"},
|
||||
{Country: "c"},
|
||||
{VPN: constants.OpenVPN, Country: "a"},
|
||||
{VPN: constants.OpenVPN, Country: "b"},
|
||||
{VPN: constants.OpenVPN, Country: "c"},
|
||||
},
|
||||
filtered: []models.MullvadServer{
|
||||
{Country: "b"},
|
||||
{VPN: constants.OpenVPN, Country: "b"},
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{City: "a"},
|
||||
{City: "b"},
|
||||
{City: "c"},
|
||||
{VPN: constants.OpenVPN, City: "a"},
|
||||
{VPN: constants.OpenVPN, City: "b"},
|
||||
{VPN: constants.OpenVPN, City: "c"},
|
||||
},
|
||||
filtered: []models.MullvadServer{
|
||||
{City: "b"},
|
||||
{VPN: constants.OpenVPN, City: "b"},
|
||||
},
|
||||
},
|
||||
"filter by ISP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
ISPs: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{ISP: "a"},
|
||||
{ISP: "b"},
|
||||
{ISP: "c"},
|
||||
{VPN: constants.OpenVPN, ISP: "a"},
|
||||
{VPN: constants.OpenVPN, ISP: "b"},
|
||||
{VPN: constants.OpenVPN, ISP: "c"},
|
||||
},
|
||||
filtered: []models.MullvadServer{
|
||||
{ISP: "b"},
|
||||
{VPN: constants.OpenVPN, ISP: "b"},
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
filtered: []models.MullvadServer{
|
||||
{Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
},
|
||||
},
|
||||
"filter by owned": {
|
||||
selection: configuration.ServerSelection{
|
||||
Owned: true,
|
||||
},
|
||||
selection: settings.ServerSelection{
|
||||
OwnedOnly: boolPtr(true),
|
||||
}.WithDefaults(constants.Mullvad),
|
||||
servers: []models.MullvadServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b", Owned: true},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
filtered: []models.MullvadServer{
|
||||
{Hostname: "b", Owned: true},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ package mullvad
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (m *Mullvad) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc, constants.AES128gcm}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func (m *Mullvad) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
|
||||
// Mullvad specific
|
||||
@@ -44,8 +44,8 @@ func (m *Mullvad) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if settings.Auth != "" {
|
||||
lines = append(lines, "auth "+settings.Auth)
|
||||
if *settings.Auth != "" {
|
||||
lines = append(lines, "auth "+*settings.Auth)
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
@@ -53,22 +53,22 @@ func (m *Mullvad) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package nordvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (n *Nordvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (n *Nordvpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
var port uint16 = 1194
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
port = 443
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package nordvpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (n *Nordvpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (n *Nordvpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.NordvpnServer, err error) {
|
||||
selectedNumbers := make([]string, len(selection.Numbers))
|
||||
for i := range selection.Numbers {
|
||||
|
||||
@@ -3,24 +3,26 @@ package nordvpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (n *Nordvpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = 1450
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
mssFix = 1450
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -28,17 +30,17 @@ func (n *Nordvpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Nordvpn specific
|
||||
"tun-mtu-extra 32",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"mssfix " + strconv.Itoa(int(mssFix)),
|
||||
"ping 15",
|
||||
"remote-cert-tls server",
|
||||
"reneg-sec 0",
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
"comp-lzo", // Required, NordVPN does not work without it
|
||||
|
||||
// Added constant values
|
||||
@@ -60,13 +62,13 @@ func (n *Nordvpn) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package perfectprivacy
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Perfectprivacy) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Perfectprivacy) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const defaultPort uint16 = 443
|
||||
port := defaultPort
|
||||
if selection.OpenVPN.CustomPort > 0 {
|
||||
port = selection.OpenVPN.CustomPort
|
||||
if *selection.OpenVPN.CustomPort > 0 {
|
||||
port = *selection.OpenVPN.CustomPort
|
||||
}
|
||||
protocol := utils.GetProtocol(selection)
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package perfectprivacy
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Perfectprivacy) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Perfectprivacy) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.PerfectprivacyServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,24 +3,26 @@ package perfectprivacy
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Perfectprivacy) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc, constants.AES256gcm}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = 1450
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
mssFix = 1450
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -28,18 +30,18 @@ func (p *Perfectprivacy) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Perfect Privacy specific
|
||||
"ping 5",
|
||||
"tun-mtu 1500",
|
||||
"tun-mtu-extra 32",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"mssfix " + strconv.Itoa(int(mssFix)),
|
||||
"reneg-sec 3600",
|
||||
"key-direction 1",
|
||||
"tls-cipher TLS_CHACHA20_POLY1305_SHA256:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-128-CBC-SHA:TLS_AES_256_GCM_SHA384:TLS-RSA-WITH-AES-256-CBC-SHA", //nolint:lll
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -59,13 +61,13 @@ func (p *Perfectprivacy) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
// Perfect Privacy specific IPv6
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (p *Privado) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Privado) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 1194
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
return connection, fmt.Errorf("%w: TCP for provider Privado", ErrProtocolUnsupported)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package privado
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privado) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Privado) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.PrivadoServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,20 +3,21 @@ package privado
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privado) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -24,14 +25,14 @@ func (p *Privado) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Privado specific
|
||||
"ping 10",
|
||||
"tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA",
|
||||
"verify-x509-name " + connection.Hostname + " name",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -47,21 +48,21 @@ func (p *Privado) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package privateinternetaccess
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *PIA) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *PIA) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package privateinternetaccess
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *PIA) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *PIA) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.PIAServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,16 +3,16 @@ package privateinternetaccess
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *PIA) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
var defaultCipher, defaultAuth, X509CRL, certificate string
|
||||
switch settings.EncPreset {
|
||||
switch *settings.PIAEncPreset {
|
||||
case constants.PIAEncryptionPresetNormal:
|
||||
defaultCipher = constants.AES128cbc
|
||||
defaultAuth = constants.SHA1
|
||||
@@ -34,8 +34,9 @@ func (p *PIA) BuildConf(connection models.Connection,
|
||||
settings.Ciphers = []string{defaultCipher}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = defaultAuth
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = defaultAuth
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -43,12 +44,13 @@ func (p *PIA) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// PIA specific
|
||||
"remote-cert-tls server",
|
||||
"reneg-sec 0",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -66,25 +68,21 @@ func (p *PIA) BuildConf(connection models.Connection,
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
}
|
||||
|
||||
if settings.Auth != "" {
|
||||
lines = append(lines, "auth "+settings.Auth)
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -4,21 +4,23 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func getPort(openvpnSelection configuration.OpenVPNSelection) (
|
||||
func getPort(openvpnSelection settings.OpenVPNSelection) (
|
||||
port uint16, err error) {
|
||||
if openvpnSelection.CustomPort == 0 {
|
||||
return getDefaultPort(openvpnSelection.TCP, openvpnSelection.EncPreset), nil
|
||||
customPort := *openvpnSelection.CustomPort
|
||||
tcp := *openvpnSelection.TCP
|
||||
if customPort == 0 {
|
||||
return getDefaultPort(tcp, *openvpnSelection.PIAEncPreset), nil
|
||||
}
|
||||
|
||||
if err := checkPort(openvpnSelection.CustomPort, openvpnSelection.TCP); err != nil {
|
||||
if err := checkPort(customPort, tcp); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return openvpnSelection.CustomPort, nil
|
||||
return customPort, nil
|
||||
}
|
||||
|
||||
func getDefaultPort(tcp bool, encryptionPreset string) (port uint16) {
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package privatevpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privatevpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Privatevpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 1194
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
port = 443
|
||||
}
|
||||
if selection.OpenVPN.CustomPort > 0 {
|
||||
port = selection.OpenVPN.CustomPort
|
||||
if *selection.OpenVPN.CustomPort > 0 {
|
||||
port = *selection.OpenVPN.CustomPort
|
||||
}
|
||||
|
||||
servers, err := p.filterServers(selection)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package privatevpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privatevpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Privatevpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.PrivatevpnServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,20 +3,21 @@ package privatevpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privatevpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES128gcm}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -24,12 +25,12 @@ func (p *Privatevpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Privatevpn specific
|
||||
"remote-cert-tls server",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -50,17 +51,17 @@ func (p *Privatevpn) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Protonvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Protonvpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
port, err := getPort(selection.OpenVPN.TCP, selection.OpenVPN.CustomPort)
|
||||
port, err := getPort(*selection.OpenVPN.TCP, *selection.OpenVPN.CustomPort)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package protonvpn
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Protonvpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Protonvpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.ProtonvpnServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
@@ -18,7 +18,7 @@ func (p *Protonvpn) filterServers(selection configuration.ServerSelection) (
|
||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
utils.FilterByPossibilities(server.Name, selection.Names),
|
||||
selection.FreeOnly && !strings.Contains(strings.ToLower(server.Name), "free"):
|
||||
*selection.FreeOnly && !strings.Contains(strings.ToLower(server.Name), "free"):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
|
||||
@@ -3,25 +3,27 @@ package protonvpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Protonvpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
const defaultMSSFix = 1450
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = defaultMSSFix
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
const defaultMSSFix = 1450
|
||||
mssFix = defaultMSSFix
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -29,16 +31,16 @@ func (p *Protonvpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Protonvpn specific
|
||||
"remote-cert-tls server",
|
||||
"tun-mtu-extra 32",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"mssfix " + strconv.Itoa(int(mssFix)),
|
||||
"reneg-sec 0",
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -59,13 +61,13 @@ func (p *Protonvpn) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/custom"
|
||||
@@ -37,8 +37,8 @@ import (
|
||||
|
||||
// Provider contains methods to read and modify the openvpn configuration to connect as a client.
|
||||
type Provider interface {
|
||||
GetConnection(selection configuration.ServerSelection) (connection models.Connection, err error)
|
||||
BuildConf(connection models.Connection, settings configuration.OpenVPN) (lines []string, err error)
|
||||
GetConnection(selection settings.ServerSelection) (connection models.Connection, err error)
|
||||
BuildConf(connection models.Connection, settings settings.OpenVPN) (lines []string, err error)
|
||||
PortForwarder
|
||||
}
|
||||
|
||||
@@ -96,6 +96,6 @@ func New(provider string, allServers models.AllServers, timeNow func() time.Time
|
||||
case constants.Windscribe:
|
||||
return windscribe.New(allServers.Windscribe.Servers, randSource)
|
||||
default:
|
||||
return nil // should never occur
|
||||
panic("provider " + provider + " is unknown") // should never occur
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package purevpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Purevpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Purevpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 53
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
port = 80
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package purevpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Purevpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Purevpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.PurevpnServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,14 +3,14 @@ package purevpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Purevpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256gcm}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func (p *Purevpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Purevpn specific
|
||||
"ping 10",
|
||||
@@ -46,21 +46,21 @@ func (p *Purevpn) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if settings.Auth != "" {
|
||||
lines = append(lines, "auth "+settings.Auth)
|
||||
if *settings.Auth != "" {
|
||||
lines = append(lines, "auth "+*settings.Auth)
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package surfshark
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (s *Surfshark) GetConnection(selection configuration.ServerSelection) (
|
||||
func (s *Surfshark) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
var port uint16 = 1194
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
port = 1443
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package surfshark
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (s *Surfshark) filterServers(selection configuration.ServerSelection) (
|
||||
func (s *Surfshark) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.SurfsharkServer, err error) {
|
||||
for _, server := range s.servers {
|
||||
switch {
|
||||
@@ -16,7 +16,7 @@ func (s *Surfshark) filterServers(selection configuration.ServerSelection) (
|
||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
utils.FilterByProtocol(selection, server.TCP, server.UDP),
|
||||
selection.MultiHopOnly && !server.MultiHop:
|
||||
*selection.MultiHopOnly && !server.MultiHop:
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
|
||||
@@ -5,27 +5,27 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func Test_Surfshark_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.SurfsharkServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filtered []models.SurfsharkServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Surfshark),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.SurfsharkServer{
|
||||
@@ -33,6 +33,7 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Surfshark),
|
||||
filtered: []models.SurfsharkServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
@@ -40,9 +41,9 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by region": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Regions: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Surfshark),
|
||||
servers: []models.SurfsharkServer{
|
||||
{Region: "a", UDP: true},
|
||||
{Region: "b", UDP: true},
|
||||
@@ -53,9 +54,9 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by country": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Countries: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Surfshark),
|
||||
servers: []models.SurfsharkServer{
|
||||
{Country: "a", UDP: true},
|
||||
{Country: "b", UDP: true},
|
||||
@@ -66,9 +67,9 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Surfshark),
|
||||
servers: []models.SurfsharkServer{
|
||||
{City: "a", UDP: true},
|
||||
{City: "b", UDP: true},
|
||||
@@ -79,9 +80,9 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Surfshark),
|
||||
servers: []models.SurfsharkServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
@@ -92,11 +93,11 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by protocol": {
|
||||
selection: configuration.ServerSelection{
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
selection: settings.ServerSelection{
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
}.WithDefaults(constants.Surfshark),
|
||||
servers: []models.SurfsharkServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true, TCP: true},
|
||||
@@ -107,9 +108,9 @@ func Test_Surfshark_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by multihop only": {
|
||||
selection: configuration.ServerSelection{
|
||||
MultiHopOnly: true,
|
||||
},
|
||||
selection: settings.ServerSelection{
|
||||
MultiHopOnly: boolPtr(true),
|
||||
}.WithDefaults(constants.Surfshark),
|
||||
servers: []models.SurfsharkServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", MultiHop: true, UDP: true},
|
||||
|
||||
@@ -3,25 +3,27 @@ package surfshark
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (s *Surfshark) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256gcm}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
const defaultMSSFix = 1450
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = defaultMSSFix
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
const defaultMSSFix = 1450
|
||||
mssFix = defaultMSSFix
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -29,17 +31,17 @@ func (s *Surfshark) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Surfshark specific
|
||||
"tun-mtu-extra 32",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"mssfix " + strconv.Itoa(int(mssFix)),
|
||||
"ping 15",
|
||||
"remote-cert-tls server",
|
||||
"reneg-sec 0",
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -59,13 +61,13 @@ func (s *Surfshark) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package torguard
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (t *Torguard) GetConnection(selection configuration.ServerSelection) (
|
||||
func (t *Torguard) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
var port uint16 = 1912
|
||||
if selection.OpenVPN.CustomPort > 0 {
|
||||
port = selection.OpenVPN.CustomPort
|
||||
if *selection.OpenVPN.CustomPort > 0 {
|
||||
port = *selection.OpenVPN.CustomPort
|
||||
}
|
||||
|
||||
servers, err := t.filterServers(selection)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package torguard
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (t *Torguard) filterServers(selection configuration.ServerSelection) (
|
||||
func (t *Torguard) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.TorguardServer, err error) {
|
||||
for _, server := range t.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,25 +3,27 @@ package torguard
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (t *Torguard) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256gcm}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
|
||||
const defaultMSSFix = 1450
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = defaultMSSFix
|
||||
mssFix := *settings.MSSFix
|
||||
if mssFix == 0 {
|
||||
const defaultMSSFix = 1450
|
||||
mssFix = defaultMSSFix
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -29,11 +31,11 @@ func (t *Torguard) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Torguard specific
|
||||
"tun-mtu-extra 32",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"mssfix " + strconv.Itoa(int(mssFix)),
|
||||
"sndbuf 393216",
|
||||
"rcvbuf 393216",
|
||||
"ping 5",
|
||||
@@ -41,7 +43,7 @@ func (t *Torguard) BuildConf(connection models.Connection,
|
||||
"reneg-sec 0",
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -57,7 +59,7 @@ func (t *Torguard) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
@@ -68,7 +70,7 @@ func (t *Torguard) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
@@ -16,13 +16,13 @@ func commaJoin(slice []string) string {
|
||||
|
||||
var ErrNoServerFound = errors.New("no server found")
|
||||
|
||||
func NoServerFoundError(selection configuration.ServerSelection) (err error) {
|
||||
func NoServerFoundError(selection settings.ServerSelection) (err error) {
|
||||
var messageParts []string
|
||||
|
||||
messageParts = append(messageParts, "VPN "+selection.VPN)
|
||||
|
||||
protocol := constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
messageParts = append(messageParts, "protocol "+protocol)
|
||||
@@ -57,7 +57,7 @@ func NoServerFoundError(selection configuration.ServerSelection) (err error) {
|
||||
messageParts = append(messageParts, part)
|
||||
}
|
||||
|
||||
if selection.Owned {
|
||||
if *selection.OwnedOnly {
|
||||
messageParts = append(messageParts, "owned servers only")
|
||||
}
|
||||
|
||||
@@ -105,12 +105,12 @@ func NoServerFoundError(selection configuration.ServerSelection) (err error) {
|
||||
messageParts = append(messageParts, part)
|
||||
}
|
||||
|
||||
if selection.OpenVPN.EncPreset != "" {
|
||||
part := "encryption preset " + selection.OpenVPN.EncPreset
|
||||
if *selection.OpenVPN.PIAEncPreset != "" {
|
||||
part := "encryption preset " + *selection.OpenVPN.PIAEncPreset
|
||||
messageParts = append(messageParts, part)
|
||||
}
|
||||
|
||||
if selection.FreeOnly {
|
||||
if *selection.FreeOnly {
|
||||
messageParts = append(messageParts, "free tier only")
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
@@ -17,15 +17,15 @@ import (
|
||||
// Otherwise, it picks a random connection from the pool of connections
|
||||
// and sets the target IP address as the IP if this one is set.
|
||||
func PickConnection(connections []models.Connection,
|
||||
selection configuration.ServerSelection, randSource rand.Source) (
|
||||
selection settings.ServerSelection, randSource rand.Source) (
|
||||
connection models.Connection, err error) {
|
||||
if selection.TargetIP != nil && selection.VPN == constants.Wireguard {
|
||||
if len(selection.TargetIP) > 0 && selection.VPN == constants.Wireguard {
|
||||
// we need the right public key
|
||||
return getTargetIPConnection(connections, selection.TargetIP)
|
||||
}
|
||||
|
||||
connection = pickRandomConnection(connections, randSource)
|
||||
if selection.TargetIP != nil {
|
||||
if len(selection.TargetIP) > 0 {
|
||||
connection.IP = selection.TargetIP
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func GetPort(selection configuration.ServerSelection,
|
||||
func GetPort(selection settings.ServerSelection,
|
||||
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
||||
switch selection.VPN {
|
||||
case constants.Wireguard:
|
||||
customPort := selection.Wireguard.EndpointPort
|
||||
customPort := *selection.Wireguard.EndpointPort
|
||||
if customPort > 0 {
|
||||
return customPort
|
||||
}
|
||||
return defaultWireguard
|
||||
default: // OpenVPN
|
||||
customPort := selection.OpenVPN.CustomPort
|
||||
customPort := *selection.OpenVPN.CustomPort
|
||||
if customPort > 0 {
|
||||
return customPort
|
||||
}
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
return defaultOpenVPNTCP
|
||||
}
|
||||
return defaultOpenVPNUDP
|
||||
|
||||
@@ -3,11 +3,14 @@ package utils
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
func uint16Ptr(n uint16) *uint16 { return &n }
|
||||
|
||||
func Test_GetPort(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -18,47 +21,53 @@ func Test_GetPort(t *testing.T) {
|
||||
)
|
||||
|
||||
testCases := map[string]struct {
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
port uint16
|
||||
}{
|
||||
"default": {
|
||||
port: defaultOpenVPNUDP,
|
||||
selection: settings.ServerSelection{}.WithDefaults(""),
|
||||
port: defaultOpenVPNUDP,
|
||||
},
|
||||
"OpenVPN UDP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
},
|
||||
port: defaultOpenVPNUDP,
|
||||
},
|
||||
"OpenVPN TCP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
port: defaultOpenVPNTCP,
|
||||
},
|
||||
"OpenVPN custom port": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
CustomPort: 1234,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(1234),
|
||||
},
|
||||
},
|
||||
port: 1234,
|
||||
},
|
||||
"Wireguard": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
},
|
||||
}.WithDefaults(""),
|
||||
port: defaultWireguard,
|
||||
},
|
||||
"Wireguard custom port": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
Wireguard: configuration.WireguardSelection{
|
||||
EndpointPort: 1234,
|
||||
Wireguard: settings.WireguardSelection{
|
||||
EndpointPort: uint16Ptr(1234),
|
||||
},
|
||||
},
|
||||
port: 1234,
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func GetProtocol(selection configuration.ServerSelection) (protocol string) {
|
||||
if selection.VPN == constants.OpenVPN && selection.OpenVPN.TCP {
|
||||
func GetProtocol(selection settings.ServerSelection) (protocol string) {
|
||||
if selection.VPN == constants.OpenVPN && *selection.OpenVPN.TCP {
|
||||
return constants.TCP
|
||||
}
|
||||
return constants.UDP
|
||||
}
|
||||
|
||||
func FilterByProtocol(selection configuration.ServerSelection,
|
||||
func FilterByProtocol(selection settings.ServerSelection,
|
||||
serverTCP, serverUDP bool) (filtered bool) {
|
||||
switch selection.VPN {
|
||||
case constants.Wireguard:
|
||||
return !serverUDP
|
||||
default: // OpenVPN
|
||||
wantTCP := selection.OpenVPN.TCP
|
||||
wantTCP := *selection.OpenVPN.TCP
|
||||
wantUDP := !wantTCP
|
||||
return (wantTCP && !serverTCP) || (wantUDP && !serverUDP)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package utils
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -12,29 +12,32 @@ func Test_GetProtocol(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
protocol string
|
||||
}{
|
||||
"default": {
|
||||
protocol: constants.UDP,
|
||||
},
|
||||
"OpenVPN UDP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
},
|
||||
protocol: constants.UDP,
|
||||
},
|
||||
"OpenVPN TCP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
protocol: constants.TCP,
|
||||
},
|
||||
"Wireguard": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
},
|
||||
protocol: constants.UDP,
|
||||
@@ -57,60 +60,60 @@ func Test_FilterByProtocol(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
serverTCP bool
|
||||
serverUDP bool
|
||||
filtered bool
|
||||
}{
|
||||
"Wireguard and server has UDP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
},
|
||||
serverUDP: true,
|
||||
filtered: false,
|
||||
},
|
||||
"Wireguard and server has not UDP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
},
|
||||
serverUDP: false,
|
||||
filtered: true,
|
||||
},
|
||||
"OpenVPN UDP and server has UDP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: false,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
},
|
||||
serverUDP: true,
|
||||
filtered: false,
|
||||
},
|
||||
"OpenVPN UDP and server has not UDP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: false,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
},
|
||||
serverUDP: false,
|
||||
filtered: true,
|
||||
},
|
||||
"OpenVPN TCP and server has TCP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
serverTCP: true,
|
||||
filtered: false,
|
||||
},
|
||||
"OpenVPN TCP and server has not TCP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
},
|
||||
serverTCP: false,
|
||||
|
||||
@@ -3,16 +3,16 @@ package utils
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/wireguard"
|
||||
)
|
||||
|
||||
func BuildWireguardSettings(connection models.Connection,
|
||||
userSettings configuration.Wireguard) (settings wireguard.Settings) {
|
||||
settings.PrivateKey = userSettings.PrivateKey
|
||||
userSettings settings.Wireguard) (settings wireguard.Settings) {
|
||||
settings.PrivateKey = *userSettings.PrivateKey
|
||||
settings.PublicKey = connection.PubKey
|
||||
settings.PreSharedKey = userSettings.PreSharedKey
|
||||
settings.PreSharedKey = *userSettings.PreSharedKey
|
||||
settings.InterfaceName = userSettings.Interface
|
||||
|
||||
const rulePriority = 101 // 100 is to receive external connections
|
||||
|
||||
@@ -4,18 +4,20 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/wireguard"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func stringPtr(s string) *string { return &s }
|
||||
|
||||
func Test_BuildWireguardSettings(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
connection models.Connection
|
||||
userSettings configuration.Wireguard
|
||||
userSettings settings.Wireguard
|
||||
settings wireguard.Settings
|
||||
}{
|
||||
"some settings": {
|
||||
@@ -24,10 +26,10 @@ func Test_BuildWireguardSettings(t *testing.T) {
|
||||
Port: 51821,
|
||||
PubKey: "public",
|
||||
},
|
||||
userSettings: configuration.Wireguard{
|
||||
PrivateKey: "private",
|
||||
PreSharedKey: "pre-shared",
|
||||
Addresses: []*net.IPNet{
|
||||
userSettings: settings.Wireguard{
|
||||
PrivateKey: stringPtr("private"),
|
||||
PreSharedKey: stringPtr("pre-shared"),
|
||||
Addresses: []net.IPNet{
|
||||
{IP: net.IPv4(1, 1, 1, 1), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||
{IP: net.IPv4(2, 2, 2, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ package vpnunlimited
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
func (p *Provider) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 1194
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
return connection, ErrProtocolUnsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) filterServers(selection configuration.ServerSelection) (
|
||||
func (p *Provider) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.VPNUnlimitedServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
@@ -14,8 +14,8 @@ func (p *Provider) filterServers(selection configuration.ServerSelection) (
|
||||
utils.FilterByPossibilities(server.Country, selection.Countries),
|
||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
selection.FreeOnly && !server.Free,
|
||||
selection.StreamOnly && !server.Stream,
|
||||
*selection.FreeOnly && !server.Free,
|
||||
*selection.StreamOnly && !server.Stream,
|
||||
utils.FilterByProtocol(selection, server.TCP, server.UDP):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/parse"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
lines = []string{
|
||||
"client",
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// VPNUnlimited specific
|
||||
"ping 5",
|
||||
@@ -40,35 +42,43 @@ func (p *Provider) BuildConf(connection models.Connection,
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
}
|
||||
|
||||
if settings.Auth != "" {
|
||||
lines = append(lines, "auth "+settings.Auth)
|
||||
if *settings.Auth != "" {
|
||||
lines = append(lines, "auth "+*settings.Auth)
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
constants.VPNUnlimitedCertificateAuthority)...)
|
||||
lines = append(lines, utils.WrapOpenvpnCert(
|
||||
settings.ClientCrt)...)
|
||||
lines = append(lines, utils.WrapOpenvpnKey(
|
||||
settings.ClientKey)...)
|
||||
|
||||
certData, err := parse.ExtractCert([]byte(*settings.ClientCrt))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client cert is not valid: %w", err)
|
||||
}
|
||||
lines = append(lines, utils.WrapOpenvpnCert(certData)...)
|
||||
|
||||
keyData, err := parse.ExtractPrivateKey([]byte(*settings.ClientKey))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client key is not valid: %w", err)
|
||||
}
|
||||
lines = append(lines, utils.WrapOpenvpnKey(keyData)...)
|
||||
|
||||
lines = append(lines, "")
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
|
||||
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
||||
|
||||
func (v *Vyprvpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (v *Vyprvpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 443
|
||||
const protocol = constants.UDP
|
||||
if selection.OpenVPN.TCP {
|
||||
if *selection.OpenVPN.TCP {
|
||||
return connection, fmt.Errorf("%w: TCP for provider VyprVPN", ErrProtocolUnsupported)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package vyprvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (v *Vyprvpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (v *Vyprvpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.VyprvpnServer, err error) {
|
||||
for _, server := range v.servers {
|
||||
switch {
|
||||
|
||||
@@ -3,20 +3,21 @@ package vyprvpn
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (v *Vyprvpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256cbc}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA256
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -24,7 +25,7 @@ func (v *Vyprvpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Vyprvpn specific
|
||||
"ping 10",
|
||||
@@ -32,7 +33,7 @@ func (v *Vyprvpn) BuildConf(connection models.Connection,
|
||||
// "verify-x509-name lu1.vyprvpn.com name",
|
||||
"tls-cipher TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA", //nolint:lll
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
"comp-lzo",
|
||||
|
||||
// Added constant values
|
||||
@@ -53,14 +54,14 @@ func (v *Vyprvpn) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package wevpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Wevpn) GetConnection(selection configuration.ServerSelection) (
|
||||
func (w *Wevpn) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
@@ -32,7 +32,7 @@ func (w *Wevpn) GetConnection(selection configuration.ServerSelection) (
|
||||
return utils.PickConnection(connections, selection, w.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection configuration.ServerSelection) (port uint16) {
|
||||
func getPort(selection settings.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 1195
|
||||
defaultOpenVPNUDP = 1194
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -18,14 +18,14 @@ func Test_Wevpn_GetConnection(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.WevpnServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
}.WithDefaults(constants.Wevpn),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
@@ -34,37 +34,41 @@ func Test_Wevpn_GetConnection(t *testing.T) {
|
||||
{UDP: true, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{UDP: true, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Wevpn),
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(1, 1, 1, 1),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"target IP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||
},
|
||||
}.WithDefaults(constants.Wevpn),
|
||||
servers: []models.WevpnServer{
|
||||
{UDP: true, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{UDP: true, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{UDP: true, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"with filter": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Wevpn),
|
||||
servers: []models.WevpnServer{
|
||||
{UDP: true, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{UDP: true, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{UDP: true, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package wevpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Wevpn) filterServers(selection configuration.ServerSelection) (
|
||||
func (w *Wevpn) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.WevpnServer, err error) {
|
||||
for _, server := range w.servers {
|
||||
switch {
|
||||
|
||||
@@ -5,27 +5,27 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func Test_Wevpn_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.WevpnServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filtered []models.WevpnServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Wevpn),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.WevpnServer{
|
||||
@@ -33,6 +33,7 @@ func Test_Wevpn_filterServers(t *testing.T) {
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Wevpn),
|
||||
filtered: []models.WevpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
@@ -40,9 +41,9 @@ func Test_Wevpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by protocol": {
|
||||
selection: configuration.ServerSelection{
|
||||
OpenVPN: configuration.OpenVPNSelection{TCP: true},
|
||||
},
|
||||
selection: settings.ServerSelection{
|
||||
OpenVPN: settings.OpenVPNSelection{TCP: boolPtr(true)},
|
||||
}.WithDefaults(constants.Wevpn),
|
||||
servers: []models.WevpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", TCP: true},
|
||||
@@ -53,9 +54,9 @@ func Test_Wevpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Wevpn),
|
||||
servers: []models.WevpnServer{
|
||||
{City: "a", UDP: true},
|
||||
{City: "b", UDP: true},
|
||||
@@ -66,9 +67,9 @@ func Test_Wevpn_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Wevpn),
|
||||
servers: []models.WevpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package wevpn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/parse"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Wevpn) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{constants.AES256gcm}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -24,7 +27,7 @@ func (w *Wevpn) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Wevpn specific
|
||||
"ping 30",
|
||||
@@ -32,7 +35,7 @@ func (w *Wevpn) BuildConf(connection models.Connection,
|
||||
"redirect-gateway def1 bypass-dhcp",
|
||||
"reneg-sec 0",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -52,25 +55,29 @@ func (w *Wevpn) BuildConf(connection models.Connection,
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if settings.IPv6 {
|
||||
if *settings.IPv6 {
|
||||
lines = append(lines, "tun-ipv6")
|
||||
} else {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnKey(
|
||||
settings.ClientKey)...)
|
||||
keyData, err := parse.ExtractPrivateKey([]byte(*settings.ClientKey))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client key is not valid: %w", err)
|
||||
}
|
||||
lines = append(lines, utils.WrapOpenvpnKey(keyData)...)
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
constants.WevpnCA)...)
|
||||
lines = append(lines, utils.WrapOpenvpnCert(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package windscribe
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Windscribe) GetConnection(selection configuration.ServerSelection) (
|
||||
func (w *Windscribe) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
@@ -34,7 +34,7 @@ func (w *Windscribe) GetConnection(selection configuration.ServerSelection) (
|
||||
return utils.PickConnection(connections, selection, w.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection configuration.ServerSelection) (port uint16) {
|
||||
func getPort(selection settings.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 443
|
||||
defaultOpenVPNUDP = 1194
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -18,53 +18,55 @@ func Test_Windscribe_GetConnection(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.WindscribeServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Windscribe),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.WindscribeServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Windscribe),
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(1, 1, 1, 1),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"target IP": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||
},
|
||||
}.WithDefaults(constants.Windscribe),
|
||||
servers: []models.WindscribeServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"with filter": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Windscribe),
|
||||
servers: []models.WindscribeServer{
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||
},
|
||||
connection: models.Connection{
|
||||
Type: constants.OpenVPN,
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1194,
|
||||
Protocol: constants.UDP,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package windscribe
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Windscribe) filterServers(selection configuration.ServerSelection) (
|
||||
func (w *Windscribe) filterServers(selection settings.ServerSelection) (
|
||||
servers []models.WindscribeServer, err error) {
|
||||
for _, server := range w.servers {
|
||||
switch {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -17,32 +17,31 @@ func Test_Windscribe_filterServers(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.WindscribeServer
|
||||
selection configuration.ServerSelection
|
||||
selection settings.ServerSelection
|
||||
filtered []models.WindscribeServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Windscribe),
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.WindscribeServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
selection: settings.ServerSelection{}.WithDefaults(constants.Windscribe),
|
||||
filtered: []models.WindscribeServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
},
|
||||
"filter OpenVPN out": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
},
|
||||
}.WithDefaults(constants.Windscribe),
|
||||
servers: []models.WindscribeServer{
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.Wireguard, Hostname: "b"},
|
||||
@@ -53,42 +52,42 @@ func Test_Windscribe_filterServers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
"filter by region": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Regions: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Windscribe),
|
||||
servers: []models.WindscribeServer{
|
||||
{Region: "a"},
|
||||
{Region: "b"},
|
||||
{Region: "c"},
|
||||
{VPN: constants.OpenVPN, Region: "a"},
|
||||
{VPN: constants.OpenVPN, Region: "b"},
|
||||
{VPN: constants.OpenVPN, Region: "c"},
|
||||
},
|
||||
filtered: []models.WindscribeServer{
|
||||
{Region: "b"},
|
||||
{VPN: constants.OpenVPN, Region: "b"},
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Windscribe),
|
||||
servers: []models.WindscribeServer{
|
||||
{City: "a"},
|
||||
{City: "b"},
|
||||
{City: "c"},
|
||||
{VPN: constants.OpenVPN, City: "a"},
|
||||
{VPN: constants.OpenVPN, City: "b"},
|
||||
{VPN: constants.OpenVPN, City: "c"},
|
||||
},
|
||||
filtered: []models.WindscribeServer{
|
||||
{City: "b"},
|
||||
{VPN: constants.OpenVPN, City: "b"},
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
selection: settings.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
}.WithDefaults(constants.Windscribe),
|
||||
servers: []models.WindscribeServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
||||
},
|
||||
filtered: []models.WindscribeServer{
|
||||
{Hostname: "b"},
|
||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ package windscribe
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Windscribe) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
if len(settings.Ciphers) == 0 {
|
||||
settings.Ciphers = []string{
|
||||
constants.AES256gcm,
|
||||
@@ -19,8 +19,9 @@ func (w *Windscribe) BuildConf(connection models.Connection,
|
||||
}
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
auth := *settings.Auth
|
||||
if auth == "" {
|
||||
auth = constants.SHA512
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
@@ -28,7 +29,7 @@ func (w *Windscribe) BuildConf(connection models.Connection,
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"verb " + strconv.Itoa(*settings.Verbosity),
|
||||
|
||||
// Windscribe specific
|
||||
"ping 10",
|
||||
@@ -37,7 +38,7 @@ func (w *Windscribe) BuildConf(connection models.Connection,
|
||||
"key-direction 1",
|
||||
"reneg-sec 0",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
"auth " + auth,
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
@@ -57,17 +58,17 @@ func (w *Windscribe) BuildConf(connection models.Connection,
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
if !*settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
if *settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
if !*settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user