2021-02-06 11:05:50 -05:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
|
|
import (
|
2021-08-17 16:54:22 +00:00
|
|
|
"fmt"
|
2021-02-06 11:05:50 -05:00
|
|
|
"net"
|
2021-08-17 16:54:22 +00:00
|
|
|
|
|
|
|
|
"github.com/qdm12/golibs/params"
|
2021-02-06 11:05:50 -05:00
|
|
|
)
|
|
|
|
|
|
2021-05-10 18:18:12 +00: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"`
|
2021-02-17 20:36:30 -05:00
|
|
|
// TODO comments
|
2021-04-25 15:44:45 -04:00
|
|
|
// Cyberghost, PIA, Protonvpn, Surfshark, Windscribe, Vyprvpn, NordVPN
|
2021-02-06 11:05:50 -05:00
|
|
|
Regions []string `json:"regions"`
|
|
|
|
|
|
|
|
|
|
// Cyberghost
|
2021-07-31 14:53:34 +00:00
|
|
|
Groups []string `json:"groups"`
|
2021-02-06 11:05:50 -05:00
|
|
|
|
2021-06-20 09:21:48 -07:00
|
|
|
// Fastestvpn, HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited
|
2021-06-20 09:18:03 -07:00
|
|
|
Countries []string `json:"countries"`
|
2021-06-20 09:21:48 -07:00
|
|
|
// HideMyAss, IPVanish, IVPN, Mullvad, PrivateVPN, Protonvpn, PureVPN, VPNUnlimited, Windscribe
|
2021-06-20 09:18:03 -07:00
|
|
|
Cities []string `json:"cities"`
|
2021-06-20 09:21:48 -07:00
|
|
|
// Fastestvpn, HideMyAss, IPVanish, IVPN, PrivateVPN, Windscribe, Privado, Protonvpn, VPNUnlimited
|
2021-06-20 09:18:03 -07:00
|
|
|
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"`
|
|
|
|
|
|
2021-05-23 21:51:12 +00:00
|
|
|
// ProtonVPN
|
|
|
|
|
FreeOnly bool `json:"free_only"`
|
2021-06-20 09:18:03 -07:00
|
|
|
|
|
|
|
|
// VPNUnlimited
|
|
|
|
|
StreamOnly bool `json:"stream_only"`
|
2021-08-17 16:54:22 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|