subscription

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLegacyAccessDenied = errors.New("access denied")

Functions

func RenderTemplate

func RenderTemplate(
	templateStr string,
	outputFormat string,
	siteName string,
	subscribeName string,
	nodes []*NodeInfo,
	userSubscribe *UserSubscribe,
	userInfo UserInfo,
	params map[string]string,
) ([]byte, error)

RenderTemplate 渲染订阅配置模板(按照原项目逻辑)

Types

type NodeInfo

type NodeInfo struct {
	ID          int64
	Sort        int
	Name        string
	Server      string
	Port        uint16
	Type        string
	Tags        []string
	NodeGroupID int64

	Security                           string
	SNI                                string
	AllowInsecure                      bool
	Fingerprint                        string
	RealityServerAddr                  string
	RealityServerPort                  int
	RealityPrivateKey                  string
	RealityPublicKey                   string
	RealityShortId                     string
	Transport                          string
	Host                               string
	Path                               string
	ServiceName                        string
	Mc1Mode                            string
	Mc1CidrSegments                    []string
	MundoUsername                      string
	MundoCertificateFingerprint        string
	MundoFakeTitle                     string
	MundoFakeMessage                   string
	MundoAcceptProxyProtocol           bool
	MundoUseTLSCertificate             bool
	Method                             string
	ServerKey                          string
	Flow                               string
	HopPorts                           string
	HopInterval                        int
	ObfsPassword                       string
	UpMbps                             int
	DownMbps                           int
	DisableSNI                         bool
	ReduceRtt                          bool
	UDPRelayMode                       string
	CongestionController               string
	PaddingScheme                      string
	Multiplex                          string
	XhttpMode                          string
	XhttpExtra                         string
	Encryption                         string
	EncryptionMode                     string
	EncryptionRtt                      string
	EncryptionTicket                   string
	EncryptionServerPadding            string
	EncryptionPrivateKey               string
	EncryptionClientPadding            string
	EncryptionPassword                 string
	Ratio                              float64
	CertMode                           string
	CertDNSProvider                    string
	CertDNSEnv                         string
	SimnetPsk                          string
	SimnetKeyID                        int
	SimnetTicketID                     string
	SimnetPath                         string
	SimnetCarrier                      string
	SimnetAfEnabled                    bool
	SimnetAfPathMode                   string
	SimnetAfPathPrefix                 string
	SimnetAfPathSuffix                 string
	SimnetAfMagicMode                  string
	SimnetAfResponseJitterMs           int
	SimnetAfHandshakePolymorphism      bool
	SimnetAfSettingsJitter             bool
	SimnetAfFakeHeaderInjection        bool
	SimnetClientMaxConcurrentStreams   int
	SimnetClientMaxStreamsPerSession   int
	SimnetClientSessionIdleTimeoutSecs int
	SimnetClientMaxUDPSessions         int
	OmniflowCarrier                    string
	OmniflowPath                       string
	OmniflowContentType                string
	OmniflowProfileJson                string
	OmniflowCaCertPath                 string
	OmniflowTargetMeta                 string
	OmniflowSpkiPin                    string
	OmniflowAdaptiveTlsEnabled         bool
	OmniflowTlsFingerprint             string
	OmniflowSniMode                    string
	OmniflowPaddingMode                string
	OmniflowAfEnabled                  bool
	OmniflowAfPathMode                 string
	OmniflowAfPathPrefix               string
	OmniflowAfPathSuffix               string
	OmniflowAfPathRotationSecs         int
	OmniflowAfPathSkewSlots            int
}

NodeInfo 节点信息

func (*NodeInfo) NormalizeSimnet

func (n *NodeInfo) NormalizeSimnet()

type SubscribeApplication

type SubscribeApplication struct {
	ID                int64
	Name              string
	Icon              string
	Description       string
	Scheme            string
	UserAgent         string
	IsDefault         bool
	SubscribeTemplate string
	OutputFormat      string
	DownloadLink      string
}

SubscribeApplication 订阅应用配置

type SubscribeRuntimeConfig

type SubscribeRuntimeConfig struct {
	PanDomain      bool
	UserAgentLimit bool
	UserAgentList  string
}

type SubscriptionRepo

type SubscriptionRepo interface {
	// ValidateTokenAndGetSubscribe 验证token并获取用户订阅信息
	ValidateTokenAndGetSubscribe(ctx context.Context, token string) (*UserSubscribe, error)

	// GetAvailableNodes 获取可用节点列表
	GetAvailableNodes(ctx context.Context, userSubscribe *UserSubscribe) ([]*NodeInfo, error)

	// GetUserInfo 获取用户信息
	GetUserInfo(ctx context.Context, userID int64) (*UserInfo, error)

	// GetSubscribeInfo 获取订阅信息头
	GetSubscribeInfo(ctx context.Context, userSubscribe *UserSubscribe) string

	// UpdateSubscribeLog 更新订阅活动日志
	UpdateSubscribeLog(ctx context.Context, userSubscribe *UserSubscribe, userAgent, clientIP string) error

	// GetSubscribeApplications 获取所有订阅应用配置
	GetSubscribeApplications(ctx context.Context) ([]*SubscribeApplication, error)

	// GetSubscribeDomain 获取订阅域名配置(用于生成订阅URL)
	GetSubscribeDomain(ctx context.Context) string

	// GetSubscribePath 获取订阅路径配置(用于生成订阅URL)
	GetSubscribePath(ctx context.Context) string

	// GetSiteName 获取站点名称
	GetSiteName(ctx context.Context) string

	// GetSubscribeRuntimeConfig 获取订阅运行时配置
	GetSubscribeRuntimeConfig(ctx context.Context) (*SubscribeRuntimeConfig, error)
}

SubscriptionRepo 订阅配置数据仓库接口

type SubscriptionUseCase

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

SubscriptionUseCase 订阅配置用例

func NewSubscriptionUseCase

func NewSubscriptionUseCase(repo SubscriptionRepo) *SubscriptionUseCase

NewSubscriptionUseCase 创建订阅配置用例

func (*SubscriptionUseCase) GetSubscribeApplications

func (uc *SubscriptionUseCase) GetSubscribeApplications(ctx context.Context) ([]*SubscribeApplication, error)

func (*SubscriptionUseCase) GetSubscribeConfig

func (uc *SubscriptionUseCase) GetSubscribeConfig(ctx context.Context, req *v1.GetSubscribeConfigRequest, userAgent, clientIP, requestURI, requestHost string, gatewayMode bool, queryParams map[string]string) (*v1.GetSubscribeConfigReply, error)

GetSubscribeConfig 获取订阅配置 - 按照原项目逻辑实现

func (*SubscriptionUseCase) ResolveDownloadMeta

func (uc *SubscriptionUseCase) ResolveDownloadMeta(ctx context.Context, _ *v1.GetSubscribeConfigRequest, userAgent string) (string, string, error)

func (*SubscriptionUseCase) ValidateLegacyRequest

func (uc *SubscriptionUseCase) ValidateLegacyRequest(ctx context.Context, token, requestHost, userAgent string, clients []*SubscribeApplication) error

type TemplateData

type TemplateData struct {
	SiteName      string
	SubscribeName string
	OutputFormat  string
	Proxies       []map[string]interface{}
	UserInfo      UserInfo
	Params        map[string]string
}

TemplateData 模板数据结构

type UserInfo

type UserInfo struct {
	ID         int64
	Email      string
	InviteCode string

	// 扩展信息(用于模板渲染)
	Password     string    `json:"password"`
	ExpiredAt    time.Time `json:"expired_at"`
	Download     int64     `json:"download"`
	Upload       int64     `json:"upload"`
	Traffic      int64     `json:"traffic"`
	SubscribeURL string    `json:"subscribe_url"`
	// SubscribeID is the ProxyUserSubscribe table primary key (SID).
	// Used by SimNet per-user key_id derivation to match the Node's key_id.
	SubscribeID int64 `json:"subscribe_id"`
}

UserInfo 用户信息

type UserSubscribe

type UserSubscribe struct {
	ID          int64
	UserID      int64
	SubscribeID int64
	Token       string
	UUID        string
	StartTime   int64
	ExpireTime  int64
	Traffic     int64
	Download    int64
	Upload      int64
	Status      int

	// 过期期间流量
	ExpiredDownload int64
	ExpiredUpload   int64

	// 扩展信息
	SubscribeName string
	NodeGroups    []int64
	NodeTags      []string
	NodeGroupID   int64
}

UserSubscribe 用户订阅信息

Jump to

Keyboard shortcuts

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