func ServeOnce(c *server.Config, cf string, hd *httpdown.HTTP) (*server.AuthServer, httpdown.Server) { glog.Infof("Config from %s (%d users, %d ACL entries)", cf, len(c.Users), len(c.ACL)) as, err := server.NewAuthServer(c) if err != nil { glog.Exitf("Failed to create auth server: %s", err) } hs := &http.Server{ Addr: c.Server.ListenAddress, Handler: as, TLSConfig: &tls.Config{ NextProtos: []string{"http/1.1"}, Certificates: make([]tls.Certificate, 1), }, } glog.Infof("Cert file: %s", c.Server.CertFile) glog.Infof("Key file : %s", c.Server.KeyFile) hs.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(c.Server.CertFile, c.Server.KeyFile) if err != nil { glog.Exitf("Failed to load certificate and key: %s", err) } s, err := hd.ListenAndServe(hs) if err != nil { glog.Exitf("Failed to set up listener: %s", err) } glog.Infof("Serving") return as, s }
func ServeOnce(c *config.Config, cf string, hd *httpdown.HTTP) (*server.AuthServer, httpdown.Server) { glog.Infof("Config from %s (%d users, %d ACL static entries)", cf, len(c.Users), len(c.ACL)) as, ms, err := server.NewAuthServer(c) if err != nil { glog.Exitf("Failed to create auth server: %s", err) } var tlsConfig *tls.Config if c.Server.CertFile != "" || c.Server.KeyFile != "" { // Check for partial configuration. if c.Server.CertFile == "" || c.Server.KeyFile == "" { glog.Exitf("Failed to load certificate and key: both were not provided") } tlsConfig = &tls.Config{ MinVersion: tls.VersionTLS10, PreferServerCipherSuites: true, CipherSuites: []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, tls.TLS_RSA_WITH_AES_128_CBC_SHA, tls.TLS_RSA_WITH_AES_256_CBC_SHA, }, NextProtos: []string{"http/1.1"}, Certificates: make([]tls.Certificate, 1), } glog.Infof("Cert file: %s", c.Server.CertFile) glog.Infof("Key file : %s", c.Server.KeyFile) tlsConfig.Certificates[0], err = tls.LoadX509KeyPair(c.Server.CertFile, c.Server.KeyFile) if err != nil { glog.Exitf("Failed to load certificate and key: %s", err) } } else { glog.Warning("Running without TLS") } hs := &http.Server{ Addr: c.Server.ListenAddress, Handler: as, TLSConfig: tlsConfig, } s, err := hd.ListenAndServe(hs) if err != nil { glog.Exitf("Failed to set up listener: %s", err) } ms.RunManagerServer() glog.Infof("Serving") return as, s }
func newServer() (*server, error) { var s server s.data = make(map[string][]byte) s.fwd = make(map[string]chan<- readerDone) hs := http.Server{ Addr: ":0", Handler: http.HandlerFunc(s.httpHandler), } ln, err := net.Listen("tcp", ":0") if err != nil { return nil, err } var h httpdown.HTTP s.s = h.Serve(&hs, ln) s.port = ln.Addr().(*net.TCPAddr).Port return &s, nil }
func ServeOnce(c *server.Config, cf string, hd *httpdown.HTTP) (*server.AuthServer, httpdown.Server) { glog.Infof("Config from %s (%d users, %d ACL entries)", cf, len(c.Users), len(c.ACL)) as, err := server.NewAuthServer(c) if err != nil { glog.Exitf("Failed to create auth server: %s", err) } var tlsConfig *tls.Config if c.Server.CertFile != "" || c.Server.KeyFile != "" { // Check for partial configuration. if c.Server.CertFile == "" || c.Server.KeyFile == "" { glog.Exitf("Failed to load certificate and key: both were not provided") } tlsConfig = &tls.Config{ NextProtos: []string{"http/1.1"}, Certificates: make([]tls.Certificate, 1), } glog.Infof("Cert file: %s", c.Server.CertFile) glog.Infof("Key file : %s", c.Server.KeyFile) tlsConfig.Certificates[0], err = tls.LoadX509KeyPair(c.Server.CertFile, c.Server.KeyFile) if err != nil { glog.Exitf("Failed to load certificate and key: %s", err) } } else { glog.Warning("Running without TLS") } hs := &http.Server{ Addr: c.Server.ListenAddress, Handler: as, TLSConfig: tlsConfig, } s, err := hd.ListenAndServe(hs) if err != nil { glog.Exitf("Failed to set up listener: %s", err) } glog.Infof("Serving") return as, s }
func main() { flag.Parse() origAttr, err := makeRaw(os.Stdout.Fd()) if err != nil { panic(err) } defer func() { if err := tcsetattr(os.Stdout.Fd(), origAttr); err != nil { glog.Error(err) // Nothing much we can do about this error. } }() c := exec.Command("nethack") c.Env = append(c.Env, os.Environ()...) // I have no idea if this is right, but it seems to work. c.Env = append(c.Env, "TERM=xterm") pty, err := pty.Start(c) if err != nil { panic(err) } v := vt{vt100.NewVT100(24, 80), new(sync.Mutex)} vtexport.Export("/debug/vt100", v.VT100, v) server := http.Server{ Addr: fmt.Sprintf(":%d", port), Handler: http.DefaultServeMux, } vReaderRaw, vWriter := io.Pipe() vReader := bufio.NewReader(vReaderRaw) dupOut, err := ioutil.TempFile("", "nh_output.txt") if err != nil { panic(err) } exit := make(chan struct{}, 0) go func() { for { _, err := io.Copy(pty, os.Stdin) if err != nil { if err != io.EOF { glog.Error(err) } return } } }() go func() { defer func() { exit <- struct{}{} }() multi := io.MultiWriter(os.Stdout, dupOut, vWriter) for { _, err := io.Copy(multi, pty) if err != nil { if err != io.EOF { glog.Error(err) } return } } }() go func() { for { cmd, err := vt100.Decode(vReader) if err == nil { v.Lock() err = v.Process(cmd) v.Unlock() } if err == nil { continue } if _, isUnsupported := err.(vt100.UnsupportedError); isUnsupported { // This gets exported through an expvar. continue } if err != io.EOF { glog.Error(err) } return } }() downServer, err := httpdown.HTTP{ StopTimeout: time.Second * 5, }.ListenAndServe(&server) if err != nil { panic(err) } <-exit downServer.Stop() downServer.Wait() }