mirror of
https://github.com/Alexey71/opera-proxy.git
synced 2026-05-13 14:11:00 +00:00
API proxy feature
This commit is contained in:
@@ -114,6 +114,7 @@ type CLIArgs struct {
|
|||||||
apiClientType string
|
apiClientType string
|
||||||
apiClientVersion string
|
apiClientVersion string
|
||||||
apiUserAgent string
|
apiUserAgent string
|
||||||
|
apiProxy string
|
||||||
bootstrapDNS *CSVArg
|
bootstrapDNS *CSVArg
|
||||||
refresh time.Duration
|
refresh time.Duration
|
||||||
refreshRetry time.Duration
|
refreshRetry time.Duration
|
||||||
@@ -164,6 +165,7 @@ func parse_args() *CLIArgs {
|
|||||||
flag.StringVar(&args.apiLogin, "api-login", "se0316", "SurfEasy API login")
|
flag.StringVar(&args.apiLogin, "api-login", "se0316", "SurfEasy API login")
|
||||||
flag.StringVar(&args.apiPassword, "api-password", "SILrMEPBmJuhomxWkfm3JalqHX2Eheg1YhlEZiMh8II", "SurfEasy API password")
|
flag.StringVar(&args.apiPassword, "api-password", "SILrMEPBmJuhomxWkfm3JalqHX2Eheg1YhlEZiMh8II", "SurfEasy API password")
|
||||||
flag.StringVar(&args.apiAddress, "api-address", "", fmt.Sprintf("override IP address of %s", API_DOMAIN))
|
flag.StringVar(&args.apiAddress, "api-address", "", fmt.Sprintf("override IP address of %s", API_DOMAIN))
|
||||||
|
flag.StringVar(&args.apiProxy, "api-proxy", "", "additional proxy server used to access SurfEasy API")
|
||||||
flag.Var(args.bootstrapDNS, "bootstrap-dns",
|
flag.Var(args.bootstrapDNS, "bootstrap-dns",
|
||||||
"comma-separated list of DNS/DoH/DoT resolvers for initial discovery of SurfEasy API address. "+
|
"comma-separated list of DNS/DoH/DoT resolvers for initial discovery of SurfEasy API address. "+
|
||||||
"Supported schemes are: dns://, https://, tls://, tcp://. "+
|
"Supported schemes are: dns://, https://, tls://, tcp://. "+
|
||||||
@@ -241,9 +243,9 @@ func run() int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xproxy.RegisterDialerType("http", proxyFromURLWrapper)
|
||||||
|
xproxy.RegisterDialerType("https", proxyFromURLWrapper)
|
||||||
if args.proxy != "" {
|
if args.proxy != "" {
|
||||||
xproxy.RegisterDialerType("http", proxyFromURLWrapper)
|
|
||||||
xproxy.RegisterDialerType("https", proxyFromURLWrapper)
|
|
||||||
proxyURL, err := url.Parse(args.proxy)
|
proxyURL, err := url.Parse(args.proxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mainLogger.Critical("Unable to parse base proxy URL: %v", err)
|
mainLogger.Critical("Unable to parse base proxy URL: %v", err)
|
||||||
@@ -258,16 +260,29 @@ func run() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
seclientDialer := d
|
seclientDialer := d
|
||||||
|
if args.apiProxy != "" {
|
||||||
|
apiProxyURL, err := url.Parse(args.apiProxy)
|
||||||
|
if err != nil {
|
||||||
|
mainLogger.Critical("Unable to parse base proxy URL: %v", err)
|
||||||
|
return 6
|
||||||
|
}
|
||||||
|
pxDialer, err := xproxy.FromURL(apiProxyURL, seclientDialer)
|
||||||
|
if err != nil {
|
||||||
|
mainLogger.Critical("Unable to instantiate base proxy dialer: %v", err)
|
||||||
|
return 7
|
||||||
|
}
|
||||||
|
seclientDialer = pxDialer.(dialer.ContextDialer)
|
||||||
|
}
|
||||||
if args.apiAddress != "" {
|
if args.apiAddress != "" {
|
||||||
mainLogger.Info("Using fixed API host address = %s", args.apiAddress)
|
mainLogger.Info("Using fixed API host address = %s", args.apiAddress)
|
||||||
seclientDialer = dialer.NewFixedDialer(args.apiAddress, d)
|
seclientDialer = dialer.NewFixedDialer(args.apiAddress, seclientDialer)
|
||||||
} else if len(args.bootstrapDNS.values) > 0 {
|
} else if len(args.bootstrapDNS.values) > 0 {
|
||||||
resolver, err := resolver.FastFromURLs(args.bootstrapDNS.values...)
|
resolver, err := resolver.FastFromURLs(args.bootstrapDNS.values...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mainLogger.Critical("Unable to instantiate DNS resolver: %v", err)
|
mainLogger.Critical("Unable to instantiate DNS resolver: %v", err)
|
||||||
return 4
|
return 4
|
||||||
}
|
}
|
||||||
seclientDialer = dialer.NewResolvingDialer(resolver, d)
|
seclientDialer = dialer.NewResolvingDialer(resolver, seclientDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dialing w/o SNI, receiving self-signed certificate, so skip verification.
|
// Dialing w/o SNI, receiving self-signed certificate, so skip verification.
|
||||||
|
|||||||
Reference in New Issue
Block a user