Maintenance: split each provider in a package
- Fix VyprVPN port - Fix missing Auth overrides
This commit is contained in:
41
internal/provider/protonvpn/connection.go
Normal file
41
internal/provider/protonvpn/connection.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package protonvpn
|
||||
|
||||
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 (p *Protonvpn) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
port, err := getPort(selection.TCP, selection.CustomPort)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
servers, err := p.filterServers(selection)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
connections := make([]models.OpenVPNConnection, len(servers))
|
||||
for i := range servers {
|
||||
connections[i] = models.OpenVPNConnection{
|
||||
IP: servers[i].EntryIP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
}
|
||||
}
|
||||
|
||||
if selection.TargetIP != nil {
|
||||
return utils.GetTargetIPConnection(connections, selection.TargetIP)
|
||||
}
|
||||
|
||||
return utils.PickRandomConnection(connections, p.randSource), nil
|
||||
}
|
||||
29
internal/provider/protonvpn/filter.go
Normal file
29
internal/provider/protonvpn/filter.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Protonvpn) filterServers(selection configuration.ServerSelection) (
|
||||
servers []models.ProtonvpnServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
case
|
||||
utils.FilterByPossibilities(server.Country, selection.Countries),
|
||||
utils.FilterByPossibilities(server.Region, selection.Regions),
|
||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
utils.FilterByPossibilities(server.Name, selection.Names):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
|
||||
if len(servers) == 0 {
|
||||
return nil, utils.NoServerFoundError(selection)
|
||||
}
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
74
internal/provider/protonvpn/openvpnconf.go
Normal file
74
internal/provider/protonvpn/openvpnconf.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"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 (p *Protonvpn) BuildConf(connection models.OpenVPNConnection,
|
||||
username string, settings configuration.OpenVPN) (lines []string) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
}
|
||||
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
}
|
||||
|
||||
const defaultMSSFix = 1450
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = defaultMSSFix
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
"client",
|
||||
"dev tun",
|
||||
"nobind",
|
||||
"persist-key",
|
||||
"remote-cert-tls server",
|
||||
"tls-exit",
|
||||
|
||||
// Protonvpn specific
|
||||
"tun-mtu 1500",
|
||||
"tun-mtu-extra 32",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"reneg-sec 0",
|
||||
"fast-io",
|
||||
"key-direction 1",
|
||||
"pull",
|
||||
"comp-lzo no",
|
||||
|
||||
// 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 !settings.Root {
|
||||
lines = append(lines, "user "+username)
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
constants.ProtonvpnCertificate)...)
|
||||
lines = append(lines, utils.WrapOpenvpnTLSAuth(
|
||||
constants.ProtonvpnOpenvpnStaticKeyV1)...)
|
||||
|
||||
lines = append(lines, "")
|
||||
|
||||
return lines
|
||||
}
|
||||
41
internal/provider/protonvpn/port.go
Normal file
41
internal/provider/protonvpn/port.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func getPort(tcp bool, customPort uint16) (port uint16, err error) {
|
||||
if customPort == 0 {
|
||||
const defaultTCPPort, defaultUDPPort = 443, 1194
|
||||
if tcp {
|
||||
return defaultTCPPort, nil
|
||||
}
|
||||
return defaultUDPPort, nil
|
||||
}
|
||||
|
||||
if err := checkPort(customPort, tcp); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return customPort, nil
|
||||
}
|
||||
|
||||
var ErrInvalidPort = errors.New("invalid port number")
|
||||
|
||||
func checkPort(port uint16, tcp bool) (err error) {
|
||||
if tcp {
|
||||
switch port {
|
||||
case 443, 5995, 8443: //nolint:gomnd
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%w: %d for protocol TCP", ErrInvalidPort, port)
|
||||
}
|
||||
}
|
||||
switch port {
|
||||
case 80, 443, 1194, 4569, 5060: //nolint:gomnd
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%w: %d for protocol UDP", ErrInvalidPort, port)
|
||||
}
|
||||
}
|
||||
17
internal/provider/protonvpn/portforward.go
Normal file
17
internal/provider/protonvpn/portforward.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"github.com/qdm12/golibs/os"
|
||||
)
|
||||
|
||||
func (p *Protonvpn) 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 ProtonVPN")
|
||||
}
|
||||
19
internal/provider/protonvpn/provider.go
Normal file
19
internal/provider/protonvpn/provider.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package protonvpn
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type Protonvpn struct {
|
||||
servers []models.ProtonvpnServer
|
||||
randSource rand.Source
|
||||
}
|
||||
|
||||
func New(servers []models.ProtonvpnServer, randSource rand.Source) *Protonvpn {
|
||||
return &Protonvpn{
|
||||
servers: servers,
|
||||
randSource: randSource,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user