Documentation
¶
Overview ¶
Package subsettings holds the subscription settings of the installation (SubscriptionService): names and texts, the apps the public user page recommends, the server-name template and the format rules. They are stored as one protojson value in the setting table under Key, validated on the way in, and read at request time through a small cache that Update invalidates.
default_dns_preset_id and link_dns are not part of the stored document: the DNS module owns the instance default preset and the offer for the link apps (one source of truth), and SubscriptionService reads and writes them through that module.
Index ¶
- Constants
- Variables
- func CheckResponseHeaders(list []*adminv1.ResponseHeader) ([]*adminv1.ResponseHeader, error)
- func DNSChoice(s *adminv1.SubscriptionSettings) bool
- func Defaults() *adminv1.SubscriptionSettings
- func LinkAWG(s *adminv1.SubscriptionSettings) bool
- func LinkAutoSelect(s *adminv1.SubscriptionSettings) bool
- func Load(ctx context.Context, st *store.Store) (*adminv1.SubscriptionSettings, error)
- func MigrateLinkDeviceLimit(ctx context.Context, st *store.Store) error
- func MigrateM3(ctx context.Context, st *store.Store) error
- func MigrateSingbox(ctx context.Context, st *store.Store) error
- func Normalize(s *adminv1.SubscriptionSettings)
- func PagePassword(s *adminv1.SubscriptionSettings) bool
- func Parse(value string) (*adminv1.SubscriptionSettings, error)
- func SelfService(s *adminv1.SubscriptionSettings) bool
- func SentValue(value string, b64 bool) string
- func Validate(s *adminv1.SubscriptionSettings) error
- type Cache
- func (c *Cache) ClientAPIEnabled(ctx context.Context) bool
- func (c *Cache) Get(ctx context.Context) *adminv1.SubscriptionSettings
- func (c *Cache) Invalidate()
- func (c *Cache) ProbeReports(ctx context.Context) bool
- func (c *Cache) Update(ctx context.Context, s *adminv1.SubscriptionSettings) (*adminv1.SubscriptionSettings, error)
- func (c *Cache) UpdateRevoking(ctx context.Context, s *adminv1.SubscriptionSettings) (*adminv1.SubscriptionSettings, int, error)
- type SentHeader
Constants ¶
const ( MaxResponseHeaders = 20 MaxHeaderName = 64 MaxHeaderValue = 1000 MaxHeadersBytes = 4096 )
Limits of the owner's own response headers (SubscriptionSettings.response_headers). The total is the bytes of all names and values as they are sent, with the separators: what one answer can carry at most if every entry applies to it. A reverse proxy in front of the panel buffers a response's headers in 4 or 8 KiB, and the panel's own headers take about 1 KiB of that.
const ( MaxRules = 50 MaxApps = 30 )
Limits enforced by Validate.
const DefaultNameTemplate = "{flag} {country} · {profile}"
DefaultNameTemplate is the server-name template of a fresh install and of an empty template: the country and profile, so servers using different protocols or exits stay recognizable in the client's list. Migration 00035 moves installations off the previous "{flag} {country}" default.
const DefaultUpdateHours = 12
DefaultUpdateHours is what an interval of 0 means.
const Key = "subscription_settings"
Key is the setting-table key of the stored document.
Variables ¶
var ErrInvalid = errors.New("invalid subscription settings")
ErrInvalid wraps every validation failure (the RPC maps it to INVALID_ARGUMENT).
Functions ¶
func CheckResponseHeaders ¶
func CheckResponseHeaders(list []*adminv1.ResponseHeader) ([]*adminv1.ResponseHeader, error)
CheckResponseHeaders normalizes a copy of list and checks it as a save does (for the preview of an unsaved list); the returned list is the normalized copy.
func DNSChoice ¶ added in v0.1.17
func DNSChoice(s *adminv1.SubscriptionSettings) bool
DNSChoice reports whether people may pick the DNS of each server on the public page (DnsService.SetNodeDnsOptions says what is offered). Settings stored before the key existed have none: absent means off, a new feature does not switch itself on.
func Defaults ¶
func Defaults() *adminv1.SubscriptionSettings
Defaults are the settings of a fresh install: on Windows and macOS kl!ck leads the page (recommended, with its klick://add link) and Happ follows; on iOS and Android Happ is recommended with the happ://add link; AmneziaVPN for the Amnezia kind on every platform, from the store on a phone; Mihomo clients (kl!ck is one) get the YAML profile; users may manage their own AmneziaWG devices on the page.
func LinkAWG ¶ added in v0.1.80
func LinkAWG(s *adminv1.SubscriptionSettings) bool
LinkAWG reports whether Mihomo profiles carry AmneziaWG servers. Settings stored before the switch existed have no key: absent means on, so an upgrade keeps today's behaviour.
func LinkAutoSelect ¶
func LinkAutoSelect(s *adminv1.SubscriptionSettings) bool
LinkAutoSelect reports whether Mihomo and sing-box profiles include an automatic server group. Settings stored before the switch existed have no key: absent means on, so an upgrade keeps the current server list usable by default.
func Load ¶
Load reads the stored settings; an install that never saved any gets Defaults(). The mode of the device limit, which has a setting of its own (see linkModeKey), is merged in: a panel that was never given one reads as TRACK.
func MigrateLinkDeviceLimit ¶ added in v0.1.39
MigrateLinkDeviceLimit gives an installation the mode of its device limit, once: a panel that has users counts only (TRACK, so that nobody over the limit is cut off by an upgrade: the owner raises limits and switches to ENFORCE himself), a panel with none refuses from the start (ENFORCE). The setting is its own marker, written only when absent, so a mode the owner chose is never overwritten and isolates that start together agree on the first value. Idempotent.
func MigrateM3 ¶
MigrateM3 gives an installation whose saved settings predate them the two Mihomo format rules (mihomo, clash -> Mihomo YAML), once: the marker setting sub_rules_m3 = 1 is written in the same transaction, so a rule the admin deletes later is not added back. An installation that never saved settings needs nothing (Defaults() has the rules); it only gets the marker. Idempotent and safe to call at every start.
func MigrateSingbox ¶ added in v0.1.40
MigrateSingbox gives an installation whose saved settings predate the sing-box profile the rule `sing-box` -> sing-box JSON, once, at the end of the list: the marker setting sub_rules_singbox = 1 is written in the same transaction, so a rule the admin deletes later is not added back. The apps this rule catches (SFA, SFI) got a link list they cannot read before, so there is nothing to lose. A rule of the same User-Agent text (any case), whatever its format, is the admin's and is left alone. An installation that never saved settings needs nothing (Defaults() has the rule); it only gets the marker. Idempotent and safe to call at every start.
func Normalize ¶
func Normalize(s *adminv1.SubscriptionSettings)
Normalize trims the free-text fields in place (what Update stores).
func PagePassword ¶
func PagePassword(s *adminv1.SubscriptionSettings) bool
PagePassword reports whether the user's page asks for its password (see package pagepass). Settings stored before the key existed have none: absent means on, so an upgrade protects every page.
func Parse ¶ added in v0.1.26
func Parse(value string) (*adminv1.SubscriptionSettings, error)
Parse reads a stored subscription-settings document. Missing documents should use Defaults instead.
func SelfService ¶
func SelfService(s *adminv1.SubscriptionSettings) bool
SelfService reports whether users may add, rotate and revoke their own AmneziaWG devices on the public page. Settings stored before the key existed have none: absent means on.
func SentValue ¶
SentValue is the value as it goes out: the text itself, or "base64:" and its base64 (the way the panel sends the title).
func Validate ¶
func Validate(s *adminv1.SubscriptionSettings) error
Validate checks a whole document; nil = storable.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache serves the settings to the subscription handler: one database read per TTL, dropped by Update.
func NewCache ¶
NewCache makes the cache. log may be nil. It also runs MigrateM3, MigrateSingbox and MigrateLinkDeviceLimit (the panel builds the cache once at start, in both editions); a failure is logged and the next start tries again.
func NewCacheWithoutMigrations ¶ added in v0.1.41
NewCacheWithoutMigrations is NewCache that leaves the data migrations to the Worker that owns them: the edge's public Worker only reads, and spends no database reads on them when it starts. log may be nil.
func (*Cache) ClientAPIEnabled ¶
ClientAPIEnabled reports whether the owner enabled client API discovery; it shares the subscription settings cache.
func (*Cache) Get ¶
func (c *Cache) Get(ctx context.Context) *adminv1.SubscriptionSettings
Get returns the settings; the result is shared and must not be modified. A subscription fetch must not fail over settings: when the document cannot be read, the last good copy is kept (the next call reads again), and the defaults are returned without being cached. The read does not end with the caller's context: one app that gave up on a slow panel must not decide what everyone else is served for the next minute.
func (*Cache) ProbeReports ¶ added in v0.1.51
ProbeReports says whether the panel takes the reports of the kl!ck probe (store.SettingClientProbe), as cached with the settings: a switch reaches the subscription answers within the TTL. Off while nothing could be read yet.
func (*Cache) Update ¶
func (c *Cache) Update(ctx context.Context, s *adminv1.SubscriptionSettings) (*adminv1.SubscriptionSettings, error)
Update validates, stores and caches s (a copy is stored; s itself is not kept). See UpdateRevoking.
func (*Cache) UpdateRevoking ¶ added in v0.1.39
func (c *Cache) UpdateRevoking(ctx context.Context, s *adminv1.SubscriptionSettings) (*adminv1.SubscriptionSettings, int, error)
UpdateRevoking is Update that also says how many people lost their shared device to a switch to STRICT, which revokes them in the same batch that stores the mode (the caller tells the nodes). s.link_device_limit unset leaves the stored mode as it is; the returned settings always carry the mode in force.
type SentHeader ¶
SentHeader is one own header as an answer carries it.
func ResponseHeadersFor ¶
func ResponseHeadersFor(s *adminv1.SubscriptionSettings, groupID string, format adminv1.SubFormat) []SentHeader
ResponseHeadersFor are the own headers the answer of one format carries for a person of one group, in the order of the list; when two entries of one name apply, the first wins. The caller sends them with a successful subscription answer only.