1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Implement command /identify.

This commit is contained in:
Juliusz Chroboczek 2024-04-30 18:18:32 +02:00
parent ae42f388fe
commit f3e88a6d8b
4 changed files with 77 additions and 2 deletions

View file

@ -1853,6 +1853,39 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if err != nil { if err != nil {
return c.error(err) 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": case "kick":
if !member("op", c.permissions) { if !member("op", c.permissions) {
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))

View file

@ -2251,6 +2251,9 @@ function userMenu(elt) {
items.push({label: 'Kick out', onClick: () => { items.push({label: 'Kick out', onClick: () => {
serverConnection.userAction('kick', id); serverConnection.userAction('kick', id);
}}); }});
items.push({label: 'Identify', onClick: () => {
serverConnection.userAction('identify', id);
}});
} }
} }
/** @ts-ignore */ /** @ts-ignore */
@ -2778,6 +2781,19 @@ function gotUserMessage(id, dest, username, time, privileged, kind, error, messa
} }
localMessage(s); localMessage(s);
break; 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: default:
console.warn(`Got unknown user message ${kind}`); console.warn(`Got unknown user message ${kind}`);
break; break;
@ -3393,6 +3409,13 @@ commands.kick = {
f: userCommand, f: userCommand,
}; };
commands.identify = {
parameters: 'user [message]',
description: 'identify a user',
predicate: operatorPredicate,
f: userCommand,
};
commands.op = { commands.op = {
parameters: 'user', parameters: 'user',
description: 'give operator status', description: 'give operator status',

View file

@ -538,8 +538,18 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("Websocket upgrade: %v", err) log.Printf("Websocket upgrade: %v", err)
return 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() { go func() {
err := rtpconn.StartClient(conn) err := rtpconn.StartClient(conn, addr)
if err != nil { if err != nil {
log.Printf("client: %v", err) log.Printf("client: %v", err)
} }

View file

@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"net"
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
@ -216,7 +217,15 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
return 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) _, err = group.AddClient(g.Name(), c, creds)
if err != nil { if err != nil {