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 CanonHWID(s string) string
- func CleanClientDeviceInput(platform, model string) (string, string, error)
- func ClientApp(client string) (app, version string)
- 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, ...) map[string]NodeNetworkUtilization
- func MarshalClientOverrides(rows []ClientRule) (string, error)
- 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
- func SubscriptionStatus(u store.AccessUser, now time.Time) string
- func TokenUserChangeWindow() securitylimit.Window
- func ValidUserListPageToken(token string) bool
- func ViaMark(entryCountry string) string
- type AfterResponseRunner
- type ClientRule
- type ClientTable
- type ClientVerdict
- type CompatDevice
- type Config
- type DeviceConfig
- type DeviceHint
- type NodeInbound
- type NodeNetworkUtilization
- type OnlineSource
- type PageDNSChoice
- type PageState
- 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) CheckRelay(ctx context.Context, req *connect.Request[adminv1.CheckRelayRequest]) (*connect.Response[adminv1.CheckRelayResponse], error)
- func (s *Service) CheckSubscriptionToken(ctx context.Context, token string) (PageState, error)
- func (s *Service) ClientCompatHandler() (string, http.Handler)
- func (s *Service) ClientDeviceByKey(ctx context.Context, keyHash []byte) (store.AccessDevice, store.LinkDeviceKeyOwner, error)
- func (s *Service) ClientLeaveDevice(ctx context.Context, dev store.AccessDevice) error
- func (s *Service) ClientSubscription(ctx context.Context, dev store.AccessDevice, hint DeviceHint, caps []string) (SubView, error)
- func (s *Service) CompatDevices(ctx context.Context, userID string) (devices []CompatDevice, fingerprints, nodesWithoutHello []string, err error)
- func (s *Service) ControlRelay(ctx context.Context, id string)
- 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) CreateRelay(ctx context.Context, req *connect.Request[adminv1.CreateRelayRequest]) (*connect.Response[adminv1.CreateRelayResponse], 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) DeleteRelay(ctx context.Context, req *connect.Request[adminv1.DeleteRelayRequest]) (*connect.Response[adminv1.DeleteRelayResponse], 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) EnrolLinkDevice(ctx context.Context, userID, token string, hint DeviceHint, keyHash []byte) (store.LinkDeviceResult, error)
- 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) GetClientCompat(ctx context.Context, _ *connect.Request[adminv1.GetClientCompatRequest]) (*connect.Response[adminv1.GetClientCompatResponse], 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) GetTelegramLinks(ctx context.Context, req *connect.Request[adminv1.GetTelegramLinksRequest]) (*connect.Response[adminv1.GetTelegramLinksResponse], error)
- func (s *Service) GetUser(ctx context.Context, req *connect.Request[adminv1.GetUserRequest]) (*connect.Response[adminv1.GetUserResponse], error)
- func (s *Service) GetUserConnection(ctx context.Context, req *connect.Request[adminv1.GetUserConnectionRequest]) (*connect.Response[adminv1.GetUserConnectionResponse], error)
- func (s *Service) GroupHandler() (string, http.Handler)
- func (s *Service) IssueTelegramKey(ctx context.Context, req *connect.Request[adminv1.IssueTelegramKeyRequest]) (*connect.Response[adminv1.IssueTelegramKeyResponse], error)
- func (s *Service) KnownSubscriptionToken(ctx context.Context, token string) bool
- 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) ListOutdatedDevices(ctx context.Context, req *connect.Request[adminv1.ListOutdatedDevicesRequest]) (*connect.Response[adminv1.ListOutdatedDevicesResponse], 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) ListRelayCandidates(ctx context.Context, req *connect.Request[adminv1.ListRelayCandidatesRequest]) (*connect.Response[adminv1.ListRelayCandidatesResponse], error)
- func (s *Service) ListRelays(ctx context.Context, req *connect.Request[adminv1.ListRelaysRequest]) (*connect.Response[adminv1.ListRelaysResponse], 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) PreviewSubscriptionWith(ctx context.Context, userID string, opt SubOptions) (SubView, error)
- func (s *Service) ProfileHandler() (string, http.Handler)
- func (s *Service) Recompute(ctx context.Context, userIDs []string) error
- func (s *Service) ReenrolLinkDevice(ctx context.Context, userID, deviceID, token string, ...) (bool, error)
- func (s *Service) RelabelDevice(ctx context.Context, owner, deviceID, label string) (store.AccessAWGDevice, error)
- func (s *Service) RelayHandler() (string, http.Handler)
- func (s *Service) RemoveProfileFromNodes(ctx context.Context, ...) (*connect.Response[adminv1.RemoveProfileFromNodesResponse], 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) RevokeTelegramKey(ctx context.Context, req *connect.Request[adminv1.RevokeTelegramKeyRequest]) (*connect.Response[adminv1.RevokeTelegramKeyResponse], 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) RotateTelegramKey(ctx context.Context, req *connect.Request[adminv1.RotateTelegramKeyRequest]) (*connect.Response[adminv1.RotateTelegramKeyResponse], error)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SetNodeSharing(ctx context.Context, req *connect.Request[adminv1.SetNodeSharingRequest]) (*connect.Response[adminv1.SetNodeSharingResponse], error)
- func (s *Service) SetPageDNS(ctx context.Context, userID string, c PageDNSChoice) error
- func (s *Service) SetRelayGateForTest(gate func(context.Context, store.RelayLink) error)
- func (s *Service) SetRelayHints(...)
- func (s *Service) SetRelaySettleForTest(settle func(context.Context, store.RelayLink) error)
- func (s *Service) SetRelayWaitForTest(wait, poll time.Duration)
- func (s *Service) SetSnapshotHookForTest(hook func())
- 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) TrustTunnelHandler() (string, http.Handler)
- func (s *Service) TwinProfile(ctx context.Context, req *connect.Request[adminv1.TwinProfileRequest]) (*connect.Response[adminv1.TwinProfileResponse], error)
- func (s *Service) UnblockDevice(ctx context.Context, req *connect.Request[adminv1.UnblockDeviceRequest]) (*connect.Response[adminv1.UnblockDeviceResponse], error)
- func (s *Service) UpdateClientCompat(ctx context.Context, req *connect.Request[adminv1.UpdateClientCompatRequest]) (*connect.Response[adminv1.UpdateClientCompatResponse], 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) UpdateRelay(ctx context.Context, req *connect.Request[adminv1.UpdateRelayRequest]) (*connect.Response[adminv1.UpdateRelayResponse], 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
- type TrustTunnelKeyLinks
Constants ¶
const ( CoreXray = "xray" CoreMihomo = "mihomo" CoreSingbox = "singbox" CoreOwn = "own" CoreUnknown = "unknown" )
The cores an app can run on. xray, mihomo and singbox send a classical share for a classical fingerprint without exception; own (an own implementation) and unknown say nothing about it.
const ( ClientOK = "ok" ClientBelow = "below_minimum" ClientUnsupported = "unsupported" ClientUnknown = "unknown" )
The states of a device against the table.
const ( ReasonVersion = "version" // below the lowest known good version ReasonApp = "app" // no version of the app works ReasonFingerprint = "fingerprint" // the profile's fingerprint is classical ReasonAppUnknown = "app_unknown" // the table does not know the app ReasonNoThreshold = "no_threshold" // a known app, but no known good version for this case ReasonNoVersion = "no_version" // the device reported no version )
The reasons of a state other than ok.
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.
const ( // RefusalDeviceLimit: the person has no room for a new device or a returning idle device (ENFORCE and STRICT). RefusalDeviceLimit = "device_limit" // RefusalDeviceBlocked: the owner blocked the device of the app. RefusalDeviceBlocked = "device_blocked" // RefusalNoDeviceID: STRICT, and the app reports no device ID (X-HWID). RefusalNoDeviceID = "no_device_id" // RefusalClientAPIEnrolled: the device of the app was enrolled in the client API, so its credentials go to the holder of its key // only, not to whoever sends its HWID with the link. RefusalClientAPIEnrolled = "client_api_enrolled" )
The reasons of SubView.Refusal. They are stable words: the subscription handler words them for the apps (subs.stateNote).
const MarkIPv6 = "ipv6"
MarkIPv6 is SubServer.Mark of the twin that connects to the node's IPv6 entry.
const MarkVia = "via:"
MarkVia is the prefix of SubServer.Mark of a relay's twin; the rest is the country code of the entry node.
const NeverVersion = "never"
NeverVersion is the value of MinOther for an app that never sends the share with a Firefox or Safari fingerprint.
const TokenUserChangeLimit = 10
TokenUserChangeLimit is how many users an API token may change without the owner in the fixed one-hour window that starts with its first counted change. A leaked token must not be able to rewrite every user before anyone looks.
Variables ¶
var ErrClientRules = errors.New("invalid client table")
ErrClientRules wraps every refusal of a table (the RPC maps it to INVALID_ARGUMENT).
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 CanonHWID ¶ added in v0.1.39
CanonHWID is the identity of a device in an X-HWID header: [A-Za-z0-9=-]{10,64} after trimming (the rule of Remnawave, so the same apps work), lower-cased and without dashes, so the alternative HWID of Happ on a desktop and the upper-case UUID of INCY name the same device. "" for anything else, and for a value that is nothing but dashes. A byte loop, no regexp: it runs on every request.
func CleanClientDeviceInput ¶
CleanClientDeviceInput applies the platform and model rules used by the device page to client API enrolment.
func ClientApp ¶
ClientApp is the app id of a stored client string ("Happ/3.4.2", "kl!ck/0.5.1", "NekoBox/Android") and the version it reports ("" when it reports none).
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", "zh", "fa", "tr"; any other is English); the code itself when unknown.
func CurrentNetworkUtilization ¶ added in v0.1.13
func CurrentNetworkUtilization(nodeIDs []string, capacityMbps map[string]int, rows map[string]store.NodeLiveRow, now time.Time) map[string]NodeNetworkUtilization
CurrentNetworkUtilization returns one fresh sample per distinct connected node. LoadPercent is the larger of the RX/TX rate as a percentage of its configured capacity and CPU use. Nodes without a recent sample are omitted.
func MarshalClientOverrides ¶
func MarshalClientOverrides(rows []ClientRule) (string, error)
MarshalClientOverrides is the stored form: "" for no changes.
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.
func SubscriptionStatus ¶
func SubscriptionStatus(u store.AccessUser, now time.Time) string
SubscriptionStatus is the status a subscription fetch would derive for the person now (a due quota reset applied first).
func TokenUserChangeWindow ¶
func TokenUserChangeWindow() securitylimit.Window
TokenUserChangeWindow is the shared limiter window the MCP layer peeks at to decide, at plan time, whether a plan would be refused at apply and so must wait for the owner.
func ValidUserListPageToken ¶
ValidUserListPageToken accepts only cursors emitted by the current user-list encoding.
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 ClientRule ¶
type ClientRule struct {
App string `json:"app"`
Platform string `json:"platform,omitempty"`
Core string `json:"core"`
Unsupported bool `json:"unsupported,omitempty"`
MinChrome string `json:"min_chrome,omitempty"`
MinOther string `json:"min_other,omitempty"`
Title string `json:"-"`
}
ClientRule is one row of the table. Title is output only (the name the UI shows); it is not stored.
func ClientDefaults ¶
func ClientDefaults() []ClientRule
ClientDefaults is a copy of the built-in table.
func ClientOverridesOf ¶
func ClientOverridesOf(want []ClientRule) ([]ClientRule, error)
ClientOverridesOf validates the whole table the owner wants and returns what to store: the rows that differ from the built-in table or are not in it. A built-in row missing from the table goes back to its built-in value.
func ParseClientOverrides ¶
func ParseClientOverrides(raw string) ([]ClientRule, error)
ParseClientOverrides reads the stored list. Rows it cannot read are an error: the caller then keeps the built-in table.
type ClientTable ¶
type ClientTable struct {
// contains filtered or unexported fields
}
ClientTable is the table in force: the built-in rows with the owner's changes.
func NewClientTable ¶
func NewClientTable(overrides []ClientRule) ClientTable
NewClientTable lays the owner's changes over the built-in table: a change replaces the built-in row of the same app and platform, any other is added. It does not validate; ParseClientOverrides does.
func (ClientTable) Rules ¶
func (t ClientTable) Rules() []ClientRule
Rules are the rows in force, built-in order first and the owner's own after.
func (ClientTable) Verdict ¶
func (t ClientTable) Verdict(client, platform, fingerprint string) ClientVerdict
Verdict judges a stored client string on a platform against a REALITY fingerprint of a profile ("" = chrome, the default).
type ClientVerdict ¶
type ClientVerdict struct {
State, Reason string
Need string // ClientBelow: the lowest version known to work
Title string // the app's name in the table, "" for an app it does not know
}
ClientVerdict is what the table says about one device against one fingerprint.
type CompatDevice ¶
type CompatDevice struct {
store.ClientCompatDevice
UserName string
Verdict ClientVerdict
Fingerprint string // the one that gave the verdict
// What the nodes counted of the device's ClientHellos (ListOutdatedDevices fills these in), the class of the counts, and
// where the class and the verdict disagree ("worse", "better" or "").
Hello store.HelloKexSums
Actual adminv1.ClientCompatActual
Mismatch string
}
CompatDevice is a device that receives REALITY and what the table says about it.
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
// StepUp is auth.Service.RequireStepUp. A nil callback denies destructive user deletion.
StepUp func(context.Context) error
Log *slog.Logger
AfterResponse AfterResponseRunner
// CheckPorts runs the fleet UDP delivery check; nil disables save-time checks.
CheckPorts func(context.Context, string, []uint16) ([]store.PortCheck, string, string)
// CheckRelay runs the fleet's check of a relay (fleet.CheckRelay): the stages it names (store.RelayStageLeg, RelayStagePath,
// RelayStageReverseReach, RelayStageReverseSpeed; none = leg and path), the result stored in the relay and returned. nil: relays cannot be checked, so none is switched on.
CheckRelay func(ctx context.Context, relayID string, stages ...string) (store.RelayCheck, error)
// Limiter is the shared backend for token user-change budgets and their refusal-event gate.
Limiter securitylimit.Limiter
// OwnHosts are the hosts and URLs of the panel itself (its site, admin and agent addresses): a REALITY target set on a node is never one
// of them (reality_own.go).
OwnHosts []string
}
Config of the access module.
type DeviceConfig ¶
type DeviceConfig struct {
InboundID, NodeID, NodeName, CountryCode string
ViaCountry, ViaNodeID string // a config through a relay's entry; empty for the direct and the IPv6 one
IPv6 bool // the config goes to the node's IPv6 entry
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 DeviceHint ¶ added in v0.1.39
type DeviceHint struct {
HWID string // canonical; "" = the request reports none (or an invalid one)
OS, OSVersion, Model, Agent string
}
DeviceHint is what a subscription request says about its device: the X-HWID, X-Device-OS, X-Ver-OS and X-Device-Model headers and the User-Agent, as sent. The HWID is already canonical (CanonHWID); the rest is cleaned only when a device is created or touched (meta), never on the path of a request that has nothing to write.
func NewDeviceHint ¶ added in v0.1.39
func NewDeviceHint(hwid, osName, osVersion, model, userAgent string) DeviceHint
NewDeviceHint reads the headers of a request into a hint.
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
// OnlineDevices maps device id to the ids of the connected nodes that have a session of it, in node order.
OnlineDevices() map[string][]string
}
OnlineSource tells which users and devices have an open session right now. The fleet module implements it.
type PageDNSChoice ¶ added in v0.1.17
type PageDNSChoice struct {
NodeID string
Link bool // the pick for the link apps, one for all servers (NodeID is "")
PresetID string // "" = back to the default: the node's, or what the link apps get without a pick
}
PageDNSChoice is what the page's POST <link>/dns changes: the person's pick on one node, or for the link apps. 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 PageState ¶
PageState is the state of a person's page password in the database (generation and "removed"); the password itself is computed from it and the subscription token (package pagepass).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements ProfileService, UserService, GroupService, DeviceService, AwgService and RelayService (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) CheckRelay ¶ added in v0.1.65
func (*Service) CheckSubscriptionToken ¶ added in v0.1.23
CheckSubscriptionToken checks whether a cached subscription token still exists, without building its view. It also returns the state of the person's page password, which the same one-row read holds: a handler that serves the page from a cached view decides its lock by the fresh state, with no read added.
func (*Service) ClientCompatHandler ¶
ClientCompatHandler returns the Connect path and handler of ClientCompatService.
func (*Service) ClientDeviceByKey ¶
func (s *Service) ClientDeviceByKey(ctx context.Context, keyHash []byte) (store.AccessDevice, store.LinkDeviceKeyOwner, error)
ClientDeviceByKey finds the link device a device-key hash belongs to. store.ErrNotFound: nobody's key. A key of a removed or blocked device comes back with store.ErrDeviceRevoked or store.ErrAccessBlocked and no device, only its owner.
func (*Service) ClientLeaveDevice ¶
ClientLeaveDevice removes the device the key belongs to: the same operation as the person removing it on the page (its credentials leave the nodes with the next desired state, its AWG peers are quarantined), tied to the key that authorised the call. ErrNotFound when the key stopped being the device's meanwhile. The audit row has the user and the device, no address.
func (*Service) ClientSubscription ¶
func (s *Service) ClientSubscription(ctx context.Context, dev store.AccessDevice, hint DeviceHint, caps []string) (SubView, error)
ClientSubscription builds the subscription of the link device dev, authorised by its key, in the Mistgate format: structured protocol settings, not links. Unlike the basic link fetch it may issue missing credentials to this exact device (the store checks the key again in the write batch); the basic fetch refuses a device that holds a key, and still does. caps are the X-Mistgate-Caps entries (Gecko and the AmneziaWG versions are handed out only to a client that announced them). The owner's switch that takes AmneziaWG off the link apps does not apply to this app. Errors are the store's: ErrNotFound and ErrAccessExists when the device was removed, blocked or re-keyed meanwhile.
func (*Service) CompatDevices ¶
func (s *Service) CompatDevices(ctx context.Context, userID string) (devices []CompatDevice, fingerprints, nodesWithoutHello []string, err error)
CompatDevices lists the devices that receive a VLESS REALITY server now (userID restricts it to one person), each judged by the table against every fingerprint its person's REALITY profiles use; the worst verdict stands. The fingerprints in use are returned too, sorted, and so are the names of the nodes with a live REALITY inbound whose agent does not count hellos (vless-hello-kex/1). A device is on the list when it is a live, not blocked link device with a VLESS credential and its person is active and can use a live inbound of a REALITY profile (the subscription's own rule, usable).
func (*Service) ControlRelay ¶
ControlRelay applies the mode controller (store.EvaluateRelayMode, a pure function) to one relay. The fleet calls it after the agents' bridge reports, a relay check and a change of an agent's capabilities; health calls it after every client-eye round. It reads the relay, decides, and writes only what changed.
func (*Service) CreateAwgDevice ¶
func (*Service) CreateGroup ¶
func (*Service) CreateInbound ¶
func (*Service) CreateProfile ¶
func (*Service) CreateRelay ¶ added in v0.1.65
func (*Service) CreateUser ¶
func (*Service) DeleteGroup ¶
func (*Service) DeleteInbound ¶
func (*Service) DeleteProfile ¶
func (*Service) DeleteRelay ¶ added in v0.1.65
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 node enabled for the 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) EnrolLinkDevice ¶
func (s *Service) EnrolLinkDevice(ctx context.Context, userID, token string, hint DeviceHint, keyHash []byte) (store.LinkDeviceResult, error)
EnrolLinkDevice makes the device of hint (its canonical HWID, platform, model and agent) hold credentials and the key whose hash is keyHash, in the store's one guarded batch: a new device (within the user's limit), or the user's own keyless device of that HWID, whose credentials are replaced. token is the subscription link's token, of which only the hash is kept (the device follows a rotated link by it). The errors are the store's: ErrAccessExists (the HWID is enrolled already), ErrAccessBlocked, *store.AccessLimitError, ErrNoLinkCredentials (none of the person's apps takes a link device, or their Mistgate app is switched off), ErrNotFound (the user is gone).
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) GetClientCompat ¶
func (*Service) GetDeviceConfigs ¶
func (*Service) GetProfile ¶
func (*Service) GetSubscriptionLink ¶
func (*Service) GetTelegramLinks ¶ added in v0.1.69
func (s *Service) GetTelegramLinks(ctx context.Context, req *connect.Request[adminv1.GetTelegramLinksRequest]) (*connect.Response[adminv1.GetTelegramLinksResponse], error)
GetTelegramLinks returns the Telegram proxy of one person. It is a read: no device, no key and no fetch is recorded.
func (*Service) GetUserConnection ¶ added in v0.1.53
func (s *Service) GetUserConnection(ctx context.Context, req *connect.Request[adminv1.GetUserConnectionRequest]) (*connect.Response[adminv1.GetUserConnectionResponse], error)
GetUserConnection: what the nodes saw of a person's connections over the last hours, per device, node and inbound (agent.proto LinkCounters). A read; no address is stored or returned. nodes_without_counters are the nodes the person can use whose agent does not list links/1.
func (*Service) GroupHandler ¶
GroupHandler returns the Connect path and handler of GroupService.
func (*Service) IssueTelegramKey ¶ added in v0.1.69
func (*Service) KnownSubscriptionToken ¶
KnownSubscriptionToken reports whether the token is in the index. A token that is not in it makes the index reload from the database when the last load is older than tokenIndexRefresh (never more often, however many tokens ask); a failed load answers false and is not retried for tokenIndexRetry.
func (*Service) ListGroups ¶
func (*Service) ListMimicryPresets ¶
func (*Service) ListOutdatedDevices ¶
func (*Service) ListProfiles ¶
func (*Service) ListProtocols ¶
func (*Service) ListRelayCandidates ¶ added in v0.1.65
func (*Service) ListRelays ¶ added in v0.1.65
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), writes nothing, and also returns the subscription link ("" when the panel has no public address configured).
func (*Service) PreviewSubscriptionWith ¶
func (s *Service) PreviewSubscriptionWith(ctx context.Context, userID string, opt SubOptions) (SubView, error)
PreviewSubscriptionWith is the view of a user for the admin's preview of a profile (opt.Format says which): looked up by id (ErrUnknownToken when there is none), and it writes nothing, whatever opt says: no device, no credential, no mark that the subscription was fetched. A server the person has no credentials for yet is shown with a throwaway secret.
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) ReenrolLinkDevice ¶
func (s *Service) ReenrolLinkDevice(ctx context.Context, userID, deviceID, token string, expectedKeyHash, keyHash []byte) (bool, error)
ReenrolLinkDevice gives a live device of the user a new key, by compare-and-swap on the old one, and points it at the current link. Its credentials stay. false: the old key is not the device's any more (it was rotated, or the device removed, meanwhile).
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). Any device of the person but the shared one: a key or the device of an app (see ownDevice); the result of a link device is an AccessAWGDevice without AWG data (AWG false).
func (*Service) RelayHandler ¶ added in v0.1.65
RelayHandler returns the Connect path and handler of RelayService.
func (*Service) RemoveProfileFromNodes ¶
func (s *Service) RemoveProfileFromNodes(ctx context.Context, req *connect.Request[adminv1.RemoveProfileFromNodesRequest]) (*connect.Response[adminv1.RemoveProfileFromNodesResponse], error)
RemoveProfileFromNodes takes the profile off the listed nodes in one transaction and, with delete_profile, deletes it in the same one. There is no per-node step to fail half way: the nodes learn the new desired state from the panel, so one that is offline drops the profile when it connects again (a retired node has nothing to tell).
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 from current data, which lifts LIMITED, and the nodes are notified after a reset.
func (*Service) RevokeDevice ¶
func (s *Service) RevokeDevice(ctx context.Context, req *connect.Request[adminv1.RevokeDeviceRequest]) (*connect.Response[adminv1.RevokeDeviceResponse], error)
RevokeDevice removes a device of any kind. With block the HWID of an app's device is also refused from now on (the app gets "device_blocked" instead of servers) until UnblockDevice; the shared device and a key have no HWID to block (FailedPrecondition cannot_block). Both write the audit entry device_revoke.
func (*Service) RevokeOwnDevice ¶
RevokeOwnDevice revokes a device of the given user (the public page's "remove"): an AmneziaVPN key or the device of an app that reports a device ID, not the shared device (see ownDevice). A device of someone else is "not found". Its credentials leave the nodes with the next desired state, which ends its sessions. The same app can register again as a new device (this is no block) if the user has room for it.
func (*Service) RevokeTelegramKey ¶ added in v0.1.69
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) RotateTelegramKey ¶ added in v0.1.69
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) SetNodeSharing ¶
func (*Service) SetPageDNS ¶ added in v0.1.17
SetPageDNS records the pick of a user on a node, or for the link apps. NotFound: the node is not one of the person's servers. FailedPrecondition "not_allowed": the node (or the offer for the link apps) does not have that preset. The audit row names the person, the node the owner gave names to and the preset; never the link and never an address.
func (*Service) SetRelayGateForTest ¶ added in v0.1.65
SetRelayGateForTest replaces the gate that lets a relay be switched on (nil restores the real one, relay_check.go). Call it before the service takes requests.
func (*Service) SetRelayHints ¶ added in v0.1.65
func (s *Service) SetRelayHints(f func(ctx context.Context, entryID string, nodeIDs []string) (map[string]*adminv1.RelayCountryHint, map[string]*adminv1.RelayReachHint))
SetRelayHints plugs in the source of the hints of ListRelayCandidates (health.Service.RelayHints). The health module is built after this one. Call it before the service takes requests.
func (*Service) SetRelaySettleForTest ¶ added in v0.1.65
SetRelaySettleForTest replaces the step that follows switching a relay on (nil restores the real one). Call it before the service takes requests.
func (*Service) SetRelayWaitForTest ¶ added in v0.1.65
SetRelayWaitForTest shortens the wait for the entry's report and its poll.
func (*Service) SetSnapshotHookForTest ¶
func (s *Service) SetSnapshotHookForTest(hook func())
SetSnapshotHookForTest runs hook between a subscription view's read of the person's state and the writes that follow it: the window in which another request can enrol a device.
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 request's device holds its credentials (the device is created on the first fetch of an app, 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) TrustTunnelHandler ¶
TrustTunnelHandler returns the Connect path and handler of TrustTunnelService.
func (*Service) TwinProfile ¶
func (*Service) UnblockDevice ¶ added in v0.1.39
func (s *Service) UnblockDevice(ctx context.Context, req *connect.Request[adminv1.UnblockDeviceRequest]) (*connect.Response[adminv1.UnblockDeviceResponse], error)
UnblockDevice lets the HWID of a blocked device register again (a new device with new keys, on the next fetch of the app). It writes the audit entry device_unblock. Nothing changes on the nodes.
func (*Service) UpdateClientCompat ¶
func (*Service) UpdateGroup ¶
func (*Service) UpdateInbound ¶
func (*Service) UpdateProfile ¶
func (*Service) UpdateRelay ¶ added in v0.1.65
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
// Via: the link goes through a relay of this entry node (its country code, "" if it has none); Via is only set on a twin.
Via string
// Relay: this link is a twin (a relay's server), whatever the entry's country.
Relay bool
// IPv6: this link is the "· IPv6" twin of the node's server (the node's IPv6 entry).
IPv6 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
// Kind is "link" (an app that reports a device ID), "shared" (the common place of the apps that report none), "key" (an
// AmneziaVPN or TrustTunnel key) or "telegram" (the Telegram proxy key). The person can remove and rename link/key devices.
Kind string
// OSVersion and Client are what the app last said about itself (X-Ver-OS, the first token of its User-Agent); "" if nothing.
OSVersion, Client 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
Address string // the node's own address, as its direct link and keys give it (store.AccessNode.Address; not a relay's entry)
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 request's device its AWG credentials (one per
// usable AWG profile, made on the first fetch), unless NoLinkAWG is set.
Format plugin.ClientFormat
// NoLinkAWG omits AmneziaWG from Mihomo profiles. A touching Mihomo fetch revokes the request's link-device AWG
// credentials and quarantines their peer indexes; explicit AmneziaVPN devices are unaffected.
NoLinkAWG bool
// Device is what the request says about its device (its HWID above all). With a HWID the app gets a device of its own, with
// credentials of its own; without one, or when the user has no room for another device, the shared device of the user.
Device DeviceHint
// 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 writes nothing: no device, no credentials, no mark that the
// subscription was fetched. A server the person has no credentials for yet is shown with a throwaway secret.
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
// IncludeTrustTunnel renders the person's key links for the public user page and admin key RPC only.
IncludeTrustTunnel bool
// IncludeEffectiveDNS lets the writer of a profile (Mihomo, Xray JSON, sing-box) reuse the effective preset read with node DNS.
IncludeEffectiveDNS bool
// EnrolledDevice selects the device already authenticated by its client API key. It may receive missing credentials through
// the separate enrolled-device store path; basic link requests keep their key_hash IS NULL guards.
EnrolledDevice *store.AccessDevice
// Capabilities are the parsed X-Mistgate-Caps values used only by the Mistgate settings renderer.
Capabilities []string
}
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)
Note string // stable reason a TrustTunnel server was skipped, empty for a rendered link
Protocol string // plugin id
ProfileID string
NodeID string // internal grouping key; never emitted as user-facing text
InboundID string // internal stable path input; never emitted as user-facing text
PathKey string // direct, ipv6 or relay:<node id>; internal path identity only
Node string // node name
CountryCode string // node country, ISO 3166-1 alpha-2 or ""
Location string
// PublicLabel is the node's public label, the owner's short text for people ("" = none). The client API shows it; the node name never.
PublicLabel string
// IPv6Egress says the client gets IPv6 out of this server's exit node: see ipv6Egress. A relay's twin carries its exit's value.
IPv6Egress bool
Profile string // profile name
Exit string // "direct" | "warp"
// Made is the inbound's rank in creation order. Servers are listed by country and protocol, but a repeated name is
// numbered in creation order, so a server added later never takes the name of an older one (a Mihomo select group
// remembers the chosen server by name).
Made int
// 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
// Mark labels a server that is not the node's plain one: a twin through a relay (ViaMark) or the node's IPv6 entry (MarkIPv6).
// The name builder writes it after the server's name in the language of the subscription; "" for an ordinary server.
Mark string
}
SubServer is one Lines entry with the facts the remark (server name) is built from.
type SubView ¶
type SubView struct {
UserID string
GroupID string // the person's group; the owner's own response headers can be limited to groups
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:// and vless:// 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
// Telegram are the person's tg://proxy links, one per MTProto inbound they may use and the node's IPv6 and relay twins of it.
// They belong to no subscription: they are never in Lines, Servers or a node's Conns, because an app of the link would
// list a tg:// line as a server. Only the user page and GetTelegramLinks read them.
Telegram []SubServer
// TrustTunnel are the key-owned links for the official app. They never enter Lines, Servers or a node's Conns.
TrustTunnel []SubServer
QuotaReset string // none | day | week | month | rolling_month
NextReset time.Time
DeviceLimit int
// DevicesUsed counts live devices against DeviceLimit (including AmneziaVPN and TrustTunnel keys, excluding the Telegram key);
// Devices lists all of them.
DevicesUsed int
DevicesIdle 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, AccessTelegram, AccessTrustTunnel 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, AppTelegram, AppTrustTunnel bool
// AppMistgateOff is the person's Mistgate app switch, off: a client API sync of one of their devices carries no servers.
AppMistgateOff 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 DNS of the apps that take the link (they have one resolver for the whole subscription): the person's pick for
// them, what applies without it and what the owner offers. DNSPresets are the presets the page names: the ones the nodes
// and the link apps offer and apply. Both empty unless Status is active.
DNSLink dns.LinkDNS
DNSPresets []SubDNSPreset
EffectiveDNS *dns.Preset // the preset of the link apps (Mihomo, Xray JSON, sing-box), already read with the node choices
// Format is what Lines hold (FormatURIList unless the view was asked for another).
Format plugin.ClientFormat
// LinkMode is the mode of the device limit for the apps on the link (store.LinkModeTrack, LinkModeEnforce or LinkModeStrict):
// the page words the shared place and the full limit by it.
LinkMode string
// Refusal says why an app that is entitled to servers gets none: RefusalDeviceLimit, RefusalDeviceBlocked,
// RefusalNoDeviceID or RefusalClientAPIEnrolled. "" for everyone served, for a person without access (Status says why) and for the page, which never
// registers a device. Lines and Servers are empty with it; the subscription handler answers with one entry that says why.
Refusal string
// Page is the state of the person's page password (the generation it is computed with, whether it was removed): the public
// handler decides the lock of the page and the cookie by it. It comes with the user's row, so it costs no read of its own.
Page PageState
}
SubView is what the public subscription endpoint needs about one token.
Source Files
¶
- access.go
- awg_rpc.go
- bridge_endpoint.go
- client_api.go
- clientcompat.go
- clientcompat_rpc.go
- connection.go
- country_names.go
- desired.go
- device.go
- device_hint.go
- device_rpc.go
- formats.go
- group_rpc.go
- mistgate_consumes.go
- names.go
- node_dns.go
- node_load.go
- node_share_rpc.go
- paths.go
- port_check.go
- profile_rpc.go
- reality_own.go
- reality_target.go
- relay_check.go
- relay_controller.go
- relay_reach.go
- relay_reverse.go
- relay_rpc.go
- share.go
- status.go
- sub.go
- telegram_key.go
- token_index.go
- trusttunnel_key.go
- trusttunnel_render.go
- trusttunnel_rpc.go
- twin_rpc.go
- user_change_limit.go
- user_list_proto.go
- user_rpc.go