sub

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Overview

Package sub provides subscription server functionality for the l-ui panel, including HTTP/HTTPS servers for serving subscription links and JSON configurations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDistFS

func SetDistFS(fs embed.FS)

SetDistFS installs the embedded frontend filesystem the sub server uses for its info page assets. Must be called before NewServer().Start().

Types

type ClashConfig

type ClashConfig struct {
	Proxies     []map[string]any `yaml:"proxies"`
	ProxyGroups []map[string]any `yaml:"proxy-groups"`
	Rules       []string         `yaml:"rules"`
}

type LinkProvider

type LinkProvider struct {
	// contains filtered or unexported fields
}

func NewLinkProvider

func NewLinkProvider() *LinkProvider

func (*LinkProvider) LinksForClient

func (p *LinkProvider) LinksForClient(host string, inbound *model.Inbound, email string) []string

func (*LinkProvider) SubLinksForSubId

func (p *LinkProvider) SubLinksForSubId(host, subId string) ([]string, error)

type Outbound

type Outbound struct {
	Protocol       string               `json:"protocol"`
	Tag            string               `json:"tag"`
	StreamSettings json_util.RawMessage `json:"streamSettings"`
	Mux            json_util.RawMessage `json:"mux,omitempty"`
	Settings       map[string]any       `json:"settings,omitempty"`
}

type PageData

type PageData struct {
	Host          string
	BasePath      string
	SId           string
	Enabled       bool
	Download      string
	Upload        string
	Total         string
	Used          string
	Remained      string
	Expire        int64
	LastOnline    int64
	Datepicker    string
	DownloadByte  int64
	UploadByte    int64
	TotalByte     int64
	SubUrl        string
	SubJsonUrl    string
	SubClashUrl   string
	SubTitle      string
	SubSupportUrl string
	Result        []string
	Emails        []string
}

PageData is a view model for subpage.html PageData contains data for rendering the subscription information page.

type SUBController

type SUBController struct {
	// contains filtered or unexported fields
}

SUBController handles HTTP requests for subscription links and JSON configurations.

func NewSUBController

func NewSUBController(
	g *gin.RouterGroup,
	subPath string,
	jsonPath string,
	clashPath string,
	jsonEnabled bool,
	clashEnabled bool,
	encrypt bool,
	showInfo bool,
	rModel string,
	update string,
	jsonFragment string,
	jsonNoise string,
	jsonMux string,
	jsonRules string,
	subTitle string,
	subSupportUrl string,
	subProfileUrl string,
	subAnnounce string,
	subEnableRouting bool,
	subRoutingRules string,
) *SUBController

NewSUBController creates a new subscription controller with the given configuration.

func (*SUBController) ApplyCommonHeaders

func (a *SUBController) ApplyCommonHeaders(
	c *gin.Context,
	header,
	updateInterval,
	profileTitle string,
	profileSupportUrl string,
	profileUrl string,
	profileAnnounce string,
	profileEnableRouting bool,
	profileRoutingRules string,
)

ApplyCommonHeaders sets common HTTP headers for subscription responses including user info, update interval, and profile title.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the subscription server that serves subscription links and JSON configurations.

func NewServer

func NewServer() *Server

NewServer creates a new subscription server instance with a cancellable context.

func (*Server) GetCtx

func (s *Server) GetCtx() context.Context

GetCtx returns the server's context for cancellation and deadline management.

func (*Server) Start

func (s *Server) Start() (err error)

Start initializes and starts the subscription server with configured settings.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts down the subscription server and closes the listener.

type ServerSetting

type ServerSetting struct {
	Password string `json:"password"`
	Level    int    `json:"level"`
	Address  string `json:"address"`
	Port     int    `json:"port"`
	Flow     string `json:"flow,omitempty"`
	Method   string `json:"method,omitempty"`
}

type SubClashService

type SubClashService struct {
	SubService *SubService
	// contains filtered or unexported fields
}

func NewSubClashService

func NewSubClashService(subService *SubService) *SubClashService

func (*SubClashService) GetClash

func (s *SubClashService) GetClash(subId string, host string) (string, string, error)

type SubJsonService

type SubJsonService struct {
	SubService *SubService
	// contains filtered or unexported fields
}

SubJsonService handles JSON subscription configuration generation and management.

func NewSubJsonService

func NewSubJsonService(fragment string, noises string, mux string, rules string, subService *SubService) *SubJsonService

NewSubJsonService creates a new JSON subscription service with the given configuration.

func (*SubJsonService) GetJson

func (s *SubJsonService) GetJson(subId string, host string) (string, string, error)

GetJson generates a JSON subscription configuration for the given subscription ID and host.

type SubService

type SubService struct {
	// contains filtered or unexported fields
}

SubService provides business logic for generating subscription links and managing subscription data.

func NewSubService

func NewSubService(showInfo bool, remarkModel string) *SubService

NewSubService creates a new subscription service with the given configuration.

func (*SubService) AggregateTrafficByEmails

func (s *SubService) AggregateTrafficByEmails(emails []string) (xray.ClientTraffic, int64)

AggregateTrafficByEmails resolves traffic for every email in one query and folds the rows into a single ClientTraffic + lastOnline. xray.ClientTraffic.Email is globally unique, so a multi-inbound client's single row is attached to exactly one inbound — iterating per-inbound ClientStats would miss it on the others. Used by GetSubs, SubClashService.GetClash, and SubJsonService.GetJson to keep the sub-info header consistent across all three formats.

func (*SubService) BuildPageData

func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray.ClientTraffic, lastOnline int64, subs []string, emails []string, subURL, subJsonURL, subClashURL string, basePath string, subTitle string, subSupportUrl string) PageData

BuildPageData parses header and prepares the template view model. BuildPageData constructs page data for rendering the subscription information page.

func (*SubService) BuildURLs

func (s *SubService) BuildURLs(subPath, subJsonPath, subClashPath, subId string) (subURL, subJsonURL, subClashURL string)

BuildURLs constructs absolute subscription and JSON subscription URLs for a given subscription ID. It prioritizes configured URIs, then individual settings, and finally falls back to request-derived components.

func (s *SubService) GetLink(inbound *model.Inbound, email string) string

GetLink dispatches to the protocol-specific generator for one (inbound, client) pair. Returns "" when the inbound's protocol doesn't produce a subscription URL (socks, http, mixed, wireguard, dokodemo, tunnel). The returned string may contain multiple `\n`-separated URLs when the inbound has externalProxy set.

func (*SubService) GetSubs

func (s *SubService) GetSubs(subId string, host string) ([]string, []string, int64, xray.ClientTraffic, error)

GetSubs retrieves subscription links for a given subscription ID and host.

func (*SubService) PrepareForRequest

func (s *SubService) PrepareForRequest(host string)

PrepareForRequest sets per-request state (host + nodes map) on the shared SubService. Called by every entry point — GetSubs, GetJson, GetClash — so resolveInboundAddress sees the right host and the freshly-loaded node map regardless of which sub flavour the client hit.

func (*SubService) ResolveRequest

func (s *SubService) ResolveRequest(c *gin.Context) (scheme string, host string, hostWithPort string, hostHeader string)

ResolveRequest extracts scheme and host info from request/headers consistently. ResolveRequest extracts scheme, host, and header information from an HTTP request.

type UserVnext

type UserVnext struct {
	ID       string `json:"id"`
	Email    string `json:"email,omitempty"`
	Security string `json:"security,omitempty"`
}

type VnextSetting

type VnextSetting struct {
	Address string      `json:"address"`
	Port    int         `json:"port"`
	Users   []UserVnext `json:"users"`
}

Jump to

Keyboard shortcuts

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