From 570efbf3a6541e10a9cae000957498783571b740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 16 Nov 2020 22:21:21 +0100 Subject: [PATCH] remove unused ban endpoint. --- internal/session/session.go | 8 ----- internal/types/event/events.go | 1 - internal/types/session.go | 1 - internal/types/websocket.go | 1 - internal/websocket/handler/admin.go | 47 --------------------------- internal/websocket/handler/handler.go | 18 ---------- internal/websocket/manager.go | 7 ---- internal/websocket/websocket.go | 12 ------- 8 files changed, 95 deletions(-) diff --git a/internal/session/session.go b/internal/session/session.go index 4f569dd9..5973e8a0 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -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 } diff --git a/internal/types/event/events.go b/internal/types/event/events.go index a542e757..02a227ea 100644 --- a/internal/types/event/events.go +++ b/internal/types/event/events.go @@ -38,7 +38,6 @@ const ( ) const ( - ADMIN_BAN = "admin/ban" ADMIN_KICK = "admin/kick" ADMIN_LOCK = "admin/lock" ADMIN_UNLOCK = "admin/unlock" diff --git a/internal/types/session.go b/internal/types/session.go index 1ede9ac1..cb620d79 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -8,7 +8,6 @@ type Session interface { Admin() bool IsHost() bool Connected() bool - Address() string SetName(name string) SetSocket(socket WebSocket) SetPeer(peer Peer) diff --git a/internal/types/websocket.go b/internal/types/websocket.go index 442e607b..630c5d65 100644 --- a/internal/types/websocket.go +++ b/internal/types/websocket.go @@ -3,7 +3,6 @@ package types import "net/http" type WebSocket interface { - Address() string Send(v interface{}) error Destroy() error } diff --git a/internal/websocket/handler/admin.go b/internal/websocket/handler/admin.go index 8784eb46..3c6da808 100644 --- a/internal/websocket/handler/admin.go +++ b/internal/websocket/handler/admin.go @@ -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}) -} diff --git a/internal/websocket/handler/handler.go b/internal/websocket/handler/handler.go index 60b82470..77bfb699 100644 --- a/internal/websocket/handler/handler.go +++ b/internal/websocket/handler/handler.go @@ -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 { diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index df80519b..78299640 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -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, } diff --git a/internal/websocket/websocket.go b/internal/websocket/websocket.go index 11645794..53dcb43e 100644 --- a/internal/websocket/websocket.go +++ b/internal/websocket/websocket.go @@ -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()