mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
inactive cursors access control.
This commit is contained in:
parent
6b417131f2
commit
437eb44003
@ -57,12 +57,14 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) e
|
|||||||
data := &MemberCreatePayload{
|
data := &MemberCreatePayload{
|
||||||
// default values
|
// default values
|
||||||
Profile: types.MemberProfile{
|
Profile: types.MemberProfile{
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
CanConnect: true,
|
CanConnect: true,
|
||||||
CanWatch: true,
|
CanWatch: true,
|
||||||
CanHost: true,
|
CanHost: true,
|
||||||
CanAccessClipboard: true,
|
CanAccessClipboard: true,
|
||||||
|
SendsInactiveCursor: true,
|
||||||
|
CanSeeInactiveCursors: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,12 +9,14 @@ import (
|
|||||||
func New() types.MemberProvider {
|
func New() types.MemberProvider {
|
||||||
return &MemberProviderCtx{
|
return &MemberProviderCtx{
|
||||||
profile: types.MemberProfile{
|
profile: types.MemberProfile{
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
CanConnect: true,
|
CanConnect: true,
|
||||||
CanWatch: true,
|
CanWatch: true,
|
||||||
CanHost: true,
|
CanHost: true,
|
||||||
CanAccessClipboard: true,
|
CanAccessClipboard: true,
|
||||||
|
SendsInactiveCursor: true,
|
||||||
|
CanSeeInactiveCursors: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,26 +22,30 @@ func (provider *MemberProviderCtx) Connect() error {
|
|||||||
if provider.config.AdminPassword != "" {
|
if provider.config.AdminPassword != "" {
|
||||||
// create default admin account at startup
|
// create default admin account at startup
|
||||||
_, err = provider.Insert("admin", provider.config.AdminPassword, types.MemberProfile{
|
_, err = provider.Insert("admin", provider.config.AdminPassword, types.MemberProfile{
|
||||||
Name: "Administrator",
|
Name: "Administrator",
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
CanConnect: true,
|
CanConnect: true,
|
||||||
CanWatch: true,
|
CanWatch: true,
|
||||||
CanHost: true,
|
CanHost: true,
|
||||||
CanAccessClipboard: true,
|
CanAccessClipboard: true,
|
||||||
|
SendsInactiveCursor: true,
|
||||||
|
CanSeeInactiveCursors: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if provider.config.UserPassword != "" {
|
if provider.config.UserPassword != "" {
|
||||||
// create default user account at startup
|
// create default user account at startup
|
||||||
_, err = provider.Insert("user", provider.config.UserPassword, types.MemberProfile{
|
_, err = provider.Insert("user", provider.config.UserPassword, types.MemberProfile{
|
||||||
Name: "User",
|
Name: "User",
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
CanConnect: true,
|
CanConnect: true,
|
||||||
CanWatch: true,
|
CanWatch: true,
|
||||||
CanHost: true,
|
CanHost: true,
|
||||||
CanAccessClipboard: true,
|
CanAccessClipboard: true,
|
||||||
|
SendsInactiveCursor: true,
|
||||||
|
CanSeeInactiveCursors: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,6 +254,22 @@ func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *SessionManagerCtx) InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{}) {
|
||||||
|
for _, session := range manager.List() {
|
||||||
|
if !session.State().IsConnected || !session.Profile().CanSeeInactiveCursors {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if exclude != nil {
|
||||||
|
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
session.Send(event, payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
// events
|
// events
|
||||||
// ---
|
// ---
|
||||||
|
@ -54,7 +54,7 @@ func (session *SessionCtx) IsHost() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetCursor(cursor types.Cursor) {
|
func (session *SessionCtx) SetCursor(cursor types.Cursor) {
|
||||||
if session.manager.InactiveCursors() {
|
if session.manager.InactiveCursors() && session.profile.SendsInactiveCursor {
|
||||||
session.manager.SetCursor(cursor, session)
|
session.manager.SetCursor(cursor, session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MemberProfile struct {
|
type MemberProfile struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IsAdmin bool `json:"is_admin"`
|
IsAdmin bool `json:"is_admin"`
|
||||||
CanLogin bool `json:"can_login"`
|
CanLogin bool `json:"can_login"`
|
||||||
CanConnect bool `json:"can_connect"`
|
CanConnect bool `json:"can_connect"`
|
||||||
CanWatch bool `json:"can_watch"`
|
CanWatch bool `json:"can_watch"`
|
||||||
CanHost bool `json:"can_host"`
|
CanHost bool `json:"can_host"`
|
||||||
CanAccessClipboard bool `json:"can_access_clipboard"`
|
CanAccessClipboard bool `json:"can_access_clipboard"`
|
||||||
|
SendsInactiveCursor bool `json:"sends_inactive_cursor"`
|
||||||
|
CanSeeInactiveCursors bool `json:"can_see_inactive_cursors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberProvider interface {
|
type MemberProvider interface {
|
||||||
|
@ -60,6 +60,7 @@ type SessionManager interface {
|
|||||||
|
|
||||||
Broadcast(event string, payload interface{}, exclude interface{})
|
Broadcast(event string, payload interface{}, exclude interface{})
|
||||||
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
||||||
|
InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{})
|
||||||
|
|
||||||
OnCreated(listener func(session Session))
|
OnCreated(listener func(session Session))
|
||||||
OnDeleted(listener func(session Session))
|
OnDeleted(listener func(session Session))
|
||||||
|
@ -173,8 +173,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Send to subscribers only.
|
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, cursors, nil)
|
||||||
manager.sessions.AdminBroadcast(event.SESSION_CURSORS, cursors, nil)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user