add option to override proxy endpoint address

This commit is contained in:
Vladislav Yarmak 2025-01-27 14:59:22 +02:00
parent 78e69822da
commit 1e42c66880

14
main.go
View file

@ -103,6 +103,7 @@ type CLIArgs struct {
certChainWorkaround bool certChainWorkaround bool
caFile string caFile string
fakeSNI string fakeSNI string
overrideProxyAddress string
} }
func parse_args() *CLIArgs { func parse_args() *CLIArgs {
@ -150,6 +151,7 @@ func parse_args() *CLIArgs {
"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.")