From 8f6b6306d69f6a645537b01aeccbd63e062e123d Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sun, 12 Apr 2020 20:01:33 +0000 Subject: [PATCH] Formatting of files (goimport) --- internal/constants/paths.go | 60 ++++---- internal/constants/tinyproxy.go | 40 ++--- internal/constants/vpn.go | 42 +++--- internal/windscribe/conf.go | 236 +++++++++++++++--------------- internal/windscribe/windscribe.go | 48 +++--- 5 files changed, 213 insertions(+), 213 deletions(-) diff --git a/internal/constants/paths.go b/internal/constants/paths.go index ce338bf1..23c8b3fa 100644 --- a/internal/constants/paths.go +++ b/internal/constants/paths.go @@ -1,30 +1,30 @@ -package constants - -import ( - "github.com/qdm12/private-internet-access-docker/internal/models" -) - -const ( - // UnboundConf is the file path to the Unbound configuration file - UnboundConf models.Filepath = "/etc/unbound/unbound.conf" - // ResolvConf is the file path to the system resolv.conf file - ResolvConf models.Filepath = "/etc/resolv.conf" - // CACertificates is the file path to the CA certificates file - CACertificates models.Filepath = "/etc/ssl/certs/ca-certificates.crt" - // OpenVPNAuthConf is the file path to the OpenVPN auth file - OpenVPNAuthConf models.Filepath = "/etc/openvpn/auth.conf" - // OpenVPNConf is the file path to the OpenVPN client configuration file - OpenVPNConf models.Filepath = "/etc/openvpn/target.ovpn" - // TunnelDevice is the file path to tun device - TunnelDevice models.Filepath = "/dev/net/tun" - // NetRoute is the path to the file containing information on the network route - NetRoute models.Filepath = "/proc/net/route" - // TinyProxyConf is the filepath to the tinyproxy configuration file - TinyProxyConf models.Filepath = "/etc/tinyproxy/tinyproxy.conf" - // ShadowsocksConf is the filepath to the shadowsocks configuration file - ShadowsocksConf models.Filepath = "/etc/shadowsocks.json" - // RootHints is the filepath to the root.hints file used by Unbound - RootHints models.Filepath = "/etc/unbound/root.hints" - // RootKey is the filepath to the root.key file used by Unbound - RootKey models.Filepath = "/etc/unbound/root.key" -) +package constants + +import ( + "github.com/qdm12/private-internet-access-docker/internal/models" +) + +const ( + // UnboundConf is the file path to the Unbound configuration file + UnboundConf models.Filepath = "/etc/unbound/unbound.conf" + // ResolvConf is the file path to the system resolv.conf file + ResolvConf models.Filepath = "/etc/resolv.conf" + // CACertificates is the file path to the CA certificates file + CACertificates models.Filepath = "/etc/ssl/certs/ca-certificates.crt" + // OpenVPNAuthConf is the file path to the OpenVPN auth file + OpenVPNAuthConf models.Filepath = "/etc/openvpn/auth.conf" + // OpenVPNConf is the file path to the OpenVPN client configuration file + OpenVPNConf models.Filepath = "/etc/openvpn/target.ovpn" + // TunnelDevice is the file path to tun device + TunnelDevice models.Filepath = "/dev/net/tun" + // NetRoute is the path to the file containing information on the network route + NetRoute models.Filepath = "/proc/net/route" + // TinyProxyConf is the filepath to the tinyproxy configuration file + TinyProxyConf models.Filepath = "/etc/tinyproxy/tinyproxy.conf" + // ShadowsocksConf is the filepath to the shadowsocks configuration file + ShadowsocksConf models.Filepath = "/etc/shadowsocks.json" + // RootHints is the filepath to the root.hints file used by Unbound + RootHints models.Filepath = "/etc/unbound/root.hints" + // RootKey is the filepath to the root.key file used by Unbound + RootKey models.Filepath = "/etc/unbound/root.key" +) diff --git a/internal/constants/tinyproxy.go b/internal/constants/tinyproxy.go index 732f7714..d239a847 100644 --- a/internal/constants/tinyproxy.go +++ b/internal/constants/tinyproxy.go @@ -1,20 +1,20 @@ -package constants - -import ( - "github.com/qdm12/private-internet-access-docker/internal/models" -) - -const ( - // TinyProxyInfoLevel is the info log level for TinyProxy - TinyProxyInfoLevel models.TinyProxyLogLevel = "Info" - // TinyProxyConnectLevel is the info log level for TinyProxy - TinyProxyConnectLevel models.TinyProxyLogLevel = "Connect" - // TinyProxyNoticeLevel is the info log level for TinyProxy - TinyProxyNoticeLevel models.TinyProxyLogLevel = "Notice" - // TinyProxyWarnLevel is the warning log level for TinyProxy - TinyProxyWarnLevel models.TinyProxyLogLevel = "Warning" - // TinyProxyErrorLevel is the error log level for TinyProxy - TinyProxyErrorLevel models.TinyProxyLogLevel = "Error" - // TinyProxyCriticalLevel is the critical log level for TinyProxy - TinyProxyCriticalLevel models.TinyProxyLogLevel = "Critical" -) +package constants + +import ( + "github.com/qdm12/private-internet-access-docker/internal/models" +) + +const ( + // TinyProxyInfoLevel is the info log level for TinyProxy + TinyProxyInfoLevel models.TinyProxyLogLevel = "Info" + // TinyProxyConnectLevel is the info log level for TinyProxy + TinyProxyConnectLevel models.TinyProxyLogLevel = "Connect" + // TinyProxyNoticeLevel is the info log level for TinyProxy + TinyProxyNoticeLevel models.TinyProxyLogLevel = "Notice" + // TinyProxyWarnLevel is the warning log level for TinyProxy + TinyProxyWarnLevel models.TinyProxyLogLevel = "Warning" + // TinyProxyErrorLevel is the error log level for TinyProxy + TinyProxyErrorLevel models.TinyProxyLogLevel = "Error" + // TinyProxyCriticalLevel is the critical log level for TinyProxy + TinyProxyCriticalLevel models.TinyProxyLogLevel = "Critical" +) diff --git a/internal/constants/vpn.go b/internal/constants/vpn.go index 9f672e81..c34702ed 100644 --- a/internal/constants/vpn.go +++ b/internal/constants/vpn.go @@ -1,21 +1,21 @@ -package constants - -import ( - "github.com/qdm12/private-internet-access-docker/internal/models" -) - -const ( - // PrivateInternetAccess is a VPN provider - PrivateInternetAccess models.VPNProvider = "private internet access" - // Mullvad is a VPN provider - Mullvad models.VPNProvider = "mullvad" - // Windscribe is a VPN provider - Windscribe models.VPNProvider = "windscribe" -) - -const ( - // TCP is a network protocol (reliable and slower than UDP) - TCP models.NetworkProtocol = "tcp" - // UDP is a network protocol (unreliable and faster than TCP) - UDP models.NetworkProtocol = "udp" -) +package constants + +import ( + "github.com/qdm12/private-internet-access-docker/internal/models" +) + +const ( + // PrivateInternetAccess is a VPN provider + PrivateInternetAccess models.VPNProvider = "private internet access" + // Mullvad is a VPN provider + Mullvad models.VPNProvider = "mullvad" + // Windscribe is a VPN provider + Windscribe models.VPNProvider = "windscribe" +) + +const ( + // TCP is a network protocol (reliable and slower than UDP) + TCP models.NetworkProtocol = "tcp" + // UDP is a network protocol (unreliable and faster than TCP) + UDP models.NetworkProtocol = "udp" +) diff --git a/internal/windscribe/conf.go b/internal/windscribe/conf.go index 306ed93e..df6c0134 100644 --- a/internal/windscribe/conf.go +++ b/internal/windscribe/conf.go @@ -1,118 +1,118 @@ -package windscribe - -import ( - "fmt" - "net" - "strings" - - "github.com/qdm12/golibs/files" - "github.com/qdm12/private-internet-access-docker/internal/constants" - "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) { - var subdomain string - for _, server := range constants.WindscribeServers() { - if server.Region == region { - subdomain = server.Subdomain - break - } - } - if len(subdomain) == 0 { - return nil, fmt.Errorf("no server found for region %q", region) - } - hostname := subdomain + ".windscribe.com" - IPs, err := c.lookupIP(hostname) - if err != nil { - return nil, err - } - if targetIP != nil { - found := false - for i := range IPs { - if IPs[i].Equal(targetIP) { - found = true - break - } - } - if !found { - return nil, fmt.Errorf("target IP address %q not found from IP addresses resolved from %s", targetIP, hostname) - } - IPs = []net.IP{targetIP} - } - var port uint16 - switch { - case customPort > 0: - port = customPort - case protocol == constants.TCP: - port = 1194 - case protocol == constants.UDP: - port = 443 - default: - return nil, fmt.Errorf("protocol %q is unknown", protocol) - } - for _, IP := range IPs { - connections = append(connections, models.OpenVPNConnection{IP: IP, Port: port, Protocol: protocol}) - } - return connections, nil -} - -func (c *configurator) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string) (err error) { - if len(cipher) == 0 { - cipher = "AES-256-CBC" - } - if len(auth) == 0 { - auth = "sha512" - } - lines := []string{ - "client", - "dev tun", - "nobind", - "persist-key", - "persist-tun", - - // Windscribe specific - "resolv-retry infinite", - "comp-lzo", - "remote-cert-tls server", - "key-direction 1", - - // Added constant values - "auth-nocache", - "mute-replay-warnings", - "pull-filter ignore \"auth-token\"", // prevent auth failed loops - "auth-retry nointeract", - "remote-random", - - // Modified variables - fmt.Sprintf("verb %d", verbosity), - fmt.Sprintf("auth-user-pass %s", constants.OpenVPNAuthConf), - fmt.Sprintf("proto %s", string(connections[0].Protocol)), - fmt.Sprintf("cipher %s", cipher), - fmt.Sprintf("auth %s", auth), - } - if strings.HasSuffix(cipher, "-gcm") { - lines = append(lines, "ncp-ciphers AES-256-GCM:AES-256-CBC:AES-128-GCM") - } - if !root { - lines = append(lines, "user nonrootuser") - } - for _, connection := range connections { - lines = append(lines, fmt.Sprintf("remote %s %d", connection.IP.String(), connection.Port)) - } - lines = append(lines, []string{ - "", - "-----BEGIN CERTIFICATE-----", - constants.WindscribeCertificate, - "-----END CERTIFICATE-----", - "", - }...) - lines = append(lines, []string{ - "", - "-----BEGIN OpenVPN Static key V1-----", - constants.WindscribeOpenvpnStaticKeyV1, - "-----END OpenVPN Static key V1-----", - "", - "", - }...) - return c.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(uid, gid), files.Permissions(0400)) -} +package windscribe + +import ( + "fmt" + "net" + "strings" + + "github.com/qdm12/golibs/files" + "github.com/qdm12/private-internet-access-docker/internal/constants" + "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) { + var subdomain string + for _, server := range constants.WindscribeServers() { + if server.Region == region { + subdomain = server.Subdomain + break + } + } + if len(subdomain) == 0 { + return nil, fmt.Errorf("no server found for region %q", region) + } + hostname := subdomain + ".windscribe.com" + IPs, err := c.lookupIP(hostname) + if err != nil { + return nil, err + } + if targetIP != nil { + found := false + for i := range IPs { + if IPs[i].Equal(targetIP) { + found = true + break + } + } + if !found { + return nil, fmt.Errorf("target IP address %q not found from IP addresses resolved from %s", targetIP, hostname) + } + IPs = []net.IP{targetIP} + } + var port uint16 + switch { + case customPort > 0: + port = customPort + case protocol == constants.TCP: + port = 1194 + case protocol == constants.UDP: + port = 443 + default: + return nil, fmt.Errorf("protocol %q is unknown", protocol) + } + for _, IP := range IPs { + connections = append(connections, models.OpenVPNConnection{IP: IP, Port: port, Protocol: protocol}) + } + return connections, nil +} + +func (c *configurator) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string) (err error) { + if len(cipher) == 0 { + cipher = "AES-256-CBC" + } + if len(auth) == 0 { + auth = "sha512" + } + lines := []string{ + "client", + "dev tun", + "nobind", + "persist-key", + "persist-tun", + + // Windscribe specific + "resolv-retry infinite", + "comp-lzo", + "remote-cert-tls server", + "key-direction 1", + + // Added constant values + "auth-nocache", + "mute-replay-warnings", + "pull-filter ignore \"auth-token\"", // prevent auth failed loops + "auth-retry nointeract", + "remote-random", + + // Modified variables + fmt.Sprintf("verb %d", verbosity), + fmt.Sprintf("auth-user-pass %s", constants.OpenVPNAuthConf), + fmt.Sprintf("proto %s", string(connections[0].Protocol)), + fmt.Sprintf("cipher %s", cipher), + fmt.Sprintf("auth %s", auth), + } + if strings.HasSuffix(cipher, "-gcm") { + lines = append(lines, "ncp-ciphers AES-256-GCM:AES-256-CBC:AES-128-GCM") + } + if !root { + lines = append(lines, "user nonrootuser") + } + for _, connection := range connections { + lines = append(lines, fmt.Sprintf("remote %s %d", connection.IP.String(), connection.Port)) + } + lines = append(lines, []string{ + "", + "-----BEGIN CERTIFICATE-----", + constants.WindscribeCertificate, + "-----END CERTIFICATE-----", + "", + }...) + lines = append(lines, []string{ + "", + "-----BEGIN OpenVPN Static key V1-----", + constants.WindscribeOpenvpnStaticKeyV1, + "-----END OpenVPN Static key V1-----", + "", + "", + }...) + return c.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(uid, gid), files.Permissions(0400)) +} diff --git a/internal/windscribe/windscribe.go b/internal/windscribe/windscribe.go index 2f515ce6..11176903 100644 --- a/internal/windscribe/windscribe.go +++ b/internal/windscribe/windscribe.go @@ -1,24 +1,24 @@ -package windscribe - -import ( - "net" - - "github.com/qdm12/golibs/files" - "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 -type Configurator interface { - 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) -} - -type configurator struct { - fileManager files.FileManager - lookupIP func(host string) ([]net.IP, error) -} - -// NewConfigurator returns a new Configurator object -func NewConfigurator(fileManager files.FileManager) Configurator { - return &configurator{fileManager, net.LookupIP} -} +package windscribe + +import ( + "net" + + "github.com/qdm12/golibs/files" + "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 +type Configurator interface { + 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) +} + +type configurator struct { + fileManager files.FileManager + lookupIP func(host string) ([]net.IP, error) +} + +// NewConfigurator returns a new Configurator object +func NewConfigurator(fileManager files.FileManager) Configurator { + return &configurator{fileManager, net.LookupIP} +}