From f3e88a6d8b2f9e20b935a318af57646da9f0b7a0 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 30 Apr 2024 18:18:32 +0200 Subject: [PATCH] Implement command /identify. --- rtpconn/webclient.go | 33 +++++++++++++++++++++++++++++++++ static/galene.js | 23 +++++++++++++++++++++++ webserver/webserver.go | 12 +++++++++++- webserver/whip.go | 11 ++++++++++- 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 5606904..ea843a1 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1853,6 +1853,39 @@ func handleClientMessage(c *webClient, m clientMessage) error { if err != nil { return c.error(err) } + case "identify": + if !member("op", c.permissions) { + return c.error(group.UserError("not authorised")) + } + d := g.GetClient(m.Dest) + if d == nil { + return c.error( + group.UserError("client not found"), + ) + } + value := make(map[string]any) + value["id"] = d.Id() + if username := d.Username(); username != "" { + value["username"] = username + } + if addr := d.Addr(); addr != nil { + value["address"] = addr.String() + } + type warner interface { + Warn(bool, string) error + } + w, ok := d.(warner) + if ok { + w.Warn(false, "Your IP address has been " + + "communicated to user " + + c.Username() + ".") + } + c.write(clientMessage{ + Type: "usermessage", + Kind: "userinfo", + Privileged: true, + Value: value, + }) case "kick": if !member("op", c.permissions) { return c.error(group.UserError("not authorised")) diff --git a/static/galene.js b/static/galene.js index 0f226fe..8a3d5ed 100644 --- a/static/galene.js +++ b/static/galene.js @@ -2251,6 +2251,9 @@ function userMenu(elt) { items.push({label: 'Kick out', onClick: () => { serverConnection.userAction('kick', id); }}); + items.push({label: 'Identify', onClick: () => { + serverConnection.userAction('identify', id); + }}); } } /** @ts-ignore */ @@ -2778,6 +2781,19 @@ function gotUserMessage(id, dest, username, time, privileged, kind, error, messa } localMessage(s); break; + case 'userinfo': + if(!privileged) { + console.error(`Got unprivileged message of kind ${kind}`); + return; + } + let u = message.username ? + 'username ' + message.username : + 'unknown username'; + let a = message.address ? + 'address ' + message.address : + 'unknown address'; + localMessage(`User ${message.id} has ${u} and ${a}.`); + break; default: console.warn(`Got unknown user message ${kind}`); break; @@ -3393,6 +3409,13 @@ commands.kick = { f: userCommand, }; +commands.identify = { + parameters: 'user [message]', + description: 'identify a user', + predicate: operatorPredicate, + f: userCommand, +}; + commands.op = { parameters: 'user', description: 'give operator status', diff --git a/webserver/webserver.go b/webserver/webserver.go index 55c82f0..07605c0 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -538,8 +538,18 @@ func wsHandler(w http.ResponseWriter, r *http.Request) { log.Printf("Websocket upgrade: %v", err) return } + + var addr net.Addr + println(r.RemoteAddr) + tcpaddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr) + if err != nil { + log.Printf("ResolveTCPAddr: %v", err) + } else { + addr = tcpaddr + } + go func() { - err := rtpconn.StartClient(conn) + err := rtpconn.StartClient(conn, addr) if err != nil { log.Printf("client: %v", err) } diff --git a/webserver/whip.go b/webserver/whip.go index 15f69dc..a5d6a8a 100644 --- a/webserver/whip.go +++ b/webserver/whip.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "log" + "net" "net/http" "net/url" "path" @@ -216,7 +217,15 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) { return } - c := rtpconn.NewWhipClient(g, id, token) + var addr net.Addr + tcpaddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr) + if err != nil { + log.Printf("ResolveTCPAddr: %v", err) + } else { + addr = tcpaddr + } + + c := rtpconn.NewWhipClient(g, id, token, addr) _, err = group.AddClient(g.Name(), c, creds) if err != nil {