Documentation
¶
Overview ¶
Package sentinel provides IP banning functionality for oCMS. It allows administrators to ban IPs by full address or wildcard pattern, automatically ban IPs accessing certain paths, and whitelist trusted IPs.
Index ¶
- type ActiveChecker
- type AutoBanPath
- type BannedIP
- type EventLogger
- type Module
- func (m *Module) AdminURL() string
- func (m *Module) CheckAutoBanPath(path string) string
- func (m *Module) GetMiddleware() func(http.Handler) http.Handler
- func (m *Module) Init(ctx *module.Context) error
- func (m *Module) IsAutoBanEnabled() bool
- func (m *Module) IsBanCheckEnabled() bool
- func (m *Module) IsIPBanned(ip string) bool
- func (m *Module) IsIPWhitelisted(ip string) bool
- func (m *Module) LookupCountry(ip string) string
- func (m *Module) Middleware() func(http.Handler) http.Handler
- func (m *Module) Migrations() []module.Migration
- func (m *Module) RegisterAdminRoutes(r chi.Router)
- func (m *Module) RegisterRoutes(_ chi.Router)
- func (m *Module) SetActiveChecker(checker ActiveChecker)
- func (m *Module) SetEventLogger(logger EventLogger)
- func (m *Module) SetSessionManager(sm *scs.SessionManager)
- func (m *Module) Shutdown() error
- func (m *Module) SidebarLabel() string
- func (m *Module) TemplateFuncs() template.FuncMap
- func (m *Module) TranslationsFS() embed.FS
- type WhitelistedIP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveChecker ¶ added in v0.7.0
ActiveChecker checks whether a named module is currently active. Used by the middleware to check active status at runtime.
type AutoBanPath ¶
type AutoBanPath struct {
ID int64 `json:"id"`
PathPattern string `json:"path_pattern"`
Notes string `json:"notes"`
CreatedAt time.Time `json:"created_at"`
CreatedBy int64 `json:"created_by"`
}
AutoBanPath represents a path pattern that triggers automatic IP banning.
type BannedIP ¶
type BannedIP struct {
ID int64 `json:"id"`
IPPattern string `json:"ip_pattern"`
CountryCode string `json:"country_code"`
Notes string `json:"notes"`
URL string `json:"url"`
BannedAt time.Time `json:"banned_at"`
CreatedBy int64 `json:"created_by"`
}
BannedIP represents a banned IP record.
type EventLogger ¶ added in v0.7.0
type EventLogger interface {
LogEvent(ctx context.Context, level, category, message string, userID *int64, ipAddress, requestURL string, metadata map[string]any) error
}
EventLogger logs events to the admin event log. Satisfied by *service.EventService.
type Module ¶
type Module struct {
module.BaseModule
// contains filtered or unexported fields
}
Module implements the module.Module interface for IP banning.
func (*Module) CheckAutoBanPath ¶
CheckAutoBanPath checks if the path matches any auto-ban pattern. Returns the matched pattern if found, empty string otherwise.
func (*Module) GetMiddleware ¶
GetMiddleware returns the IP ban checking middleware for use in router setup.
func (*Module) IsAutoBanEnabled ¶
IsAutoBanEnabled returns whether auto-ban by path is enabled.
func (*Module) IsBanCheckEnabled ¶
IsBanCheckEnabled returns whether IP ban checking is enabled.
func (*Module) IsIPBanned ¶
IsIPBanned checks if the given IP matches any banned pattern.
func (*Module) IsIPWhitelisted ¶
IsIPWhitelisted checks if the given IP matches any whitelisted pattern.
func (*Module) LookupCountry ¶
LookupCountry returns the country code for an IP address.
func (*Module) Middleware ¶
Middleware returns HTTP middleware that checks whitelist, bans, and auto-ban paths.
func (*Module) Migrations ¶
Migrations returns database migrations for the module.
func (*Module) RegisterAdminRoutes ¶
RegisterAdminRoutes registers admin routes for the module.
func (*Module) RegisterRoutes ¶
RegisterRoutes registers public routes for the module.
func (*Module) SetActiveChecker ¶ added in v0.7.0
func (m *Module) SetActiveChecker(checker ActiveChecker)
SetActiveChecker sets the active status checker for runtime middleware checks. The middleware uses this to skip processing when the module is deactivated at runtime.
func (*Module) SetEventLogger ¶ added in v0.7.0
func (m *Module) SetEventLogger(logger EventLogger)
SetEventLogger sets the event logger for logging security events to the admin event log.
func (*Module) SetSessionManager ¶
func (m *Module) SetSessionManager(sm *scs.SessionManager)
SetSessionManager sets the session manager for checking authenticated users. This allows the middleware to skip auto-banning for admin/editor users.
func (*Module) SidebarLabel ¶
SidebarLabel returns the display label for the admin sidebar.
func (*Module) TemplateFuncs ¶
TemplateFuncs returns template functions provided by the module.
func (*Module) TranslationsFS ¶
TranslationsFS returns the embedded filesystem containing module translations.