Files
gluetun/internal/configuration/selection.go

96 lines
2.5 KiB
Go
Raw Normal View History

2021-02-06 11:05:50 -05:00
package configuration
import (
"fmt"
2021-02-06 11:05:50 -05:00
"net"
"github.com/qdm12/golibs/params"
2021-02-06 11:05:50 -05:00
)
type ServerSelection struct { //nolint:maligned
2021-02-06 11:05:50 -05:00
// Common
2021-02-06 18:31:14 +00:00
TargetIP net.IP `json:"target_ip,omitempty"`
// TODO comments
// Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN
2021-02-06 11:05:50 -05:00
Regions []string `json:"regions"`
// Cyberghost
Groups []string `json:"groups"`
2021-02-06 11:05:50 -05:00
// Fastestvpn, HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited
Countries []string `json:"countries"`
// HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited, Windscribe
Cities []string `json:"cities"`
// Fastestvpn, HideMyAss, IPVanish, IVPN, PrivateVPN, Windscribe, Privado, Protonvpn, VPNUnlimited
Hostnames []string `json:"hostnames"`
Names []string `json:"names"` // Protonvpn
2021-02-06 11:05:50 -05:00
// Mullvad
ISPs []string `json:"isps"`
Owned bool `json:"owned"`
// NordVPN
Numbers []uint16 `json:"numbers"`
// ProtonVPN
FreeOnly bool `json:"free_only"`
// VPNUnlimited
StreamOnly bool `json:"stream_only"`
OpenVPN OpenVPNSelection `json:"openvpn"`
}
type OpenVPNSelection struct {
TCP bool `json:"tcp"` // UDP if TCP is false
CustomPort uint16 `json:"custom_port"` // HideMyAss, Mullvad, PIA, ProtonVPN, Windscribe
EncPreset string `json:"encryption_preset"` // PIA - needed to get the port number
}
func (settings *OpenVPNSelection) lines() (lines []string) {
lines = append(lines, lastIndent+"OpenVPN selection:")
lines = append(lines, indent+lastIndent+"Protocol: "+protoToString(settings.TCP))
if settings.CustomPort != 0 {
lines = append(lines, indent+lastIndent+"Custom port: "+fmt.Sprint(settings.CustomPort))
}
if settings.EncPreset != "" {
lines = append(lines, indent+lastIndent+"PIA encryption preset: "+settings.EncPreset)
}
return lines
}
func (settings *OpenVPNSelection) readProtocolOnly(env params.Env) (err error) {
settings.TCP, err = readProtocol(env)
return err
}
func (settings *OpenVPNSelection) readProtocolAndPort(env params.Env) (err error) {
settings.TCP, err = readProtocol(env)
if err != nil {
return err
}
settings.CustomPort, err = readPortOrZero(env, "PORT")
if err != nil {
return fmt.Errorf("environment variable PORT: %w", err)
}
return nil
2021-02-06 11:05:50 -05:00
}
// PortForwarding contains settings for port forwarding.
type PortForwarding struct {
2021-02-06 18:31:14 +00:00
Enabled bool `json:"enabled"`
Filepath string `json:"filepath"`
2021-02-06 11:05:50 -05:00
}
func (p *PortForwarding) lines() (lines []string) {
return []string{
2021-02-06 18:31:14 +00:00
lastIndent + "File path: " + p.Filepath,
2021-02-06 11:05:50 -05:00
}
}