mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
remove unused ban endpoint.
This commit is contained in:
parent
d87a10b23a
commit
570efbf3a6
@ -39,14 +39,6 @@ func (session *SessionCtx) Connected() bool {
|
||||
return session.connected
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Address() string {
|
||||
if session.socket == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return session.socket.Address()
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetName(name string) {
|
||||
session.name = name
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
ADMIN_BAN = "admin/ban"
|
||||
ADMIN_KICK = "admin/kick"
|
||||
ADMIN_LOCK = "admin/lock"
|
||||
ADMIN_UNLOCK = "admin/unlock"
|
||||
|
@ -8,7 +8,6 @@ type Session interface {
|
||||
Admin() bool
|
||||
IsHost() bool
|
||||
Connected() bool
|
||||
Address() string
|
||||
SetName(name string)
|
||||
SetSocket(socket WebSocket)
|
||||
SetPeer(peer Peer)
|
||||
|
@ -3,7 +3,6 @@ package types
|
||||
import "net/http"
|
||||
|
||||
type WebSocket interface {
|
||||
Address() string
|
||||
Send(v interface{}) error
|
||||
Destroy() error
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
@ -148,48 +146,3 @@ func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Ad
|
||||
ID: session.ID(),
|
||||
}, []string{payload.ID})
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) adminBan(session types.Session, payload *message.Admin) error {
|
||||
if !session.Admin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
}
|
||||
|
||||
target, ok := h.sessions.Get(payload.ID)
|
||||
if !ok {
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find target session")
|
||||
return nil
|
||||
}
|
||||
|
||||
if target.Admin() {
|
||||
h.logger.Debug().Msg("target is an admin, baling")
|
||||
return nil
|
||||
}
|
||||
|
||||
remote := target.Address()
|
||||
if remote == "" {
|
||||
h.logger.Debug().Msg("no remote address, baling")
|
||||
return nil
|
||||
}
|
||||
|
||||
address := strings.SplitN(remote, ":", -1)
|
||||
if len(address[0]) < 1 {
|
||||
h.logger.Debug().Str("address", remote).Msg("no remote address, baling")
|
||||
return nil
|
||||
}
|
||||
|
||||
h.logger.Debug().Str("address", remote).Msg("adding address to banned")
|
||||
|
||||
h.banned[address[0]] = true
|
||||
|
||||
if err := target.Disconnect("banned"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_BAN,
|
||||
Target: target.ID(),
|
||||
ID: session.ID(),
|
||||
}, []string{payload.ID})
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ func New(
|
||||
desktop: desktop,
|
||||
capture: capture,
|
||||
webrtc: webrtc,
|
||||
banned: make(map[string]bool),
|
||||
locked: false,
|
||||
}
|
||||
}
|
||||
@ -38,22 +37,10 @@ type MessageHandlerCtx struct {
|
||||
webrtc types.WebRTCManager
|
||||
desktop types.DesktopManager
|
||||
capture types.CaptureManager
|
||||
banned map[string]bool
|
||||
locked bool
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) Connected(session types.Session, socket types.WebSocket) (bool, string) {
|
||||
address := socket.Address()
|
||||
if address != "" {
|
||||
ok, banned := h.banned[address]
|
||||
if ok && banned {
|
||||
h.logger.Debug().Str("address", address).Msg("banned")
|
||||
return false, "banned"
|
||||
}
|
||||
} else {
|
||||
h.logger.Debug().Msg("no remote address")
|
||||
}
|
||||
|
||||
if h.locked && !session.Admin(){
|
||||
h.logger.Debug().Msg("server locked")
|
||||
return false, "locked"
|
||||
@ -141,11 +128,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
||||
err = utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminGive(session, payload)
|
||||
})
|
||||
case event.ADMIN_BAN:
|
||||
payload := &message.Admin{}
|
||||
err = utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminBan(session, payload)
|
||||
})
|
||||
case event.ADMIN_KICK:
|
||||
payload := &message.Admin{}
|
||||
err = utils.Unmarshal(payload, raw, func() error {
|
||||
|
@ -141,16 +141,9 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e
|
||||
return connection.Close()
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
ip := r.RemoteAddr
|
||||
// if allow poxy {
|
||||
// ip = utils.ReadUserIP(r)
|
||||
// }
|
||||
|
||||
socket := &WebSocketCtx{
|
||||
session: session,
|
||||
ws: ws,
|
||||
address: ip,
|
||||
connection: connection,
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package websocket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@ -12,22 +11,11 @@ import (
|
||||
|
||||
type WebSocketCtx struct {
|
||||
session types.Session
|
||||
address string
|
||||
ws *WebSocketManagerCtx
|
||||
connection *websocket.Conn
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func (socket *WebSocketCtx) Address() string {
|
||||
//remote := socket.connection.RemoteAddr()
|
||||
address := strings.SplitN(socket.address, ":", -1)
|
||||
if len(address[0]) < 1 {
|
||||
return socket.address
|
||||
}
|
||||
|
||||
return address[0]
|
||||
}
|
||||
|
||||
func (socket *WebSocketCtx) Send(v interface{}) error {
|
||||
socket.mu.Lock()
|
||||
defer socket.mu.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user