mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-18 01:14:10 +02:00
initial code
This commit is contained in:
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -122,6 +123,10 @@ func filterServer(server models.Server,
|
||||
return true
|
||||
}
|
||||
|
||||
if filterByPorts(selection, server.PortsTCP) {
|
||||
return true
|
||||
}
|
||||
|
||||
// TODO filter port forward server for PIA
|
||||
|
||||
return false
|
||||
@@ -165,3 +170,21 @@ func filterByProtocol(selection settings.ServerSelection,
|
||||
return (wantTCP && !serverTCP) || (wantUDP && !serverUDP)
|
||||
}
|
||||
}
|
||||
|
||||
func filterByPorts(selection settings.ServerSelection,
|
||||
serverPorts []uint16,
|
||||
) (filtered bool) {
|
||||
if len(serverPorts) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
customPort := *selection.OpenVPN.CustomPort
|
||||
if selection.VPN == vpn.Wireguard {
|
||||
customPort = *selection.Wireguard.EndpointPort
|
||||
}
|
||||
if customPort == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return !slices.Contains(serverPorts, customPort)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func commaJoin(slice []string) string {
|
||||
return strings.Join(slice, ", ")
|
||||
}
|
||||
|
||||
func noServerFoundError(selection settings.ServerSelection) (err error) {
|
||||
func noServerFoundError(selection settings.ServerSelection) (err error) { //nolint:gocyclo
|
||||
var messageParts []string
|
||||
|
||||
messageParts = append(messageParts, "VPN "+selection.VPN)
|
||||
@@ -155,6 +155,15 @@ func noServerFoundError(selection settings.ServerSelection) (err error) {
|
||||
"target ip address "+targetIP.String())
|
||||
}
|
||||
|
||||
customPort := *selection.OpenVPN.CustomPort
|
||||
if selection.VPN == vpn.Wireguard {
|
||||
customPort = *selection.Wireguard.EndpointPort
|
||||
}
|
||||
if customPort > 0 {
|
||||
messageParts = append(messageParts,
|
||||
fmt.Sprintf("%s endpoint port %d", selection.VPN, customPort))
|
||||
}
|
||||
|
||||
message := "for " + strings.Join(messageParts, "; ")
|
||||
|
||||
return fmt.Errorf("no server found: %s", message)
|
||||
|
||||
@@ -26,10 +26,14 @@ func parseHardcodedServers() (allServers models.AllServers) {
|
||||
}
|
||||
|
||||
for provider, metadata := range allServers.ProviderToServers {
|
||||
if metadata.Filepath == "" {
|
||||
panic(fmt.Sprintf("embedded manifest file servers.json should have the filepath field set for %s", provider))
|
||||
}
|
||||
filename := path.Base(metadata.Filepath)
|
||||
providerFile, err := serversmodule.Files.Open(filename)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("reading embedded provider file %s for %s: %s", filename, provider, err))
|
||||
const rootURL = "https://github.com/qdm12/gluetun-servers/blob/main/pkg/servers"
|
||||
panic(fmt.Sprintf("reading embedded provider file defined at %s/%s.json: %s", rootURL, filename, err))
|
||||
}
|
||||
defer providerFile.Close() // no-op
|
||||
|
||||
|
||||
@@ -33,7 +33,10 @@ func Test_parseHardcodedServers(t *testing.T) {
|
||||
func Test_parseHardcodedServers_filepathsAndEmbeddedProviderFiles(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
hardcodedServers := parseHardcodedServers()
|
||||
var hardcodedServers models.AllServers
|
||||
require.NotPanics(t, func() {
|
||||
hardcodedServers = parseHardcodedServers()
|
||||
})
|
||||
|
||||
allProviders := providers.All()
|
||||
for _, provider := range allProviders {
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
"nordvpn": {
|
||||
"filepath": "/gluetun/servers/nordvpn.json"
|
||||
},
|
||||
"ovpn": {
|
||||
"filepath": "/gluetun/servers/ovpn.json"
|
||||
},
|
||||
"perfect privacy": {
|
||||
"filepath": "/gluetun/servers/perfect privacy.json"
|
||||
},
|
||||
@@ -69,4 +72,4 @@
|
||||
"windscribe": {
|
||||
"filepath": "/gluetun/servers/windscribe.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user