random ports when used as an application proxy

This commit is contained in:
idk
2019-04-07 23:53:14 -04:00
parent 40a6fed393
commit cc03b14338
2 changed files with 21 additions and 21 deletions

View File

@ -51,14 +51,14 @@ var addr string
func main() {
lb := littleboss.New(*tunnelName)
proxyaddr := "127.0.0.1:7950"
controladdr := "127.0.0.1:7951"
for _, flag := range os.Args {
if flag == "-run-command" {
proxyaddr = "127.0.0.1:0"
controladdr = "127.0.0.1:0"
}
}
proxyaddr := "127.0.0.1:7950"
controladdr := "127.0.0.1:7951"
for _, flag := range os.Args {
if flag == "-run-command" {
proxyaddr = "127.0.0.1:0"
controladdr = "127.0.0.1:0"
}
}
ln := lb.Listener("proxy-addr", "tcp", proxyaddr, "The address of the proxy")
cln := lb.Listener("control-addr", "tcp", controladdr, "The address of the controller")
lb.Run(func(ctx context.Context) {
@ -163,7 +163,7 @@ func proxyMain(ctx context.Context, ln net.Listener, cln net.Listener) {
log.Println("Launching ", *runCommand, "with proxy http://"+ln.Addr().String())
cmd := exec.Command(*runCommand, strings.Split(*runArguments, " ")...)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {

View File

@ -151,10 +151,10 @@ func (p *SAMHTTPProxy) get(wr http.ResponseWriter, req *http.Request) {
resp, err := p.client.Do(req)
if err != nil {
msg := "Proxy Error " + err.Error()
if ! Quiet{
http.Error(wr, msg, http.StatusBadRequest)
if !Quiet {
http.Error(wr, msg, http.StatusBadRequest)
}
plog(msg)
plog(msg)
return
}
defer resp.Body.Close()
@ -168,25 +168,25 @@ func (p *SAMHTTPProxy) connect(wr http.ResponseWriter, req *http.Request) {
plog("CONNECT via i2p to", req.URL.Host)
dest_conn, err := p.goSam.Dial("tcp", req.URL.Host)
if err != nil {
if ! Quiet {
http.Error(wr, err.Error(), http.StatusServiceUnavailable)
if !Quiet {
http.Error(wr, err.Error(), http.StatusServiceUnavailable)
}
return
return
}
wr.WriteHeader(http.StatusOK)
hijacker, ok := wr.(http.Hijacker)
if !ok {
if !Quiet {
http.Error(wr, "Hijacking not supported", http.StatusInternalServerError)
if !Quiet {
http.Error(wr, "Hijacking not supported", http.StatusInternalServerError)
}
return
return
}
client_conn, _, err := hijacker.Hijack()
if err != nil {
if !Quiet{
http.Error(wr, err.Error(), http.StatusServiceUnavailable)
if !Quiet {
http.Error(wr, err.Error(), http.StatusServiceUnavailable)
}
return
return
}
go proxycommon.Transfer(dest_conn, client_conn)
go proxycommon.Transfer(client_conn, dest_conn)