resources

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyRegistrationOpen          = "__REGISTRATION_OPEN__"
	KeyJitRegistrationEnabled    = "__JIT_REGISTRATION_ENABLED__"
	KeyTurnEnabled               = "__TURN_ENABLED__"
	KeyLogDisabled               = "__LOG_DISABLED__"
	KeyIrohEnabled               = "__IROH_ENABLED__"
	KeySsEnabled                 = "__SS_ENABLED__"
	KeySsWsEnabled               = "__SS_WS_ENABLED__"
	KeySsGrpcEnabled             = "__SS_GRPC_ENABLED__"
	KeyAutoPurgeSeen             = "__AUTO_PURGE_SEEN__"
	KeyHTTPProxyEnabled          = "__HTTP_PROXY_ENABLED__"
	KeyAdminWebEnabled           = "__ADMIN_WEB_ENABLED__"
	KeyRegistrationTokenRequired = "__REGISTRATION_TOKEN_REQUIRED__"
	KeyWebIMAPEnabled            = "__WEBIMAP_ENABLED__"
	KeyWebSMTPEnabled            = "__WEBSMTP_ENABLED__"
	KeyFederationPolicy          = "__FEDERATION_POLICY__"
	KeyFederationEnabled         = "__FEDERATION_ENABLED__"

	// Port settings
	KeySMTPPort = "__SMTP_PORT__"
	// SubmissionPort is the normal SMTP Submission STARTTLS listener (tcp://..., default 587).
	KeySubmissionPort = "__SUBMISSION_PORT__"
	// SubmissionTLSPort is the implicit TLS Submission listener (tls://..., default 465).
	KeySubmissionTLSPort = "__SUBMISSION_TLS_PORT__"
	KeyIMAPPort          = "__IMAP_PORT__"
	KeyIMAPTLSPort       = "__IMAP_TLS_PORT__"
	KeyTurnPort          = "__TURN_PORT__"
	KeySaslPort          = "__SASL_PORT__"
	KeyIrohPort          = "__IROH_PORT__"
	KeySsPort            = "__SS_PORT__"
	KeySsWsPort          = "__SS_WS_PORT__"
	KeySsGrpcPort        = "__SS_GRPC_PORT__"
	KeyHTTPPort          = "__HTTP_PORT__"
	KeyHTTPSPort         = "__HTTPS_PORT__"
	KeyHTTPProxyPort     = "__HTTP_PROXY_PORT__"

	// Per-port access control ("true" = local only, default unset = public)
	KeySMTPLocalOnly          = "__SMTP_LOCAL_ONLY__"
	KeySubmissionLocalOnly    = "__SUBMISSION_LOCAL_ONLY__"
	KeySubmissionTLSLocalOnly = "__SUBMISSION_TLS_LOCAL_ONLY__"
	KeyIMAPLocalOnly          = "__IMAP_LOCAL_ONLY__"
	KeyIMAPTLSLocalOnly       = "__IMAP_TLS_LOCAL_ONLY__"
	KeyTurnLocalOnly          = "__TURN_LOCAL_ONLY__"
	KeySaslLocalOnly          = "__SASL_LOCAL_ONLY__"
	KeyIrohLocalOnly          = "__IROH_LOCAL_ONLY__"
	KeyHTTPLocalOnly          = "__HTTP_LOCAL_ONLY__"
	KeyHTTPSLocalOnly         = "__HTTPS_LOCAL_ONLY__"

	// Configuration settings
	KeySMTPHostname        = "__SMTP_HOSTNAME__"
	KeyTurnRealm           = "__TURN_REALM__"
	KeyTurnSecret          = "__TURN_SECRET__"
	KeyTurnRelayIP         = "__TURN_RELAY_IP__"
	KeyTurnTTL             = "__TURN_TTL__"
	KeyIrohRelayURL        = "__IROH_RELAY_URL__"
	KeySsCipher            = "__SS_CIPHER__"
	KeySsPassword          = "__SS_PASSWORD__"
	KeyHTTPProxyPath       = "__HTTP_PROXY_PATH__"
	KeyHTTPProxyUsername   = "__HTTP_PROXY_USERNAME__"
	KeyHTTPProxyPassword   = "__HTTP_PROXY_PASSWORD__"
	KeyAdminPath           = "__ADMIN_PATH__"
	KeyAdminWebPath        = "__ADMIN_WEB_PATH__"
	KeyDcloginIMAPSecurity = "__DCLOGIN_IMAP_SECURITY__"
	KeyDcloginSMTPSecurity = "__DCLOGIN_SMTP_SECURITY__"
	KeyLanguage            = "__LANGUAGE__"
)

Setting key constants for all configurable values.

Variables

View Source
var DNSCacheHandler = EndpointCacheHandler

DNSCacheHandler is an alias for backward compatibility.

Functions

func AccountsHandler

func AccountsHandler(deps AccountsDeps) func(string, json.RawMessage) (interface{}, int, error)

AccountsHandler creates a handler for /admin/accounts.

func AdminWebHandler added in v0.21.0

func AdminWebHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

AdminWebHandler creates a handler for /admin/services/admin_web.

func AllSettingsHandler added in v0.15.0

func AllSettingsHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

AllSettingsHandler creates a handler for GET /admin/settings that returns all settings at once.

func AutoPurgeSeenHandler added in v0.36.0

func AutoPurgeSeenHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

AutoPurgeSeenHandler creates a handler for /admin/services/auto_purge_seen.

func BlocklistHandler added in v0.15.0

func BlocklistHandler(deps BlocklistDeps) func(string, json.RawMessage) (interface{}, int, error)

BlocklistHandler creates a handler for /admin/blocklist.

func CacheReloadHandler added in v0.44.0

func CacheReloadHandler(deps CacheReloadDeps) func(string, json.RawMessage) (interface{}, int, error)

CacheReloadHandler handles POST /admin/cache/reload. It refreshes in-memory caches that mirror on-disk state so tools like `maddy creds` / `maddy accounts` take effect without restarting the server.

func EndpointCacheHandler added in v0.16.0

func EndpointCacheHandler(deps EndpointCacheDeps) func(string, json.RawMessage) (interface{}, int, error)

EndpointCacheHandler creates a handler for /admin/endpoint-cache (and /admin/dns for backward compat). All reads and writes go through the in-memory Cache so changes are immediately visible to the running server without a DB round-trip.

func ExchangerHandler added in v0.31.0

func ExchangerHandler(deps ExchangerDeps) func(string, json.RawMessage) (interface{}, int, error)

ExchangerHandler creates a handler for /admin/exchangers.

func FederationPolicyHandler added in v0.39.0

func FederationPolicyHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

FederationPolicyHandler creates a handler for /admin/settings/federation. Uses the genericDBToggleHandler pattern for __FEDERATION_ENABLED__.

func FederationRulesHandler added in v0.39.0

func FederationRulesHandler() func(string, json.RawMessage) (interface{}, int, error)

FederationRulesHandler creates a handler for /admin/federation/rules. Supports GET (list), POST (add), and DELETE (remove) operations. All reads come from RAM (no DB query); writes are synchronous dual-writes.

func FederationServersHandler added in v0.39.0

func FederationServersHandler() func(string, json.RawMessage) (interface{}, int, error)

FederationServersHandler creates a handler for /admin/federation/servers. Reads directly from RAM via the FederationTracker, no DB hit.

func GenericSettingHandler added in v0.15.0

func GenericSettingHandler(settingKey string, deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

GenericSettingHandler creates a handler for a single string-valued DB setting. Supports GET (read), POST with action "set" + "value", and POST with action "reset".

func HTTPProxyHandler added in v0.26.0

func HTTPProxyHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

HTTPProxyHandler creates a handler for /admin/services/http_proxy.

func IrohHandler

func IrohHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

IrohHandler creates a handler for /admin/services/iroh.

func JitRegistrationHandler

func JitRegistrationHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

JitRegistrationHandler creates a handler for /admin/registration/jit.

func LogHandler added in v0.15.0

func LogHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

LogHandler creates a handler for /admin/services/log.

func NoticeHandler added in v0.22.0

func NoticeHandler(deps NoticeDeps) func(string, json.RawMessage) (interface{}, int, error)

NoticeHandler creates a handler for /admin/notice. POST: Send an admin notice (unencrypted email) to one or all users. GET: Returns basic info about the notice capability.

func QueueHandler

func QueueHandler(deps QueueDeps) func(string, json.RawMessage) (interface{}, int, error)

QueueHandler creates a handler for /admin/queue.

func QuotaHandler

func QuotaHandler(deps QuotaDeps) func(string, json.RawMessage) (interface{}, int, error)

QuotaHandler creates a handler for /admin/quota.

func RegistrationHandler

func RegistrationHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

RegistrationHandler creates a handler for /admin/registration.

func ReloadHandler added in v0.15.0

func ReloadHandler(deps ReloadDeps) func(string, json.RawMessage) (interface{}, int, error)

ReloadHandler creates a handler for POST /admin/reload. This endpoint regenerates the configuration file from DB-stored overrides and triggers a process exit so the service manager (e.g. systemd) restarts the daemon. This is not the same as SIGUSR2 (which only reloads in-memory caches).

func RestartHandler added in v0.15.0

func RestartHandler() func(method string, body json.RawMessage) (interface{}, int, error)

RestartHandler creates a handler for POST /admin/restart. It schedules a service restart via systemctl after a short delay so the HTTP response can be sent back to the client first.

func ShadowsocksHandler

func ShadowsocksHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

ShadowsocksHandler creates a handler for /admin/services/shadowsocks.

func SharesHandler

func SharesHandler(deps SharesDeps) func(string, json.RawMessage) (interface{}, int, error)

SharesHandler creates a handler for /admin/shares.

func SsGrpcHandler added in v0.26.0

func SsGrpcHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

SsGrpcHandler creates a handler for /admin/services/ss_grpc.

func SsWsHandler added in v0.26.0

func SsWsHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

SsWsHandler creates a handler for /admin/services/ss_ws.

func StatusHandler

func StatusHandler(deps StatusDeps) func(method string, body json.RawMessage) (interface{}, int, error)

StatusHandler creates a handler for /admin/status.

func StorageHandler

func StorageHandler(deps StorageDeps) func(method string, body json.RawMessage) (interface{}, int, error)

StorageHandler creates a handler for /admin/storage.

func TokensHandler added in v0.35.0

func TokensHandler(deps TokensDeps) func(string, json.RawMessage) (interface{}, int, error)

TokensHandler creates a handler for /admin/registration-token. GET: List all tokens with pending reservation counts. POST: Create or update a token. DELETE: Remove a token.

func TurnHandler

func TurnHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

TurnHandler creates a handler for /admin/services/turn.

func WebIMAPHandler added in v0.37.0

func WebIMAPHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

WebIMAPHandler creates a handler for /admin/services/webimap. WebIMAP is disabled by default.

func WebSMTPHandler added in v0.37.0

func WebSMTPHandler(deps SettingsToggleDeps) func(string, json.RawMessage) (interface{}, int, error)

WebSMTPHandler creates a handler for /admin/services/websmtp. WebSMTP is disabled by default.

Types

type AccountsDeps

type AccountsDeps struct {
	AuthDB     module.PlainUserDB
	Storage    module.ManageableStorage
	MailDomain string // Domain for email addresses (e.g., example.com)
}

AccountsDeps are the dependencies needed by the accounts resource handler.

type AllSettingsResponse added in v0.15.0

type AllSettingsResponse struct {
	// Toggle settings
	Registration         string `json:"registration"`            // "open" or "closed"
	JitRegistration      string `json:"jit_registration"`        // "enabled" or "disabled"
	TurnEnabled          string `json:"turn_enabled"`            // "enabled" or "disabled"
	IrohEnabled          string `json:"iroh_enabled"`            // "enabled" or "disabled"
	SsEnabled            string `json:"ss_enabled"`              // "enabled" or "disabled"
	AutoPurgeSeenEnabled string `json:"auto_purge_seen_enabled"` // "enabled" or "disabled"
	LogDisabled          string `json:"log_disabled"`            // "enabled" or "disabled"
	AdminWebEnabled      string `json:"admin_web_enabled"`       // "enabled" or "disabled"
	WebIMAPEnabled       string `json:"webimap_enabled"`         // "enabled" or "disabled"
	WebSMTPEnabled       string `json:"websmtp_enabled"`         // "enabled" or "disabled"
	FederationEnabled    bool   `json:"federation_enabled"`
	FederationPolicy     string `json:"federation_policy"` // "ACCEPT" or "REJECT"

	// Port settings
	SMTPPort          settingValueResponse `json:"smtp_port"`
	SubmissionPort    settingValueResponse `json:"submission_port"`
	SubmissionTLSPort settingValueResponse `json:"submission_tls_port"`
	IMAPPort          settingValueResponse `json:"imap_port"`
	IMAPTLSPort       settingValueResponse `json:"imap_tls_port"`
	TurnPort          settingValueResponse `json:"turn_port"`
	SaslPort          settingValueResponse `json:"sasl_port"`
	IrohPort          settingValueResponse `json:"iroh_port"`
	SsPort            settingValueResponse `json:"ss_port"`
	SsWsPort          settingValueResponse `json:"ss_ws_port"`
	SsGrpcPort        settingValueResponse `json:"ss_grpc_port"`
	HTTPPort          settingValueResponse `json:"http_port"`
	HTTPSPort         settingValueResponse `json:"https_port"`

	// Per-port access control: "public" (default) or "local" (Shadowsocks only)
	SMTPAccess          string `json:"smtp_access"`
	SubmissionAccess    string `json:"submission_access"`
	SubmissionTLSAccess string `json:"submission_tls_access"`
	IMAPAccess          string `json:"imap_access"`
	IMAPTLSAccess       string `json:"imap_tls_access"`
	TurnAccess          string `json:"turn_access"`
	SaslAccess          string `json:"sasl_access"`
	IrohAccess          string `json:"iroh_access"`
	HTTPAccess          string `json:"http_access"`
	HTTPSAccess         string `json:"https_access"`

	// Hostname / address settings
	SMTPHostname   settingValueResponse `json:"smtp_hostname"`
	TurnRealm      settingValueResponse `json:"turn_realm"`
	TurnSecret     settingValueResponse `json:"turn_secret"`
	TurnRelayIP    settingValueResponse `json:"turn_relay_ip"`
	TurnTTL        settingValueResponse `json:"turn_ttl"`
	IrohRelayURL   settingValueResponse `json:"iroh_relay_url"`
	SsCipher       settingValueResponse `json:"ss_cipher"`
	SsPassword     settingValueResponse `json:"ss_password"`
	ShadowsocksURL string               `json:"shadowsocks_url"`

	// Proxy toggle settings
	SsWsEnabled      string `json:"ss_ws_enabled"`      // "enabled" or "disabled"
	SsGrpcEnabled    string `json:"ss_grpc_enabled"`    // "enabled" or "disabled"
	HTTPProxyEnabled string `json:"http_proxy_enabled"` // "enabled" or "disabled"

	// HTTP Proxy settings
	HTTPProxyPort     settingValueResponse `json:"http_proxy_port"`
	HTTPProxyPath     settingValueResponse `json:"http_proxy_path"`
	HTTPProxyUsername settingValueResponse `json:"http_proxy_username"`
	HTTPProxyPassword settingValueResponse `json:"http_proxy_password"`

	AdminPath           settingValueResponse `json:"admin_path"`
	AdminWebPath        settingValueResponse `json:"admin_web_path"`
	DcloginIMAPSecurity settingValueResponse `json:"dclogin_imap_security"`
	DcloginSMTPSecurity settingValueResponse `json:"dclogin_smtp_security"`
	Language            settingValueResponse `json:"language"`
}

AllSettingsResponse is the response for GET /admin/settings.

type BlocklistDeps added in v0.15.0

type BlocklistDeps struct {
	Storage module.ManageableStorage
}

BlocklistDeps are the dependencies needed by the blocklist resource handler.

type CacheReloadDeps added in v0.44.0

type CacheReloadDeps struct {
	AuthDB module.PlainUserDB
	// Storage may implement module.QuotaCacheReloader (e.g. storage.imapsql).
	Storage interface{}
}

CacheReloadDeps wires optional cache reload implementations for the running process.

type DNSCacheDeps

type DNSCacheDeps = EndpointCacheDeps

DNSCacheDeps is an alias for backward compatibility.

type DatabaseInfo

type DatabaseInfo struct {
	Driver    string `json:"driver"`
	SizeBytes int64  `json:"size_bytes"`
}

type DiskInfo

type DiskInfo struct {
	TotalBytes     uint64  `json:"total_bytes"`
	UsedBytes      uint64  `json:"used_bytes"`
	AvailableBytes uint64  `json:"available_bytes"`
	PercentUsed    float64 `json:"percent_used"`
}

type EmailServers

type EmailServers struct {
	ConnectionIPs int `json:"connection_ips"`
	DomainServers int `json:"domain_servers"`
	IPServers     int `json:"ip_servers"`
}

type EndpointCacheDeps added in v0.16.0

type EndpointCacheDeps struct {
	Cache *endpoint_cache.Cache
}

EndpointCacheDeps are the dependencies needed by the endpoint cache handler.

type ExchangerDeps added in v0.31.0

type ExchangerDeps struct {
	DB *gorm.DB
}

ExchangerDeps are the dependencies needed by the exchanger handler.

type FederationRuleEntry added in v0.39.0

type FederationRuleEntry struct {
	Domain    string `json:"domain"`
	CreatedAt int64  `json:"created_at"`
}

FederationRuleEntry is a single domain rule for JSON serialization.

type FederationRuleRequest added in v0.39.0

type FederationRuleRequest struct {
	Domain string `json:"domain"`
}

FederationRuleRequest is the request body for POST/DELETE /admin/federation/rules.

type FederationRulesResponse added in v0.39.0

type FederationRulesResponse struct {
	Rules []FederationRuleEntry `json:"rules"`
	Total int                   `json:"total"`
}

FederationRulesResponse is the response for GET /admin/federation/rules.

type FederationServerEntry added in v0.39.0

type FederationServerEntry struct {
	Domain               string  `json:"domain"`
	QueuedMessages       int64   `json:"queued_messages"`
	FailedHTTP           int64   `json:"failed_http"`
	FailedHTTPS          int64   `json:"failed_https"`
	FailedSMTP           int64   `json:"failed_smtp"`
	SuccessHTTP          int64   `json:"success_http"`
	SuccessHTTPS         int64   `json:"success_https"`
	SuccessSMTP          int64   `json:"success_smtp"`
	InboundDeliveries    int64   `json:"inbound_deliveries"`
	SuccessfulDeliveries int64   `json:"successful_deliveries"`
	MeanLatencyMs        float64 `json:"mean_latency_ms"`
	LastActive           int64   `json:"last_active"`
}

FederationServerEntry is a single server stat for JSON serialization.

type FederationServersResponse added in v0.39.0

type FederationServersResponse struct {
	Servers []FederationServerEntry `json:"servers"`
	Total   int                     `json:"total"`
}

FederationServersResponse is the response for GET /admin/federation/servers.

type NoticeDeps added in v0.22.0

type NoticeDeps struct {
	AuthDB     module.PlainUserDB
	Storage    module.ManageableStorage
	MailDomain string
}

NoticeDeps are the dependencies needed by the notice resource handler.

type QueueDeps

type QueueDeps struct {
	Storage module.ManageableStorage
}

QueueDeps are the dependencies needed by the queue resource handler.

type QuotaDeps

type QuotaDeps struct {
	Storage module.ManageableStorage
}

QuotaDeps are the dependencies needed by the quota resource handler.

type ReloadDeps added in v0.15.0

type ReloadDeps struct {
	// ReloadConfig is called to regenerate the config file and restart the service.
	// It reads port/config overrides from the DB, regenerates maddy.conf, and restarts.
	// Returns nil on success; the caller should expect the process to be terminated shortly after.
	ReloadConfig func() error
}

ReloadDeps provides the callback for reloading the service configuration.

type ServiceStatus

type ServiceStatus struct {
	Connections int `json:"connections"`
	UniqueIPs   int `json:"unique_ips"`
}

type SettingsToggleDeps

type SettingsToggleDeps struct {
	IsRegistrationOpen           func() (bool, error)
	SetRegistrationOpen          func(bool) error
	IsJitRegistrationEnabled     func() (bool, error)
	SetJitRegistrationEnabled    func(bool) error
	IsTurnEnabled                func() (bool, error)
	SetTurnEnabled               func(bool) error
	DeleteSetting                func(key string) error
	GetShadowsocksActiveSettings func() (password, cipher, port string)
	GetSetting                   func(key string) (string, bool, error)
	SetSetting                   func(key, value string) error
}

SettingsToggleDeps provides methods to read/write settings flags.

type SharesDeps

type SharesDeps struct {
	DB *gorm.DB
}

SharesDeps are the dependencies needed by the shares resource handler.

type StateDirInfo

type StateDirInfo struct {
	Path      string `json:"path"`
	SizeBytes int64  `json:"size_bytes"`
}

type StatusDeps

type StatusDeps struct {
	GetUserCount func() (int, error)
	GetSetting   func(string) (string, bool, error)
}

StatusDeps are the dependencies needed by the status resource handler.

type StatusResponse

type StatusResponse struct {
	Version          string         `json:"version"`
	IMAP             *ServiceStatus `json:"imap,omitempty"`
	TURN             *TurnStatus    `json:"turn,omitempty"`
	Shadowsocks      *ServiceStatus `json:"shadowsocks,omitempty"`
	Users            *UsersStatus   `json:"users"`
	Uptime           *UptimeStatus  `json:"uptime"`
	EmailServers     *EmailServers  `json:"email_servers,omitempty"`
	SentMessages     int64          `json:"sent_messages"`
	OutboundMessages int64          `json:"outbound_messages"`
	ReceivedMessages int64          `json:"received_messages"`
}

StatusResponse is the response body for /admin/status.

type StorageDeps

type StorageDeps struct {
	StateDir string
	DBDriver string
	DBDSN    string
}

StorageDeps are the dependencies needed by the storage resource handler.

type StorageResponse

type StorageResponse struct {
	Disk     *DiskInfo     `json:"disk"`
	StateDir *StateDirInfo `json:"state_dir"`
	Database *DatabaseInfo `json:"database,omitempty"`
}

StorageResponse is the response body for /admin/storage.

type TokensDeps added in v0.35.0

type TokensDeps struct {
	DB *gorm.DB
}

TokensDeps provides the DB connection for token management.

type TurnStatus

type TurnStatus struct {
	Relays int `json:"relays"`
}

type UptimeStatus

type UptimeStatus struct {
	BootTime string `json:"boot_time"`
	Duration string `json:"duration"`
}

type UsersStatus

type UsersStatus struct {
	Registered int `json:"registered"`
}

Jump to

Keyboard shortcuts

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