From b262d91cccd42f90707b255fdf3bb85515d0f105 Mon Sep 17 00:00:00 2001 From: "Quentin McGaw (desktop)" Date: Fri, 23 Jul 2021 02:47:04 +0000 Subject: [PATCH] Feat: add -all flag to update all VPN servers --- internal/cli/update.go | 7 ++++++- internal/configuration/updater.go | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/cli/update.go b/internal/cli/update.go index 390a8b00..fb0a5648 100644 --- a/internal/cli/update.go +++ b/internal/cli/update.go @@ -28,12 +28,13 @@ var ( func (c *cli) Update(ctx context.Context, args []string, os os.OS, logger logging.Logger) error { options := configuration.Updater{CLI: true} - var endUserMode, maintainerMode bool + var endUserMode, maintainerMode, updateAll bool flagSet := flag.NewFlagSet("update", flag.ExitOnError) flagSet.BoolVar(&endUserMode, "enduser", false, "Write results to /gluetun/servers.json (for end users)") flagSet.BoolVar(&maintainerMode, "maintainer", false, "Write results to ./internal/constants/servers.json to modify the program (for maintainers)") flagSet.StringVar(&options.DNSAddress, "dns", "8.8.8.8", "DNS resolver address to use") + flagSet.BoolVar(&updateAll, "all", false, "Update servers for all VPN providers") flagSet.BoolVar(&options.Cyberghost, "cyberghost", false, "Update Cyberghost servers") flagSet.BoolVar(&options.Fastestvpn, "fastestvpn", false, "Update FastestVPN servers") flagSet.BoolVar(&options.HideMyAss, "hidemyass", false, "Update HideMyAss servers") @@ -58,6 +59,10 @@ func (c *cli) Update(ctx context.Context, args []string, os os.OS, logger loggin return ErrModeUnspecified } + if updateAll { + options.EnableAll() + } + const clientTimeout = 10 * time.Second httpClient := &http.Client{Timeout: clientTimeout} storage := storage.New(logger, os, constants.ServersData) diff --git a/internal/configuration/updater.go b/internal/configuration/updater.go index ce2a0a96..9b389b73 100644 --- a/internal/configuration/updater.go +++ b/internal/configuration/updater.go @@ -48,7 +48,7 @@ func (settings *Updater) lines() (lines []string) { return lines } -func (settings *Updater) read(r reader) (err error) { +func (settings *Updater) EnableAll() { settings.Cyberghost = true settings.HideMyAss = true settings.Ipvanish = true @@ -66,7 +66,10 @@ func (settings *Updater) read(r reader) (err error) { settings.VPNUnlimited = true settings.Vyprvpn = true settings.Windscribe = true - settings.CLI = false +} + +func (settings *Updater) read(r reader) (err error) { + settings.EnableAll() // use cloudflare in plaintext to not be blocked by DNS over TLS by default. // If a plaintext address is set in the DNS settings, this one will be used. // TODO use custom future encrypted DNS written in Go without blocking