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 is not part of the stored document: the DNS module owns the instance default preset (one source of truth), and SubscriptionService reads and writes it through that module.
Index ¶
- Constants
- Variables
- func Defaults() *adminv1.SubscriptionSettings
- func Load(ctx context.Context, st *store.Store) (*adminv1.SubscriptionSettings, error)
- func MigrateM3(ctx context.Context, st *store.Store) error
- func Normalize(s *adminv1.SubscriptionSettings)
- func PagePassword(s *adminv1.SubscriptionSettings) bool
- func SelfService(s *adminv1.SubscriptionSettings) bool
- func Validate(s *adminv1.SubscriptionSettings) error
- type Cache
Constants ¶
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 Defaults ¶
func Defaults() *adminv1.SubscriptionSettings
Defaults are the settings of a fresh install: Happ on iOS, Android, Windows and macOS with the happ://add link, recommended (it leads the page); AmneziaVPN for the Amnezia kind on every platform, from the store on a phone; Mihomo clients get the YAML profile; users may manage their own AmneziaWG devices on the page.
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 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 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 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 (the panel builds the cache once at start); a failure is logged and the next start tries again.
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 stored document that cannot be read yields the defaults (logged once per refresh): a subscription fetch must not fail over settings.
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).