Documentation
¶
Overview ¶
Package web runs website hosting accounts on a node: one Linux user per account, its own PHP-FPM master as a systemd unit (cgroup limits, sandbox), Caddy site blocks imported by the node's Caddyfile, MariaDB databases and a crontab. Everything the panel sends is validated here before it reaches a config file or a command line.
Index ¶
- Variables
- func Caddy(s proto.WebsiteSpec) string
- func Crontab(s proto.WebsiteSpec) string
- func DatabaseName(user, name string) (string, error)
- func FPMConfig(s proto.WebsiteSpec) string
- func Unit(s proto.WebsiteSpec, fpmBinary string) string
- func ValidDomain(d string) bool
- func Validate(s proto.WebsiteSpec) error
- type Manager
- func (m *Manager) App(ctx context.Context, req proto.WebsiteApp) (proto.WebsiteAppResult, error)
- func (m *Manager) Apply(ctx context.Context, s proto.WebsiteSpec) error
- func (m *Manager) Backup(ctx context.Context, req proto.WebsiteBackup) (proto.WebsiteBackupList, error)
- func (m *Manager) Capabilities() proto.WebCapabilities
- func (m *Manager) CheckQuota(id string, n int64) error
- func (m *Manager) DB(ctx context.Context, req proto.WebsiteDB) (proto.WebsiteDBList, error)
- func (m *Manager) Delete(ctx context.Context, id string) error
- func (m *Manager) DiskLoop(ctx context.Context)
- func (m *Manager) IDs() []string
- func (m *Manager) Load() error
- func (m *Manager) Lookup(id string) (dir string, uid int, ok bool)
- func (m *Manager) Status(ctx context.Context, id string) (proto.WebsiteStatus, error)
Constants ¶
This section is empty.
Variables ¶
var WordPressURL = "https://wordpress.org/latest.tar.gz"
WordPressURL is the official release (tests point it elsewhere).
Functions ¶
func Caddy ¶
func Caddy(s proto.WebsiteSpec) string
Caddy renders the account's site blocks. Suspended accounts answer 503.
func Crontab ¶
func Crontab(s proto.WebsiteSpec) string
Crontab renders the account's crontab ("%" is special in cron and is escaped).
func DatabaseName ¶
DatabaseName is the full name of an account database: <username>_<suffix>.
func FPMConfig ¶
func FPMConfig(s proto.WebsiteSpec) string
FPMConfig renders the account's php-fpm.conf (the master runs as the account user).
func Unit ¶
func Unit(s proto.WebsiteSpec, fpmBinary string) string
Unit renders the systemd unit: the PHP-FPM master as the account user, in its own cgroup with limits, and sandboxed so it sees only its home directory.
func ValidDomain ¶
ValidDomain accepts lowercase host names (no wildcards, no IPs, at most 253 characters).
func Validate ¶
func Validate(s proto.WebsiteSpec) error
Validate checks a spec completely; nothing reaches the system before it passes.
Types ¶
type Manager ¶
type Manager struct {
DataDir string // specs live in <DataDir>/websites
CaddyDir string // site blocks, imported by the Caddyfile
CaddyFile string
Logger *slog.Logger
// Exec runs a command (replaced in tests).
Exec func(ctx context.Context, stdin []byte, name string, args ...string) ([]byte, error)
// contains filtered or unexported fields
}
Manager runs the websites of this node.
func (*Manager) App ¶
func (m *Manager) App(ctx context.Context, req proto.WebsiteApp) (proto.WebsiteAppResult, error)
App installs WordPress or deploys a Git repository into one of the account's domains.
func (*Manager) Backup ¶
func (m *Manager) Backup(ctx context.Context, req proto.WebsiteBackup) (proto.WebsiteBackupList, error)
Backup creates, restores, deletes or lists archives in ~/backups. An archive holds sites/ and databases/<name>.sql. Archives live in the user's home, so on restore they are untrusted: they are unpacked as the account user, and SQL is imported through a temporary database user that can only touch that one database.
func (*Manager) Capabilities ¶
func (m *Manager) Capabilities() proto.WebCapabilities
Capabilities reports the web stack installed on this node.
func (*Manager) CheckQuota ¶
CheckQuota refuses writes of n more bytes once the account is at its disk limit.
func (*Manager) DB ¶
DB manages the account's databases. Each database has a user of the same name that may only use that database (at most 20 connections).
func (*Manager) Delete ¶
Delete removes a website: its PHP unit, site blocks, cron, databases, files and user.