sub

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sub builds the per-user subscription: the machine payload consumed by VPN clients and the human-facing page (QR + one-tap import buttons).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppRedirect added in v0.11.0

func AppRedirect(href template.URL) ([]byte, error)

AppRedirect renders the deep-link hand-off page for one client's share link.

func Base64Payload

func Base64Payload(links []string) string

Base64Payload is the universal v2ray-style subscription body: the links joined by newlines, base64-encoded. Consumed by v2rayNG, Hiddify, Streisand, NekoBox, Shadowrocket, etc.

func ClashWithTemplateMulti added in v1.0.0

func ClashWithTemplateMulti(u model.User, servers []Server, template string) string

ClashWithTemplateMulti injects the user's proxies into a RoscomVPN-style Mihomo routing template. The template carries two "# LEAVE THIS LINE!" markers: the `proxies:` line (full proxy definitions) and a slot inside the main select group (proxy node names). Falls back to the plain config if the template has no proxies marker.

func ClashYAML

func ClashYAML(u model.User, set *model.Settings) string

ClashYAML renders a minimal self-contained Clash-Meta config for one server.

func ClashYAMLMulti added in v1.0.0

func ClashYAMLMulti(u model.User, servers []Server) string

ClashYAMLMulti renders a Clash-Meta (Mihomo) config spanning every server: all proxies under one select group. servers[0] is the local server (group title + rules).

func Font added in v1.5.0

func Font(name string) ([]byte, bool)

Font returns an embedded webfont by bare file name. It refuses any name with a path separator, so a request can only ever name a file directly inside fonts/.

func Logo() []byte

Logo returns the embedded РосПанель logo (SVG).

func Page

func Page(u model.User, servers []Server, billing Billing) ([]byte, error)

Page renders the human-facing subscription page (usage stats, QR of the sub URL, copy button, per-client import buttons, and the raw links). Page renders the human-facing subscription page. sets spans every server the user is on — the local one plus each enabled node — so the "individual configs" list shows one labelled entry per protocol × server (with a single server it's unchanged). sets[0] is the local server, used for the sub URL, branding and billing.

func ShareLinks(u model.User, srv Server) []string

ShareLinks returns one server's links for a user, in client-import order: the enabled built-in lanes first, then each custom inbound in its display order. Protocols switched off in the Connections panel are omitted.

func ShareLinksAll added in v1.0.0

func ShareLinksAll(u model.User, servers []Server) []string

ShareLinksAll concatenates the links for a user across every server — the local one plus each enabled node — so a subscription carries one entry per lane × server. Each settings clone carries its own host/ports/keys and a NodeLabel that disambiguates the links.

func SingBoxJSON

func SingBoxJSON(u model.User, set *model.Settings) string

SingBoxJSON renders an importable sing-box configuration for a single server.

func SingBoxJSONMulti added in v1.0.0

func SingBoxJSONMulti(u model.User, servers []Server) string

SingBoxJSONMulti renders a sing-box config spanning every server (local + each node): one outbound per lane × server, all gathered under the selector/urltest groups. servers[0] is the local server, used for the group title + DNS bootstrap anchor.

func SubTitle

func SubTitle(u model.User, set *model.Settings) string

SubTitle is the per-user profile title: the configured subscription title (or «РосПанель» by default), optionally suffixed with the user name when SubNameInTitle is enabled.

func URL

func URL(set *model.Settings, token string) string

URL is the public subscription URL for a token (always https on the host).

Types

type Billing added in v0.11.0

type Billing struct {
	Show        bool
	CurrentPlan string        // active plan name ("" = none / manual)
	ExpireText  string        // "до DD.MM.YYYY" for a paid expiry, else ""
	Plans       []BillingPlan // paid plans offered for purchase/renewal
	Providers   []BillingPay  // enabled payment methods (empty ⇒ manual only)
	Manual      bool          // no automatic provider ⇒ pay button creates a manual order
	Note        string        // manual-payment instructions when no provider is set
	PayPath     string        // POST target that starts a payment (<SubURL>/pay)
	OrderPath   string        // GET target that reports a pending provider payment (<SubURL>/order)
	// Locked is true while a paid plan is active: only that plan (renewal) is shown,
	// switching to another is blocked, and Cancelable offers cancellation instead.
	Locked     bool
	Cancelable bool
	CancelPath string // POST target that cancels the active plan (<SubURL>/cancel)
}

Billing is the optional "renew / pay" block on the subscription page. It's built by the server (which has plan + payment-provider access) and left zero (Show false) when billing is off or no paid plans exist.

type BillingPay added in v0.11.0

type BillingPay struct {
	Key   string
	Label string
}

BillingPay is one payment method the user can choose.

type BillingPlan added in v0.11.0

type BillingPlan struct {
	ID      int64
	Name    string
	Label   string // price + period, e.g. "199 ₽ / 30 дн."
	Current bool   // the user's currently active plan
}

BillingPlan is one purchasable paid tariff shown on the page.

type DeepLink struct {
	Label    string
	Platform string
	Href     template.URL
}

DeepLink is one "open in client" button. Href is template.URL so html/template keeps the custom client schemes (happ://, v2rayng://, …) instead of sanitizing them to "#ZgotmplZ". Platform notes which OS the client targets.

func DeepLinks(subURL string) []DeepLink

DeepLinks builds best-effort import deep-links for the popular clients, most popular first. Schemes drift across client releases — verify periodically.

type Server added in v1.5.0

type Server struct {
	Set    *model.Settings
	Custom []model.Inbound
	Access model.Access
}

Server is one server as a subscription sees it: its effective settings (host, SNI, ports, REALITY material, node label), its enabled custom inbounds, and the requesting user's access to this server's lanes.

Settings and inbounds travel together because they answer the same question from different tables — the built-in lanes live in the settings row, the custom ones in their own table keyed by server. Access rides along so a subscription only ever lists the lanes the user is actually allowed (their credential is on the server for exactly those); it's the same gate as config generation, applied to what the client is told.

func One added in v1.5.0

func One(set *model.Settings) []Server

One wraps a single server with no custom inbounds and unrestricted access — the shape every legacy single-server helper and test needs.

func Servers added in v1.5.0

func Servers(sets []*model.Settings, custom map[int64][]model.Inbound, access model.Access) []Server

Servers pairs each settings value with its server's custom inbounds (looked up by Settings.ServerID) and the requesting user's access, applied to every server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL