Feature: Protonvpn filter servers with FREE_ONLY
This commit is contained in:
@@ -99,6 +99,8 @@ ENV VPNSP=pia \
|
|||||||
SERVER_NUMBER= \
|
SERVER_NUMBER= \
|
||||||
# NordVPN and ProtonVPN only:
|
# NordVPN and ProtonVPN only:
|
||||||
SERVER_NAME= \
|
SERVER_NAME= \
|
||||||
|
# ProtonVPN only:
|
||||||
|
FREE_ONLY= \
|
||||||
# Openvpn
|
# Openvpn
|
||||||
OPENVPN_CIPHER= \
|
OPENVPN_CIPHER= \
|
||||||
OPENVPN_AUTH= \
|
OPENVPN_AUTH= \
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ func Test_OpenVPN_JSON(t *testing.T) {
|
|||||||
"owned": false,
|
"owned": false,
|
||||||
"custom_port": 0,
|
"custom_port": 0,
|
||||||
"numbers": null,
|
"numbers": null,
|
||||||
"encryption_preset": ""
|
"encryption_preset": "",
|
||||||
|
"free_only": false
|
||||||
},
|
},
|
||||||
"extra_config": {
|
"extra_config": {
|
||||||
"encryption_preset": "",
|
"encryption_preset": "",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package configuration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/golibs/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (settings *Provider) protonvpnLines() (lines []string) {
|
func (settings *Provider) protonvpnLines() (lines []string) {
|
||||||
@@ -25,6 +26,10 @@ func (settings *Provider) protonvpnLines() (lines []string) {
|
|||||||
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
|
lines = append(lines, lastIndent+"Hostnames: "+commaJoin(settings.ServerSelection.Hostnames))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if settings.ServerSelection.FreeOnly {
|
||||||
|
lines = append(lines, lastIndent+"Free only: yes")
|
||||||
|
}
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,5 +76,10 @@ func (settings *Provider) readProtonvpn(r reader) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings.ServerSelection.FreeOnly, err = r.env.YesNo("FREE_ONLY", params.Default("no"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ type ServerSelection struct { //nolint:maligned
|
|||||||
|
|
||||||
// PIA
|
// PIA
|
||||||
EncryptionPreset string `json:"encryption_preset"`
|
EncryptionPreset string `json:"encryption_preset"`
|
||||||
|
|
||||||
|
// ProtonVPN
|
||||||
|
FreeOnly bool `json:"free_only"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExtraConfigOptions struct {
|
type ExtraConfigOptions struct {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package protonvpn
|
package protonvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration"
|
"github.com/qdm12/gluetun/internal/configuration"
|
||||||
"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,7 +17,8 @@ func (p *Protonvpn) filterServers(selection configuration.ServerSelection) (
|
|||||||
utils.FilterByPossibilities(server.Region, selection.Regions),
|
utils.FilterByPossibilities(server.Region, selection.Regions),
|
||||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||||
utils.FilterByPossibilities(server.Name, selection.Names):
|
utils.FilterByPossibilities(server.Name, selection.Names),
|
||||||
|
selection.FreeOnly && !strings.Contains(strings.ToLower(server.Name), "free"):
|
||||||
default:
|
default:
|
||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ func NoServerFoundError(selection configuration.ServerSelection) (err error) {
|
|||||||
messageParts = append(messageParts, part)
|
messageParts = append(messageParts, part)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if selection.FreeOnly {
|
||||||
|
messageParts = append(messageParts, "free tier only")
|
||||||
|
}
|
||||||
|
|
||||||
message := "for " + strings.Join(messageParts, "; ")
|
message := "for " + strings.Join(messageParts, "; ")
|
||||||
|
|
||||||
return fmt.Errorf("%w: %s", ErrNoServerFound, message)
|
return fmt.Errorf("%w: %s", ErrNoServerFound, message)
|
||||||
|
|||||||
Reference in New Issue
Block a user