From 679ac5680671b800c4e2f6de2357de42cdf06811 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 1 Dec 2023 14:35:32 +0200 Subject: [PATCH 1/2] customizable User-Agent --- holaapi.go | 13 +++++++++++-- main.go | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/holaapi.go b/holaapi.go index 065e842..e4d9818 100644 --- a/holaapi.go +++ b/holaapi.go @@ -26,7 +26,6 @@ import ( "github.com/google/uuid" ) -const USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" const EXT_BROWSER = "chrome" const PRODUCT = "cws" const CCGI_URL = "https://client.hola.org/client_cgi/" @@ -41,6 +40,16 @@ var TemporaryBanError = errors.New("temporary ban detected") var PermanentBanError = errors.New("permanent ban detected") var EmptyResponseError = errors.New("empty response") +var userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0" + +func SetUserAgent(ua string) { + userAgent = ua +} + +func GetUserAgent() string { + return userAgent +} + type CountryList []string type BgInitResponse struct { @@ -158,7 +167,7 @@ func do_req(ctx context.Context, client *http.Client, method, url string, query, if query != nil { req.URL.RawQuery = query.Encode() } - req.Header.Set("User-Agent", USER_AGENT) + req.Header.Set("User-Agent", userAgent) resp, err := client.Do(req) if err != nil { return nil, err diff --git a/main.go b/main.go index e97e164..9591487 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,7 @@ type CLIArgs struct { backoffInitial time.Duration backoffDeadline time.Duration hideSNI bool + userAgent string } func parse_args() CLIArgs { @@ -94,6 +95,7 @@ func parse_args() CLIArgs { "Format: ://[login:password@]host[:port] "+ "Examples: http://user:password@192.168.1.1:3128, socks5://10.0.0.1:1080") flag.StringVar(&args.caFile, "cafile", "", "use custom CA certificate bundle file") + flag.StringVar(&args.userAgent, "user-agent", GetUserAgent(), "value of User-Agent header in requests") flag.BoolVar(&args.hideSNI, "hide-SNI", true, "hide SNI in TLS sessions with proxy server") flag.Parse() if args.country == "" { @@ -176,6 +178,8 @@ func run() int { UpdateHolaDialer(dialer) } + SetUserAgent(args.userAgent) + if args.list_countries { return print_countries(args.timeout) } From 54fa9a4831b8230b5e785d4186a015cebcf3c519 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 1 Dec 2023 14:39:14 +0200 Subject: [PATCH 2/2] upd doc --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6b7c081..aa4deea 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ zagent248.hola.org,165.22.65.3,22222,22223,22224,22225,22226,digitalocean | resolver | String | DNS/DoH/DoT resolver to workaround Hola blocked hosts. See https://github.com/ameshkov/dnslookup/ for upstream DNS URL format. (default "https://cloudflare-dns.com/dns-query") | | rotate | Duration | rotate user ID once per given period (default 1h0m0s) | | timeout | Duration | timeout for network operations (default 35s) | +| user-agent | String | value of User-Agent header in requests (default "Mozilla/5.0 (X11; Linux x86\_64; rv:109.0) Gecko/20100101 Firefox/118.0") | | verbosity | Number | logging verbosity (10 - debug, 20 - info, 30 - warning, 40 - error, 50 - critical) (default 20) | ## See also