auto-configure proxy rules helper

This commit is contained in:
idk
2019-08-26 00:02:06 -04:00
parent f2e5d26367
commit c14fa29339
2 changed files with 48 additions and 8 deletions

View File

@ -137,14 +137,6 @@ func SetControlHost(s string) func(*SAMHTTPProxy) error {
}
}
//SetKeysPath sets the path to the key save files
func SetKeysPath(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.keyspath = s
return nil
}
}
//SetContrlPort sets the host of the client's Proxy controller
func SetControlPort(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
@ -160,6 +152,37 @@ func SetControlPort(s string) func(*SAMHTTPProxy) error {
}
}
//SetProxyHost sets the host of the client's Proxy controller
func SetProxyHost(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.proxyHost = s
return nil
}
}
//SetProxyPort sets the host of the client's Proxy controller
func SetProxyPort(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid port; non-number")
}
if port < 65536 && port > -1 {
c.proxyPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetKeysPath sets the path to the key save files
func SetKeysPath(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.keyspath = s
return nil
}
}
//SetHost sets the host of the client's SAM bridge
func SetHost(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {

View File

@ -241,6 +241,23 @@ func (p *SAMHTTPProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
}
// SetupProxy sets proxy environment variables based on the settings in use by the proxy
func (p *SAMHTTPProxy) SetupProxy() {
SetupProxy(p.Target())
}
// SetupProxy sets proxy environment variables based on a string address
func SetupProxy(addr string) {
os.Setenv("http_proxy", "http://"+addr)
os.Setenv("https_proxy", "http://"+addr)
os.Setenv("ftp_proxy", "http://"+addr)
os.Setenv("all_proxy", "http://"+addr)
os.Setenv("HTTP_PROXY", "http://"+addr)
os.Setenv("HTTPS_PROXY", "http://"+addr)
os.Setenv("FTP_PROXY", "http://"+addr)
os.Setenv("ALL_PROXY", "http://"+addr)
}
func (p *SAMHTTPProxy) reset(wr http.ResponseWriter, req *http.Request) {
plog("Validating control access from", req.RemoteAddr, p.controlHost+":"+p.controlPort)
if strings.SplitN(req.RemoteAddr, ":", 2)[0] == p.controlHost {