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 ¶
- func SetDistFS(fs embed.FS)
- type ClashConfig
- type LinkProvider
- type Outbound
- type PageData
- type SUBController
- type Server
- type ServerSetting
- type SubClashService
- type SubJsonService
- type SubService
- func (s *SubService) AggregateTrafficByEmails(emails []string) (xray.ClientTraffic, int64)
- func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray.ClientTraffic, lastOnline int64, ...) PageData
- func (s *SubService) BuildURLs(subPath, subJsonPath, subClashPath, subId string) (subURL, subJsonURL, subClashURL string)
- func (s *SubService) GetLink(inbound *model.Inbound, email string) string
- func (s *SubService) GetSubs(subId string, host string) ([]string, []string, int64, xray.ClientTraffic, error)
- func (s *SubService) PrepareForRequest(host string)
- func (s *SubService) ResolveRequest(c *gin.Context) (scheme string, host string, hostWithPort string, hostHeader string)
- type UserVnext
- type VnextSetting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClashConfig ¶
type LinkProvider ¶
type LinkProvider struct {
// contains filtered or unexported fields
}
func NewLinkProvider ¶
func NewLinkProvider() *LinkProvider
func (*LinkProvider) LinksForClient ¶
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 ¶
GetCtx returns the server's context for cancellation and deadline management.
type ServerSetting ¶
type SubClashService ¶
type SubClashService struct {
SubService *SubService
// contains filtered or unexported fields
}
func NewSubClashService ¶
func NewSubClashService(subService *SubService) *SubClashService
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.
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 (*SubService) GetLink ¶
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.