Documentation
¶
Overview ¶
Package webserver is the newest webserver.
Index ¶
- Variables
- func CheckRateLimit(r *http.Request, username string) bool
- func ClearSuccessfulLogin(r *http.Request, username string)
- func Configure(_initial_options Options)
- func CreateWizardConfig(opts Options)
- func GetClientIP(r *http.Request) string
- func GetOrCreateCSRFToken(r *http.Request) string
- func HandleAuthError(w http.ResponseWriter, err error, r *http.Request, username string)
- func InitWikis() error
- func Listen()
- func RegisterWikiSetupHook(hook WikiSetupHook)
- func Rehash() error
- func RehashWiki(wikiName string) error
- func SanitizeInput(input string) string
- func SetSecurityHeaders(w http.ResponseWriter)
- func Shutdown()
- func Stop() error
- func TemplateNames() []string
- func ValidateAuthForm(username, password string) error
- func ValidateCSRFToken(r *http.Request, sessionToken string) bool
- type Options
- type PermissionChecker
- type Session
- type SessionManager
- type WikiInfo
- type WikiSetupHook
Constants ¶
This section is empty.
Variables ¶
var Auth *authenticator.Authenticator
Auth is the server authentication service.
var Conf *wikifier.Page
Conf is the webserver configuration page.
It is available only after Configure is called.
var Router *router.Router
Router is the HTTP router.
It is available only after Configure is called.
var Server *http.Server
Server is the *http.Server.
It is available only after Configure is called.
var SessMgr *scs.SessionManager
SessMgr is the session manager service.
var Wikis map[string]*WikiInfo
Wikis is all wikis served by this webserver.
Functions ¶
func CheckRateLimit ¶ added in v0.3.5
CheckRateLimit checks if a request should be rate limited
func ClearSuccessfulLogin ¶ added in v0.3.5
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 GetOrCreateCSRFToken ¶ added in v0.3.5
GetOrCreateCSRFToken gets existing csrf token or creates new one for session
func HandleAuthError ¶ added in v0.3.5
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
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
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
ValidateAuthForm validates authentication form data
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
Logo string
Host string
*wiki.Wiki
// contains filtered or unexported fields
}
WikiInfo represents a wiki hosted on this webserver.