Maint: Remove CYBERGHOST_GROUP (change)

- It does not make any sense with newer server data
- It was to be deprecated anyway
This commit is contained in:
Quentin McGaw (desktop)
2021-09-23 13:54:24 +00:00
parent 625de1c834
commit f9aadeef1c
17 changed files with 1910 additions and 1846 deletions

View File

@@ -106,7 +106,6 @@ ENV VPNSP=pia \
PORT_FORWARDING=off \ PORT_FORWARDING=off \
PORT_FORWARDING_STATUS_FILE="/tmp/gluetun/forwarded_port" \ PORT_FORWARDING_STATUS_FILE="/tmp/gluetun/forwarded_port" \
# # Cyberghost only: # # Cyberghost only:
CYBERGHOST_GROUP="Premium UDP Europe" \
OPENVPN_CLIENTCRT_SECRETFILE=/run/secrets/openvpn_clientcrt \ OPENVPN_CLIENTCRT_SECRETFILE=/run/secrets/openvpn_clientcrt \
OPENVPN_CLIENTKEY_SECRETFILE=/run/secrets/openvpn_clientkey \ OPENVPN_CLIENTKEY_SECRETFILE=/run/secrets/openvpn_clientkey \
# # Nordvpn only: # # Nordvpn only:

View File

@@ -16,12 +16,6 @@ func (settings *Provider) readCyberghost(r reader) (err error) {
return err return err
} }
settings.ServerSelection.Groups, err = r.env.CSVInside("CYBERGHOST_GROUP",
constants.CyberghostGroupChoices(servers))
if err != nil {
return fmt.Errorf("environment variable CYBERGHOST_GROUP: %w", err)
}
settings.ServerSelection.Countries, err = r.env.CSVInside("COUNTRY", settings.ServerSelection.Countries, err = r.env.CSVInside("COUNTRY",
constants.CyberghostCountryChoices(servers), constants.CyberghostCountryChoices(servers),
params.RetroKeys([]string{"REGION"}, r.onRetroActive)) params.RetroKeys([]string{"REGION"}, r.onRetroActive))

View File

@@ -25,13 +25,11 @@ func Test_Provider_lines(t *testing.T) {
Name: constants.Cyberghost, Name: constants.Cyberghost,
ServerSelection: ServerSelection{ ServerSelection: ServerSelection{
VPN: constants.OpenVPN, VPN: constants.OpenVPN,
Groups: []string{"group"},
Countries: []string{"a", "El country"}, Countries: []string{"a", "El country"},
}, },
}, },
lines: []string{ lines: []string{
"|--Cyberghost settings:", "|--Cyberghost settings:",
" |--Server groups: group",
" |--Countries: a, El country", " |--Countries: a, El country",
" |--OpenVPN selection:", " |--OpenVPN selection:",
" |--Protocol: udp", " |--Protocol: udp",

View File

@@ -15,9 +15,6 @@ type ServerSelection struct { //nolint:maligned
// Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN // Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN
Regions []string `json:"regions"` Regions []string `json:"regions"`
// Cyberghost
Groups []string `json:"groups"`
// Fastestvpn, HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited // Fastestvpn, HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited
Countries []string `json:"countries"` Countries []string `json:"countries"`
// HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited, Windscribe // HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited, Windscribe
@@ -51,10 +48,6 @@ func (selection ServerSelection) toLines() (lines []string) {
lines = append(lines, lastIndent+"Target IP address: "+selection.TargetIP.String()) lines = append(lines, lastIndent+"Target IP address: "+selection.TargetIP.String())
} }
if len(selection.Groups) > 0 {
lines = append(lines, lastIndent+"Server groups: "+commaJoin(selection.Groups))
}
if len(selection.Countries) > 0 { if len(selection.Countries) > 0 {
lines = append(lines, lastIndent+"Countries: "+commaJoin(selection.Countries)) lines = append(lines, lastIndent+"Countries: "+commaJoin(selection.Countries))
} }

View File

@@ -1,8 +1,6 @@
package constants package constants
import ( import (
"sort"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
) )
@@ -19,23 +17,6 @@ func CyberghostCountryChoices(servers []models.CyberghostServer) (choices []stri
return makeUnique(choices) return makeUnique(choices)
} }
func CyberghostGroupChoices(servers []models.CyberghostServer) (choices []string) {
uniqueChoices := map[string]struct{}{}
for _, server := range servers {
uniqueChoices[server.Group] = struct{}{}
}
choices = make([]string, 0, len(uniqueChoices))
for choice := range uniqueChoices {
choices = append(choices, choice)
}
sortable := sort.StringSlice(choices)
sortable.Sort()
return sortable
}
func CyberghostHostnameChoices(servers []models.CyberghostServer) (choices []string) { func CyberghostHostnameChoices(servers []models.CyberghostServer) (choices []string) {
choices = make([]string, len(servers)) choices = make([]string, len(servers))
for i := range servers { for i := range servers {

View File

@@ -1,30 +0,0 @@
package constants
import (
"testing"
"github.com/golang/mock/gomock"
"github.com/qdm12/gluetun/internal/storage"
"github.com/qdm12/golibs/logging/mock_logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_CyberghostGroupChoices(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
logger := mock_logging.NewMockLogger(ctrl)
logger.EXPECT().Info(gomock.Any())
storage, err := storage.New(logger, "")
require.NoError(t, err)
servers := storage.GetServers()
expected := []string{"NoSpy TCP Europe", "NoSpy UDP Europe",
"Premium TCP Europe", "Premium UDP Europe"}
choices := CyberghostGroupChoices(servers.GetCyberghost())
assert.Equal(t, expected, choices)
}

View File

@@ -18,7 +18,7 @@ func markdownTableHeading(legendFields ...string) (markdown string) {
} }
func (s *CyberghostServers) ToMarkdown() (markdown string) { func (s *CyberghostServers) ToMarkdown() (markdown string) {
markdown = markdownTableHeading("Country", "Group", "Hostname") markdown = markdownTableHeading("Country", "Hostname", "TCP", "UDP")
for _, server := range s.Servers { for _, server := range s.Servers {
markdown += server.ToMarkdown() + "\n" markdown += server.ToMarkdown() + "\n"
} }
@@ -26,7 +26,8 @@ func (s *CyberghostServers) ToMarkdown() (markdown string) {
} }
func (s CyberghostServer) ToMarkdown() (markdown string) { func (s CyberghostServer) ToMarkdown() (markdown string) {
return fmt.Sprintf("| %s | %s | `%s` |", s.Country, s.Group, s.Hostname) return fmt.Sprintf("| %s | `%s` | %s | %s |", s.Country, s.Hostname,
boolToMarkdown(s.TCP), boolToMarkdown(s.UDP))
} }
func (s *FastestvpnServers) ToMarkdown() (markdown string) { func (s *FastestvpnServers) ToMarkdown() (markdown string) {

View File

@@ -11,16 +11,16 @@ func Test_CyberghostServers_ToMarkdown(t *testing.T) {
servers := CyberghostServers{ servers := CyberghostServers{
Servers: []CyberghostServer{ Servers: []CyberghostServer{
{Country: "a", Group: "A", Hostname: "xa"}, {Country: "a", UDP: true, Hostname: "xa"},
{Country: "b", Group: "A", Hostname: "xb"}, {Country: "b", TCP: true, Hostname: "xb"},
}, },
} }
markdown := servers.ToMarkdown() markdown := servers.ToMarkdown()
const expected = "| Country | Group | Hostname |\n" + const expected = "| Country | Hostname | TCP | UDP |\n" +
"| --- | --- | --- |\n" + "| --- | --- | --- | --- |\n" +
"| a | A | `xa` |\n" + "| a | `xa` | ❎ | ✅ |\n" +
"| b | A | `xb` |\n" "| b | `xb` | ✅ | ❎ |\n"
assert.Equal(t, expected, markdown) assert.Equal(t, expected, markdown)
} }

View File

@@ -6,8 +6,9 @@ import (
type CyberghostServer struct { type CyberghostServer struct {
Country string `json:"country"` Country string `json:"country"`
Group string `json:"group"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
TCP bool `json:"tcp"`
UDP bool `json:"udp"`
IPs []net.IP `json:"ips"` IPs []net.IP `json:"ips"`
} }

View File

@@ -2,11 +2,8 @@ package cyberghost
import ( import (
"errors" "errors"
"fmt"
"strings"
"github.com/qdm12/gluetun/internal/configuration" "github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils" "github.com/qdm12/gluetun/internal/provider/utils"
) )
@@ -15,27 +12,10 @@ var ErrGroupMismatchesProtocol = errors.New("server group does not match protoco
func (c *Cyberghost) filterServers(selection configuration.ServerSelection) ( func (c *Cyberghost) filterServers(selection configuration.ServerSelection) (
servers []models.CyberghostServer, err error) { servers []models.CyberghostServer, err error) {
if len(selection.Groups) == 0 {
if selection.OpenVPN.TCP {
selection.Groups = tcpGroupChoices(c.servers)
} else {
selection.Groups = udpGroupChoices(c.servers)
}
}
// Check each group match the protocol
groupsCheckFn := groupsAreAllUDP
if selection.OpenVPN.TCP {
groupsCheckFn = groupsAreAllTCP
}
if err := groupsCheckFn(selection.Groups); err != nil {
return nil, err
}
for _, server := range c.servers { for _, server := range c.servers {
switch { switch {
case case
utils.FilterByPossibilities(server.Group, selection.Groups), utils.FilterByProtocol(selection, server.TCP, server.UDP),
utils.FilterByPossibilities(server.Country, selection.Countries), utils.FilterByPossibilities(server.Country, selection.Countries),
utils.FilterByPossibilities(server.Hostname, selection.Hostnames): utils.FilterByPossibilities(server.Hostname, selection.Hostnames):
default: default:
@@ -49,51 +29,3 @@ func (c *Cyberghost) filterServers(selection configuration.ServerSelection) (
return servers, nil return servers, nil
} }
func tcpGroupChoices(servers []models.CyberghostServer) (choices []string) {
const tcp = true
return groupsForTCP(servers, tcp)
}
func udpGroupChoices(servers []models.CyberghostServer) (choices []string) {
const tcp = false
return groupsForTCP(servers, tcp)
}
func groupsForTCP(servers []models.CyberghostServer, tcp bool) (choices []string) {
allGroups := constants.CyberghostGroupChoices(servers)
choices = make([]string, 0, len(allGroups))
for _, group := range allGroups {
switch {
case tcp && groupIsTCP(group):
choices = append(choices, group)
case !tcp && !groupIsTCP(group):
choices = append(choices, group)
}
}
return choices
}
func groupIsTCP(group string) bool {
return strings.Contains(strings.ToLower(group), "tcp")
}
func groupsAreAllTCP(groups []string) error {
for _, group := range groups {
if !groupIsTCP(group) {
return fmt.Errorf("%w: group %s for protocol TCP",
ErrGroupMismatchesProtocol, group)
}
}
return nil
}
func groupsAreAllUDP(groups []string) error {
for _, group := range groups {
if groupIsTCP(group) {
return fmt.Errorf("%w: group %s for protocol UDP",
ErrGroupMismatchesProtocol, group)
}
}
return nil
}

View File

@@ -25,22 +25,22 @@ func Test_Cyberghost_filterServers(t *testing.T) {
}, },
"servers without filter defaults to UDP": { "servers without filter defaults to UDP": {
servers: []models.CyberghostServer{ servers: []models.CyberghostServer{
{Country: "a", Group: "Premium TCP Asia"}, {Country: "a", TCP: true},
{Country: "b", Group: "Premium TCP Europe"}, {Country: "b", TCP: true},
{Country: "c", Group: "Premium UDP Asia"}, {Country: "c", UDP: true},
{Country: "d", Group: "Premium UDP Europe"}, {Country: "d", UDP: true},
}, },
filteredServers: []models.CyberghostServer{ filteredServers: []models.CyberghostServer{
{Country: "c", Group: "Premium UDP Asia"}, {Country: "c", UDP: true},
{Country: "d", Group: "Premium UDP Europe"}, {Country: "d", UDP: true},
}, },
}, },
"servers with TCP selection": { "servers with TCP selection": {
servers: []models.CyberghostServer{ servers: []models.CyberghostServer{
{Country: "a", Group: "Premium TCP Asia"}, {Country: "a", TCP: true},
{Country: "b", Group: "Premium TCP Europe"}, {Country: "b", TCP: true},
{Country: "c", Group: "Premium UDP Asia"}, {Country: "c", UDP: true},
{Country: "d", Group: "Premium UDP Europe"}, {Country: "d", UDP: true},
}, },
selection: configuration.ServerSelection{ selection: configuration.ServerSelection{
OpenVPN: configuration.OpenVPNSelection{ OpenVPN: configuration.OpenVPNSelection{
@@ -48,79 +48,37 @@ func Test_Cyberghost_filterServers(t *testing.T) {
}, },
}, },
filteredServers: []models.CyberghostServer{ filteredServers: []models.CyberghostServer{
{Country: "a", Group: "Premium TCP Asia"}, {Country: "a", TCP: true},
{Country: "b", Group: "Premium TCP Europe"}, {Country: "b", TCP: true},
}, },
}, },
"servers with regions filter": { "servers with regions filter": {
servers: []models.CyberghostServer{ servers: []models.CyberghostServer{
{Country: "a", Group: "Premium UDP Asia"}, {Country: "a", UDP: true},
{Country: "b", Group: "Premium UDP Asia"}, {Country: "b", UDP: true},
{Country: "c", Group: "Premium UDP Asia"}, {Country: "c", UDP: true},
{Country: "d", Group: "Premium UDP Asia"}, {Country: "d", UDP: true},
}, },
selection: configuration.ServerSelection{ selection: configuration.ServerSelection{
Countries: []string{"a", "c"}, Countries: []string{"a", "c"},
}, },
filteredServers: []models.CyberghostServer{ filteredServers: []models.CyberghostServer{
{Country: "a", Group: "Premium UDP Asia"}, {Country: "a", UDP: true},
{Country: "c", Group: "Premium UDP Asia"}, {Country: "c", UDP: true},
},
},
"servers with group filter": {
servers: []models.CyberghostServer{
{Country: "a", Group: "Premium UDP Europe"},
{Country: "b", Group: "Premium UDP Europe"},
{Country: "c", Group: "Premium TCP Europe"},
{Country: "d", Group: "Premium TCP Europe"},
},
selection: configuration.ServerSelection{
Groups: []string{"Premium UDP Europe"},
},
filteredServers: []models.CyberghostServer{
{Country: "a", Group: "Premium UDP Europe"},
{Country: "b", Group: "Premium UDP Europe"},
},
},
"servers with bad group filter": {
servers: []models.CyberghostServer{
{Country: "a", Group: "Premium TCP Europe"},
{Country: "b", Group: "Premium TCP Europe"},
{Country: "c", Group: "Premium UDP Europe"},
{Country: "d", Group: "Premium UDP Europe"},
},
selection: configuration.ServerSelection{
Groups: []string{"Premium TCP Europe"},
},
err: errors.New("server group does not match protocol: group Premium TCP Europe for protocol UDP"),
},
"servers with regions and group filter": {
servers: []models.CyberghostServer{
{Country: "a", Group: "Premium UDP Europe"},
{Country: "b", Group: "Premium TCP Europe"},
{Country: "c", Group: "Premium UDP Asia"},
{Country: "d", Group: "Premium TCP Asia"},
},
selection: configuration.ServerSelection{
Countries: []string{"a", "c"},
Groups: []string{"Premium UDP Europe"},
},
filteredServers: []models.CyberghostServer{
{Country: "a", Group: "Premium UDP Europe"},
}, },
}, },
"servers with hostnames filter": { "servers with hostnames filter": {
servers: []models.CyberghostServer{ servers: []models.CyberghostServer{
{Hostname: "a", Group: "Premium UDP Asia"}, {Hostname: "a", UDP: true},
{Hostname: "b", Group: "Premium UDP Asia"}, {Hostname: "b", UDP: true},
{Hostname: "c", Group: "Premium UDP Asia"}, {Hostname: "c", UDP: true},
}, },
selection: configuration.ServerSelection{ selection: configuration.ServerSelection{
Hostnames: []string{"a", "c"}, Hostnames: []string{"a", "c"},
}, },
filteredServers: []models.CyberghostServer{ filteredServers: []models.CyberghostServer{
{Hostname: "a", Group: "Premium UDP Asia"}, {Hostname: "a", UDP: true},
{Hostname: "c", Group: "Premium UDP Asia"}, {Hostname: "c", UDP: true},
}, },
}, },
} }
@@ -142,41 +100,3 @@ func Test_Cyberghost_filterServers(t *testing.T) {
}) })
} }
} }
func Test_tcpGroupChoices(t *testing.T) {
t.Parallel()
servers := []models.CyberghostServer{
{Group: "Premium TCP Asia"},
{Group: "Premium TCP Europe"},
{Group: "Premium TCP USA"},
{Group: "Premium UDP Asia"},
{Group: "Premium UDP Europe"},
{Group: "Premium UDP USA"},
}
expected := []string{
"Premium TCP Asia", "Premium TCP Europe", "Premium TCP USA",
}
choices := tcpGroupChoices(servers)
assert.Equal(t, expected, choices)
}
func Test_udpGroupChoices(t *testing.T) {
t.Parallel()
servers := []models.CyberghostServer{
{Group: "Premium TCP Asia"},
{Group: "Premium TCP Europe"},
{Group: "Premium TCP USA"},
{Group: "Premium UDP Asia"},
{Group: "Premium UDP Europe"},
{Group: "Premium UDP USA"},
}
expected := []string{
"Premium UDP Asia", "Premium UDP Europe", "Premium UDP USA",
}
choices := udpGroupChoices(servers)
assert.Equal(t, expected, choices)
}

View File

@@ -27,16 +27,6 @@ func NoServerFoundError(selection configuration.ServerSelection) (err error) {
} }
messageParts = append(messageParts, "protocol "+protocol) messageParts = append(messageParts, "protocol "+protocol)
switch len(selection.Groups) {
case 0:
case 1:
part := "group " + selection.Groups[0]
messageParts = append(messageParts, part)
default:
part := "groups " + commaJoin(selection.Groups)
messageParts = append(messageParts, part)
}
switch len(selection.Countries) { switch len(selection.Countries) {
case 0: case 0:
case 1: case 1:

View File

@@ -51,7 +51,7 @@ func Test_versions(t *testing.T) {
"Cyberghost": { "Cyberghost": {
model: models.CyberghostServer{}, model: models.CyberghostServer{},
version: allServers.Cyberghost.Version, version: allServers.Cyberghost.Version,
digest: "c2f6f43b", digest: "9ce64729",
}, },
"Fastestvpn": { "Fastestvpn": {
model: models.FastestvpnServer{}, model: models.FastestvpnServer{},

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,17 @@
package cyberghost package cyberghost
func getGroups() map[string]string { import "github.com/qdm12/gluetun/internal/constants"
func getGroupIDToProtocol() map[string]string {
return map[string]string{ return map[string]string{
"87-1": "Premium UDP Europe", "87-1": constants.UDP, // Premium UDP Europe
"94-1": "Premium UDP USA", "94-1": constants.UDP, // Premium UDP USA
"95-1": "Premium UDP Asia", "95-1": constants.UDP, // Premium UDP Asia
"87-8": "NoSpy UDP Europe", "87-8": constants.UDP, // NoSpy UDP Europe
"97-1": "Premium TCP Europe", "97-1": constants.TCP, // Premium TCP Europe
"93-1": "Premium TCP USA", "93-1": constants.TCP, // Premium TCP USA
"96-1": "Premium TCP Asia", "96-1": constants.TCP, // Premium TCP Asia
"97-8": "NoSpy TCP Europe", "97-8": constants.TCP, // NoSpy TCP Europe
} }
} }

View File

@@ -10,24 +10,25 @@ import (
type hostToServer map[string]models.CyberghostServer type hostToServer map[string]models.CyberghostServer
func getPossibleServers() (possibleServers hostToServer) { func getPossibleServers() (possibleServers hostToServer) {
groups := getGroups() groupIDToProtocol := getGroupIDToProtocol()
cyberghostCountryCodes := getSubdomainToRegion() cyberghostCountryCodes := getSubdomainToRegion()
allCountryCodes := constants.CountryCodes() allCountryCodes := constants.CountryCodes()
possibleCountryCodes := mergeCountryCodes(cyberghostCountryCodes, allCountryCodes) possibleCountryCodes := mergeCountryCodes(cyberghostCountryCodes, allCountryCodes)
n := len(groups) * len(possibleCountryCodes) n := len(groupIDToProtocol) * len(possibleCountryCodes)
possibleServers = make(hostToServer, n) // key is the host possibleServers = make(hostToServer, n) // key is the host
for groupID, groupName := range groups { for groupID, protocol := range groupIDToProtocol {
for countryCode, country := range possibleCountryCodes { for countryCode, country := range possibleCountryCodes {
const domain = "cg-dialup.net" const domain = "cg-dialup.net"
possibleHost := groupID + "-" + countryCode + "." + domain possibleHost := groupID + "-" + countryCode + "." + domain
possibleServer := models.CyberghostServer{ possibleServer := models.CyberghostServer{
Hostname: possibleHost, Hostname: possibleHost,
Country: country, Country: country,
Group: groupName, TCP: protocol == constants.TCP,
UDP: protocol == constants.UDP,
} }
possibleServers[possibleHost] = possibleServer possibleServers[possibleHost] = possibleServer
} }

View File

@@ -9,11 +9,8 @@ import (
func sortServers(servers []models.CyberghostServer) { func sortServers(servers []models.CyberghostServer) {
sort.Slice(servers, func(i, j int) bool { sort.Slice(servers, func(i, j int) bool {
if servers[i].Country == servers[j].Country { if servers[i].Country == servers[j].Country {
if servers[i].Group == servers[j].Group {
return servers[i].Hostname < servers[j].Hostname return servers[i].Hostname < servers[j].Hostname
} }
return servers[i].Group < servers[j].Group
}
return servers[i].Country < servers[j].Country return servers[i].Country < servers[j].Country
}) })
} }