mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
auth moved from websockets to session.
This commit is contained in:
37
internal/session/auth.go
Normal file
37
internal/session/auth.go
Normal file
@ -0,0 +1,37 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
// TODO: Refactor
|
||||
func (manager *SessionManagerCtx) Authenticate(r *http.Request) (string, string, bool, error) {
|
||||
ip := r.RemoteAddr
|
||||
|
||||
//if ws.conf.Proxy {
|
||||
// ip = utils.ReadUserIP(r)
|
||||
//}
|
||||
|
||||
id, err := utils.NewUID(32)
|
||||
if err != nil {
|
||||
return "", ip, false, err
|
||||
}
|
||||
|
||||
passwords, ok := r.URL.Query()["password"]
|
||||
if !ok || len(passwords[0]) < 1 {
|
||||
return "", ip, false, fmt.Errorf("no password provided")
|
||||
}
|
||||
|
||||
if passwords[0] == manager.config.AdminPassword {
|
||||
return id, ip, true, nil
|
||||
}
|
||||
|
||||
if passwords[0] == manager.config.Password {
|
||||
return id, ip, false, nil
|
||||
}
|
||||
|
||||
return "", ip, false, fmt.Errorf("invalid password: %s", passwords[0])
|
||||
}
|
@ -6,14 +6,16 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/config"
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
func New(capture types.CaptureManager) *SessionManagerCtx {
|
||||
func New(capture types.CaptureManager, config *config.Session) *SessionManagerCtx {
|
||||
return &SessionManagerCtx{
|
||||
logger: log.With().Str("module", "session").Logger(),
|
||||
host: nil,
|
||||
capture: capture,
|
||||
config: config,
|
||||
members: make(map[string]*SessionCtx),
|
||||
emmiter: events.New(),
|
||||
}
|
||||
@ -23,6 +25,7 @@ type SessionManagerCtx struct {
|
||||
logger zerolog.Logger
|
||||
host types.Session
|
||||
capture types.CaptureManager
|
||||
config *config.Session
|
||||
members map[string]*SessionCtx
|
||||
emmiter events.EventEmmiter
|
||||
}
|
||||
|
Reference in New Issue
Block a user