Maintenance: split each provider in a package
- Fix VyprVPN port - Fix missing Auth overrides
This commit is contained in:
40
internal/provider/cyberghost/connection.go
Normal file
40
internal/provider/cyberghost/connection.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
const port = 443
|
||||
protocol := constants.UDP
|
||||
if selection.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
servers, err := c.filterServers(selection)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.OpenVPNConnection{
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
}
|
||||
connections = append(connections, connection)
|
||||
}
|
||||
}
|
||||
|
||||
if selection.TargetIP != nil {
|
||||
return utils.GetTargetIPConnection(connections, selection.TargetIP)
|
||||
}
|
||||
|
||||
return utils.PickRandomConnection(connections, c.randSource), nil
|
||||
}
|
||||
28
internal/provider/cyberghost/filter.go
Normal file
28
internal/provider/cyberghost/filter.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) filterServers(selection configuration.ServerSelection) (
|
||||
servers []models.CyberghostServer, err error) {
|
||||
for _, server := range c.servers {
|
||||
switch {
|
||||
case selection.Group != "" && !strings.EqualFold(selection.Group, server.Group), // TODO make CSV
|
||||
utils.FilterByPossibilities(server.Region, selection.Regions),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
|
||||
if len(servers) == 0 {
|
||||
return nil, utils.NoServerFoundError(selection)
|
||||
}
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
115
internal/provider/cyberghost/filter_test.go
Normal file
115
internal/provider/cyberghost/filter_test.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_Cyberghost_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := map[string]struct {
|
||||
servers []models.CyberghostServer
|
||||
selection configuration.ServerSelection
|
||||
filteredServers []models.CyberghostServer
|
||||
err error
|
||||
}{
|
||||
"no servers": {
|
||||
err: errors.New("no server found: for protocol udp"),
|
||||
},
|
||||
"servers without filter": {
|
||||
servers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "b", Group: "1"},
|
||||
{Region: "c", Group: "2"},
|
||||
{Region: "d", Group: "2"},
|
||||
},
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "b", Group: "1"},
|
||||
{Region: "c", Group: "2"},
|
||||
{Region: "d", Group: "2"},
|
||||
},
|
||||
},
|
||||
"servers with regions filter": {
|
||||
servers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "b", Group: "1"},
|
||||
{Region: "c", Group: "2"},
|
||||
{Region: "d", Group: "2"},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
Regions: []string{"a", "c"},
|
||||
},
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "c", Group: "2"},
|
||||
},
|
||||
},
|
||||
"servers with group filter": {
|
||||
servers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "b", Group: "1"},
|
||||
{Region: "c", Group: "2"},
|
||||
{Region: "d", Group: "2"},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
Group: "1",
|
||||
},
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "b", Group: "1"},
|
||||
},
|
||||
},
|
||||
"servers with regions and group filter": {
|
||||
servers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
{Region: "b", Group: "1"},
|
||||
{Region: "c", Group: "2"},
|
||||
{Region: "d", Group: "2"},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
Regions: []string{"a", "c"},
|
||||
Group: "1",
|
||||
},
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Region: "a", Group: "1"},
|
||||
},
|
||||
},
|
||||
"servers with hostnames filter": {
|
||||
servers: []models.CyberghostServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "b"},
|
||||
{Hostname: "c"},
|
||||
},
|
||||
selection: configuration.ServerSelection{
|
||||
Hostnames: []string{"a", "c"},
|
||||
},
|
||||
filteredServers: []models.CyberghostServer{
|
||||
{Hostname: "a"},
|
||||
{Hostname: "c"},
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := &Cyberghost{servers: testCase.servers}
|
||||
filteredServers, err := c.filterServers(testCase.selection)
|
||||
|
||||
if testCase.err != nil {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, testCase.err.Error(), err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, testCase.filteredServers, filteredServers)
|
||||
})
|
||||
}
|
||||
}
|
||||
81
internal/provider/cyberghost/openvpnconf.go
Normal file
81
internal/provider/cyberghost/openvpnconf.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) BuildConf(connection models.OpenVPNConnection,
|
||||
username string, settings configuration.OpenVPN) (lines []string) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA256
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
"client",
|
||||
"dev tun",
|
||||
"nobind",
|
||||
"persist-key",
|
||||
"persist-tun",
|
||||
"remote-cert-tls server",
|
||||
"ping 10",
|
||||
"ping-exit 60",
|
||||
"ping-timer-rem",
|
||||
"tls-exit",
|
||||
|
||||
// Cyberghost specific
|
||||
// "redirect-gateway def1",
|
||||
"ncp-disable",
|
||||
"explicit-exit-notify 2",
|
||||
"script-security 2",
|
||||
"route-delay 5",
|
||||
|
||||
// Added constant values
|
||||
"auth-nocache",
|
||||
"mute-replay-warnings",
|
||||
"pull-filter ignore \"auth-token\"", // prevent auth failed loops
|
||||
"auth-retry nointeract",
|
||||
"suppress-timestamps",
|
||||
|
||||
// Modified variables
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
connection.ProtoLine(),
|
||||
connection.RemoteLine(),
|
||||
"data-ciphers-fallback " + settings.Cipher,
|
||||
"data-ciphers " + settings.Cipher,
|
||||
"auth " + settings.Auth,
|
||||
}
|
||||
|
||||
if strings.HasSuffix(settings.Cipher, "-gcm") {
|
||||
lines = append(lines, "ncp-ciphers AES-256-GCM:AES-256-CBC:AES-128-GCM")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
lines = append(lines, "user "+username)
|
||||
}
|
||||
|
||||
if settings.MSSFix > 0 {
|
||||
lines = append(lines, "mssfix "+strconv.Itoa(int(settings.MSSFix)))
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
constants.CyberghostCertificate)...)
|
||||
lines = append(lines, utils.WrapOpenvpnCert(
|
||||
settings.Provider.ExtraConfigOptions.ClientCertificate)...)
|
||||
lines = append(lines, utils.WrapOpenvpnKey(
|
||||
settings.Provider.ExtraConfigOptions.ClientKey)...)
|
||||
|
||||
lines = append(lines, "")
|
||||
|
||||
return lines
|
||||
}
|
||||
17
internal/provider/cyberghost/portforward.go
Normal file
17
internal/provider/cyberghost/portforward.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"github.com/qdm12/golibs/os"
|
||||
)
|
||||
|
||||
func (c *Cyberghost) PortForward(ctx context.Context, client *http.Client,
|
||||
openFile os.OpenFileFunc, pfLogger logging.Logger, gateway net.IP,
|
||||
fw firewall.Configurator, syncState func(port uint16) (pfFilepath string)) {
|
||||
panic("port forwarding is not supported for Cyberghost")
|
||||
}
|
||||
19
internal/provider/cyberghost/provider.go
Normal file
19
internal/provider/cyberghost/provider.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package cyberghost
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type Cyberghost struct {
|
||||
servers []models.CyberghostServer
|
||||
randSource rand.Source
|
||||
}
|
||||
|
||||
func New(servers []models.CyberghostServer, randSource rand.Source) *Cyberghost {
|
||||
return &Cyberghost{
|
||||
servers: servers,
|
||||
randSource: randSource,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user