Formatting of files (goimport)

This commit is contained in:
Quentin McGaw
2020-04-12 20:01:33 +00:00
parent fb4c9b8a58
commit 8f6b6306d6
5 changed files with 213 additions and 213 deletions

View File

@@ -1,30 +1,30 @@
package constants package constants
import ( import (
"github.com/qdm12/private-internet-access-docker/internal/models" "github.com/qdm12/private-internet-access-docker/internal/models"
) )
const ( const (
// UnboundConf is the file path to the Unbound configuration file // UnboundConf is the file path to the Unbound configuration file
UnboundConf models.Filepath = "/etc/unbound/unbound.conf" UnboundConf models.Filepath = "/etc/unbound/unbound.conf"
// ResolvConf is the file path to the system resolv.conf file // ResolvConf is the file path to the system resolv.conf file
ResolvConf models.Filepath = "/etc/resolv.conf" ResolvConf models.Filepath = "/etc/resolv.conf"
// CACertificates is the file path to the CA certificates file // CACertificates is the file path to the CA certificates file
CACertificates models.Filepath = "/etc/ssl/certs/ca-certificates.crt" CACertificates models.Filepath = "/etc/ssl/certs/ca-certificates.crt"
// OpenVPNAuthConf is the file path to the OpenVPN auth file // OpenVPNAuthConf is the file path to the OpenVPN auth file
OpenVPNAuthConf models.Filepath = "/etc/openvpn/auth.conf" OpenVPNAuthConf models.Filepath = "/etc/openvpn/auth.conf"
// OpenVPNConf is the file path to the OpenVPN client configuration file // OpenVPNConf is the file path to the OpenVPN client configuration file
OpenVPNConf models.Filepath = "/etc/openvpn/target.ovpn" OpenVPNConf models.Filepath = "/etc/openvpn/target.ovpn"
// TunnelDevice is the file path to tun device // TunnelDevice is the file path to tun device
TunnelDevice models.Filepath = "/dev/net/tun" TunnelDevice models.Filepath = "/dev/net/tun"
// NetRoute is the path to the file containing information on the network route // NetRoute is the path to the file containing information on the network route
NetRoute models.Filepath = "/proc/net/route" NetRoute models.Filepath = "/proc/net/route"
// TinyProxyConf is the filepath to the tinyproxy configuration file // TinyProxyConf is the filepath to the tinyproxy configuration file
TinyProxyConf models.Filepath = "/etc/tinyproxy/tinyproxy.conf" TinyProxyConf models.Filepath = "/etc/tinyproxy/tinyproxy.conf"
// ShadowsocksConf is the filepath to the shadowsocks configuration file // ShadowsocksConf is the filepath to the shadowsocks configuration file
ShadowsocksConf models.Filepath = "/etc/shadowsocks.json" ShadowsocksConf models.Filepath = "/etc/shadowsocks.json"
// RootHints is the filepath to the root.hints file used by Unbound // RootHints is the filepath to the root.hints file used by Unbound
RootHints models.Filepath = "/etc/unbound/root.hints" RootHints models.Filepath = "/etc/unbound/root.hints"
// RootKey is the filepath to the root.key file used by Unbound // RootKey is the filepath to the root.key file used by Unbound
RootKey models.Filepath = "/etc/unbound/root.key" RootKey models.Filepath = "/etc/unbound/root.key"
) )

View File

@@ -1,20 +1,20 @@
package constants package constants
import ( import (
"github.com/qdm12/private-internet-access-docker/internal/models" "github.com/qdm12/private-internet-access-docker/internal/models"
) )
const ( const (
// TinyProxyInfoLevel is the info log level for TinyProxy // TinyProxyInfoLevel is the info log level for TinyProxy
TinyProxyInfoLevel models.TinyProxyLogLevel = "Info" TinyProxyInfoLevel models.TinyProxyLogLevel = "Info"
// TinyProxyConnectLevel is the info log level for TinyProxy // TinyProxyConnectLevel is the info log level for TinyProxy
TinyProxyConnectLevel models.TinyProxyLogLevel = "Connect" TinyProxyConnectLevel models.TinyProxyLogLevel = "Connect"
// TinyProxyNoticeLevel is the info log level for TinyProxy // TinyProxyNoticeLevel is the info log level for TinyProxy
TinyProxyNoticeLevel models.TinyProxyLogLevel = "Notice" TinyProxyNoticeLevel models.TinyProxyLogLevel = "Notice"
// TinyProxyWarnLevel is the warning log level for TinyProxy // TinyProxyWarnLevel is the warning log level for TinyProxy
TinyProxyWarnLevel models.TinyProxyLogLevel = "Warning" TinyProxyWarnLevel models.TinyProxyLogLevel = "Warning"
// TinyProxyErrorLevel is the error log level for TinyProxy // TinyProxyErrorLevel is the error log level for TinyProxy
TinyProxyErrorLevel models.TinyProxyLogLevel = "Error" TinyProxyErrorLevel models.TinyProxyLogLevel = "Error"
// TinyProxyCriticalLevel is the critical log level for TinyProxy // TinyProxyCriticalLevel is the critical log level for TinyProxy
TinyProxyCriticalLevel models.TinyProxyLogLevel = "Critical" TinyProxyCriticalLevel models.TinyProxyLogLevel = "Critical"
) )

View File

@@ -1,21 +1,21 @@
package constants package constants
import ( import (
"github.com/qdm12/private-internet-access-docker/internal/models" "github.com/qdm12/private-internet-access-docker/internal/models"
) )
const ( const (
// PrivateInternetAccess is a VPN provider // PrivateInternetAccess is a VPN provider
PrivateInternetAccess models.VPNProvider = "private internet access" PrivateInternetAccess models.VPNProvider = "private internet access"
// Mullvad is a VPN provider // Mullvad is a VPN provider
Mullvad models.VPNProvider = "mullvad" Mullvad models.VPNProvider = "mullvad"
// Windscribe is a VPN provider // Windscribe is a VPN provider
Windscribe models.VPNProvider = "windscribe" Windscribe models.VPNProvider = "windscribe"
) )
const ( const (
// TCP is a network protocol (reliable and slower than UDP) // TCP is a network protocol (reliable and slower than UDP)
TCP models.NetworkProtocol = "tcp" TCP models.NetworkProtocol = "tcp"
// UDP is a network protocol (unreliable and faster than TCP) // UDP is a network protocol (unreliable and faster than TCP)
UDP models.NetworkProtocol = "udp" UDP models.NetworkProtocol = "udp"
) )

View File

@@ -1,118 +1,118 @@
package windscribe package windscribe
import ( import (
"fmt" "fmt"
"net" "net"
"strings" "strings"
"github.com/qdm12/golibs/files" "github.com/qdm12/golibs/files"
"github.com/qdm12/private-internet-access-docker/internal/constants" "github.com/qdm12/private-internet-access-docker/internal/constants"
"github.com/qdm12/private-internet-access-docker/internal/models" "github.com/qdm12/private-internet-access-docker/internal/models"
) )
func (c *configurator) GetOpenVPNConnections(region models.WindscribeRegion, protocol models.NetworkProtocol, customPort uint16, targetIP net.IP) (connections []models.OpenVPNConnection, err error) { func (c *configurator) GetOpenVPNConnections(region models.WindscribeRegion, protocol models.NetworkProtocol, customPort uint16, targetIP net.IP) (connections []models.OpenVPNConnection, err error) {
var subdomain string var subdomain string
for _, server := range constants.WindscribeServers() { for _, server := range constants.WindscribeServers() {
if server.Region == region { if server.Region == region {
subdomain = server.Subdomain subdomain = server.Subdomain
break break
} }
} }
if len(subdomain) == 0 { if len(subdomain) == 0 {
return nil, fmt.Errorf("no server found for region %q", region) return nil, fmt.Errorf("no server found for region %q", region)
} }
hostname := subdomain + ".windscribe.com" hostname := subdomain + ".windscribe.com"
IPs, err := c.lookupIP(hostname) IPs, err := c.lookupIP(hostname)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if targetIP != nil { if targetIP != nil {
found := false found := false
for i := range IPs { for i := range IPs {
if IPs[i].Equal(targetIP) { if IPs[i].Equal(targetIP) {
found = true found = true
break break
} }
} }
if !found { if !found {
return nil, fmt.Errorf("target IP address %q not found from IP addresses resolved from %s", targetIP, hostname) return nil, fmt.Errorf("target IP address %q not found from IP addresses resolved from %s", targetIP, hostname)
} }
IPs = []net.IP{targetIP} IPs = []net.IP{targetIP}
} }
var port uint16 var port uint16
switch { switch {
case customPort > 0: case customPort > 0:
port = customPort port = customPort
case protocol == constants.TCP: case protocol == constants.TCP:
port = 1194 port = 1194
case protocol == constants.UDP: case protocol == constants.UDP:
port = 443 port = 443
default: default:
return nil, fmt.Errorf("protocol %q is unknown", protocol) return nil, fmt.Errorf("protocol %q is unknown", protocol)
} }
for _, IP := range IPs { for _, IP := range IPs {
connections = append(connections, models.OpenVPNConnection{IP: IP, Port: port, Protocol: protocol}) connections = append(connections, models.OpenVPNConnection{IP: IP, Port: port, Protocol: protocol})
} }
return connections, nil return connections, nil
} }
func (c *configurator) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string) (err error) { func (c *configurator) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string) (err error) {
if len(cipher) == 0 { if len(cipher) == 0 {
cipher = "AES-256-CBC" cipher = "AES-256-CBC"
} }
if len(auth) == 0 { if len(auth) == 0 {
auth = "sha512" auth = "sha512"
} }
lines := []string{ lines := []string{
"client", "client",
"dev tun", "dev tun",
"nobind", "nobind",
"persist-key", "persist-key",
"persist-tun", "persist-tun",
// Windscribe specific // Windscribe specific
"resolv-retry infinite", "resolv-retry infinite",
"comp-lzo", "comp-lzo",
"remote-cert-tls server", "remote-cert-tls server",
"key-direction 1", "key-direction 1",
// Added constant values // Added constant values
"auth-nocache", "auth-nocache",
"mute-replay-warnings", "mute-replay-warnings",
"pull-filter ignore \"auth-token\"", // prevent auth failed loops "pull-filter ignore \"auth-token\"", // prevent auth failed loops
"auth-retry nointeract", "auth-retry nointeract",
"remote-random", "remote-random",
// Modified variables // Modified variables
fmt.Sprintf("verb %d", verbosity), fmt.Sprintf("verb %d", verbosity),
fmt.Sprintf("auth-user-pass %s", constants.OpenVPNAuthConf), fmt.Sprintf("auth-user-pass %s", constants.OpenVPNAuthConf),
fmt.Sprintf("proto %s", string(connections[0].Protocol)), fmt.Sprintf("proto %s", string(connections[0].Protocol)),
fmt.Sprintf("cipher %s", cipher), fmt.Sprintf("cipher %s", cipher),
fmt.Sprintf("auth %s", auth), fmt.Sprintf("auth %s", auth),
} }
if strings.HasSuffix(cipher, "-gcm") { if strings.HasSuffix(cipher, "-gcm") {
lines = append(lines, "ncp-ciphers AES-256-GCM:AES-256-CBC:AES-128-GCM") lines = append(lines, "ncp-ciphers AES-256-GCM:AES-256-CBC:AES-128-GCM")
} }
if !root { if !root {
lines = append(lines, "user nonrootuser") lines = append(lines, "user nonrootuser")
} }
for _, connection := range connections { for _, connection := range connections {
lines = append(lines, fmt.Sprintf("remote %s %d", connection.IP.String(), connection.Port)) lines = append(lines, fmt.Sprintf("remote %s %d", connection.IP.String(), connection.Port))
} }
lines = append(lines, []string{ lines = append(lines, []string{
"<ca>", "<ca>",
"-----BEGIN CERTIFICATE-----", "-----BEGIN CERTIFICATE-----",
constants.WindscribeCertificate, constants.WindscribeCertificate,
"-----END CERTIFICATE-----", "-----END CERTIFICATE-----",
"</ca>", "</ca>",
}...) }...)
lines = append(lines, []string{ lines = append(lines, []string{
"<tls-auth>", "<tls-auth>",
"-----BEGIN OpenVPN Static key V1-----", "-----BEGIN OpenVPN Static key V1-----",
constants.WindscribeOpenvpnStaticKeyV1, constants.WindscribeOpenvpnStaticKeyV1,
"-----END OpenVPN Static key V1-----", "-----END OpenVPN Static key V1-----",
"</tls-auth>", "</tls-auth>",
"", "",
}...) }...)
return c.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(uid, gid), files.Permissions(0400)) return c.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(uid, gid), files.Permissions(0400))
} }

View File

@@ -1,24 +1,24 @@
package windscribe package windscribe
import ( import (
"net" "net"
"github.com/qdm12/golibs/files" "github.com/qdm12/golibs/files"
"github.com/qdm12/private-internet-access-docker/internal/models" "github.com/qdm12/private-internet-access-docker/internal/models"
) )
// Configurator contains methods to download, read and modify the openvpn configuration to connect as a client // Configurator contains methods to download, read and modify the openvpn configuration to connect as a client
type Configurator interface { type Configurator interface {
GetOpenVPNConnections(region models.WindscribeRegion, protocol models.NetworkProtocol, customPort uint16, targetIP net.IP) (connections []models.OpenVPNConnection, err error) GetOpenVPNConnections(region models.WindscribeRegion, protocol models.NetworkProtocol, customPort uint16, targetIP net.IP) (connections []models.OpenVPNConnection, err error)
BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string) (err error) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string) (err error)
} }
type configurator struct { type configurator struct {
fileManager files.FileManager fileManager files.FileManager
lookupIP func(host string) ([]net.IP, error) lookupIP func(host string) ([]net.IP, error)
} }
// NewConfigurator returns a new Configurator object // NewConfigurator returns a new Configurator object
func NewConfigurator(fileManager files.FileManager) Configurator { func NewConfigurator(fileManager files.FileManager) Configurator {
return &configurator{fileManager, net.LookupIP} return &configurator{fileManager, net.LookupIP}
} }