//AddHTTPSpecialBundles hands a default bundle to the supplied director func AddHTTPSpecialBundles(x ProxyDirector, stream HTTPStreamer, controls *xnet.Control, check bool, each xnet.EachControl, report *flux.StackReport) error { if stream == nil { return ErrBadBundle } if controls == nil { return ErrBadBundle } x.Register("chttp", func(req *ProxyRequest, d *Director, a Action) error { var err error var cert *tls.Config if req.CertFile != "" && req.KeyFile != "" { cert, err = LoadTLS(req.CertFile, req.KeyFile) if err != nil { return err } } ls, err := xnet.ListenTCP("tcp", req.From, cert, controls, each, report) if err != nil { return err } return x.ServeCustom(ls, func(con net.Conn, d Directors) error { xcon, ok := con.(*xnet.XConn) flux.Report(nil, fmt.Sprintf("Retrieving HTTP XConn from net.Conn for IP %s -> %t", con.RemoteAddr().String(), ok)) if !ok { return xnet.ErrBadXConn } ip, err := xcon.Container().IP() flux.Report(err, fmt.Sprintf("Retrieving Container IP from HTTP XConn for %s -> %s", con.RemoteAddr().String(), ip)) if err != nil { return err } req.Addr = ip addr := net.JoinHostPort(ip, fmt.Sprintf("%d", req.Port)) // addr := net.JoinHostPort(ip, string(req.Port)) cn, err := stream.StreamWithConn(xcon, addr, cert) flux.Report(err, fmt.Sprintf("Initiated HTTP tcp container proxy Scheme for %s -> %s", con.RemoteAddr().String(), addr)) if err != nil { return err } rip, _, _ := net.SplitHostPort(ip) cn.Meta["container_ip"] = ip cn.Meta["remote_ip"] = rip cn.Meta["local_ip"] = con.LocalAddr().String() cn.Meta["name"] = xcon.Container().Name() cn.Meta["port"] = fmt.Sprintf("%d", req.Port) a(cn) return nil }, check) }) return nil }
//AddSSHSpecialBundles hands a default bundle to the supplied director func AddSSHSpecialBundles(x ProxyDirector, sv SSHStreamer, serv *SSHStreamServer, controls *xnet.Control, check bool, each xnet.EachControl) error { if serv == nil { return ErrBadBundle } if sv == nil { return ErrBadBundle } if controls == nil { return ErrBadBundle } x.Register("cssh", func(req *ProxyRequest, d *Director, a Action) error { var err error var cert *tls.Config if req.CertFile != "" && req.KeyFile != "" { cert, err = LoadTLS(req.CertFile, req.KeyFile) if err != nil { return err } } rq, _ := serv.Reports() ls, err := xnet.ListenTCP("tcp", req.From, cert, controls, each, rq) if err != nil { return err } return x.ServeCustom(ls, func(con net.Conn, d Directors) error { xcon, ok := con.(*xnet.XConn) flux.Report(nil, fmt.Sprintf("Retrieving XConn from net.Conn for IP %s -> %t", con.RemoteAddr().String(), ok)) if !ok { return xnet.ErrBadXConn } ip, err := xcon.Container().IP() flux.Report(err, fmt.Sprintf("Retrieving Container IP from XConn for %s -> %s", con.RemoteAddr().String(), ip)) if err != nil { return err } req.Addr = ip addr := net.JoinHostPort(ip, fmt.Sprintf("%d", req.Port)) // addr := net.JoinHostPort(ip, string(req.Port)) sl, cl, err := serv.StreamConnection(xcon, addr, nil) flux.Report(err, fmt.Sprintf("Initiated ssh authentication Scheme for %s and %s", con.RemoteAddr().String(), addr)) if err != nil { return err } cn, err := sv.Stream(sl, cl) flux.Report(err, fmt.Sprintf("Initiated ssh proxy Scheme for %s -> %s", con.RemoteAddr().String(), addr)) if err != nil { return err } rip, _, _ := net.SplitHostPort(cl.Client.Meta.RemoteAddr().String()) cn.Meta["cip"] = ip cn.Meta["rip"] = rip cn.Meta["name"] = xcon.Container().Name() cn.Meta["port"] = fmt.Sprintf("%d", req.Port) cn.Meta["pass"] = string(cl.Client.Pass) cn.Meta["user"] = cl.Client.Meta.User() a(cn) cn.open.Emit(true) return nil }, check) }) return nil }