diff --git a/README.md b/README.md index 18abf7b..363149e 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ Options: DNS Listen on UDP (default true) -explicit-proxy-listen [host]:port Explicit Proxy listen address for HTTP/HTTPS, as [host]:port Note: This proxy doesn't use authentication info of the `http_proxy` and `https_proxy` environment variables (default ":3132") + -explicit-proxy-only + Boot Explicit Proxies only -explicit-proxy-with-auth-listen [host]:port Explicit Proxy with auth listen address for HTTP/HTTPS, as [host]:port Note: This proxy uses authentication info of the `http_proxy` and `https_proxy` environment variables (default ":3133") -http-proxy-listen [host]:port diff --git a/build.sh b/build.sh index 7c48349..708e573 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/sh -VERSION=0.4 +VERSION=0.5 DIR=$(cd $(dirname $0); pwd) cd $DIR diff --git a/cmd/transproxy/main.go b/cmd/transproxy/main.go index 0f7fc45..e5054a2 100644 --- a/cmd/transproxy/main.go +++ b/cmd/transproxy/main.go @@ -66,6 +66,10 @@ var ( "explicit-proxy-with-auth-listen", ":3133", "Explicit Proxy with auth listen address for HTTP/HTTPS, as `[host]:port` Note: This proxy uses authentication info of the `http_proxy` and `https_proxy` environment variables", ) + explicitProxyOnly = fs.Bool( + "explicit-proxy-only", false, "Boot Explicit Proxies only", + ) + dnsOverTCPDisabled = fs.Bool( "dns-over-tcp-disabled", false, "Disable DNS-over-TCP for querying to public DNS") @@ -94,6 +98,26 @@ func main() { // seed the global random number generator, used in secureoperator rand.Seed(time.Now().UTC().UnixNano()) + if *explicitProxyOnly { + startExplicitProxyOnly() + } else { + startAllProxy() + } +} + +func startExplicitProxyOnly() { + startExplicitProxy() + + // serve until exit + sig := make(chan os.Signal) + signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) + <-sig + + log.Printf("info: Proxy servers stopping.") + log.Printf("info: go-transproxy exited.") +} + +func startAllProxy() { // setup logger colog.SetDefaultLevel(colog.LDebug) colog.SetMinLevel(colog.LInfo) @@ -114,8 +138,8 @@ func main() { if noProxy == "" { noProxy = os.Getenv("NO_PROXY") } - np := parseNoProxy(noProxy) + np := parseNoProxy(noProxy) // start servers tcpProxy := transproxy.NewTCPProxy( transproxy.TCPProxyConfig{ @@ -163,25 +187,7 @@ func main() { log.Fatalf("alert: %s", err.Error()) } - explicitProxyWithAuth := transproxy.NewExplicitProxy( - transproxy.ExplicitProxyConfig{ - ListenAddress: *explicitProxyWithAuthListenAddress, - UseProxyAuthorization: true, - }, - ) - if err := explicitProxyWithAuth.Start(); err != nil { - log.Fatalf("alert: %s", err.Error()) - } - - explicitProxy := transproxy.NewExplicitProxy( - transproxy.ExplicitProxyConfig{ - ListenAddress: *explicitProxyListenAddress, - UseProxyAuthorization: false, - }, - ) - if err := explicitProxy.Start(); err != nil { - log.Fatalf("alert: %s", err.Error()) - } + startExplicitProxy() log.Printf("info: All proxy servers started.") @@ -233,6 +239,28 @@ func main() { log.Printf("info: go-transproxy exited.") } +func startExplicitProxy() { + explicitProxyWithAuth := transproxy.NewExplicitProxy( + transproxy.ExplicitProxyConfig{ + ListenAddress: *explicitProxyWithAuthListenAddress, + UseProxyAuthorization: true, + }, + ) + if err := explicitProxyWithAuth.Start(); err != nil { + log.Fatalf("alert: %s", err.Error()) + } + + explicitProxy := transproxy.NewExplicitProxy( + transproxy.ExplicitProxyConfig{ + ListenAddress: *explicitProxyListenAddress, + UseProxyAuthorization: false, + }, + ) + if err := explicitProxy.Start(); err != nil { + log.Fatalf("alert: %s", err.Error()) + } +} + func useDNSProxy() bool { if *privateDNS == "" && *publicDNS == "" && *dnsOverHTTPSEnabled == false { return false