diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go index 5656cb7b09f9a55e4817be2e89f90c32ba62ce36..2f051ecbe69f3bd7250e4efd9133c27b6b478a84 100644 --- a/cmd/auth/auth.go +++ b/cmd/auth/auth.go @@ -45,8 +45,8 @@ func (s *AuthServiceImpl) Authenticate(ctx context.Context, message *auth.UserPa }) r := &auth.AuthResponse{} - r.Authenticated = true - return r, nil + r.Authenticated = false + if err != nil { log.Printf("Error authenticating user: %s due to: %s", message.Username, err) r.Error = err.Error() diff --git a/cmd/rdpgw/main.go b/cmd/rdpgw/main.go index 26caeed986ec11f662cc760d637cf41a4aff9afa..4ab1d7504cefb6e4cfef2e4ef47c33744f23d5a6 100644 --- a/cmd/rdpgw/main.go +++ b/cmd/rdpgw/main.go @@ -200,7 +200,6 @@ func main() { } else { gw.CheckHost = security.CheckHost } - gwserver = &gw if conf.Server.Authentication == config.AuthenticationBasic { h := web.BasicAuthHandler{SocketAddress: conf.Server.AuthSocket} @@ -214,7 +213,6 @@ func main() { } http.Handle("/metrics", promhttp.Handler()) http.HandleFunc("/tokeninfo", web.TokenInfo) - http.HandleFunc("/list", List) if conf.Server.Tls == config.TlsDisable { err = server.ListenAndServe() @@ -225,14 +223,3 @@ func main() { log.Fatal("ListenAndServe: ", err) } } - -var gwserver *protocol.Gateway - -func List(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - for k, v := range protocol.Connections { - fmt.Fprintf(w, "Id: %s Rdg-Id: %s User: %s From: %s Connected Since: %s Bytes Sent: %d Bytes Received: %d Last Seen: %s Target: %s\n", - k, v.Tunnel.RDGId, v.Tunnel.UserName, v.Tunnel.RemoteAddr, v.Tunnel.ConnectedOn, v.Tunnel.BytesSent, v.Tunnel.BytesReceived, - v.Tunnel.LastSeen, v.Tunnel.TargetServer) - } -} diff --git a/cmd/rdpgw/protocol/process.go b/cmd/rdpgw/protocol/process.go index de6262dc279d51db777064d8ca309bec10718b10..3cfa9fcae1d9230f2838b13ff73b8298d2eca19d 100644 --- a/cmd/rdpgw/protocol/process.go +++ b/cmd/rdpgw/protocol/process.go @@ -24,6 +24,9 @@ type Processor struct { // tunnel is the underlying connection with the client tunnel *Tunnel + + // ctl is a channel to control the processor in case of events + ctl chan int } func NewProcessor(gw *Gateway, tunnel *Tunnel) *Processor { @@ -31,6 +34,7 @@ func NewProcessor(gw *Gateway, tunnel *Tunnel) *Processor { gw: gw, state: SERVER_STATE_INITIALIZED, tunnel: tunnel, + ctl: make(chan int), } return h } @@ -168,8 +172,6 @@ func (p *Processor) Process(ctx context.Context) error { } msg := p.channelCloseResponse(ERROR_SUCCESS) p.tunnel.Write(msg) - //p.tunnel.transportIn.Close() - //p.tunnel.transportOut.Close() p.state = SERVER_STATE_CLOSED return nil default: diff --git a/cmd/rdpgw/protocol/track.go b/cmd/rdpgw/protocol/track.go index 83c4179e3e3913bef7add1b592da19d5d96e6d8c..250a35ba25b016f5040e7a4f868878b96c895b5d 100644 --- a/cmd/rdpgw/protocol/track.go +++ b/cmd/rdpgw/protocol/track.go @@ -1,5 +1,7 @@ package protocol +import "fmt" + var Connections map[string]*Monitor type Monitor struct { @@ -7,6 +9,10 @@ type Monitor struct { Tunnel *Tunnel } +const ( + ctlDisconnect = -1 +) + func RegisterTunnel(t *Tunnel, p *Processor) { if Connections == nil { Connections = make(map[string]*Monitor) @@ -22,6 +28,19 @@ func RemoveTunnel(t *Tunnel) { delete(Connections, t.Id) } +func Disconnect(id string) error { + if Connections == nil { + return fmt.Errorf("%s connection does not exist", id) + } + + if m, ok := Connections[id]; !ok { + m.Processor.ctl <- ctlDisconnect + return nil + } + + return fmt.Errorf("%s connection does not exist", id) +} + // CalculateSpeedPerSecond calculate moving average. /* func CalculateSpeedPerSecond(connId string) (in int, out int) {