pad

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 33 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const UnavailableStatus = 503

UnavailableStatus is the HTTP status for ErrPadUnavailable: the client may retry, and a load balancer may send the retry to another instance.

Variables

View Source
var ErrPadUnavailable = errors.New("pad temporarily unavailable")

ErrPadUnavailable is returned by LockPad and RLockPad when the pad cannot be locked or brought up to the stored state, typically because the database is unreachable. The caller must not touch the pad then: its cached copy may be behind what other instances stored.

Functions

func AccountsOf added in v0.7.0

func AccountsOf(store db.DataStore, cfg *settings.Settings) *accounts.Manager

AccountsOf returns the account manager of store, set up from cfg on first use.

func AuthorTokenFromCookies added in v0.7.0

func AuthorTokenFromCookies(cookie func(key string, defaultValue ...string) string, cfg *settings.Settings) string

AuthorTokenFromCookies is the author token of the request's cookies, or "" when there is none or it is malformed: the prefixed name first, then the plain "token" earlier versions wrote from JavaScript.

func CheckAccess

func CheckAccess(ctx fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, readOnlyManager *ReadOnlyManager) error

CheckAccess keeps the historical signature (no hook system) and runs without any plugin preAuthorize/preAuthzFailure hooks. New callers should prefer CheckAccessWithHooks so that plugins get a chance to permit or deny early.

func CheckAccessWithHooks added in v0.6.3

func CheckAccessWithHooks(ctx fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, readOnlyManager *ReadOnlyManager, hookSystem *hooks.Hook) error

func CreateNewPad added in v0.0.2

func CreateNewPad(ds db.DataStore) *pad.Pad

func EnsureAuthorTokenCookie added in v0.7.0

func EnsureAuthorTokenCookie(c fiber.Ctx, cfg *settings.Settings) string

EnsureAuthorTokenCookie makes sure the browser has an HttpOnly author token cookie and returns the token (etherpad-lite's ensureAuthorTokenCookie). The token is the author's identity; set from JavaScript, as before, any script running in the page could read it and act as the author (delete pads they created, for one). A valid token the browser already has is kept, so authors keep their identity; a cookie that is not HttpOnly yet is rewritten as HttpOnly with the same value.

func GetTxtFromAText added in v0.0.2

func GetTxtFromAText(retrievedPad *pad.Pad, atext apool.AText) (*string, error)

func IntegratorSessionIDCookie added in v0.7.0

func IntegratorSessionIDCookie(cookie func(key string, defaultValue ...string) string, prefix string) string

IntegratorSessionIDCookie reads the sessionID cookie an integrator set through the HTTP API's createSession (etherpad-lite #7045, #7755): the prefixed name first, then the plain one. The value is percent-decoded; one that cannot be decoded counts as absent.

func NeedsUser added in v0.7.0

func NeedsUser(path string) bool

NeedsUser reports whether the access check of path looks at who is logged in; health probes, public assets and the login's own pages do not, so a login session need not be read for them.

func NormalizeAuthzLevel

func NormalizeAuthzLevel(level interface{}) (*string, error)

NormalizeAuthzLevel mirrors the original webaccess.normalizeAuthzLevel: `true` normalizes to "create", the three known levels pass through, and everything else (false, empty, unknown strings) is denied.

func RequestUser added in v0.7.0

func RequestUser(ctx fiber.Ctx) *webaccess.SocketClientRequest

RequestUser is the user webaccess authenticated for this request, or nil.

func ResolvePadAuthorization added in v0.7.0

func ResolvePadAuthorization(store db.DataStore, user *webaccess.SocketClientRequest, padId string, cfg *settings.Settings, hookSystem *hooks.Hook) string

ResolvePadAuthorization decides the level of user (nil: a visitor who is not logged in) for the real pad padId like webaccess does for "/p/<padId>": by the grants of the account management, admins always "create", and with requireAuthorization the authorize hooks limit a logged-in person's level ("" = no access).

func SetAuthorTokenCookie added in v0.7.0

func SetAuthorTokenCookie(c fiber.Ctx, cfg *settings.Settings, token string)

SetAuthorTokenCookie writes token as the HttpOnly author token cookie (and drops the older JavaScript-readable one).

func SetAuthorTokenCookieLax added in v0.7.0

func SetAuthorTokenCookieLax(c fiber.Ctx, cfg *settings.Settings, token string)

SetAuthorTokenCookieLax is SetAuthorTokenCookie with SameSite=Lax always: for a token the browser takes over (a session transfer), which no other site may trigger.

func SetLoginPage added in v0.7.0

func SetLoginPage(fn func(redirect string) string)

SetLoginPage sets the pads' login page (lib/api/padlogin); nil turns the redirect to it off.

func SplitRemoveLastRune added in v0.0.2

func SplitRemoveLastRune(s string) []string

func UserCanModify

func UserCanModify(padId *string, req *webaccess.SocketClientRequest, readOnlyManager ReadOnlyManager, cfg *settings.Settings) bool

UserCanModify tells whether the request user (nil: a visitor) may change the pad: never through a read-only id; otherwise by the level webaccess remembered for the pad, or the level the account management gives.

Types

type ApiSessionInfo added in v0.6.3

type ApiSessionInfo struct {
	GroupID    string `json:"groupID"`
	AuthorID   string `json:"authorID"`
	ValidUntil int64  `json:"validUntil"`
}

ApiSessionInfo is the stored payload of an API session.

type ClientType

type ClientType interface {
}

type DeletionTokens added in v0.7.0

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

DeletionTokens manages the deletion tokens of pads.

func NewDeletionTokens added in v0.7.0

func NewDeletionTokens(store db.DataStore) *DeletionTokens

func (*DeletionTokens) CreateIfAbsent added in v0.7.0

func (d *DeletionTokens) CreateIfAbsent(padID string) (*string, error)

CreateIfAbsent returns a new token for the pad, or nil when the pad already has one: the plaintext is handed out exactly once. The insert is atomic, so two instances creating at once cannot both hand out a token.

func (*DeletionTokens) IsValid added in v0.7.0

func (d *DeletionTokens) IsValid(padID, token string) bool

IsValid reports whether token is the pad's deletion token.

func (*DeletionTokens) Remove added in v0.7.0

func (d *DeletionTokens) Remove(padID string) error

Remove drops the pad's token; called when the pad is removed.

func (*DeletionTokens) Transfer added in v0.7.0

func (d *DeletionTokens) Transfer(srcPadID, dstPadID string) error

Transfer hands the source pad's token to a moved pad, unless the destination already has one (it may have been handed out meanwhile). The source's token is removed with the source pad.

type GlobalPadCache

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

func (*GlobalPadCache) DeletePad

func (g *GlobalPadCache) DeletePad(padID string)

func (*GlobalPadCache) GetPad

func (g *GlobalPadCache) GetPad(padID string) *pad.Pad

func (*GlobalPadCache) SetPad

func (g *GlobalPadCache) SetPad(padID string, pad *pad.Pad)

type GrantedAccess

type GrantedAccess struct {
	AccessStatus string
	AuthorId     string
}

type IdRequest

type IdRequest struct {
	ReadOnlyPadId string
	PadId         string
	ReadOnly      bool
}

type LineModel added in v0.0.2

type LineModel = models.LineModel

LineModel is an alias for models.LineModel for backwards compatibility

func AnalyzeLine added in v0.0.2

func AnalyzeLine(text string, aline string, attrpool apool.APool) (*LineModel, error)

type List

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

func NewList

func NewList(db db.DataStore) List

func (*List) AddPad

func (l *List) AddPad(padID string)

func (*List) GetPads

func (l *List) GetPads() []string

func (*List) RemovePad

func (l *List) RemovePad(padID string)

type Manager

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

func NewManager

func NewManager(db db.DataStore, hook *hooks.Hook) *Manager

func (*Manager) CanOpenPadId added in v0.7.0

func (m *Manager) CanOpenPadId(padID string) (bool, error)

CanOpenPadId reports whether a pad with this id may be opened: either the id is valid for a new pad, or a pad with exactly this id already exists (ids with ":" were allowed before, see pad.IsLegacyPadId).

func (*Manager) CatchUp added in v0.7.0

func (m *Manager) CatchUp(id string, fn func(p *pad.Pad)) bool

CatchUp brings the cached pad id up to the stored state under the pad's local write lock and calls fn with it, to send its clients what other instances stored. It reports false if the pad is not cached here (then it has no clients here) or was deleted.

func (*Manager) DoesPadExist

func (m *Manager) DoesPadExist(padID string) (*bool, error)

func (*Manager) GetPad

func (m *Manager) GetPad(padID string, text *string, authorId *string) (*pad.Pad, error)

func (*Manager) GetTypedPad added in v0.6.5

func (m *Manager) GetTypedPad(padID string, documentType string, authorId *string) (*pad.Pad, error)

GetTypedPad loads or creates a pad of a specific document type. For an existing pad the stored type is kept; documentType only applies on first creation (it is set before Init so Init -> AppendRevision -> Save persists it via CreatePad).

func (*Manager) IsValidPadId

func (m *Manager) IsValidPadId(padID string) bool

func (*Manager) LockPad added in v0.6.8

func (m *Manager) LockPad(ids ...string) (unlock func(), err error)

LockPad takes the write lock of every given pad and returns a function that releases them. Use it around any change to a pad.

Besides the lock within this process it takes the pads' locks in the database, all or none, which excludes writers in other Etherpad instances on the same database, and then brings the cached pads up to the stored state. If any of that fails nothing is held and the error wraps ErrPadUnavailable.

func (*Manager) PurgePad added in v0.7.0

func (m *Manager) PurgePad(padID string) error

PurgePad removes a pad's records without loading it: for pads that cannot be loaded any more (damaged, or an id that is no longer valid).

func (*Manager) RLockPad added in v0.6.8

func (m *Manager) RLockPad(ids ...string) (unlock func(), err error)

RLockPad takes the read lock of every given pad and returns a function that releases them. Use it around reads of a live pad's text, pool or revisions. Readers share the lock: a cached pad is compared with the stored version under the read lock, and only a pad that is behind (another instance wrote to it) is refreshed under the write lock first.

func (*Manager) RemovePad

func (m *Manager) RemovePad(padID string) error

func (*Manager) SanitizePadId

func (m *Manager) SanitizePadId(padID string) (string, error)

SanitizePadId maps a requested pad id to the one to use, like etherpad-lite's sanitizePadId: an existing pad keeps its id; otherwise whitespace and then ":" are replaced by "_", stopping as soon as a pad with the id exists. The result may still be invalid ("a$b"); callers check it with CanOpenPadId.

func (*Manager) SetLowerCasePadIds added in v0.7.0

func (m *Manager) SetLowerCasePadIds(enabled func() bool)

SetLowerCasePadIds connects the lowerCasePadIds setting (etherpad-lite): when it reports true, a requested id that names no existing pad is lower-cased, so "/p/Foo" opens (or creates) "foo"; pads created before with upper-case letters stay reachable under their id.

func (*Manager) UnloadPad added in v0.0.2

func (m *Manager) UnloadPad(id string)

type ReadOnlyManager

type ReadOnlyManager struct {
	Store db.DataStore
}

func NewReadOnlyManager

func NewReadOnlyManager(db db.DataStore) *ReadOnlyManager

func (*ReadOnlyManager) GetIds

func (r *ReadOnlyManager) GetIds(id *string) (*IdRequest, error)

func (*ReadOnlyManager) GetPadId added in v0.0.2

func (r *ReadOnlyManager) GetPadId(readonlyId string) (*string, error)

func (*ReadOnlyManager) GetReadOnlyId

func (r *ReadOnlyManager) GetReadOnlyId(pad string) string

func (*ReadOnlyManager) IsReadOnlyID added in v0.0.2

func (r *ReadOnlyManager) IsReadOnlyID(id *string) bool

type Retention added in v0.6.8

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

Retention removes pads that have not been edited for the configured period. The feature is deliberately opt-in and dry-run by default.

func NewRetention added in v0.6.8

func NewRetention(manager *Manager, store db.DataStore, setting *settings.Settings, logger *zap.SugaredLogger) *Retention

func (*Retention) CheckOnOpen added in v0.6.8

func (r *Retention) CheckOnOpen(padID string) *RetentionNotice

CheckOnOpen checks retention immediately before a pad is loaded. It returns a notice for the browser and leaves the normal pad-loading path unchanged. The caller must hold the pad's write lock (see Manager.LockPad), since an expired pad is deleted right here.

func (*Retention) SetLeader added in v0.7.0

func (r *Retention) SetLeader(isLeader func() bool)

SetLeader makes the periodic sweep run only while isLeader returns true. Call it before Start.

func (*Retention) Start added in v0.6.8

func (r *Retention) Start()

Start starts the background sweep. The first sweep is delayed to avoid adding startup load to a large installation.

func (*Retention) Stop added in v0.6.8

func (r *Retention) Stop()

type RetentionNotice added in v0.6.8

type RetentionNotice struct {
	State           string
	MsRemaining     int64
	DeleteAfterDays int
}

RetentionNotice is sent to the pad client when a pad is close to, or has reached, its configured retention limit.

type SecurityManager

type SecurityManager struct {
	ReadOnlyManager *ReadOnlyManager
	PadManager      *Manager
	AuthorManager   *author.Manager
	SessionManager  *SessionManager
	// contains filtered or unexported fields
}

func NewSecurityManager

func NewSecurityManager(db db.DataStore, hooks *hooks.Hook, padManager *Manager, cfg *settings.Settings) *SecurityManager

NewSecurityManager creates a SecurityManager that reads its access rules from cfg instead of the global settings, so tests can run in parallel with different settings.

func (*SecurityManager) CheckAccess

func (s *SecurityManager) CheckAccess(padId *string, sessionCookie *string, token *string, userSettings *webaccess.SocketClientRequest) (*GrantedAccess, error)

func (*SecurityManager) CheckRequestAccess added in v0.7.0

func (s *SecurityManager) CheckRequestAccess(ctx fiber.Ctx, padId string) (*GrantedAccess, error)

CheckRequestAccess is CheckAccess for an HTTP request on a pad: with the user webaccess authenticated, the token cookie and the integrator's sessionID cookie, as etherpad-lite's import and export routes do.

func (*SecurityManager) HasPadAccess added in v0.0.2

func (s *SecurityManager) HasPadAccess(ctx fiber.Ctx) bool

func (*SecurityManager) RequestCanModify added in v0.7.0

func (s *SecurityManager) RequestCanModify(ctx fiber.Ctx, padId string) bool

RequestCanModify tells whether the request may change the pad: not through a read-only id and not with a read-only authorization.

type SessionManager

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

func NewSessionManager

func NewSessionManager(db db.DataStore) *SessionManager

func (*SessionManager) CreateSession added in v0.6.3

func (sm *SessionManager) CreateSession(groupID string, authorID string, validUntil int64) (string, error)

CreateSession stores a new API session and registers it in the group and author listings. Validation of group/author existence and expiry is the caller's responsibility (the API layer mirrors the original's checks).

func (*SessionManager) DeleteSession added in v0.6.3

func (sm *SessionManager) DeleteSession(sessionID string) (bool, error)

DeleteSession removes a session and its listing entries. The boolean reports whether the session existed.

func (*SessionManager) DoesSessionExist added in v0.6.3

func (sm *SessionManager) DoesSessionExist(sessionID string) (bool, error)

DoesSessionExist reports whether a session record exists.

func (*SessionManager) FindAuthorID added in v0.6.3

func (sm *SessionManager) FindAuthorID(groupID string, sessionCookie *string) *string

FindAuthorID mirrors the original SessionManager.findAuthorID: the cookie may be enclosed in double quotes (upstream #3819) and may carry a comma-separated list of session ids. The author of the first session that belongs to the given group and is not expired is returned.

func (*SessionManager) GetSessionInfo added in v0.6.3

func (sm *SessionManager) GetSessionInfo(sessionID string) (*ApiSessionInfo, error)

GetSessionInfo returns the session payload, or (nil, nil) if the session does not exist.

func (*SessionManager) ListSessionsOfAuthor added in v0.6.3

func (sm *SessionManager) ListSessionsOfAuthor(authorID string) (map[string]ApiSessionInfo, error)

ListSessionsOfAuthor returns all sessions registered for an author.

func (*SessionManager) ListSessionsOfGroup added in v0.6.3

func (sm *SessionManager) ListSessionsOfGroup(groupID string) (map[string]ApiSessionInfo, error)

ListSessionsOfGroup returns all sessions registered for a group.

type UserSettings

type UserSettings struct {
	CanCreate         bool
	ReadOnly          bool
	PadAuthorizations *map[string]string
}

Jump to

Keyboard shortcuts

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