sentinel

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 Module

type Module struct {
	module.BaseModule
	// contains filtered or unexported fields
}

Module implements the module.Module interface for IP banning.

func New

func New() *Module

New creates a new instance of the Sentinel module.

func (*Module) AdminURL

func (m *Module) AdminURL() string

AdminURL returns the admin dashboard URL for the module.

func (*Module) CheckAutoBanPath

func (m *Module) CheckAutoBanPath(path string) string

CheckAutoBanPath checks if the path matches any auto-ban pattern. Returns the matched pattern if found, empty string otherwise.

func (*Module) GetMiddleware

func (m *Module) GetMiddleware() func(http.Handler) http.Handler

GetMiddleware returns the IP ban checking middleware for use in router setup.

func (*Module) Init

func (m *Module) Init(ctx *module.Context) error

Init initializes the module with the given context.

func (*Module) IsAutoBanEnabled

func (m *Module) IsAutoBanEnabled() bool

IsAutoBanEnabled returns whether auto-ban by path is enabled.

func (*Module) IsBanCheckEnabled

func (m *Module) IsBanCheckEnabled() bool

IsBanCheckEnabled returns whether IP ban checking is enabled.

func (*Module) IsIPBanned

func (m *Module) IsIPBanned(ip string) bool

IsIPBanned checks if the given IP matches any banned pattern.

func (*Module) IsIPWhitelisted

func (m *Module) IsIPWhitelisted(ip string) bool

IsIPWhitelisted checks if the given IP matches any whitelisted pattern.

func (*Module) LookupCountry

func (m *Module) LookupCountry(ip string) string

LookupCountry returns the country code for an IP address.

func (*Module) Middleware

func (m *Module) Middleware() func(http.Handler) http.Handler

Middleware returns HTTP middleware that checks whitelist, bans, and auto-ban paths.

func (*Module) Migrations

func (m *Module) Migrations() []module.Migration

Migrations returns database migrations for the module.

func (*Module) RegisterAdminRoutes

func (m *Module) RegisterAdminRoutes(r chi.Router)

RegisterAdminRoutes registers admin routes for the module.

func (*Module) RegisterRoutes

func (m *Module) RegisterRoutes(_ chi.Router)

RegisterRoutes registers public routes for the module.

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) Shutdown

func (m *Module) Shutdown() error

Shutdown performs cleanup when the module is shutting down.

func (*Module) SidebarLabel

func (m *Module) SidebarLabel() string

SidebarLabel returns the display label for the admin sidebar.

func (*Module) TemplateFuncs

func (m *Module) TemplateFuncs() template.FuncMap

TemplateFuncs returns template functions provided by the module.

func (*Module) TranslationsFS

func (m *Module) TranslationsFS() embed.FS

TranslationsFS returns the embedded filesystem containing module translations.

type WhitelistedIP

type WhitelistedIP struct {
	ID        int64     `json:"id"`
	IPPattern string    `json:"ip_pattern"`
	Notes     string    `json:"notes"`
	CreatedAt time.Time `json:"created_at"`
	CreatedBy int64     `json:"created_by"`
}

WhitelistedIP represents a whitelisted IP that bypasses all checks.

Jump to

Keyboard shortcuts

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