-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(providers): add giganews support (#2479)
- Loading branch information
Showing
16 changed files
with
958 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ body: | |
- Cyberghost | ||
- ExpressVPN | ||
- FastestVPN | ||
- Giganews | ||
- HideMyAss | ||
- IPVanish | ||
- IVPN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package giganews | ||
|
||
import ( | ||
"github.com/qdm12/gluetun/internal/configuration/settings" | ||
"github.com/qdm12/gluetun/internal/models" | ||
"github.com/qdm12/gluetun/internal/provider/utils" | ||
) | ||
|
||
func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( | ||
connection models.Connection, err error) { | ||
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:gomnd | ||
return utils.GetConnection(p.Name(), | ||
p.storage, selection, defaults, ipv6Supported, p.randSource) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package giganews | ||
|
||
import ( | ||
"github.com/qdm12/gluetun/internal/configuration/settings" | ||
"github.com/qdm12/gluetun/internal/constants/openvpn" | ||
"github.com/qdm12/gluetun/internal/models" | ||
"github.com/qdm12/gluetun/internal/provider/utils" | ||
) | ||
|
||
func (p *Provider) OpenVPNConfig(connection models.Connection, | ||
settings settings.OpenVPN, ipv6Supported bool) (lines []string) { | ||
//nolint:gomnd | ||
providerSettings := utils.OpenVPNProviderSettings{ | ||
RemoteCertTLS: true, | ||
AuthUserPass: true, | ||
Ciphers: []string{ | ||
openvpn.AES256cbc, | ||
}, | ||
Auth: openvpn.SHA256, | ||
Ping: 10, | ||
CAs: []string{"MIIGDjCCA/agAwIBAgIJAL2ON5xbane/MA0GCSqGSIb3DQEBDQUAMIGTMQswCQYDVQQGEwJDSDEQMA4GA1UECAwHTHVjZXJuZTEPMA0GA1UEBwwGTWVnZ2VuMRkwFwYDVQQKDBBHb2xkZW4gRnJvZyBHbWJIMSEwHwYDVQQDDBhHb2xkZW4gRnJvZyBHbWJIIFJvb3QgQ0ExIzAhBgkqhkiG9w0BCQEWFGFkbWluQGdvbGRlbmZyb2cuY29tMB4XDTE5MTAxNzIwMTQxMFoXDTM5MTAxMjIwMTQxMFowgZMxCzAJBgNVBAYTAkNIMRAwDgYDVQQIDAdMdWNlcm5lMQ8wDQYDVQQHDAZNZWdnZW4xGTAXBgNVBAoMEEdvbGRlbiBGcm9nIEdtYkgxITAfBgNVBAMMGEdvbGRlbiBGcm9nIEdtYkggUm9vdCBDQTEjMCEGCSqGSIb3DQEJARYUYWRtaW5AZ29sZGVuZnJvZy5jb20wggIiMA0GCSqGSIb3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FR2Qy5a6/kWwZ1JQVYof1J1EzY6mU7YLMHOdjfmeci5i0vg8+9kGMsc/7Wm69L1BeqpDB3ZEAgmOtda2jwOevJ4sABmRoSThFp4DeMcxb62HW1zZCCpgzWv/33+pZdPvnZHSz7RGoxH4Ln7eBf3oo2PMlu7wCsid3HUdgkRf2Og1RJIrFfEjb7jga1JbKX2Qo/FH3txzdUimKiDRv3ccFmEOqjndUG6hP+7/EsI43oCPYOvZR+u5GdOkhYrDGZlvjXeJ1CpQxTR/EX+Vt7F8YG+i2LkO7lhPLb+LzgPAxVPCcEMHruuUlE1BYxxzRMOW4X4kjHvJjZGISxa9lgTY3e0mnoQNQVBHKfzI2vGLwvcrFcCIrVxeEbj2dryfByyhZlrNPFbXyf7P4OSfk+fVh6Is1IF1wksfLY/6gWvcmXB8JwmKFDa9s5NfzXnzP3VMrNUWXN3G8Eee6qzKKTDsJ70OrgAx9j9a+dMLfe1vP5t6GQj5"}, //nolint:lll | ||
TLSCipher: "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA", //nolint:lll | ||
ExtraLines: []string{ | ||
"comp-lzo", | ||
}, | ||
} | ||
return utils.OpenVPNConfig(providerSettings, connection, settings, ipv6Supported) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package giganews | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/qdm12/gluetun/internal/constants/providers" | ||
"github.com/qdm12/gluetun/internal/provider/common" | ||
"github.com/qdm12/gluetun/internal/provider/giganews/updater" | ||
) | ||
|
||
type Provider struct { | ||
storage common.Storage | ||
randSource rand.Source | ||
common.Fetcher | ||
} | ||
|
||
func New(storage common.Storage, randSource rand.Source, | ||
unzipper common.Unzipper, updaterWarner common.Warner, | ||
parallelResolver common.ParallelResolver) *Provider { | ||
return &Provider{ | ||
storage: storage, | ||
randSource: randSource, | ||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver), | ||
} | ||
} | ||
|
||
func (p *Provider) Name() string { | ||
return providers.Giganews | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package updater | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
var errNotOvpnExt = errors.New("filename does not have the openvpn file extension") | ||
|
||
func parseFilename(fileName string) ( | ||
region string, err error, | ||
) { | ||
const suffix = ".ovpn" | ||
if !strings.HasSuffix(fileName, suffix) { | ||
return "", fmt.Errorf("%w: %s", errNotOvpnExt, fileName) | ||
} | ||
|
||
region = strings.TrimSuffix(fileName, suffix) | ||
region = strings.ReplaceAll(region, " - ", " ") | ||
return region, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package updater | ||
|
||
import ( | ||
"net/netip" | ||
|
||
"github.com/qdm12/gluetun/internal/constants/vpn" | ||
"github.com/qdm12/gluetun/internal/models" | ||
) | ||
|
||
type hostToServer map[string]models.Server | ||
|
||
func (hts hostToServer) add(host, region string, tcp, udp bool) { | ||
server, ok := hts[host] | ||
if !ok { | ||
server.VPN = vpn.OpenVPN | ||
server.Hostname = host | ||
server.Region = region | ||
} | ||
if tcp { | ||
server.TCP = true | ||
} | ||
if udp { | ||
server.UDP = true | ||
} | ||
hts[host] = server | ||
} | ||
|
||
func (hts hostToServer) toHostsSlice() (hosts []string) { | ||
hosts = make([]string, 0, len(hts)) | ||
for host := range hts { | ||
hosts = append(hosts, host) | ||
} | ||
return hosts | ||
} | ||
|
||
func (hts hostToServer) adaptWithIPs(hostToIPs map[string][]netip.Addr) { | ||
for host, IPs := range hostToIPs { | ||
server := hts[host] | ||
server.IPs = IPs | ||
hts[host] = server | ||
} | ||
for host, server := range hts { | ||
if len(server.IPs) == 0 { | ||
delete(hts, host) | ||
} | ||
} | ||
} | ||
|
||
func (hts hostToServer) toServersSlice() (servers []models.Server) { | ||
servers = make([]models.Server, 0, len(hts)) | ||
for _, server := range hts { | ||
servers = append(servers, server) | ||
} | ||
return servers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package updater | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/qdm12/gluetun/internal/updater/resolver" | ||
) | ||
|
||
func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { | ||
const ( | ||
maxFailRatio = 0.1 | ||
maxDuration = 5 * time.Second | ||
betweenDuration = time.Second | ||
maxNoNew = 2 | ||
maxFails = 2 | ||
) | ||
return resolver.ParallelSettings{ | ||
Hosts: hosts, | ||
MaxFailRatio: maxFailRatio, | ||
Repeat: resolver.RepeatSettings{ | ||
MaxDuration: maxDuration, | ||
BetweenDuration: betweenDuration, | ||
MaxNoNew: maxNoNew, | ||
MaxFails: maxFails, | ||
SortIPs: true, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package updater | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/qdm12/gluetun/internal/models" | ||
"github.com/qdm12/gluetun/internal/provider/common" | ||
"github.com/qdm12/gluetun/internal/updater/openvpn" | ||
) | ||
|
||
func (u *Updater) FetchServers(ctx context.Context, minServers int) ( | ||
servers []models.Server, err error) { | ||
const url = "https://support.vyprvpn.com/hc/article_attachments/360052617332/Vypr_OpenVPN_20200320.zip" | ||
contents, err := u.unzipper.FetchAndExtract(ctx, url) | ||
if err != nil { | ||
return nil, err | ||
} else if len(contents) < minServers { | ||
return nil, fmt.Errorf("%w: %d and expected at least %d", | ||
common.ErrNotEnoughServers, len(contents), minServers) | ||
} | ||
|
||
hts := make(hostToServer) | ||
|
||
for fileName, content := range contents { | ||
if !strings.HasSuffix(fileName, ".ovpn") { | ||
continue // not an OpenVPN file | ||
} | ||
|
||
host, warning, err := openvpn.ExtractHost(content) | ||
if warning != "" { | ||
u.warner.Warn(warning) | ||
} | ||
if err != nil { | ||
// treat error as warning and go to next file | ||
u.warner.Warn(err.Error() + " in " + fileName) | ||
continue | ||
} | ||
host = strings.ReplaceAll(host, "vyprvpn.com", "vpn.giganews.com") | ||
|
||
tcp, udp, err := openvpn.ExtractProto(content) | ||
if err != nil { | ||
// treat error as warning and go to next file | ||
u.warner.Warn(err.Error() + " in " + fileName) | ||
continue | ||
} | ||
|
||
region, err := parseFilename(fileName) | ||
if err != nil { | ||
// treat error as warning and go to next file | ||
u.warner.Warn(err.Error()) | ||
continue | ||
} | ||
|
||
hts.add(host, region, tcp, udp) | ||
} | ||
|
||
if len(hts) < minServers { | ||
return nil, fmt.Errorf("%w: %d and expected at least %d", | ||
common.ErrNotEnoughServers, len(hts), minServers) | ||
} | ||
|
||
hosts := hts.toHostsSlice() | ||
resolveSettings := parallelResolverSettings(hosts) | ||
hostToIPs, warnings, err := u.parallelResolver.Resolve(ctx, resolveSettings) | ||
for _, warning := range warnings { | ||
u.warner.Warn(warning) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(hostToIPs) < minServers { | ||
return nil, fmt.Errorf("%w: %d and expected at least %d", | ||
common.ErrNotEnoughServers, len(servers), minServers) | ||
} | ||
|
||
hts.adaptWithIPs(hostToIPs) | ||
|
||
servers = hts.toServersSlice() | ||
|
||
sort.Sort(models.SortableServers(servers)) | ||
|
||
return servers, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package updater | ||
|
||
import ( | ||
"github.com/qdm12/gluetun/internal/provider/common" | ||
) | ||
|
||
type Updater struct { | ||
unzipper common.Unzipper | ||
parallelResolver common.ParallelResolver | ||
warner common.Warner | ||
} | ||
|
||
func New(unzipper common.Unzipper, warner common.Warner, | ||
parallelResolver common.ParallelResolver) *Updater { | ||
return &Updater{ | ||
unzipper: unzipper, | ||
parallelResolver: parallelResolver, | ||
warner: warner, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.