Documentation
¶
Overview ¶
Package access is the panel's access module: profiles and their inbounds, groups, users, devices and credentials, the user status rules (disabled > expired > limited > active), the effective-access rule that turns all of it into desired state for a node, and the data of the public subscription.
The admin Profile/User/Group/Device/Awg services are methods of Service; ProfileHandler, UserHandler, GroupHandler, DeviceHandler and AwgHandler wrap it for Connect. Every change that can alter what a node should run ends in StateNotifier.StateChanged().
Index ¶
- Constants
- Variables
- func AdvancePeriod(reset string, periodStart, now time.Time) (time.Time, bool)
- func ComputeStatus(disabled bool, expiresAt time.Time, quota, used uint64, now time.Time) string
- func CountryName(cc, lang string) string
- func CurrentNetworkUtilization(nodeIDs []string, capacityMbps map[string]int, source NetworkUsageSource, ...) map[string]NodeNetworkUtilization
- func NextReset(reset string, periodStart time.Time) time.Time
- func PeriodStart(reset string, t time.Time) time.Time
- func ServerLabeler(lang string) func(cc, location string) string
- type AfterResponseRunner
- type AgentSessionSource
- type CPUUsageSource
- type CapabilitySource
- type Config
- type DeviceConfig
- type NetworkUsageSource
- type NodeInbound
- type NodeNetworkUtilization
- type OnlineSource
- type PageDNSChoice
- type Service
- func (s *Service) AddAWGDevice(ctx context.Context, by, userID, profileID, platform, label string) (store.AccessAWGDevice, []DeviceConfig, error)
- func (s *Service) AwgHandler() (string, http.Handler)
- func (s *Service) CheckSubscriptionToken(ctx context.Context, token string) error
- func (s *Service) CreateAwgDevice(ctx context.Context, req *connect.Request[adminv1.CreateAwgDeviceRequest]) (*connect.Response[adminv1.CreateAwgDeviceResponse], error)
- func (s *Service) CreateGroup(ctx context.Context, req *connect.Request[adminv1.CreateGroupRequest]) (*connect.Response[adminv1.CreateGroupResponse], error)
- func (s *Service) CreateInbound(ctx context.Context, req *connect.Request[adminv1.CreateInboundRequest]) (*connect.Response[adminv1.CreateInboundResponse], error)
- func (s *Service) CreateProfile(ctx context.Context, req *connect.Request[adminv1.CreateProfileRequest]) (*connect.Response[adminv1.CreateProfileResponse], error)
- func (s *Service) CreateUser(ctx context.Context, req *connect.Request[adminv1.CreateUserRequest]) (*connect.Response[adminv1.CreateUserResponse], error)
- func (s *Service) DeleteGroup(ctx context.Context, req *connect.Request[adminv1.DeleteGroupRequest]) (*connect.Response[adminv1.DeleteGroupResponse], error)
- func (s *Service) DeleteInbound(ctx context.Context, req *connect.Request[adminv1.DeleteInboundRequest]) (*connect.Response[adminv1.DeleteInboundResponse], error)
- func (s *Service) DeleteProfile(ctx context.Context, req *connect.Request[adminv1.DeleteProfileRequest]) (*connect.Response[adminv1.DeleteProfileResponse], error)
- func (s *Service) DeleteUsers(ctx context.Context, req *connect.Request[adminv1.DeleteUsersRequest]) (*connect.Response[adminv1.DeleteUsersResponse], error)
- func (s *Service) Desired(ctx context.Context, nodeID string) ([]NodeInbound, error)
- func (s *Service) DeviceConfigs(ctx context.Context, by, owner, deviceID string) (store.AccessAWGDevice, []DeviceConfig, error)
- func (s *Service) DeviceHandler() (string, http.Handler)
- func (s *Service) ExtendUsers(ctx context.Context, req *connect.Request[adminv1.ExtendUsersRequest]) (*connect.Response[adminv1.ExtendUsersResponse], error)
- func (s *Service) GenerateObfuscation(_ context.Context, req *connect.Request[adminv1.GenerateObfuscationRequest]) (*connect.Response[adminv1.GenerateObfuscationResponse], error)
- func (s *Service) GetDeviceConfigs(ctx context.Context, req *connect.Request[adminv1.GetDeviceConfigsRequest]) (*connect.Response[adminv1.GetDeviceConfigsResponse], error)
- func (s *Service) GetProfile(ctx context.Context, req *connect.Request[adminv1.GetProfileRequest]) (*connect.Response[adminv1.GetProfileResponse], error)
- func (s *Service) GetSubscriptionLink(ctx context.Context, req *connect.Request[adminv1.GetSubscriptionLinkRequest]) (*connect.Response[adminv1.GetSubscriptionLinkResponse], error)
- func (s *Service) GetUser(ctx context.Context, req *connect.Request[adminv1.GetUserRequest]) (*connect.Response[adminv1.GetUserResponse], error)
- func (s *Service) GroupHandler() (string, http.Handler)
- func (s *Service) ListGroups(ctx context.Context, _ *connect.Request[adminv1.ListGroupsRequest]) (*connect.Response[adminv1.ListGroupsResponse], error)
- func (s *Service) ListMimicryPresets(context.Context, *connect.Request[adminv1.ListMimicryPresetsRequest]) (*connect.Response[adminv1.ListMimicryPresetsResponse], error)
- func (s *Service) ListProfiles(ctx context.Context, _ *connect.Request[adminv1.ListProfilesRequest]) (*connect.Response[adminv1.ListProfilesResponse], error)
- func (s *Service) ListProtocols(ctx context.Context, _ *connect.Request[adminv1.ListProtocolsRequest]) (*connect.Response[adminv1.ListProtocolsResponse], error)
- func (s *Service) ListUsers(ctx context.Context, req *connect.Request[adminv1.ListUsersRequest]) (*connect.Response[adminv1.ListUsersResponse], error)
- func (s *Service) PreviewProfile(ctx context.Context, req *connect.Request[adminv1.PreviewProfileRequest]) (*connect.Response[adminv1.PreviewProfileResponse], error)
- func (s *Service) PreviewSubscription(ctx context.Context, userID string) (SubView, string, error)
- func (s *Service) ProfileHandler() (string, http.Handler)
- func (s *Service) Recompute(ctx context.Context, userIDs []string) error
- func (s *Service) RelabelDevice(ctx context.Context, owner, deviceID, label string) (store.AccessAWGDevice, error)
- func (s *Service) RenameDevice(ctx context.Context, req *connect.Request[adminv1.RenameDeviceRequest]) (*connect.Response[adminv1.RenameDeviceResponse], error)
- func (s *Service) ResetUserTraffic(ctx context.Context, req *connect.Request[adminv1.ResetUserTrafficRequest]) (*connect.Response[adminv1.ResetUserTrafficResponse], error)
- func (s *Service) RevokeDevice(ctx context.Context, req *connect.Request[adminv1.RevokeDeviceRequest]) (*connect.Response[adminv1.RevokeDeviceResponse], error)
- func (s *Service) RevokeOwnDevice(ctx context.Context, by, owner, deviceID string) error
- func (s *Service) RotateDevice(ctx context.Context, by, owner, deviceID string) (store.AccessAWGDevice, []DeviceConfig, error)
- func (s *Service) RotateDeviceKeys(ctx context.Context, req *connect.Request[adminv1.RotateDeviceKeysRequest]) (*connect.Response[adminv1.RotateDeviceKeysResponse], error)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SetPageDNS(ctx context.Context, userID string, c PageDNSChoice) error
- func (s *Service) SetTouchHookForTest(hook func(started bool))
- func (s *Service) SetUsersEnabled(ctx context.Context, req *connect.Request[adminv1.SetUsersEnabledRequest]) (*connect.Response[adminv1.SetUsersEnabledResponse], error)
- func (s *Service) Subscription(ctx context.Context, token string) (SubView, error)
- func (s *Service) SubscriptionWith(ctx context.Context, token string, opt SubOptions) (SubView, error)
- func (s *Service) Sweep(ctx context.Context) (int, error)
- func (s *Service) TwinProfile(ctx context.Context, req *connect.Request[adminv1.TwinProfileRequest]) (*connect.Response[adminv1.TwinProfileResponse], error)
- func (s *Service) UpdateGroup(ctx context.Context, req *connect.Request[adminv1.UpdateGroupRequest]) (*connect.Response[adminv1.UpdateGroupResponse], error)
- func (s *Service) UpdateInbound(ctx context.Context, req *connect.Request[adminv1.UpdateInboundRequest]) (*connect.Response[adminv1.UpdateInboundResponse], error)
- func (s *Service) UpdateProfile(ctx context.Context, req *connect.Request[adminv1.UpdateProfileRequest]) (*connect.Response[adminv1.UpdateProfileResponse], error)
- func (s *Service) UpdateUser(ctx context.Context, req *connect.Request[adminv1.UpdateUserRequest]) (*connect.Response[adminv1.UpdateUserResponse], error)
- func (s *Service) UserHandler() (string, http.Handler)
- type StateNotifier
- type SubAWG
- type SubAWGProfile
- type SubConn
- type SubDNSPreset
- type SubDevice
- type SubNode
- type SubNodeDNS
- type SubOptions
- type SubServer
- type SubView
Constants ¶
const ( DNSNotFound = "not_found" DNSNotAllowed = "not_allowed" )
Error codes of SetPageDNS, the messages of its FailedPrecondition/NotFound errors (the page's codes).
const ( StatusActive = "active" StatusDisabled = "disabled" StatusExpired = "expired" StatusLimited = "limited" )
User statuses as stored in user.status.
const ( ResetNone = "none" ResetDay = "day" ResetWeek = "week" ResetMonth = "month" ResetRollingMonth = "rolling_month" )
Quota reset periods as stored in user.quota_reset.
Variables ¶
var ErrUnknownToken = errors.New("access: unknown subscription token")
ErrUnknownToken is returned for a subscription token that belongs to nobody.
Functions ¶
func AdvancePeriod ¶
AdvancePeriod returns the period start valid at now (periodStart itself while the period is running) and whether a reset happened. Rolling periods move in whole 30-day steps so they keep their anchor.
func ComputeStatus ¶
ComputeStatus applies the precedence disabled > expired > limited > active. A zero expiresAt means the term never ends, quota 0 means unlimited; usage at or above the quota limits the user.
func CountryName ¶
CountryName is the localised name of a country code in lang ("ru", "en"); the code itself when unknown.
func CurrentNetworkUtilization ¶ added in v0.1.13
func CurrentNetworkUtilization(nodeIDs []string, capacityMbps map[string]int, source NetworkUsageSource, now time.Time) map[string]NodeNetworkUtilization
CurrentNetworkUtilization returns one sample per distinct node. LoadPercent is how busy the node is: the larger of RX/TX divided by its configured symmetric capacity, or its CPU use when the source reports it (CPUUsageSource) and that is higher. A one-core VPS usually runs out of CPU before its link, and the CPU is known without the owner typing the provider's limit; with neither the percentage is nil. Nodes without a recent sample are omitted.
func NextReset ¶
NextReset is when the period that started at periodStart ends; zero when it never does.
func PeriodStart ¶
PeriodStart is the start of the quota period that contains t: 00:00 UTC of the day, of the Monday, of the 1st; for none and rolling_month periods have no calendar anchor, so it is t itself.
func ServerLabeler ¶ added in v0.1.16
ServerLabeler names servers for the people who use them, one call per node in order: the country and the location ("Germany · Frankfurt"), "Server" for a node with neither, and a number where a name repeats ("Germany 2"). Never the panel's node name. The user page's channel card and the AmneziaVPN keys name servers this way.
Types ¶
type AfterResponseRunner ¶ added in v0.1.27
type AfterResponseRunner func(func())
AfterResponseRunner starts work that must not delay a request response. A nil runner uses a goroutine.
type AgentSessionSource ¶ added in v0.1.17
AgentSessionSource is an optional interface of the online source of New (the fleet module implements it): whether the agent of a node holds a live session with the panel.
type CPUUsageSource ¶ added in v0.1.19
type CPUUsageSource interface {
CPUUsage(nodeID string) (pct float64, sampledAt time.Time, ok bool)
}
CPUUsageSource is an optional interface of the NetworkUsageSource (the fleet module implements it): the node's CPU use in percent from the same agent samples, and when the panel received it.
type CapabilitySource ¶
CapabilitySource is an optional interface of the notify / online argument of New (the fleet module implements it): whether the agent of a node announced a capability string ("awg/1"). known is false while the node has never connected, so a fresh node is not treated as too old.
type Config ¶
type Config struct {
// SubscriptionBaseURL is the public subscription address up to and including the secret prefix, e.g.
// "https://sub.example.com/k3xq8"; the user's token is appended after a slash.
SubscriptionBaseURL string
Log *slog.Logger
AfterResponse AfterResponseRunner
}
Config of the access module.
type DeviceConfig ¶
type DeviceConfig struct {
InboundID, NodeID, NodeName, CountryCode string
Server string // the public name of the node ("Germany 2"): the user page shows this, never NodeName
ProfileName, AWGVersion string // "3.1" | "2.0"
Conf string // WireGuard-style .conf (AmneziaVPN and AmneziaWG import it)
VPNKey string // the vpn:// key for AmneziaVPN
ConfFilename string // already safe, never derived from raw user input
// Stale: the device held an older config of this profile that this one replaces.
Stale bool
MinClients []protocols.ClientReq
// Warnings are stable codes the UI localises: amnezia_desktop_mtu, dns_fallback, dns_no_split.
Warnings []string
}
DeviceConfig is the config of a device on one node.
type NetworkUsageSource ¶ added in v0.1.9
type NetworkUsageSource interface {
NetworkUsage(nodeID string) (rxBps, txBps uint64, sampledAt time.Time, ok bool)
}
NetworkUsageSource is implemented by the fleet module. Rates are host network-interface bits per second; sampledAt is the panel receive time of that agent sample.
type NodeInbound ¶
type NodeInbound struct {
Spec plugin.InboundSpec
Creds []plugin.UserCred
}
NodeInbound is one inbound of a node's desired state: the spec and the complete credential set.
type NodeNetworkUtilization ¶ added in v0.1.13
NodeNetworkUtilization is a fresh host-level network sample and, when the node's symmetric capacity is known, its utilization in the busier direction (RX or TX).
type OnlineSource ¶
type OnlineSource interface {
// OnlineUsers maps user id to the id of the node of the user's newest open session.
OnlineUsers() map[string]string
}
OnlineSource tells which users have an open session right now. The fleet module implements it.
type PageDNSChoice ¶ added in v0.1.17
PageDNSChoice is what the page's POST <link>/dns changes: the person's pick on one node. Nothing here reaches the nodes (DNS is carried by the client); the next subscription fetch and the next fetch of a key carry it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements ProfileService, UserService, GroupService, DeviceService and AwgService (adminv1connect handler interfaces).
func New ¶
func New(st *store.Store, v *vault.Vault, reg *protocols.Registry, notify StateNotifier, online OnlineSource, cfg Config) (*Service, error)
New builds the service. notify and online may be nil (nothing to notify, nobody online).
func (*Service) AddAWGDevice ¶
func (s *Service) AddAWGDevice(ctx context.Context, by, userID, profileID, platform, label string) (store.AccessAWGDevice, []DeviceConfig, error)
AddAWGDevice creates an AWG device of a user on a profile and returns it with its configs. Preconditions, each a FailedPrecondition whose message starts with a stable code: user_disabled, app_disabled, profile_not_in_group, no_inbound, "agent too old", device_limit ("device_limit: 5/5"), subnet_full.
func (*Service) AwgHandler ¶
AwgHandler returns the Connect path and handler of AwgService.
func (*Service) CheckSubscriptionToken ¶ added in v0.1.23
CheckSubscriptionToken checks whether a cached subscription token still exists, without building its view.
func (*Service) CreateAwgDevice ¶
func (*Service) CreateGroup ¶
func (*Service) CreateInbound ¶
func (*Service) CreateProfile ¶
func (*Service) CreateUser ¶
func (*Service) DeleteGroup ¶
func (*Service) DeleteInbound ¶
func (*Service) DeleteProfile ¶
func (*Service) DeleteUsers ¶
func (*Service) Desired ¶
Desired computes what a node should run: its enabled inbounds and, for each, the credentials allowed by the effective-access rule written at the top of user.proto:
user ACTIVE AND profile in the user's group AND (all nodes OR node selected) AND one of the user's enabled apps consumes the protocol AND the inbound is enabled.
The fleet module turns the result into the agent's DesiredState. An inbound whose settings cannot be built (corrupt profile) is left out rather than blocking every other inbound of the node, and is marked failed with the reason in last_error (buildFailed), so the node page shows why it is not running.
func (*Service) DeviceConfigs ¶
func (s *Service) DeviceConfigs(ctx context.Context, by, owner, deviceID string) (store.AccessAWGDevice, []DeviceConfig, error)
DeviceConfigs renders the configs of a device for every usable node and marks the device as having received the profile's current epoch (its "needs a new key" badge goes away). owner "" = an admin, else the user the device must belong to. The returned device already shows the new epoch. Only the person's own fetch (owner set) counts as the device holding the DNS of every server now: an admin who looks at the keys has not delivered them.
func (*Service) DeviceHandler ¶
DeviceHandler returns the Connect path and handler of DeviceService.
func (*Service) ExtendUsers ¶
func (s *Service) ExtendUsers(ctx context.Context, req *connect.Request[adminv1.ExtendUsersRequest]) (*connect.Response[adminv1.ExtendUsersResponse], error)
ExtendUsers moves the term end to max(now, current) + days. Users without a term end are left alone: extending "forever" would silently put an end date on them.
func (*Service) GenerateObfuscation ¶
func (*Service) GetDeviceConfigs ¶
func (*Service) GetProfile ¶
func (*Service) GetSubscriptionLink ¶
func (*Service) GroupHandler ¶
GroupHandler returns the Connect path and handler of GroupService.
func (*Service) ListGroups ¶
func (*Service) ListMimicryPresets ¶
func (*Service) ListProfiles ¶
func (*Service) ListProtocols ¶
func (*Service) PreviewProfile ¶
func (*Service) PreviewSubscription ¶
PreviewSubscription is Subscription for the admin's preview of the user page: it looks the user up by id (ErrUnknownToken when there is none), does not record a fetch on the device, and also returns the subscription link ("" when the panel has no public address configured).
func (*Service) ProfileHandler ¶
ProfileHandler returns the Connect path and handler of ProfileService (session checks are added by the HTTP server).
func (*Service) Recompute ¶
Recompute refreshes the status of the given users; the fleet calls it after it added their usage, so a quota overrun takes effect within one stats interval. Changed statuses notify the nodes.
func (*Service) RelabelDevice ¶
func (s *Service) RelabelDevice(ctx context.Context, owner, deviceID, label string) (store.AccessAWGDevice, error)
RelabelDevice changes the label of a device (device.model) and returns it (without DNSStale: the page keeps what it knows about that).
func (*Service) RenameDevice ¶
func (*Service) ResetUserTraffic ¶
func (s *Service) ResetUserTraffic(ctx context.Context, req *connect.Request[adminv1.ResetUserTrafficRequest]) (*connect.Response[adminv1.ResetUserTrafficResponse], error)
ResetUserTraffic zeroes used_bytes of the current period. The period start (so the next reset) and the traffic history stay; the status is recomputed, which lifts LIMITED, and the nodes hear about it through Recompute-style notification when a status changed.
func (*Service) RevokeDevice ¶
func (*Service) RevokeOwnDevice ¶
RevokeOwnDevice revokes an AWG device of the given user (the public page's "remove"); a device of someone else is "not found". The peer leaves the nodes with the next desired state, which ends its sessions.
func (*Service) RotateDevice ¶
func (s *Service) RotateDevice(ctx context.Context, by, owner, deviceID string) (store.AccessAWGDevice, []DeviceConfig, error)
RotateDevice gives the device a new key pair and PSK on the same tunnel address. The old key stops working with the next desired state.
func (*Service) RotateDeviceKeys ¶
func (*Service) Run ¶
Run maintains user statuses until ctx ends: a sweep at start and then every minute (expiry and quota period resets happen by the clock, not by an event).
func (*Service) SetPageDNS ¶ added in v0.1.17
SetPageDNS records the pick of a user on a node. NotFound: the node is not one of the person's servers. FailedPrecondition "not_allowed": the node does not offer that preset. The audit row names the person and the node the owner gave names to, and the preset; never the link and never an address.
func (*Service) SetTouchHookForTest ¶ added in v0.1.23
SetTouchHookForTest observes when an asynchronous subscription touch starts and finishes.
func (*Service) SetUsersEnabled ¶
func (*Service) Subscription ¶
Subscription resolves a token. The lookup is by sha256(token), so the comparison never sees the token itself. For an active user it makes sure the implicit device holds its credentials (created on first fetch if missing, e.g. after a revoke) and renders one line per usable inbound.
func (*Service) SubscriptionWith ¶
func (s *Service) SubscriptionWith(ctx context.Context, token string, opt SubOptions) (SubView, error)
SubscriptionWith is Subscription with a client format (see SubOptions).
func (*Service) Sweep ¶
Sweep recomputes the status of every user and returns how many changed. A full scan of the user table once a minute (a few thousand rows); an expiry-ordered index walk if it ever shows in a profile.
func (*Service) TwinProfile ¶
func (*Service) UpdateGroup ¶
func (*Service) UpdateInbound ¶
func (*Service) UpdateProfile ¶
func (*Service) UpdateUser ¶
type StateNotifier ¶
type StateNotifier interface{ StateChanged() }
StateNotifier is implemented by the fleet module: desired state of the nodes must be recomputed and pushed. It must be cheap and non-blocking (the fleet debounces).
type SubAWG ¶
type SubAWG struct {
ProfileID, ProfileName string
Version string // "3.1" | "2.0"
Address string // "10.66.4.5, fd66:66:0:1::5"
Stale bool // the profile changed in a way that breaks the config the device holds
// DNSStale lists the nodes where the DNS that applies to the person is not the one this device's key holds (see markDNSStale).
DNSStale []string
LastHandshake time.Time
MinClients []protocols.ClientReq
}
SubAWG is what the public page shows about an AmneziaWG device. The keys are not part of it: the page fetches them on demand (DeviceConfigs).
type SubAWGProfile ¶
type SubAWGProfile struct {
ID, Name, Version string
Egress string // "direct" | "warp"
Countries []string // country codes of its usable nodes, in subscription order, without repeats ("" left out)
}
SubAWGProfile is an AmneziaWG profile a device can be added on. The page names it by what a person can tell apart: the countries of its nodes, its exit and its version, never by the profile's own name.
type SubConn ¶ added in v0.1.17
type SubConn struct {
Way string // "link" | "key"
Exit string // "direct" | "warp"
ProfileID string // the AmneziaWG profile of a key
Server int // a link: the index into SubView.Servers (unused when MihomoOnly)
// MihomoOnly: a link that only the Mihomo apps can use (Gecko). The URI list has no server for it, so Server means nothing.
MihomoOnly bool
}
SubConn is one way to use a node: by the link or by a key.
type SubDNSPreset ¶ added in v0.1.17
SubDNSPreset is a preset the page names: the stored name and description, translated by the page (dns.Preset.NameIn).
type SubDevice ¶
type SubDevice struct {
ID, Platform, Model string
App string // "happ" | "amnezia" | ""
LastSeen time.Time
Online bool
AWG *SubAWG // set for an AmneziaWG device
}
SubDevice is one device of the user as the public page lists it.
type SubNode ¶ added in v0.1.17
type SubNode struct {
ID string
Name string // the panel's node name: never emitted as user-facing text
CountryCode string
Location string
// Online: the node's agent is connected (a live session, or a network sample not older than 90 seconds).
Online bool
// LoadPercent is as in SubServer: nil when the capacity or a fresh sample is missing.
LoadPercent *int
Conns []SubConn
DNS *SubNodeDNS // nil: the owner offers no choice on this node
}
SubNode is one node as the page's server list shows it.
type SubNodeDNS ¶ added in v0.1.17
type SubNodeDNS struct {
Choice string // what the person picked ("" = nothing, or a pick the node no longer offers)
Effective string // the preset id that applies on this server
Options []string // what the owner offers, in order
Default string // what applies without a pick: the node's default, else the person's usual DNS (rule 3)
// KeysToRefresh are the AmneziaWG devices of the person with a key on this server that holds a DNS other than the one
// that applies now.
KeysToRefresh []string
}
SubNodeDNS is what the page says about the DNS of one server; nil on a server that offers no choice.
type SubOptions ¶
type SubOptions struct {
// Format of the lines; "" = FormatURIList. FormatMihomo also gives the implicit device its AWG credentials
// (one per usable AWG profile, made on the first fetch): a Mihomo client has no device identity, so all of the
// user's Mihomo clients share them.
Format plugin.ClientFormat
// Name is the server name a Mihomo proxy carries; nil = "<node> · <profile>".
Name func(SubServer) string
// NoTouch: the view is for the page, not for an app, so it does not mark the implicit device as having fetched the subscription.
NoTouch bool
// NoPageData: the view is for an app, so it leaves out what only the user page shows (the DNS of each node, the
// presets they name, the keys that hold an older DNS) and does not read it.
NoPageData bool
// IncludeEffectiveDNS lets the Mihomo writer reuse the effective preset read with node DNS.
IncludeEffectiveDNS bool
}
SubOptions says how a subscription view is rendered.
type SubServer ¶
type SubServer struct {
URI string // the same string as the matching Lines entry (a proxy for the Mihomo format)
Protocol string // plugin id
ProfileID string
NodeID string // internal grouping key; never emitted as user-facing text
Node string // node name
CountryCode string // node country, ISO 3166-1 alpha-2 or ""
Location string
Profile string // profile name
Exit string // "direct" | "warp"
// LoadPercent is the larger of this node's RX/TX rates as a percentage of its configured symmetric capacity.
// It is nil when capacity is unknown or the node has no fresh sample. The rates themselves stay out of the view:
// whatever reaches a user must not tell when the other person on a node streams.
LoadPercent *int
}
SubServer is one Lines entry with the facts the remark (server name) is built from.
type SubView ¶
type SubView struct {
UserID string
UserName string
SubscriptionName string
Status string // active | disabled | expired | limited
// Usage in the current quota period (Up + Down = the user's used bytes), quota and term end; zero = none.
Up, Down, Total uint64
Expires time.Time
// Lines are the client fragments, one per usable inbound; empty unless Status is active. In the default
// format they are hysteria2:// URIs; for SubOptions.Format = FormatMihomo each is one proxy as an element of a
// YAML list, rendered by its plugin (the assembler adds groups, dns and rules).
Lines []string
// What the public user page and the server names need; all optional (a fake Source may leave them zero).
// Servers parallels Lines (same order) with the facts behind each line: the subscription handler renders the
// remark (#fragment) from them. Devices, QuotaReset and the rest describe the user, not the protocols.
Servers []SubServer
QuotaReset string // none | day | week | month | rolling_month
NextReset time.Time
DeviceLimit int
// DevicesUsed counts the devices that count against DeviceLimit (live credentials); Devices lists them.
DevicesUsed int
Devices []SubDevice
// AWGProfiles are the AmneziaWG profiles the user could add a device on right now (in the group, with a usable
// inbound; empty unless the Amnezia toggle is on).
AWGProfiles []SubAWGProfile
// AccessHapp / AccessAmnezia: the user's app toggle AND a usable deployed inbound whose protocol that app
// can consume (the user page shows only what works).
AccessHapp, AccessAmnezia bool
// AppAmnezia is the user's AmneziaVPN toggle alone (AccessAmnezia also needs a live inbound and an active user): a person
// whose subscription ended still sees the keys they hold and can remove them.
AppAmnezia bool
// Nodes are the servers of the person, one per node, in subscription order: the ones a link carries and the ones a key
// can be made for. Empty unless Status is active.
Nodes []SubNode
// DNSLink is the preset that applies to the apps that take the link (Hysteria2 in Mihomo and in Happ have one resolver for the
// whole subscription): the person's own, the group's, the instance's. DNSPresets are the presets the page names: the ones
// the nodes offer and apply, and DNSLink when any node offers a choice. Both empty unless Status is active.
DNSLink string
DNSPresets []SubDNSPreset
EffectiveDNS *dns.Preset // the Mihomo link resolver, already read with the node choices
// Format is what Lines hold (FormatURIList unless the view was asked for another).
Format plugin.ClientFormat
}
SubView is what the public subscription endpoint needs about one token.