server

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package server provides the HTTP server and WebSocket handler for the web interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpgradeConnection

func UpgradeConnection(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

UpgradeConnection upgrades an HTTP connection to WebSocket.

Types

type CommandHandler

type CommandHandler struct {
	// contains filtered or unexported fields
}

CommandHandler processes WebSocket commands.

func NewCommandHandler

func NewCommandHandler(
	cfg *config.Config,
	getState func() types.EncoderState,
	startOutput func(string) error,
	stopOutput func(string) error,
	restartEnc func() error,
	testTriggers map[string]func() error,
) *CommandHandler

NewCommandHandler creates a new command handler.

func (*CommandHandler) Handle

func (h *CommandHandler) Handle(cmd WSCommand, conn *websocket.Conn, triggerStatusUpdate func())

Handle processes a WebSocket command and performs the requested action.

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

SessionManager handles user authentication sessions.

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager creates a new session manager.

func (*SessionManager) AuthMiddleware

func (sm *SessionManager) AuthMiddleware(username, password string) func(http.HandlerFunc) http.HandlerFunc

AuthMiddleware returns middleware that requires a valid session cookie. Unauthenticated requests are redirected to /login.

func (*SessionManager) Create

func (sm *SessionManager) Create() string

Create creates a new session and returns the token.

func (*SessionManager) CreateCSRFToken added in v0.1.5

func (sm *SessionManager) CreateCSRFToken() string

CreateCSRFToken generates a new CSRF token.

func (*SessionManager) Delete added in v0.1.5

func (sm *SessionManager) Delete(token string)

Delete removes a session token.

func (*SessionManager) Login added in v0.1.5

func (sm *SessionManager) Login(w http.ResponseWriter, r *http.Request, username, password, configUser, configPass string) bool

Login validates credentials and creates a session if valid. Returns true if login succeeded. Uses constant-time comparison to prevent timing attacks.

func (*SessionManager) Logout added in v0.1.5

func (sm *SessionManager) Logout(w http.ResponseWriter, r *http.Request)

Logout clears the session cookie and deletes the session.

func (*SessionManager) Validate

func (sm *SessionManager) Validate(token string) bool

Validate checks if a session token is valid.

func (*SessionManager) ValidateCSRFToken added in v0.1.5

func (sm *SessionManager) ValidateCSRFToken(token string) bool

ValidateCSRFToken checks if a CSRF token is valid and removes it.

type WSCommand

type WSCommand struct {
	Type string          `json:"type"`
	ID   string          `json:"id,omitempty"`
	Data json.RawMessage `json:"data,omitempty"`
}

WSCommand is a command received from a WebSocket client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL