webserver

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: ISC Imports: 30 Imported by: 0

Documentation

Overview

Package webserver is the newest webserver.

Index

Constants

This section is empty.

Variables

Auth is the server authentication service.

Conf is the webserver configuration page.

It is available only after Configure is called.

View Source
var Router *router.Router

Router is the HTTP router.

It is available only after Configure is called.

View Source
var Server *http.Server

Server is the *http.Server.

It is available only after Configure is called.

SessMgr is the session manager service.

View Source
var Wikis map[string]*WikiInfo

Wikis is all wikis served by this webserver.

Functions

func CheckRateLimit added in v0.3.5

func CheckRateLimit(r *http.Request, username string) bool

CheckRateLimit checks if a request should be rate limited

func ClearSuccessfulLogin added in v0.3.5

func ClearSuccessfulLogin(r *http.Request, username string)

ClearSuccessfulLogin clears failed attempts after successful login

func Configure

func Configure(_initial_options Options)

Configure parses a configuration file and initializes webserver.

If any errors occur, the program is terminated.

func CreateWizardConfig added in v0.2.4

func CreateWizardConfig(opts Options)

CreateWizardConfig creates a new server config file given the options.

func GetClientIP added in v0.3.5

func GetClientIP(r *http.Request) string

func GetOrCreateCSRFToken added in v0.3.5

func GetOrCreateCSRFToken(r *http.Request) string

GetOrCreateCSRFToken gets existing csrf token or creates new one for session

func HandleAuthError added in v0.3.5

func HandleAuthError(w http.ResponseWriter, err error, r *http.Request, username string)

HandleAuthError handles authentication errors with rate limiting

func InitWikis added in v0.2.4

func InitWikis() error

initialize all the wikis in the configuration

func Listen

func Listen()

start listening. Configure must be called first. If any errors occur, the program is terminated.

func RegisterWikiSetupHook added in v0.3.7

func RegisterWikiSetupHook(hook WikiSetupHook)

RegisterWikiSetupHook registers a callback to be called when a wiki is set up or rehashed

func Rehash added in v0.2.25

func Rehash() error

Rehash re-parses the server configuration and updates runtime settings. It re-reads the config file, extracts HTTP and template settings, and gracefully updates wikis.

func RehashWiki added in v0.3.7

func RehashWiki(wikiName string) error

RehashWiki reloads configuration and reinitializes a specific wiki. this is more efficient than Rehash() when only one wiki's config has changed.

func SanitizeInput added in v0.3.5

func SanitizeInput(input string) string

SanitizeInput sanitizes user input to prevent xss attacks

func SetSecurityHeaders added in v0.3.5

func SetSecurityHeaders(w http.ResponseWriter)

SetSecurityHeaders adds security headers to prevent common attacks

func Shutdown added in v0.2.25

func Shutdown()

Shutdown gracefully shuts down the webserver and all wikis

func Stop added in v0.2.25

func Stop() error

Listen runs the webserver indefinitely. Stop gracefully shuts down the server

func TemplateNames added in v0.2.4

func TemplateNames() []string

Returns the names of all available templates.

func ValidateAuthForm added in v0.3.5

func ValidateAuthForm(username, password string) error

ValidateAuthForm validates authentication form data

func ValidateCSRFToken added in v0.3.5

func ValidateCSRFToken(r *http.Request, sessionToken string) bool

ValidateCSRFToken checks if the submitted csrf token matches the session token

Types

type Options added in v0.2.4

type Options struct {
	Config   string
	Bind     string
	Port     string
	Host     string
	WikisDir string
	Pregen   bool
}

Options is the webserver command line options.

var Opts Options

Opts is the webserver options.

type PermissionChecker added in v0.3.5

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

PermissionChecker provides cached permission checking for web requests

var GlobalPermissionChecker *PermissionChecker

GlobalPermissionChecker is the global permission checker for webserver handlers

func NewPermissionChecker added in v0.3.5

func NewPermissionChecker(sessionMgr SessionManager) *PermissionChecker

NewPermissionChecker creates a new permission checker with the given session manager

func (*PermissionChecker) ClearPermissionCache added in v0.3.5

func (pc *PermissionChecker) ClearPermissionCache(r *http.Request, username string)

ClearPermissionCache clears cached permissions for a user

func (*PermissionChecker) HasServerPermission added in v0.3.5

func (pc *PermissionChecker) HasServerPermission(r *http.Request, required string) bool

HasServerPermission checks if the current user has a specific server permission with caching

func (*PermissionChecker) HasWikiPermission added in v0.3.5

func (pc *PermissionChecker) HasWikiPermission(r *http.Request, wikiName, required string) bool

HasWikiPermission checks if the current user has a specific wiki permission with caching

type Session added in v0.3.5

type Session struct {
	authenticator.User
	ServerPermissions map[string]bool            `json:"server_perms,omitempty"`
	WikiPermissions   map[string]map[string]bool `json:"wiki_perms,omitempty"`
}

Session embeds the authenticator.User and adds permission caching

func NewSession added in v0.3.5

func NewSession(user *authenticator.User) *Session

NewSession creates a new session user from an authenticator user

type SessionManager added in v0.3.5

type SessionManager interface {
	Get(ctx context.Context, key string) interface{}
	Put(ctx context.Context, key string, val interface{})
}

SessionManager interface for permission caching

type WikiInfo

type WikiInfo struct {
	Name  string // wiki shortname
	Title string // wiki title from @name in the wiki config
	Host  string

	*wiki.Wiki
	// contains filtered or unexported fields
}

WikiInfo represents a wiki hosted on this webserver.

func (*WikiInfo) Copy added in v0.2.0

func (wi *WikiInfo) Copy(w *wiki.Wiki) *WikiInfo

Copy creates a WikiInfo with all the same options, minus Wiki. It is used for working with multiple branches within a wiki.

func (*WikiInfo) Shutdown added in v0.2.25

func (wi *WikiInfo) Shutdown()

Shutdown gracefully shuts down the wiki and its services

type WikiSetupHook added in v0.3.7

type WikiSetupHook func(string, *WikiInfo) error

Jump to

Keyboard shortcuts

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