server

package
v0.8.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ServerLogger   = NewLogger("Server")
	ClientLogger   = NewLogger("Client")
	HubLogger      = NewLogger("Hub")
	AdminLogger    = NewLogger("Admin")
	PluginLogger   = NewLogger("Plugin")
	DatabaseLogger = NewLogger("Database")
	SecurityLogger = NewLogger("Security")
	FilterLogger   = NewLogger("Filter")
)

Global logger instances for different components

Functions

func BackupDatabase

func BackupDatabase(dbPath string) (string, error)

BackupDatabase creates a backup of the current database

func ClearMessages

func ClearMessages(db *sql.DB) error

func ConvertPluginMessage

func ConvertPluginMessage(pluginMsg sdk.Message) shared.Message

ConvertPluginMessage converts a plugin message to a shared message

func CreateSchema

func CreateSchema(db *sql.DB)

func GetDatabaseStats

func GetDatabaseStats(db *sql.DB) (string, error)

GetDatabaseStats returns statistics about the database

func GetMessagesAfter

func GetMessagesAfter(db *sql.DB, lastMessageID int64, limit int) []shared.Message

GetMessagesAfter retrieves messages with ID > lastMessageID

func GetRecentMessages

func GetRecentMessages(db *sql.DB) []shared.Message

func GetRecentMessagesForUser

func GetRecentMessagesForUser(db *sql.DB, username string, defaultLimit int, banGapsHistory bool) ([]shared.Message, int64)

GetRecentMessagesForUser returns personalized message history for a specific user

func InitDB

func InitDB(filepath string) *sql.DB

func InsertEncryptedMessage

func InsertEncryptedMessage(db *sql.DB, encryptedMsg *shared.EncryptedMessage)

InsertEncryptedMessage stores an encrypted message in the database

func InsertMessage

func InsertMessage(db *sql.DB, msg shared.Message)

func LogToFile

func LogToFile(filename string) error

LogToFile enables logging to a file in addition to stdout

func RunAdminPanel

func RunAdminPanel(hub *Hub, db *sql.DB, pluginManager *manager.PluginManager, liveConfig *config.Config) error

RunAdminPanel starts the admin panel TUI

func ServeWs

func ServeWs(hub *Hub, db *sql.DB, adminList []string, adminKey string, banGapsHistory bool, maxFileBytes int64) http.HandlerFunc

func SetLogLevel

func SetLogLevel(level LogLevel)

SetLogLevel sets the minimum log level (currently not implemented but ready for future use)

Types

type AdminPanel

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

AdminPanel represents the main admin panel state

func NewAdminPanel

func NewAdminPanel(hub *Hub, db *sql.DB, pluginManager *manager.PluginManager, liveConfig *config.Config) *AdminPanel

NewAdminPanel creates a new admin panel instance

func (*AdminPanel) Init

func (ap *AdminPanel) Init() tea.Cmd

Implement tea.Model interface

func (*AdminPanel) Update

func (ap *AdminPanel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*AdminPanel) View

func (ap *AdminPanel) View() string

type Client

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

type ComponentHealth

type ComponentHealth struct {
	Status    HealthStatus `json:"status"`
	Message   string       `json:"message,omitempty"`
	LastCheck time.Time    `json:"last_check"`
}

ComponentHealth represents the health of a specific component

type Config

type Config struct {
	Port     int      `json:"port"`
	Admins   []string `json:"admins"`
	AdminKey string   `json:"admin_key"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig loads configuration from a JSON file (for backward compatibility)

func LoadConfigFromDir

func LoadConfigFromDir(configDir string) (Config, error)

LoadConfigFromDir loads configuration from a directory, checking for JSON config files

type HealthCheck

type HealthCheck struct {
	Status     HealthStatus               `json:"status"`
	Timestamp  time.Time                  `json:"timestamp"`
	Version    string                     `json:"version"`
	Uptime     string                     `json:"uptime"`
	Components map[string]ComponentHealth `json:"components"`
	Metrics    SystemMetrics              `json:"metrics"`
}

HealthCheck represents a health check response

type HealthChecker

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

HealthChecker manages health check functionality

func NewHealthChecker

func NewHealthChecker(hub *Hub, db *sql.DB, version string) *HealthChecker

NewHealthChecker creates a new health checker

func (*HealthChecker) CheckHealth

func (hc *HealthChecker) CheckHealth() *HealthCheck

CheckHealth performs a comprehensive health check

func (*HealthChecker) HealthCheckHandler

func (hc *HealthChecker) HealthCheckHandler(w http.ResponseWriter, r *http.Request)

HealthCheckHandler handles HTTP health check requests

func (*HealthChecker) SimpleHealthHandler

func (hc *HealthChecker) SimpleHealthHandler(w http.ResponseWriter, r *http.Request)

SimpleHealthHandler provides a simple health check endpoint

type HealthStatus

type HealthStatus string

HealthStatus represents the overall health status

const (
	HealthStatusHealthy   HealthStatus = "healthy"
	HealthStatusDegraded  HealthStatus = "degraded"
	HealthStatusUnhealthy HealthStatus = "unhealthy"
)

func (HealthStatus) String

func (hs HealthStatus) String() string

String returns the string representation of HealthStatus

type Hub

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

func NewHub

func NewHub(pluginDir, dataDir, registryURL string, db *sql.DB) *Hub

func (*Hub) AllowUser

func (h *Hub) AllowUser(username string, adminUsername string) bool

AllowUser removes a user from temporary kick list (override early)

func (*Hub) BanUser

func (h *Hub) BanUser(username string, adminUsername string)

BanUser adds a user to the permanent ban list

func (*Hub) CleanupExpiredBans

func (h *Hub) CleanupExpiredBans()

CleanupExpiredBans removes expired bans and kicks from the lists

func (*Hub) CleanupStaleConnections

func (h *Hub) CleanupStaleConnections()

CleanupStaleConnections removes clients with broken connections

func (*Hub) ForceDisconnectUser

func (h *Hub) ForceDisconnectUser(username string, adminUsername string) bool

ForceDisconnectUser forcibly removes a user from the clients map (admin command for stale connections)

func (*Hub) GetPluginManager

func (h *Hub) GetPluginManager() *manager.PluginManager

GetPluginManager returns the plugin manager reference

func (*Hub) IsUserBanned

func (h *Hub) IsUserBanned(username string) bool

IsUserBanned checks if a user is currently banned or kicked

func (*Hub) KickUser

func (h *Hub) KickUser(username string, adminUsername string)

KickUser temporarily bans a user for 24 hours

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) UnbanUser

func (h *Hub) UnbanUser(username string, adminUsername string) bool

UnbanUser removes a user from the ban list

type LogEntry

type LogEntry struct {
	Level     LogLevel               `json:"level"`
	Timestamp time.Time              `json:"timestamp"`
	Component string                 `json:"component"`
	UserID    string                 `json:"user_id,omitempty"`
	Message   string                 `json:"message"`
	Error     string                 `json:"error,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

LogEntry represents a structured log entry

type LogLevel

type LogLevel string

LogLevel represents the severity level of a log entry

const (
	LogLevelDebug LogLevel = "DEBUG"
	LogLevelInfo  LogLevel = "INFO"
	LogLevelWarn  LogLevel = "WARN"
	LogLevelError LogLevel = "ERROR"
)

type Logger

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

Logger provides structured logging functionality

func NewLogger

func NewLogger(component string) *Logger

NewLogger creates a new logger instance for a specific component

func (*Logger) Debug

func (l *Logger) Debug(message string, data ...map[string]interface{})

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(message string, err error, data ...map[string]interface{})

Error logs an error message

func (*Logger) Info

func (l *Logger) Info(message string, data ...map[string]interface{})

Info logs an info message

func (*Logger) Warn

func (l *Logger) Warn(message string, data ...map[string]interface{})

Warn logs a warning message

func (*Logger) WithUser

func (l *Logger) WithUser(userID string) *Logger

WithUser creates a new logger instance with a specific user ID

type PluginCommandHandler

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

PluginCommandHandler handles plugin-related commands

func NewPluginCommandHandler

func NewPluginCommandHandler(pluginManager *manager.PluginManager) *PluginCommandHandler

NewPluginCommandHandler creates a new plugin command handler

func (*PluginCommandHandler) GetPluginMessageChannel

func (h *PluginCommandHandler) GetPluginMessageChannel() <-chan sdk.Message

GetPluginMessageChannel returns the channel for receiving messages from plugins

func (*PluginCommandHandler) HandlePluginCommand

func (h *PluginCommandHandler) HandlePluginCommand(cmd string, args []string, isAdmin bool) (string, error)

HandlePluginCommand handles plugin-related commands

func (*PluginCommandHandler) SendMessageToPlugins

func (h *PluginCommandHandler) SendMessageToPlugins(msg shared.Message)

SendMessageToPlugins sends a message to all enabled plugins

func (*PluginCommandHandler) UpdateUserListForPlugins

func (h *PluginCommandHandler) UpdateUserListForPlugins(users []string)

UpdateUserListForPlugins updates the user list for plugins

type ServerConfig

type ServerConfig struct {
	AdminKey     string
	AdminUsers   string
	Port         string
	EnableE2E    bool
	GlobalE2EKey string
}

func RunServerConfig

func RunServerConfig() (*ServerConfig, error)

RunServerConfig runs the interactive server configuration UI

type ServerConfigModel

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

func NewServerConfigUI

func NewServerConfigUI() ServerConfigModel

func (ServerConfigModel) GetConfig

func (m ServerConfigModel) GetConfig() *ServerConfig

GetConfig returns the built configuration

func (ServerConfigModel) Init

func (m ServerConfigModel) Init() tea.Cmd

func (ServerConfigModel) IsCancelled

func (m ServerConfigModel) IsCancelled() bool

IsCancelled returns true if the user cancelled the configuration

func (ServerConfigModel) IsFinished

func (m ServerConfigModel) IsFinished() bool

IsFinished returns true if the user completed the configuration

func (ServerConfigModel) Update

func (m ServerConfigModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (ServerConfigModel) View

func (m ServerConfigModel) View() string

type SystemMetrics

type SystemMetrics struct {
	MemoryUsage    float64 `json:"memory_usage_mb"`
	Goroutines     int     `json:"goroutines"`
	ActiveUsers    int     `json:"active_users"`
	TotalMessages  int     `json:"total_messages"`
	DatabaseStatus string  `json:"database_status"`
}

SystemMetrics represents system performance metrics

type UserList

type UserList struct {
	Users []string `json:"users"`
}

type WSMessage

type WSMessage struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type WebAdminServer

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

func NewWebAdminServer

func NewWebAdminServer(hub *Hub, db *sql.DB, cfg *config.Config) *WebAdminServer

NewWebAdminServer creates a new web admin server with full functionality

func (*WebAdminServer) RegisterRoutes

func (w *WebAdminServer) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes attaches all web admin routes to mux

Jump to

Keyboard shortcuts

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