mirror of
https://github.com/Snawoot/hola-proxy.git
synced 2026-04-05 19:58:12 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff3c0f68fc | ||
|
|
4f72e317fc | ||
|
|
4ddd1284fb | ||
|
|
4fe6636003 | ||
|
|
b5ac6d38e5 | ||
|
|
0c377308c0 | ||
|
|
3b21036b20 | ||
|
|
683bc5f1ec | ||
|
|
be2e4e5420 | ||
|
|
95adb40377 | ||
|
|
6ced446e68 | ||
|
|
9c15f5eda9 | ||
|
|
afe3e3f732 |
24
Makefile
24
Makefile
@@ -1,7 +1,8 @@
|
||||
PROGNAME = hola-proxy
|
||||
OUTSUFFIX = bin/$(PROGNAME)
|
||||
VERSION := $(shell git describe)
|
||||
BUILDOPTS = -a -tags netgo
|
||||
LDFLAGS = -ldflags '-s -w -extldflags "-static"'
|
||||
LDFLAGS = -ldflags '-s -w -extldflags "-static" -X main.version=$(VERSION)'
|
||||
|
||||
src = $(wildcard *.go)
|
||||
|
||||
@@ -54,3 +55,24 @@ $(OUTSUFFIX).windows-386.exe: $(src)
|
||||
|
||||
clean:
|
||||
rm -f bin/*
|
||||
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
run:
|
||||
go run $(LDFLAGS) .
|
||||
|
||||
install:
|
||||
go install $(BUILDOPTS) $(LDFLAGS) .
|
||||
|
||||
.PHONY: clean all native fmt install \
|
||||
bin-native \
|
||||
bin-linux-amd64 \
|
||||
bin-linux-386 \
|
||||
bin-linux-arm \
|
||||
bin-freebsd-amd64 \
|
||||
bin-freebsd-386 \
|
||||
bin-freebsd-arm \
|
||||
bin-darwin-amd64 \
|
||||
bin-windows-amd64 \
|
||||
bin-windows-386
|
||||
|
||||
@@ -44,7 +44,7 @@ Pre-built binaries available on [releases](https://github.com/Snawoot/hola-proxy
|
||||
Alternatively, you may install hola-proxy from source. Run within source directory
|
||||
|
||||
```
|
||||
go install
|
||||
make install
|
||||
```
|
||||
|
||||
#### Docker
|
||||
|
||||
26
holaapi.go
26
holaapi.go
@@ -5,6 +5,8 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/campoy/unique"
|
||||
"github.com/google/uuid"
|
||||
"io/ioutil"
|
||||
@@ -24,12 +26,17 @@ const BG_INIT_URL = CCGI_URL + "background_init"
|
||||
const ZGETTUNNELS_URL = CCGI_URL + "zgettunnels"
|
||||
const LOGIN_PREFIX = "user-uuid-"
|
||||
|
||||
var TemporaryBanError = errors.New("temporary ban detected")
|
||||
var PermanentBanError = errors.New("permanent ban detected")
|
||||
|
||||
type CountryList []string
|
||||
|
||||
type BgInitResponse struct {
|
||||
Ver string `json:"ver"`
|
||||
Key int64 `json:"key"`
|
||||
Country string `json:"country"`
|
||||
Ver string `json:"ver"`
|
||||
Key int64 `json:"key"`
|
||||
Country string `json:"country"`
|
||||
Blocked bool `json:"blocked,omitempty"`
|
||||
Permanent bool `json:"permanent,omitempty"`
|
||||
}
|
||||
|
||||
type PortMap struct {
|
||||
@@ -81,6 +88,11 @@ func do_req(ctx context.Context, method, url string, query, data url.Values) ([]
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch resp.StatusCode {
|
||||
case http.StatusOK, http.StatusCreated, http.StatusAccepted, http.StatusNoContent:
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintf("Bad HTTP response: %s", resp.Status))
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if err != nil {
|
||||
@@ -118,7 +130,15 @@ func background_init(ctx context.Context, user_uuid string) (res BgInitResponse,
|
||||
reterr = err
|
||||
return
|
||||
}
|
||||
|
||||
reterr = json.Unmarshal(resp, &res)
|
||||
if reterr == nil && res.Blocked {
|
||||
if res.Permanent {
|
||||
reterr = PermanentBanError
|
||||
} else {
|
||||
reterr = TemporaryBanError
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
10
main.go
10
main.go
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
var (
|
||||
PROTOCOL_WHITELIST map[string]bool
|
||||
version = "undefined"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -44,6 +45,7 @@ type CLIArgs struct {
|
||||
proxy_type string
|
||||
resolver string
|
||||
force_port_field string
|
||||
showVersion bool
|
||||
}
|
||||
|
||||
func parse_args() CLIArgs {
|
||||
@@ -64,6 +66,7 @@ func parse_args() CLIArgs {
|
||||
"DNS/DoH/DoT resolver to workaround Hola blocked hosts. "+
|
||||
"See https://github.com/ameshkov/dnslookup/ for upstream DNS URL format.")
|
||||
flag.BoolVar(&args.use_trial, "dont-use-trial", false, "use regular ports instead of trial ports") // would be nice to not show in help page
|
||||
flag.BoolVar(&args.showVersion, "version", false, "show program version and exit")
|
||||
flag.Parse()
|
||||
if args.country == "" {
|
||||
arg_fail("Country can't be empty string.")
|
||||
@@ -79,6 +82,11 @@ func parse_args() CLIArgs {
|
||||
|
||||
func run() int {
|
||||
args := parse_args()
|
||||
if args.showVersion {
|
||||
fmt.Println(version)
|
||||
return 0
|
||||
}
|
||||
|
||||
if args.list_countries {
|
||||
return print_countries(args.timeout)
|
||||
}
|
||||
@@ -98,6 +106,7 @@ func run() int {
|
||||
proxyLogger := NewCondLogger(log.New(logWriter, "PROXY : ",
|
||||
log.LstdFlags|log.Lshortfile),
|
||||
args.verbosity)
|
||||
mainLogger.Info("hola-proxy client version %s is starting...", version)
|
||||
mainLogger.Info("Constructing fallback DNS upstream...")
|
||||
resolver, err := NewResolver(args.resolver, args.timeout)
|
||||
if err != nil {
|
||||
@@ -120,6 +129,7 @@ func run() int {
|
||||
mainLogger.Info("Endpoint: %s", endpoint)
|
||||
mainLogger.Info("Starting proxy server...")
|
||||
handler := NewProxyHandler(endpoint, auth, resolver, proxyLogger)
|
||||
mainLogger.Info("Init complete.")
|
||||
err = http.ListenAndServe(args.bind_address, handler)
|
||||
mainLogger.Critical("Server terminated with a reason: %v", err)
|
||||
mainLogger.Info("Shutting down...")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: hola-proxy
|
||||
version: '1.4.1'
|
||||
version: '1.4.2'
|
||||
summary: Standalone Hola proxy client.
|
||||
description: |
|
||||
Standalone Hola proxy client. Just run it and it'll start plain HTTP proxy server forwarding traffic via Hola proxies of your choice.
|
||||
|
||||
Reference in New Issue
Block a user