* OWNED environment variable for Mullvad * CSV are now accepted for all servers filtering environment variables
This commit is contained in:
@@ -27,16 +27,13 @@ func newCyberghost(servers []models.CyberghostServer, timeNow timeNowFunc) *cybe
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cyberghost) filterServers(region, group string) (servers []models.CyberghostServer) {
|
||||
for i, server := range c.servers {
|
||||
if len(region) == 0 {
|
||||
server.Region = ""
|
||||
}
|
||||
if len(group) == 0 {
|
||||
server.Group = ""
|
||||
}
|
||||
if strings.EqualFold(server.Region, region) && strings.EqualFold(server.Group, group) {
|
||||
servers = append(servers, c.servers[i])
|
||||
func (c *cyberghost) filterServers(regions []string, group string) (servers []models.CyberghostServer) {
|
||||
for _, server := range c.servers {
|
||||
switch {
|
||||
case len(group) > 0 && group != server.Group,
|
||||
filterByPossibilities(server.Region, regions):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return servers
|
||||
@@ -47,9 +44,9 @@ func (c *cyberghost) GetOpenVPNConnection(selection models.ServerSelection) (con
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: 443, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := c.filterServers(selection.Region, selection.Group)
|
||||
servers := c.filterServers(selection.Regions, selection.Group)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q and group %q", selection.Region, selection.Group)
|
||||
return connection, fmt.Errorf("no server found for regions %s and group %q", commaJoin(selection.Regions), selection.Group)
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
@@ -27,21 +26,16 @@ func newMullvad(servers []models.MullvadServer, timeNow timeNowFunc) *mullvad {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mullvad) filterServers(country, city, isp string) (servers []models.MullvadServer) {
|
||||
for i, server := range m.servers {
|
||||
if len(country) == 0 {
|
||||
server.Country = ""
|
||||
}
|
||||
if len(city) == 0 {
|
||||
server.City = ""
|
||||
}
|
||||
if len(isp) == 0 {
|
||||
server.ISP = ""
|
||||
}
|
||||
if strings.EqualFold(server.Country, country) &&
|
||||
strings.EqualFold(server.City, city) &&
|
||||
strings.EqualFold(server.ISP, isp) {
|
||||
servers = append(servers, m.servers[i])
|
||||
func (m *mullvad) filterServers(countries, cities, isps []string, owned bool) (servers []models.MullvadServer) {
|
||||
for _, server := range m.servers {
|
||||
switch {
|
||||
case
|
||||
filterByPossibilities(server.Country, countries),
|
||||
filterByPossibilities(server.City, cities),
|
||||
filterByPossibilities(server.ISP, isps),
|
||||
owned && !server.Owned:
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return servers
|
||||
@@ -61,9 +55,10 @@ func (m *mullvad) GetOpenVPNConnection(selection models.ServerSelection) (connec
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := m.filterServers(selection.Country, selection.City, selection.ISP)
|
||||
servers := m.filterServers(selection.Countries, selection.Cities, selection.ISPs, selection.Owned)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for country %q, city %q and ISP %q", selection.Country, selection.City, selection.ISP)
|
||||
return connection, fmt.Errorf("no server found for countries %s, cities %s, ISPs %s and owned %t",
|
||||
commaJoin(selection.Countries), commaJoin(selection.Cities), commaJoin(selection.ISPs), selection.Owned)
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
@@ -27,22 +26,21 @@ func newNordvpn(servers []models.NordvpnServer, timeNow timeNowFunc) *nordvpn {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *nordvpn) filterServers(region string, protocol models.NetworkProtocol, number uint16) (servers []models.NordvpnServer) {
|
||||
for i, server := range n.servers {
|
||||
if len(region) == 0 {
|
||||
server.Region = ""
|
||||
}
|
||||
if number == 0 {
|
||||
server.Number = 0
|
||||
}
|
||||
|
||||
if protocol == constants.TCP && !server.TCP {
|
||||
continue
|
||||
} else if protocol == constants.UDP && !server.UDP {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(server.Region, region) && server.Number == number {
|
||||
servers = append(servers, n.servers[i])
|
||||
func (n *nordvpn) filterServers(regions []string, protocol models.NetworkProtocol, numbers []uint16) (servers []models.NordvpnServer) {
|
||||
numbersStr := make([]string, len(numbers))
|
||||
for i := range numbers {
|
||||
numbersStr[i] = fmt.Sprintf("%d", numbers[i])
|
||||
}
|
||||
for _, server := range n.servers {
|
||||
numberStr := fmt.Sprintf("%d", server.Number)
|
||||
switch {
|
||||
case
|
||||
protocol == constants.TCP && !server.TCP,
|
||||
protocol == constants.UDP && !server.UDP,
|
||||
filterByPossibilities(server.Region, regions),
|
||||
filterByPossibilities(numberStr, numbersStr):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return servers
|
||||
@@ -63,9 +61,9 @@ func (n *nordvpn) GetOpenVPNConnection(selection models.ServerSelection) (connec
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := n.filterServers(selection.Region, selection.Protocol, selection.Number)
|
||||
servers := n.filterServers(selection.Regions, selection.Protocol, selection.Numbers)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q, protocol %s and number %d", selection.Region, selection.Protocol, selection.Number)
|
||||
return connection, fmt.Errorf("no server found for region %s, protocol %s and numbers %v", commaJoin(selection.Regions), selection.Protocol, selection.Numbers)
|
||||
}
|
||||
|
||||
connections := make([]models.OpenVPNConnection, len(servers))
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
@@ -57,9 +56,9 @@ func (p *piaV3) GetOpenVPNConnection(selection models.ServerSelection) (connecti
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := filterPIAOldServers(p.servers, selection.Region)
|
||||
servers := filterPIAOldServers(p.servers, selection.Regions)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q", selection.Region)
|
||||
return connection, fmt.Errorf("no server found for regions %s", commaJoin(selection.Regions))
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
@@ -136,14 +135,13 @@ func (p *piaV3) PortForward(ctx context.Context, client *http.Client,
|
||||
}
|
||||
}
|
||||
|
||||
func filterPIAOldServers(servers []models.PIAOldServer, region string) (filtered []models.PIAOldServer) {
|
||||
if len(region) == 0 {
|
||||
return servers
|
||||
}
|
||||
func filterPIAOldServers(servers []models.PIAOldServer, regions []string) (filtered []models.PIAOldServer) {
|
||||
for _, server := range servers {
|
||||
if strings.EqualFold(server.Region, region) {
|
||||
return []models.PIAOldServer{server}
|
||||
switch {
|
||||
case filterByPossibilities(server.Region, regions):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return servers
|
||||
}
|
||||
|
||||
@@ -66,9 +66,9 @@ func (p *piaV4) GetOpenVPNConnection(selection models.ServerSelection) (connecti
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := filterPIAServers(p.servers, selection.Region)
|
||||
servers := filterPIAServers(p.servers, selection.Regions)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q", selection.Region)
|
||||
return connection, fmt.Errorf("no server found for region %s", commaJoin(selection.Regions))
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
@@ -246,16 +246,15 @@ func (p *piaV4) PortForward(ctx context.Context, client *http.Client,
|
||||
}
|
||||
}
|
||||
|
||||
func filterPIAServers(servers []models.PIAServer, region string) (filtered []models.PIAServer) {
|
||||
if len(region) == 0 {
|
||||
return servers
|
||||
}
|
||||
func filterPIAServers(servers []models.PIAServer, regions []string) (filtered []models.PIAServer) {
|
||||
for _, server := range servers {
|
||||
if strings.EqualFold(server.Region, region) {
|
||||
return []models.PIAServer{server}
|
||||
switch {
|
||||
case filterByPossibilities(server.Region, regions):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return servers
|
||||
}
|
||||
|
||||
func newPIAv4HTTPClient(serverName string) (client *http.Client, err error) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
@@ -27,21 +26,15 @@ func newPurevpn(servers []models.PurevpnServer, timeNow timeNowFunc) *purevpn {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *purevpn) filterServers(region, country, city string) (servers []models.PurevpnServer) {
|
||||
for i, server := range p.servers {
|
||||
if len(region) == 0 {
|
||||
server.Region = ""
|
||||
}
|
||||
if len(country) == 0 {
|
||||
server.Country = ""
|
||||
}
|
||||
if len(city) == 0 {
|
||||
server.City = ""
|
||||
}
|
||||
if strings.EqualFold(server.Region, region) &&
|
||||
strings.EqualFold(server.Country, country) &&
|
||||
strings.EqualFold(server.City, city) {
|
||||
servers = append(servers, p.servers[i])
|
||||
func (p *purevpn) filterServers(regions, countries, cities []string) (servers []models.PurevpnServer) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
case
|
||||
filterByPossibilities(server.Region, regions),
|
||||
filterByPossibilities(server.Country, countries),
|
||||
filterByPossibilities(server.City, cities):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return servers
|
||||
@@ -62,9 +55,10 @@ func (p *purevpn) GetOpenVPNConnection(selection models.ServerSelection) (connec
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := p.filterServers(selection.Region, selection.Country, selection.City)
|
||||
servers := p.filterServers(selection.Regions, selection.Countries, selection.Cities)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q, country %q and city %q", selection.Region, selection.Country, selection.City)
|
||||
return connection, fmt.Errorf("no server found for regions %s, countries %s and cities %s",
|
||||
commaJoin(selection.Regions), commaJoin(selection.Countries), commaJoin(selection.Cities))
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
@@ -27,16 +26,16 @@ func newSurfshark(servers []models.SurfsharkServer, timeNow timeNowFunc) *surfsh
|
||||
}
|
||||
}
|
||||
|
||||
func (s *surfshark) filterServers(region string) (servers []models.SurfsharkServer) {
|
||||
if len(region) == 0 {
|
||||
return s.servers
|
||||
}
|
||||
func (s *surfshark) filterServers(regions []string) (servers []models.SurfsharkServer) {
|
||||
for _, server := range s.servers {
|
||||
if strings.EqualFold(server.Region, region) {
|
||||
return []models.SurfsharkServer{server}
|
||||
switch {
|
||||
case
|
||||
filterByPossibilities(server.Region, regions):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return servers
|
||||
}
|
||||
|
||||
func (s *surfshark) GetOpenVPNConnection(selection models.ServerSelection) (connection models.OpenVPNConnection, err error) { //nolint:dupl
|
||||
@@ -54,9 +53,9 @@ func (s *surfshark) GetOpenVPNConnection(selection models.ServerSelection) (conn
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := s.filterServers(selection.Region)
|
||||
servers := s.filterServers(selection.Regions)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q", selection.Region)
|
||||
return connection, fmt.Errorf("no server found for region %s", commaJoin(selection.Regions))
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
|
||||
@@ -3,6 +3,7 @@ package provider
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
@@ -35,3 +36,19 @@ func tryUntilSuccessful(ctx context.Context, logger logging.Logger, fn func() er
|
||||
func pickRandomConnection(connections []models.OpenVPNConnection, source rand.Source) models.OpenVPNConnection {
|
||||
return connections[rand.New(source).Intn(len(connections))] //nolint:gosec
|
||||
}
|
||||
|
||||
func filterByPossibilities(value string, possibilities []string) (filtered bool) {
|
||||
if len(possibilities) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, possibility := range possibilities {
|
||||
if strings.EqualFold(value, possibility) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func commaJoin(slice []string) string {
|
||||
return strings.Join(slice, ",")
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
@@ -27,16 +26,16 @@ func newVyprvpn(servers []models.VyprvpnServer, timeNow timeNowFunc) *vyprvpn {
|
||||
}
|
||||
}
|
||||
|
||||
func (v *vyprvpn) filterServers(region string) (servers []models.VyprvpnServer) {
|
||||
if len(region) == 0 {
|
||||
return v.servers
|
||||
}
|
||||
func (v *vyprvpn) filterServers(regions []string) (servers []models.VyprvpnServer) {
|
||||
for _, server := range v.servers {
|
||||
if strings.EqualFold(server.Region, region) {
|
||||
return []models.VyprvpnServer{server}
|
||||
switch {
|
||||
case
|
||||
filterByPossibilities(server.Region, regions):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return servers
|
||||
}
|
||||
|
||||
func (v *vyprvpn) GetOpenVPNConnection(selection models.ServerSelection) (connection models.OpenVPNConnection, err error) {
|
||||
@@ -54,9 +53,9 @@ func (v *vyprvpn) GetOpenVPNConnection(selection models.ServerSelection) (connec
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := v.filterServers(selection.Region)
|
||||
servers := v.filterServers(selection.Regions)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q", selection.Region)
|
||||
return connection, fmt.Errorf("no server found for region %s", commaJoin(selection.Regions))
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
|
||||
@@ -27,16 +27,16 @@ func newWindscribe(servers []models.WindscribeServer, timeNow timeNowFunc) *wind
|
||||
}
|
||||
}
|
||||
|
||||
func (w *windscribe) filterServers(region string) (servers []models.WindscribeServer) {
|
||||
if len(region) == 0 {
|
||||
return w.servers
|
||||
}
|
||||
func (w *windscribe) filterServers(regions []string) (servers []models.WindscribeServer) {
|
||||
for _, server := range w.servers {
|
||||
if strings.EqualFold(server.Region, region) {
|
||||
return []models.WindscribeServer{server}
|
||||
switch {
|
||||
case
|
||||
filterByPossibilities(server.Region, regions):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return servers
|
||||
}
|
||||
|
||||
func (w *windscribe) GetOpenVPNConnection(selection models.ServerSelection) (connection models.OpenVPNConnection, err error) {
|
||||
@@ -56,9 +56,9 @@ func (w *windscribe) GetOpenVPNConnection(selection models.ServerSelection) (con
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := w.filterServers(selection.Region)
|
||||
servers := w.filterServers(selection.Regions)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q", selection.Region)
|
||||
return connection, fmt.Errorf("no server found for region %s", commaJoin(selection.Regions))
|
||||
}
|
||||
|
||||
var connections []models.OpenVPNConnection
|
||||
|
||||
Reference in New Issue
Block a user