mirror of
https://github.com/Snawoot/opera-proxy.git
synced 2025-09-02 10:42:07 +00:00
Merge pull request #84 from Snawoot/opt_override_proxy_address
Opt override proxy address
This commit is contained in:
commit
7361547a95
2 changed files with 37 additions and 26 deletions
|
@ -105,6 +105,7 @@ eu3.sec-tunnel.com,77.111.244.22,443
|
||||||
| init-retry-interval | Duration | delay between initialization retries (default 5s) |
|
| init-retry-interval | Duration | delay between initialization retries (default 5s) |
|
||||||
| list-countries | - | list available countries and exit |
|
| list-countries | - | list available countries and exit |
|
||||||
| list-proxies | - | output proxy list and exit |
|
| list-proxies | - | output proxy list and exit |
|
||||||
|
| override-proxy-address | string | use fixed proxy address instead of server address returned by SurfEasy API |
|
||||||
| proxy | String | sets base proxy to use for all dial-outs. Format: `<http\|https\|socks5\|socks5h>://[login:password@]host[:port]` Examples: `http://user:password@192.168.1.1:3128`, `socks5://10.0.0.1:1080` |
|
| proxy | String | sets base proxy to use for all dial-outs. Format: `<http\|https\|socks5\|socks5h>://[login:password@]host[:port]` Examples: `http://user:password@192.168.1.1:3128`, `socks5://10.0.0.1:1080` |
|
||||||
| refresh | Duration | login refresh interval (default 4h0m0s) |
|
| refresh | Duration | login refresh interval (default 4h0m0s) |
|
||||||
| refresh-retry | Duration | login refresh retry interval (default 5s) |
|
| refresh-retry | Duration | login refresh retry interval (default 5s) |
|
||||||
|
|
62
main.go
62
main.go
|
@ -81,28 +81,29 @@ func (a *CSVArg) Set(line string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CLIArgs struct {
|
type CLIArgs struct {
|
||||||
country string
|
country string
|
||||||
listCountries bool
|
listCountries bool
|
||||||
listProxies bool
|
listProxies bool
|
||||||
bindAddress string
|
bindAddress string
|
||||||
verbosity int
|
verbosity int
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
showVersion bool
|
showVersion bool
|
||||||
proxy string
|
proxy string
|
||||||
apiLogin string
|
apiLogin string
|
||||||
apiPassword string
|
apiPassword string
|
||||||
apiAddress string
|
apiAddress string
|
||||||
apiClientType string
|
apiClientType string
|
||||||
apiClientVersion string
|
apiClientVersion string
|
||||||
apiUserAgent string
|
apiUserAgent string
|
||||||
bootstrapDNS *CSVArg
|
bootstrapDNS *CSVArg
|
||||||
refresh time.Duration
|
refresh time.Duration
|
||||||
refreshRetry time.Duration
|
refreshRetry time.Duration
|
||||||
initRetries int
|
initRetries int
|
||||||
initRetryInterval time.Duration
|
initRetryInterval time.Duration
|
||||||
certChainWorkaround bool
|
certChainWorkaround bool
|
||||||
caFile string
|
caFile string
|
||||||
fakeSNI string
|
fakeSNI string
|
||||||
|
overrideProxyAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse_args() *CLIArgs {
|
func parse_args() *CLIArgs {
|
||||||
|
@ -145,11 +146,12 @@ func parse_args() *CLIArgs {
|
||||||
flag.DurationVar(&args.refresh, "refresh", 4*time.Hour, "login refresh interval")
|
flag.DurationVar(&args.refresh, "refresh", 4*time.Hour, "login refresh interval")
|
||||||
flag.DurationVar(&args.refreshRetry, "refresh-retry", 5*time.Second, "login refresh retry interval")
|
flag.DurationVar(&args.refreshRetry, "refresh-retry", 5*time.Second, "login refresh retry interval")
|
||||||
flag.IntVar(&args.initRetries, "init-retries", 0, "number of attempts for initialization steps, zero for unlimited retry")
|
flag.IntVar(&args.initRetries, "init-retries", 0, "number of attempts for initialization steps, zero for unlimited retry")
|
||||||
flag.DurationVar(&args.initRetryInterval, "init-retry-interval", 5 * time.Second, "delay between initialization retries")
|
flag.DurationVar(&args.initRetryInterval, "init-retry-interval", 5*time.Second, "delay between initialization retries")
|
||||||
flag.BoolVar(&args.certChainWorkaround, "certchain-workaround", true,
|
flag.BoolVar(&args.certChainWorkaround, "certchain-workaround", true,
|
||||||
"add bundled cross-signed intermediate cert to certchain to make it check out on old systems")
|
"add bundled cross-signed intermediate cert to certchain to make it check out on old systems")
|
||||||
flag.StringVar(&args.caFile, "cafile", "", "use custom CA certificate bundle file")
|
flag.StringVar(&args.caFile, "cafile", "", "use custom CA certificate bundle file")
|
||||||
flag.StringVar(&args.fakeSNI, "fake-SNI", "", "domain name to use as SNI in communications with servers")
|
flag.StringVar(&args.fakeSNI, "fake-SNI", "", "domain name to use as SNI in communications with servers")
|
||||||
|
flag.StringVar(&args.overrideProxyAddress, "override-proxy-address", "", "use fixed proxy address instead of server address returned by SurfEasy API")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if args.country == "" {
|
if args.country == "" {
|
||||||
arg_fail("Country can't be empty string.")
|
arg_fail("Country can't be empty string.")
|
||||||
|
@ -337,6 +339,15 @@ func run() int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var handlerBaseDialer dialer.ContextDialer = d
|
||||||
|
if args.overrideProxyAddress != "" {
|
||||||
|
mainLogger.Info("Original endpoint: %s", endpoint.IP)
|
||||||
|
handlerBaseDialer = dialer.NewFixedDialer(args.overrideProxyAddress, handlerBaseDialer)
|
||||||
|
mainLogger.Info("Endpoint override: %s", args.overrideProxyAddress)
|
||||||
|
} else {
|
||||||
|
mainLogger.Info("Endpoint: %s", endpoint.NetAddr())
|
||||||
|
}
|
||||||
handlerDialer := dialer.NewProxyDialer(
|
handlerDialer := dialer.NewProxyDialer(
|
||||||
dialer.WrapStringToCb(endpoint.NetAddr()),
|
dialer.WrapStringToCb(endpoint.NetAddr()),
|
||||||
dialer.WrapStringToCb(fmt.Sprintf("%s0.%s", args.country, PROXY_SUFFIX)),
|
dialer.WrapStringToCb(fmt.Sprintf("%s0.%s", args.country, PROXY_SUFFIX)),
|
||||||
|
@ -346,8 +357,7 @@ func run() int {
|
||||||
},
|
},
|
||||||
args.certChainWorkaround,
|
args.certChainWorkaround,
|
||||||
caPool,
|
caPool,
|
||||||
d)
|
handlerBaseDialer)
|
||||||
mainLogger.Info("Endpoint: %s", endpoint.NetAddr())
|
|
||||||
mainLogger.Info("Starting proxy server...")
|
mainLogger.Info("Starting proxy server...")
|
||||||
h := handler.NewProxyHandler(handlerDialer, proxyLogger)
|
h := handler.NewProxyHandler(handlerDialer, proxyLogger)
|
||||||
mainLogger.Info("Init complete.")
|
mainLogger.Info("Init complete.")
|
||||||
|
@ -407,7 +417,7 @@ func main() {
|
||||||
func retryPolicy(retries int, retryInterval time.Duration, logger *clog.CondLogger) func(string, func() error) error {
|
func retryPolicy(retries int, retryInterval time.Duration, logger *clog.CondLogger) func(string, func() error) error {
|
||||||
return func(name string, f func() error) error {
|
return func(name string, f func() error) error {
|
||||||
var err error
|
var err error
|
||||||
for i:=1; retries <= 0 || i<=retries; i++ {
|
for i := 1; retries <= 0 || i <= retries; i++ {
|
||||||
if i > 1 {
|
if i > 1 {
|
||||||
logger.Warning("Retrying action %q in %v...", name, retryInterval)
|
logger.Warning("Retrying action %q in %v...", name, retryInterval)
|
||||||
time.Sleep(retryInterval)
|
time.Sleep(retryInterval)
|
||||||
|
|
Loading…
Add table
Reference in a new issue