Refactor (#174)
- Goal was to simplify main.go complexity - Use common structures and interfaces for all vpn providers - Moved files around - Removed some alias models
This commit is contained in:
@@ -7,24 +7,6 @@ type (
|
||||
DNSProvider string
|
||||
// DNSHost is the DNS host to use for TLS validation
|
||||
DNSHost string
|
||||
// PIAEncryption defines the level of encryption for communication with PIA servers
|
||||
PIAEncryption string
|
||||
// PIARegion is used to define the list of regions available for PIA
|
||||
PIARegion string
|
||||
// MullvadCountry is used as the country for a Mullvad server
|
||||
MullvadCountry string
|
||||
// MullvadCity is used as the city for a Mullvad server
|
||||
MullvadCity string
|
||||
// MullvadProvider is used as the Internet service provider for a Mullvad server
|
||||
MullvadProvider string
|
||||
// WindscribeCity is used as the region for a Windscribe server
|
||||
WindscribeRegion string
|
||||
// SurfsharkRegion is used as the region for a Surfshark server
|
||||
SurfsharkRegion string
|
||||
// CyberghostRegion is the country name for a Cyberghost server
|
||||
CyberghostRegion string
|
||||
// CyberghostGroup is the server group for a Cyberghost server
|
||||
CyberghostGroup string
|
||||
// URL is an HTTP(s) URL address
|
||||
URL string
|
||||
// Filepath is a local filesytem file path
|
||||
@@ -32,7 +14,7 @@ type (
|
||||
// TinyProxyLogLevel is the log level for TinyProxy
|
||||
TinyProxyLogLevel string
|
||||
// VPNProvider is the name of the VPN provider to be used
|
||||
VPNProvider string
|
||||
VPNProvider string // TODO
|
||||
// NetworkProtocol contains the network protocol to be used to communicate with the VPN servers
|
||||
NetworkProtocol string
|
||||
)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
type CyberghostServer struct {
|
||||
Region CyberghostRegion
|
||||
Group CyberghostGroup
|
||||
IPs []net.IP
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
type MullvadServer struct {
|
||||
IPs []net.IP
|
||||
Country MullvadCountry
|
||||
City MullvadCity
|
||||
Provider MullvadProvider
|
||||
Owned bool
|
||||
DefaultPort uint16
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
type PIAServer struct {
|
||||
IPs []net.IP
|
||||
Region PIARegion
|
||||
}
|
||||
100
internal/models/selection.go
Normal file
100
internal/models/selection.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ProviderSettings contains settings specific to a VPN provider
|
||||
type ProviderSettings struct {
|
||||
Name VPNProvider
|
||||
ServerSelection ServerSelection
|
||||
ExtraConfigOptions ExtraConfigOptions
|
||||
PortForwarding PortForwarding
|
||||
}
|
||||
|
||||
type ServerSelection struct {
|
||||
// Common
|
||||
Protocol NetworkProtocol
|
||||
TargetIP net.IP
|
||||
|
||||
// Cyberghost, PIA, Surfshark, Windscribe
|
||||
Region string
|
||||
|
||||
// Cyberghost
|
||||
Group string
|
||||
|
||||
// Mullvad
|
||||
Country string
|
||||
City string
|
||||
ISP string
|
||||
Owned bool
|
||||
|
||||
// Mullvad, Windscribe
|
||||
CustomPort uint16
|
||||
|
||||
// PIA
|
||||
EncryptionPreset string
|
||||
}
|
||||
|
||||
type ExtraConfigOptions struct {
|
||||
ClientKey string // Cyberghost
|
||||
EncryptionPreset string // PIA
|
||||
}
|
||||
|
||||
// PortForwarding contains settings for port forwarding
|
||||
type PortForwarding struct {
|
||||
Enabled bool
|
||||
Filepath Filepath
|
||||
}
|
||||
|
||||
func (p *PortForwarding) String() string {
|
||||
if p.Enabled {
|
||||
return fmt.Sprintf("on, saved in %s", p.Filepath)
|
||||
}
|
||||
return "off"
|
||||
}
|
||||
|
||||
func (p *ProviderSettings) String() string {
|
||||
settingsList := []string{
|
||||
fmt.Sprintf("%s settings:", strings.Title(string(p.Name))),
|
||||
"Network protocol: " + string(p.ServerSelection.Protocol),
|
||||
}
|
||||
switch strings.ToLower(string(p.Name)) {
|
||||
case "private internet access":
|
||||
settingsList = []string{
|
||||
"Region: " + p.ServerSelection.Region,
|
||||
"Encryption preset: " + p.ExtraConfigOptions.EncryptionPreset,
|
||||
"Port forwarding: " + p.PortForwarding.String(),
|
||||
}
|
||||
case "mullvad":
|
||||
settingsList = []string{
|
||||
"Country: " + p.ServerSelection.Country,
|
||||
"City: " + p.ServerSelection.City,
|
||||
"ISP: " + p.ServerSelection.ISP,
|
||||
"Custom port: " + string(p.ServerSelection.CustomPort),
|
||||
}
|
||||
case "windscribe":
|
||||
settingsList = []string{
|
||||
"Region: " + p.ServerSelection.Region,
|
||||
"Custom port: " + string(p.ServerSelection.CustomPort),
|
||||
}
|
||||
case "surfshark":
|
||||
settingsList = []string{
|
||||
"Region: " + p.ServerSelection.Region,
|
||||
}
|
||||
case "cyberghost":
|
||||
settingsList = []string{
|
||||
"ClientKey: [redacted]",
|
||||
"Group: " + p.ServerSelection.Group,
|
||||
"Region: " + p.ServerSelection.Region,
|
||||
}
|
||||
}
|
||||
if p.ServerSelection.TargetIP != nil {
|
||||
settingsList = append(settingsList,
|
||||
"Target IP address: "+string(p.ServerSelection.TargetIP),
|
||||
)
|
||||
}
|
||||
return strings.Join(settingsList, "\n |--")
|
||||
}
|
||||
33
internal/models/servers.go
Normal file
33
internal/models/servers.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
type PIAServer struct {
|
||||
IPs []net.IP
|
||||
Region string
|
||||
}
|
||||
|
||||
type MullvadServer struct {
|
||||
IPs []net.IP
|
||||
Country string
|
||||
City string
|
||||
ISP string
|
||||
Owned bool
|
||||
DefaultPort uint16
|
||||
}
|
||||
|
||||
type WindscribeServer struct {
|
||||
Region string
|
||||
IPs []net.IP
|
||||
}
|
||||
|
||||
type SurfsharkServer struct {
|
||||
Region string
|
||||
IPs []net.IP
|
||||
}
|
||||
|
||||
type CyberghostServer struct {
|
||||
Region string
|
||||
Group string
|
||||
IPs []net.IP
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
type SurfsharkServer struct {
|
||||
Region SurfsharkRegion
|
||||
IPs []net.IP
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
import "net"
|
||||
|
||||
type WindscribeServer struct {
|
||||
Region WindscribeRegion
|
||||
IPs []net.IP
|
||||
}
|
||||
Reference in New Issue
Block a user