remove unused ban endpoint.

This commit is contained in:
Miroslav Šedivý 2020-11-16 22:21:21 +01:00
parent d87a10b23a
commit 570efbf3a6
8 changed files with 0 additions and 95 deletions

View File

@ -39,14 +39,6 @@ func (session *SessionCtx) Connected() bool {
return session.connected return session.connected
} }
func (session *SessionCtx) Address() string {
if session.socket == nil {
return ""
}
return session.socket.Address()
}
func (session *SessionCtx) SetName(name string) { func (session *SessionCtx) SetName(name string) {
session.name = name session.name = name
} }

View File

@ -38,7 +38,6 @@ const (
) )
const ( const (
ADMIN_BAN = "admin/ban"
ADMIN_KICK = "admin/kick" ADMIN_KICK = "admin/kick"
ADMIN_LOCK = "admin/lock" ADMIN_LOCK = "admin/lock"
ADMIN_UNLOCK = "admin/unlock" ADMIN_UNLOCK = "admin/unlock"

View File

@ -8,7 +8,6 @@ type Session interface {
Admin() bool Admin() bool
IsHost() bool IsHost() bool
Connected() bool Connected() bool
Address() string
SetName(name string) SetName(name string)
SetSocket(socket WebSocket) SetSocket(socket WebSocket)
SetPeer(peer Peer) SetPeer(peer Peer)

View File

@ -3,7 +3,6 @@ package types
import "net/http" import "net/http"
type WebSocket interface { type WebSocket interface {
Address() string
Send(v interface{}) error Send(v interface{}) error
Destroy() error Destroy() error
} }

View File

@ -1,8 +1,6 @@
package handler package handler
import ( import (
"strings"
"demodesk/neko/internal/types" "demodesk/neko/internal/types"
"demodesk/neko/internal/types/event" "demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message" "demodesk/neko/internal/types/message"
@ -148,48 +146,3 @@ func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Ad
ID: session.ID(), ID: session.ID(),
}, []string{payload.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})
}

View File

@ -27,7 +27,6 @@ func New(
desktop: desktop, desktop: desktop,
capture: capture, capture: capture,
webrtc: webrtc, webrtc: webrtc,
banned: make(map[string]bool),
locked: false, locked: false,
} }
} }
@ -38,22 +37,10 @@ type MessageHandlerCtx struct {
webrtc types.WebRTCManager webrtc types.WebRTCManager
desktop types.DesktopManager desktop types.DesktopManager
capture types.CaptureManager capture types.CaptureManager
banned map[string]bool
locked bool locked bool
} }
func (h *MessageHandlerCtx) Connected(session types.Session, socket types.WebSocket) (bool, string) { 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(){ if h.locked && !session.Admin(){
h.logger.Debug().Msg("server locked") h.logger.Debug().Msg("server locked")
return false, "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 { err = utils.Unmarshal(payload, raw, func() error {
return h.adminGive(session, payload) 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: case event.ADMIN_KICK:
payload := &message.Admin{} payload := &message.Admin{}
err = utils.Unmarshal(payload, raw, func() error { err = utils.Unmarshal(payload, raw, func() error {

View File

@ -141,16 +141,9 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e
return connection.Close() return connection.Close()
} }
// TODO: Refactor.
ip := r.RemoteAddr
// if allow poxy {
// ip = utils.ReadUserIP(r)
// }
socket := &WebSocketCtx{ socket := &WebSocketCtx{
session: session, session: session,
ws: ws, ws: ws,
address: ip,
connection: connection, connection: connection,
} }

View File

@ -2,7 +2,6 @@ package websocket
import ( import (
"encoding/json" "encoding/json"
"strings"
"sync" "sync"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -12,22 +11,11 @@ import (
type WebSocketCtx struct { type WebSocketCtx struct {
session types.Session session types.Session
address string
ws *WebSocketManagerCtx ws *WebSocketManagerCtx
connection *websocket.Conn connection *websocket.Conn
mu sync.Mutex 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 { func (socket *WebSocketCtx) Send(v interface{}) error {
socket.mu.Lock() socket.mu.Lock()
defer socket.mu.Unlock() defer socket.mu.Unlock()