server

package
v0.7.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 24 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, configDir, dbPath string, port int) 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, configDir, dbPath string, port int) *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 AdminSecurityManager

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

AdminSecurityManager handles security-related admin operations

func NewAdminSecurityManager

func NewAdminSecurityManager() *AdminSecurityManager

NewAdminSecurityManager creates a new admin security manager

func (*AdminSecurityManager) CancelConfirmation

func (asm *AdminSecurityManager) CancelConfirmation(userID string) bool

CancelConfirmation cancels a pending confirmation

func (*AdminSecurityManager) CheckConfirmation

func (asm *AdminSecurityManager) CheckConfirmation(userID, input string) (bool, *ConfirmationPrompt)

CheckConfirmation checks if a user's input matches the required confirmation

func (*AdminSecurityManager) CleanupExpiredConfirmations

func (asm *AdminSecurityManager) CleanupExpiredConfirmations()

CleanupExpiredConfirmations removes expired confirmations

func (*AdminSecurityManager) FormatConfirmationMessage

func (asm *AdminSecurityManager) FormatConfirmationMessage(prompt *ConfirmationPrompt) string

FormatConfirmationMessage formats a confirmation prompt message

func (*AdminSecurityManager) GetPendingConfirmation

func (asm *AdminSecurityManager) GetPendingConfirmation(userID string) *ConfirmationPrompt

GetPendingConfirmation returns the pending confirmation for a user

func (*AdminSecurityManager) HandleAdminCommandWithConfirmation

func (asm *AdminSecurityManager) HandleAdminCommandWithConfirmation(client *Client, command string, args []string) (bool, string)

HandleAdminCommandWithConfirmation handles admin commands that require confirmation

func (*AdminSecurityManager) RequireConfirmation

func (asm *AdminSecurityManager) RequireConfirmation(userID string, confType ConfirmationType, message string, data map[string]interface{}) *ConfirmationPrompt

RequireConfirmation creates a confirmation prompt for a destructive operation

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 ConfirmationPrompt

type ConfirmationPrompt struct {
	Type         ConfirmationType
	UserID       string
	Message      string
	Confirmation string
	Timestamp    time.Time
	Data         map[string]interface{}
}

ConfirmationPrompt represents a pending confirmation

type ConfirmationType

type ConfirmationType string

ConfirmationType represents the type of confirmation required

const (
	ConfirmationClearDB     ConfirmationType = "clear_db"
	ConfirmationBackupDB    ConfirmationType = "backup_db"
	ConfirmationBanUser     ConfirmationType = "ban_user"
	ConfirmationKickUser    ConfirmationType = "kick_user"
	ConfirmationDeleteUser  ConfirmationType = "delete_user"
	ConfirmationResetConfig ConfirmationType = "reset_config"
)

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 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"`
}

Jump to

Keyboard shortcuts

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