From e3ae09b525db47037f3458352cdfc9aea6bf8731 Mon Sep 17 00:00:00 2001 From: Bolke de Bruin <bolke@xs4all.nl> Date: Mon, 26 Sep 2022 08:32:49 +0200 Subject: [PATCH] Prepare for merge --- cmd/auth/auth.go | 4 ++-- cmd/rdpgw/main.go | 13 ------------- cmd/rdpgw/protocol/process.go | 6 ++++-- cmd/rdpgw/protocol/track.go | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go index 5656cb7..2f051ec 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 26caeed..4ab1d75 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 de6262d..3cfa9fc 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 83c4179..250a35b 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) { -- GitLab