mirror of
https://github.com/jech/galene.git
synced 2024-11-25 01:55:57 +01:00
Implement kick, op and friends.
This commit is contained in:
parent
e0eee9e7e2
commit
25825e5b22
3 changed files with 118 additions and 16 deletions
27
client.go
27
client.go
|
@ -740,6 +740,13 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
|||
|
||||
}
|
||||
}
|
||||
case sendPermissionsAction:
|
||||
c.write(clientMessage{
|
||||
Type: "permissions",
|
||||
Permissions: c.permissions,
|
||||
})
|
||||
case kickAction:
|
||||
return userError("you have been kicked")
|
||||
default:
|
||||
log.Printf("unexpected action %T", a)
|
||||
return errors.New("unexpected action")
|
||||
|
@ -754,7 +761,7 @@ func handleClientMessage(c *client, m clientMessage) error {
|
|||
switch m.Type {
|
||||
case "offer":
|
||||
if !c.permissions.Present {
|
||||
return userError("not authorized")
|
||||
return userError("not authorised")
|
||||
}
|
||||
if m.Offer == nil {
|
||||
return protocolError("null offer")
|
||||
|
@ -786,6 +793,24 @@ func handleClientMessage(c *client, m clientMessage) error {
|
|||
for _, cc := range clients {
|
||||
cc.write(m)
|
||||
}
|
||||
case "op", "unop", "present", "unpresent":
|
||||
if !c.permissions.Admin {
|
||||
c.error(userError("not authorised"))
|
||||
return nil
|
||||
}
|
||||
err := setPermission(c.group, m.Id, m.Type)
|
||||
if err != nil {
|
||||
return c.error(err)
|
||||
}
|
||||
case "kick":
|
||||
if !c.permissions.Admin {
|
||||
c.error(userError("not authorised"))
|
||||
return nil
|
||||
}
|
||||
err := kickClient(c.group, m.Id)
|
||||
if err != nil {
|
||||
return c.error(err)
|
||||
}
|
||||
default:
|
||||
log.Printf("unexpected message: %v", m.Type)
|
||||
return protocolError("unexpected message")
|
||||
|
|
63
group.go
63
group.go
|
@ -10,8 +10,8 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pion/webrtc/v2"
|
||||
|
@ -84,6 +84,10 @@ type pushTracksAction struct {
|
|||
c *client
|
||||
}
|
||||
|
||||
type sendPermissionsAction struct{}
|
||||
|
||||
type kickAction struct{}
|
||||
|
||||
var groups struct {
|
||||
mu sync.Mutex
|
||||
groups map[string]*group
|
||||
|
@ -117,7 +121,7 @@ func addGroup(name string, desc *groupDescription) (*group, error) {
|
|||
|
||||
g := groups.groups[name]
|
||||
if g == nil {
|
||||
if(desc == nil) {
|
||||
if desc == nil {
|
||||
desc, err = getDescription(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -235,6 +239,15 @@ func (g *group) getClients(except *client) []*client {
|
|||
return clients
|
||||
}
|
||||
|
||||
func (g *group) getClientUnlocked(id string) *client {
|
||||
for _, c := range g.clients {
|
||||
if c.id == id {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *group) Range(f func(c *client) bool) {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
@ -295,7 +308,7 @@ type groupUser struct {
|
|||
|
||||
func matchUser(user, pass string, users []groupUser) (bool, bool) {
|
||||
for _, u := range users {
|
||||
if (u.Username == "" || u.Username == user) {
|
||||
if u.Username == "" || u.Username == user {
|
||||
return true, (u.Password == "" || u.Password == pass)
|
||||
}
|
||||
}
|
||||
|
@ -372,22 +385,58 @@ func getPermission(desc *groupDescription, user, pass string) (userPermission, e
|
|||
p.Present = true
|
||||
return p, nil
|
||||
}
|
||||
return p, userError("not authorized")
|
||||
return p, userError("not authorised")
|
||||
}
|
||||
if found, good := matchUser(user, pass, desc.Presenter); found {
|
||||
if good {
|
||||
p.Present = true
|
||||
return p, nil
|
||||
}
|
||||
return p, userError("not authorized")
|
||||
return p, userError("not authorised")
|
||||
}
|
||||
if found, good := matchUser(user, pass, desc.Other); found {
|
||||
if good {
|
||||
return p, nil
|
||||
}
|
||||
return p, userError("not authorized")
|
||||
return p, userError("not authorised")
|
||||
}
|
||||
return p, userError("not authorized")
|
||||
return p, userError("not authorised")
|
||||
}
|
||||
|
||||
func setPermission(g *group, id string, perm string) error {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
c := g.getClientUnlocked(id)
|
||||
if c == nil {
|
||||
return userError("no such user")
|
||||
}
|
||||
|
||||
switch perm {
|
||||
case "op":
|
||||
c.permissions.Admin = true
|
||||
case "unop":
|
||||
c.permissions.Admin = false
|
||||
case "present":
|
||||
c.permissions.Present = true
|
||||
case "unpresent":
|
||||
c.permissions.Present = false
|
||||
default:
|
||||
return userError("unknown permission")
|
||||
}
|
||||
return c.action(sendPermissionsAction{})
|
||||
}
|
||||
|
||||
func kickClient(g *group, id string) error {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
c := g.getClientUnlocked(id)
|
||||
if c == nil {
|
||||
return userError("no such user")
|
||||
}
|
||||
|
||||
return c.action(kickAction{})
|
||||
}
|
||||
|
||||
type publicGroup struct {
|
||||
|
|
|
@ -15,6 +15,8 @@ let up = {}, down = {};
|
|||
|
||||
let iceServers = [];
|
||||
|
||||
let permissions = {};
|
||||
|
||||
function toHex(array) {
|
||||
let a = new Uint8Array(array);
|
||||
let s = '';
|
||||
|
@ -515,9 +517,10 @@ function gotUser(id, name, del) {
|
|||
addUser(id, name);
|
||||
}
|
||||
|
||||
function gotPermissions(permissions) {
|
||||
document.getElementById('presenterbox').disabled = !permissions.present;
|
||||
document.getElementById('sharebox').disabled = !permissions.present;
|
||||
function gotPermissions(perm) {
|
||||
permissions = perm;
|
||||
document.getElementById('presenterbox').disabled = !perm.present;
|
||||
document.getElementById('sharebox').disabled = !perm.present;
|
||||
}
|
||||
|
||||
const urlRegexp = /https?:\/\/[-a-zA-Z0-9@:%/._\+~#=?]+[-a-zA-Z0-9@:%/_\+~#=]/g;
|
||||
|
@ -634,14 +637,39 @@ function handleInput() {
|
|||
}
|
||||
|
||||
switch(cmd) {
|
||||
case '/nick':
|
||||
setNick(rest);
|
||||
storeNick(rest);
|
||||
return;
|
||||
case '/me':
|
||||
message = rest;
|
||||
me = true;
|
||||
break;
|
||||
case '/op':
|
||||
case '/unop':
|
||||
case '/kick':
|
||||
case '/present':
|
||||
case '/unpresent':
|
||||
if(!permissions.admin) {
|
||||
displayError("You're not an administrator");
|
||||
return;
|
||||
}
|
||||
let id;
|
||||
if(id in users) {
|
||||
id = rest;
|
||||
} else {
|
||||
for(let i in users) {
|
||||
if(users[i] === rest) {
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!id) {
|
||||
displayError('Unknown user ' + rest);
|
||||
return;
|
||||
}
|
||||
send({
|
||||
type: cmd.slice(1),
|
||||
id: id,
|
||||
});
|
||||
return;
|
||||
default:
|
||||
displayError('Uknown command ' + cmd);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue