Documentation
¶
Overview ¶
Package config defines the server's configuration: Config, whose boot half is read from the configuration file at start-up and whose runtime half administrators edit in the system settings table; the decoding of stored settings into those structs; the Redis keys several modules share; and the Redis helpers of start-up and installation. The composition root, the transports and the modules all read these definitions, so a setting has one name and one default everywhere.
Index ¶
- Constants
- Variables
- func ConvertValueToString(value reflect.Value) string
- func DecodeSystemConfig[T SystemConfigEntry](entries []T, target any) error
- func ParseRedisURI(uri string) (addr, password string, database int, err error)
- func RedisPing(ctx context.Context, addr, password string, database int) error
- func SystemConfigSliceReflectToStruct[T SystemConfigEntry](slice []T, structType any)
- type AdministratorConfig
- type Boot
- type Config
- type Currency
- type DeviceConfig
- type EdgeSubscribeAccessKey
- type EdgeSubscribeConfig
- type EmailConfig
- type File
- type GeoIPConfig
- type HTTPConfig
- type InviteConfig
- type JwtAuth
- type Log
- type MobileConfig
- type NodeConfig
- type NodeDBConfig
- type NodeDNS
- type NodeOutbound
- type RedisConfig
- type RegisterConfig
- type Runtime
- type SettingError
- type SiteConfig
- type SubscribeConfig
- type SystemConfigEntry
- type TLS
- type Telegram
- type TransportConfig
- type Verify
- type VerifyCode
Constants ¶
const AdminTelegramChatIdsKey = "system:telegram_admin_chat_ids"
AdminTelegramChatIdsKey cached admin Telegram chat ID list (not system config)
const AuthCodeCacheKey = "auth:verify:email"
AuthCodeCacheKey Register Code Cache Key
const AuthCodeTelephoneCacheKey = "auth:verify:telephone"
AuthCodeTelephoneCacheKey Register Code Cache Key
const CommonStatCacheKey = "common:stat"
CommonStatCacheKey CommonStat Cache Key
const CurrencyConfigKey = "system:currency_config"
CurrencyConfigKey Currency Config Key
const EmailSmtpConfigKey = "system:email_smtp_config"
EmailSmtpConfigKey Email Smtp Config Key
const GlobalConfigKey = "system:global_config"
GlobalConfigKey Global Config Key
const InviteConfigKey = "system:invite_config"
InviteConfigKey Invite Config Key
const NodeConfigKey = "system:node_config"
NodeConfigKey Node Config Key
const RegisterConfigKey = "system:register_config"
RegisterConfigKey Register Config Key
const RegisterIPLimitKeyPrefix = "register:limit:ip:"
RegisterIPLimitKeyPrefix limits new accounts created by the same client IP.
const SendCountLimitKeyPrefix = "send:limit:"
SendCountLimitKeyPrefix Send Count Limit Key Prefix eg. send:limit:register:email:xxx@ppanel.dev
const SendIntervalKeyPrefix = "send:interval:"
SendIntervalKeyPrefix Auth Code Send Interval Key Prefix
const SessionIdKey = "auth:session_id"
SessionIdKey cache session key
const SiteConfigKey = "system:site_config"
SiteConfigKey Site Config Key
const SmsConfigKey = "system:sms_config"
SmsConfigKey Mobile Config Key
const SubscribeConfigKey = "system:subscribe_config"
SubscribeConfigKey Subscribe Config Key
const TelegramBindKey = "auth:telegram_bind"
TelegramBindKey prefixes the single-use Telegram account-binding tokens handed to the bot's deep link. It is deliberately separate from SessionIdKey: a binding capability must not double as a session credential, and it is consumed on first use.
const TelegramCallbackKey = "auth:telegram_callback"
TelegramCallbackKey prefixes the redeemed Telegram login/bind callbacks. The widget result is a bearer credential that travels in a URL fragment, so it may only be exchanged once.
const TelegramConfigKey = "system:telegram_config"
TelegramConfigKey Telegram Config Key
const TosConfigKey = "system:tos_config"
TosConfigKey caches the terms-of-service settings (the "tos" category).
const VerifyCodeAttemptKeyPrefix = "auth:verify:attempt:"
VerifyCodeAttemptKeyPrefix limits guesses against a verification code.
const VerifyCodeConfigKey = "system:verify_code_config"
VerifyCodeConfigKey Verify Code Config Key
const VerifyConfigKey = "system:verify_config"
VerifyConfigKey Verify Config Key
Variables ¶
var DefaultTrustedProxies = []string{"127.0.0.0/8", "::1/128", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fc00::/7"}
DefaultTrustedProxies are the networks trusted as reverse proxies when TrustedProxies is empty: the loopback interface and the private ranges, so nginx on the same host, a Docker bridge or an internal load balancer is trusted without configuration. Clients reach a proxy panel over the public network, so a peer from these ranges is a proxy, not a client; a server its clients reach directly from a private network sets TrustedProxies to ["none"].
Functions ¶
func ConvertValueToString ¶ added in v1.20.2
ConvertValueToString converts the value to string
func DecodeSystemConfig ¶ added in v1.21.0
func DecodeSystemConfig[T SystemConfigEntry](entries []T, target any) error
DecodeSystemConfig applies persisted settings to the struct target points to. Each entry is matched to the exported field named like its key; keys without such a field are skipped, because one category can hold settings that another reader owns. The stored type selects the conversion:
- "string": the value as is;
- "bool", "int", "int64": the parsed value, an empty value meaning zero;
- "interface": the value decoded as JSON, an empty value leaving the field untouched.
A *bool field takes a boolean of any stored type, an empty value meaning unset (nil).
Every setting that cannot be applied is reported in the returned error, one *SettingError per key joined with errors.Join, and the remaining settings are still applied. A value that does not parse leaves its field at the zero value, which is what the previous, silent implementation produced, and a stored type the field cannot hold leaves the field untouched instead of panicking.
func ParseRedisURI ¶ added in v1.20.2
ParseRedisURI splits a redis:// URI, the form of the PPANEL_REDIS environment variable, into the address (port 6379 when it names none), the password and the database number of its path (0 without one). A path that is not a number is an error.
func RedisPing ¶ added in v1.20.2
RedisPing reports whether the Redis server at addr answers a PING with the given password and database. It opens a client for this one ping and closes it afterwards; ctx bounds the whole attempt, the client's dial retries included.
func SystemConfigSliceReflectToStruct ¶ added in v1.20.2
func SystemConfigSliceReflectToStruct[T SystemConfigEntry](slice []T, structType any)
SystemConfigSliceReflectToStruct applies settings like DecodeSystemConfig for callers that cannot act on a malformed setting: every setting it could not apply is logged with its key instead of being returned.
Types ¶
type AdministratorConfig ¶ added in v1.21.0
type AdministratorConfig struct {
Email string `yaml:"Email" default:"admin@ppanel.dev"`
// Password seeds the first administrator. Left empty, a random one is
// generated and printed once at the first start. Once the administrator
// exists it seeds nothing, only sits in the file in clear, and the start
// flags it: remove it from the file then.
Password string `yaml:"Password,omitempty"`
}
AdministratorConfig names the first administrator, whom the start seeds into a database that holds no account yet. The setup wizard writes the installer's email here, so an installation resumed after a failed migration seeds the same account.
type Boot ¶ added in v1.21.0
type Boot struct {
Host string `yaml:"Host" default:"0.0.0.0"`
Port int `yaml:"Port" default:"8080"`
Debug bool `yaml:"Debug" default:"false"`
// TrustedProxies lists the reverse proxies (IP addresses or CIDRs) whose
// X-Forwarded-For and X-Real-IP headers name the real client. Empty means
// DefaultTrustedProxies; the entry "private" stands for those networks in a
// longer list, and ["none"] trusts no header at all.
TrustedProxies []string `yaml:"TrustedProxies"`
// AllowedOrigins lists the browser origins CORS admits, as scheme://host[:port].
// Empty keeps the permissive default of reflecting the request's Origin.
AllowedOrigins []string `yaml:"AllowedOrigins"`
HTTP HTTPConfig `yaml:"HTTP"`
GeoIP GeoIPConfig `yaml:"GeoIP"`
AppLocation string `yaml:"AppLocation" default:"Asia/Shanghai"`
Transport TransportConfig `yaml:"Transport"`
TLS TLS `yaml:"TLS"`
JwtAuth JwtAuth `yaml:"JwtAuth"`
Logger logger.LogConf `yaml:"Logger"`
Trace trace.Config `yaml:"Trace"`
Database orm.Config `yaml:"Database"`
MySQL *orm.Config `yaml:"MySQL,omitempty"` // Deprecated: use Database.
Redis RedisConfig `yaml:"Redis"`
EdgeSubscribe EdgeSubscribeConfig `yaml:"EdgeSubscribe"`
Administrator AdministratorConfig `yaml:"Administrator"`
}
Boot is the configuration fixed for the life of the process: the listener, the connections and the secrets. Changing it takes a restart.
type Config ¶
Config is the server's whole configuration: the boot settings, read from the configuration file once at startup, and the runtime settings, which the system settings table overrides at startup and whenever an administrator changes them. The two halves are embedded, so their fields read as the Config's own; in the file they share one level.
func (Config) DatabaseConfig ¶ added in v1.2.12
func (*Config) SetDatabaseConfig ¶ added in v1.2.12
type Currency ¶ added in v1.2.5
type Currency struct {
Unit string `yaml:"Unit" default:"USD"`
Symbol string `yaml:"Symbol" default:"$"`
AccessKey string `yaml:"AccessKey" default:""`
}
Currency is the site currency: the ISO code prices are in and the symbol shown next to them. The defaults are the values the settings seed stores (CurrencyUnit USD, CurrencySymbol $), so a runtime configuration not yet loaded from the table agrees with a fresh installation; they used to disagree with each other (a CNY unit with a "USD" symbol).
type DeviceConfig ¶ added in v1.1.8
type EdgeSubscribeAccessKey ¶ added in v1.14.15
EdgeSubscribeAccessKey is an HMAC credential owned by a Worker deployment. Secret must be stored only in the PPanel runtime config and the Worker secret store; it must never be returned from an API.
type EdgeSubscribeConfig ¶ added in v1.14.15
type EdgeSubscribeConfig struct {
Enabled bool `yaml:"Enabled" default:"false"`
MaxClockSkewSeconds int64 `yaml:"MaxClockSkewSeconds" default:"300"`
Keys []EdgeSubscribeAccessKey `yaml:"Keys"`
}
EdgeSubscribeConfig configures the private manifest API consumed by the Cloudflare edge-subscribe Worker. It intentionally has no relationship to the user-facing subscription template configuration above.
type EmailConfig ¶
type EmailConfig struct {
Enable bool `yaml:"Enable" default:"true"`
Platform string `yaml:"platform"`
PlatformConfig string `yaml:"platform_config"`
EnableVerify bool `yaml:"enable_verify"`
EnableNotify bool `yaml:"enable_notify"`
EnableDomainSuffix bool `yaml:"enable_domain_suffix"`
DomainSuffixList string `yaml:"domain_suffix_list"`
VerifyEmailTemplate string `yaml:"verify_email_template"`
ExpirationEmailTemplate string `yaml:"expiration_email_template"`
MaintenanceEmailTemplate string `yaml:"maintenance_email_template"`
TrafficExceedEmailTemplate string `yaml:"traffic_exceed_email_template"`
// Subjects pair with the templates above. They are copied from the email
// auth method config by field name (internal/infra/mapping), so the
// fields must keep the names they have there; empty means the queued
// fallback subject is used.
VerifyEmailSubject string `yaml:"verify_email_subject"`
ExpirationEmailSubject string `yaml:"expiration_email_subject"`
MaintenanceEmailSubject string `yaml:"maintenance_email_subject"`
TrafficExceedEmailSubject string `yaml:"traffic_exceed_email_subject"`
}
type File ¶
type File struct {
Host string `yaml:"Host" default:"0.0.0.0"`
Port int `yaml:"Port" default:"8080"`
Transport TransportConfig `yaml:"Transport"`
TLS TLS `yaml:"TLS"`
Debug bool `yaml:"Debug" default:"false"`
TrustedProxies []string `yaml:"TrustedProxies"`
AllowedOrigins []string `yaml:"AllowedOrigins"`
HTTP HTTPConfig `yaml:"HTTP"`
GeoIP GeoIPConfig `yaml:"GeoIP"`
JwtAuth JwtAuth `yaml:"JwtAuth"`
Logger logger.LogConf `yaml:"Logger"`
Trace trace.Config `yaml:"Trace"`
Database orm.Config `yaml:"Database"`
MySQL *orm.Config `yaml:"MySQL,omitempty"` // Deprecated: use Database.
Redis RedisConfig `yaml:"Redis"`
EdgeSubscribe EdgeSubscribeConfig `yaml:"EdgeSubscribe"`
// AppLocation survives the installation's rewrite of the file: the new
// database's session zone is set from it.
AppLocation string `yaml:"AppLocation" default:"Asia/Shanghai"`
Administrator AdministratorConfig `yaml:"Administrator"`
}
func (File) DatabaseConfig ¶ added in v1.2.12
func (*File) SetDatabaseConfig ¶ added in v1.2.12
type GeoIPConfig ¶ added in v1.21.0
type GeoIPConfig struct {
// Path of the GeoLite2-City.mmdb file.
Path string `yaml:"Path" default:"./cache/GeoLite2-City.mmdb"`
// Download fetches the database from DownloadURL (the built-in mirror when
// empty) when Path is missing.
Download bool `yaml:"Download" default:"true"`
DownloadURL string `yaml:"DownloadURL" default:""`
// SHA256 is the hex digest the file must have; empty skips the check.
SHA256 string `yaml:"SHA256" default:""`
// Required makes a missing or invalid database fatal at start-up; by
// default the server starts without geolocation and logs the reason.
Required bool `yaml:"Required" default:"false"`
}
GeoIPConfig locates the MaxMind city database that enriches the audit logs with a location.
type HTTPConfig ¶ added in v1.21.0
type HTTPConfig struct {
ReadTimeoutSeconds int `yaml:"ReadTimeoutSeconds" default:"180"`
// WriteTimeoutSeconds 0 leaves response writes unbounded, which the
// streaming endpoints (order events over SSE, WebSocket) need.
WriteTimeoutSeconds int `yaml:"WriteTimeoutSeconds" default:"0"`
IdleTimeoutSeconds int `yaml:"IdleTimeoutSeconds" default:"180"`
MaxRequestBodyMB int `yaml:"MaxRequestBodyMB" default:"4"`
}
HTTPConfig bounds the API listener. The defaults are the values the server ran with before they were configurable.
type InviteConfig ¶
type MobileConfig ¶
type NodeConfig ¶
type NodeConfig struct {
NodeSecret string `yaml:"NodeSecret" default:""`
NodePullInterval int64 `yaml:"NodePullInterval" default:"60"`
NodePushInterval int64 `yaml:"NodePushInterval" default:"60"`
TrafficReportThreshold int64 `yaml:"TrafficReportThreshold" default:"0"`
IPStrategy string `yaml:"IPStrategy" default:""`
DNS []NodeDNS `yaml:"DNS"`
Block []string `yaml:"Block" `
Outbound []NodeOutbound `yaml:"Outbound"`
}
func (*NodeConfig) Marshal ¶ added in v1.1.2
func (n *NodeConfig) Marshal() ([]byte, error)
func (*NodeConfig) Unmarshal ¶ added in v1.1.2
func (n *NodeConfig) Unmarshal(data []byte) error
type NodeDBConfig ¶ added in v1.1.2
type NodeDNS ¶ added in v1.1.2
type NodeOutbound ¶ added in v1.1.2
type NodeOutbound struct {
Name string `json:"name"`
Protocol string `json:"protocol"`
Address string `json:"address"`
Port int64 `json:"port"`
User string `json:"user,omitempty"`
Password string `json:"password"`
UUID string `json:"uuid,omitempty"`
Cipher string `json:"cipher,omitempty"`
Plugin string `json:"plugin,omitempty"`
PluginOptions any `json:"plugin_opts,omitempty"`
Security string `json:"security,omitempty"`
SNI string `json:"sni,omitempty"`
ALPN []string `json:"alpn,omitempty"`
AllowInsecure bool `json:"allow_insecure,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
Transport string `json:"transport,omitempty"`
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
ServiceName string `json:"service_name,omitempty"`
XHTTPMode string `json:"xhttp_mode,omitempty"`
XHTTPExtra string `json:"xhttp_extra,omitempty"`
Flow string `json:"flow,omitempty"`
Encryption string `json:"encryption,omitempty"`
EncryptionMode string `json:"encryption_mode,omitempty"`
EncryptionRTT string `json:"encryption_rtt,omitempty"`
EncryptionTicket string `json:"encryption_ticket,omitempty"`
EncryptionPadding string `json:"encryption_client_padding,omitempty"`
EncryptionPassword string `json:"encryption_password,omitempty"`
Multiplex string `json:"multiplex,omitempty"`
UoT bool `json:"uot,omitempty"`
UoTVersion int `json:"uot_version,omitempty"`
CongestionController string `json:"congestion_controller,omitempty"`
UDPStream bool `json:"udp_stream,omitempty"`
ReduceRtt bool `json:"reduce_rtt,omitempty"`
Heartbeat int `json:"heartbeat,omitempty"`
RealityPublicKey string `json:"reality_public_key,omitempty"`
RealityShortId string `json:"reality_short_id,omitempty"`
SpiderX string `json:"spider_x,omitempty"`
Settings string `json:"settings,omitempty"`
StreamSettings string `json:"stream_settings,omitempty"`
Rules []string `json:"rules"`
}
func (*NodeOutbound) Marshal ¶ added in v1.1.2
func (n *NodeOutbound) Marshal() ([]byte, error)
type RedisConfig ¶
type RedisConfig struct {
Host string `yaml:"Host" default:"localhost:6379"`
Pass string `yaml:"Pass" default:""`
DB int `yaml:"DB" default:"0"`
// QueueDB is the Redis database of the asynq task queue, shared by the
// producer, the consumer and the scheduler. It defaults to the database
// the server always used, so an upgrade keeps its queued tasks; give
// every deployment sharing one Redis its own value.
QueueDB int `yaml:"QueueDB" default:"5"`
}
type RegisterConfig ¶
type RegisterConfig struct {
StopRegister bool `yaml:"StopRegister" default:"false"`
EnableTrial bool `yaml:"EnableTrial" default:"false"`
TrialSubscribe int64 `yaml:"TrialSubscribe" default:"0"`
TrialTime int64 `yaml:"TrialTime" default:"0"`
TrialTimeUnit string `yaml:"TrialTimeUnit" default:""`
IpRegisterLimit int64 `yaml:"IpRegisterLimit" default:"0"`
IpRegisterLimitDuration int64 `yaml:"IpRegisterLimitDuration" default:"0"`
EnableIpRegisterLimit bool `yaml:"EnableIpRegisterLimit" default:"false"`
}
type Runtime ¶ added in v1.21.0
type Runtime struct {
Site SiteConfig `yaml:"Site"`
Node NodeConfig `yaml:"Node"`
Mobile MobileConfig `yaml:"Mobile"`
Email EmailConfig `yaml:"Email"`
Device DeviceConfig `yaml:"device"`
Verify Verify `yaml:"Verify"`
VerifyCode VerifyCode `yaml:"VerifyCode"`
Register RegisterConfig `yaml:"Register"`
Subscribe SubscribeConfig `yaml:"Subscribe"`
Invite InviteConfig `yaml:"Invite"`
Telegram Telegram `yaml:"Telegram"`
Log Log `yaml:"Log"`
Currency Currency `yaml:"Currency"`
}
Runtime is the configuration an administrator edits while the server runs. The runtime state publishes it as immutable snapshots; a reload replaces a section from the system settings table.
type SettingError ¶ added in v1.21.0
SettingError reports a stored setting whose value could not be applied to the field its key names. It carries the key and the stored type but never the value, which may be a credential.
func (*SettingError) Error ¶ added in v1.21.0
func (e *SettingError) Error() string
func (*SettingError) Unwrap ¶ added in v1.21.0
func (e *SettingError) Unwrap() error
type SiteConfig ¶
type SiteConfig struct {
Host string `yaml:"Host" default:""`
SiteName string `yaml:"SiteName" default:""`
SiteDesc string `yaml:"SiteDesc" default:""`
SiteLogo string `yaml:"SiteLogo" default:""`
Keywords string `yaml:"Keywords" default:""`
CustomHTML string `yaml:"CustomHTML" default:""`
CustomData string `yaml:"CustomData" default:""`
}
type SubscribeConfig ¶
type SubscribeConfig struct {
SingleModel bool `yaml:"SingleModel" default:"false"`
SubscribePath string `yaml:"SubscribePath" default:"/v1/subscribe/config"`
SubscribeDomain string `yaml:"SubscribeDomain" default:""`
PanDomain bool `yaml:"PanDomain" default:"false"`
UserAgentLimit bool `yaml:"UserAgentLimit" default:"false"`
UserAgentList string `yaml:"UserAgentList" default:""`
ShowTutorial bool `yaml:"ShowTutorial" default:"true"`
ProfileUpdateInterval int64 `yaml:"ProfileUpdateInterval" default:"0"`
ProfileWebPageURL string `yaml:"ProfileWebPageURL" default:""`
}
type SystemConfigEntry ¶ added in v1.20.2
SystemConfigEntry is the narrow data contract needed to apply persisted configuration to a Go struct. It keeps this reflection helper independent from the database entity that happens to supply the values.
type Telegram ¶
type Telegram struct {
Enable bool `yaml:"Enable" default:"false"`
BotID int64 `yaml:"BotID" default:""`
BotName string `yaml:"BotName" default:""`
BotToken string `yaml:"BotToken" default:""`
EnableNotify bool `yaml:"EnableNotify" default:"false"`
WebHookDomain string `yaml:"WebHookDomain" default:""`
// GroupChatID is the validated administrators' group; zero when the
// group is unconfigured or failed validation, which disables every
// group-side feature (admin commands, topics, notifications).
GroupChatID int64 `yaml:"GroupChatID" default:"0"`
}
type TransportConfig ¶ added in v1.2.14
type TransportConfig struct {
Driver string `yaml:"Driver" default:"hertz"`
}
type Verify ¶
type Verify struct {
TurnstileSiteKey string `yaml:"TurnstileSiteKey" default:""`
TurnstileSecret string `yaml:"TurnstileSecret" default:""`
LoginVerify bool `yaml:"LoginVerify" default:"false"`
RegisterVerify bool `yaml:"RegisterVerify" default:"false"`
ResetPasswordVerify bool `yaml:"ResetPasswordVerify" default:"false"`
}