model

package
v0.7.16 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DisabledManual  = "manual"
	DisabledQuota   = "quota"
	DisabledExpired = "expired"
)

停用原因。

View Source
const ShareSuffix = "#share"

ShareSuffix 临时共享凭据在数据面里的名字后缀:sing-box 里叫 "alice#share",记账时去掉后缀归到 alice。 这样取消共享只断借用者的连接,本人不受影响。"#" 是用户名里禁止的字符,不会撞名。

Variables

This section is empty.

Functions

func All

func All() []interface{}

func AutoIP added in v0.6.15

func AutoIP(pub, pub6, family string) (string, string)

AutoIP 连接地址留空时订阅里用的探测地址,返回地址与它的地址族("v4" / "v6",都没有时为空)。

pub 是 PublicIP(有 IPv4 时是 IPv4;老版本副机在纯 IPv6 机器上报的是 v6),pub6 是 PublicIP6。 family 为 "v6" 时优先 IPv6,其余优先 IPv4;优先的那个没探测到就用另一个。

func BareHost added in v0.6.15

func BareHost(s string) string

BareHost 去掉 IPv6 地址外面的方括号([2001:db8::1] → 2001:db8::1);别的写法原样返回。

func DeviceCount added in v0.7.16

func DeviceCount(ips []string) int

DeviceCount 一组来源地址算几台设备(见 IPKey)。

func FamilyIPs added in v0.7.16

func FamilyIPs(addr, pub, pub6 string) (v4, v6 string)

FamilyIPs 这台服务器按地址族分开的地址(线路单独选 IP 版本时用):探测到的两个地址,手填的连接地址是哪一族就顶替哪一族。

func GBToBytes added in v0.7.16

func GBToBytes(gb float64) int64

GBToBytes GB 换算成字节(1 GB = 1024³,四舍五入)。

func IPKey added in v0.7.16

func IPKey(ip string) string

IPKey 按来源计数时用的键:IPv4 就是地址本身;IPv6 取 /64。一台设备同时有好几个 IPv6 地址、临时地址还会换, 同一个局域网的设备也都在同一个 /64 里,这样才和 IPv4 下"同一 WiFi 的多台算一个"一致,限流也不会被换地址绕过。

func NormAddrFamily added in v0.6.15

func NormAddrFamily(s string) string

NormAddrFamily 规整地址族选项:只认 "v6",其余(含 "v4"、空)都是默认的 IPv4。

func NormNodeFamily added in v0.7.16

func NormNodeFamily(raw json.RawMessage) (json.RawMessage, error)

NormNodeFamily 保存前规整:只留 {"服务器 id":"v4"|"v6"},空值(跟随服务器)去掉,一条都没有就是 nil。

func Owner added in v0.4.12

func Owner(dataPlaneName string) string

Owner 把数据面里的名字换回面板用户名(去掉共享后缀);内部用户返回空:不计用量、不算在线、不受设备数限制。

func ParseNodeFamily added in v0.7.16

func ParseNodeFamily(raw json.RawMessage) map[uint]string

ParseNodeFamily 解出线路的按服务器 IP 版本(Line.NodeFamily):服务器 id → v4 | v6;没选的不在里面。

func RelayUserName added in v0.7.16

func RelayUserName(upstreamID uint) string

RelayUserName 线路作上游时,上游在目标线路入站上的用户名。

func ResellerGroup added in v0.4.13

func ResellerGroup(id uint) string

ResellerGroup 代理在数据面里的池名(设备池 / 带宽池按它归组)。

func StartOnFirstUse added in v0.7.16

func StartOnFirstUse(update map[string]interface{}, now int64)

StartOnFirstUse 记流量的那条 UPDATE 顺带做"首次连接开始计时":等着计时的用户此刻换算成到期时间。 和记流量是同一条语句,不多一次写;用的是更新前的 activate_days。

func URLHost added in v0.7.16

func URLHost(scheme, host string, port int) string

URLHost 拼 URL 的主机部分:协议的默认端口(https 443、http 80)不写,IPv6 加方括号。 只有和协议对得上才能省:http 跑在 443 上省掉的话,浏览器会去连 80。

func ValidAddr added in v0.7.12

func ValidAddr(s string) bool

ValidAddr 连接地址只能是 IP 或域名:不带端口、协议头、路径和空格(这些会拼进分享链接把地址弄坏)。

Types

type Admin

type Admin struct {
	Id         uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	Username   string `json:"username" gorm:"uniqueIndex"`
	Password   string `json:"-"`
	LastLogins string `json:"lastLogins"`
}

Admin 面板登录账号(bcrypt 哈希,从旧面板原样迁入)。

type AgentCounter

type AgentCounter struct {
	UserName string `json:"userName" gorm:"primaryKey"`
	Up       int64  `json:"up"`
	Down     int64  `json:"down"`
}

AgentCounter 副机端:本机每用户只增不减的流量账本(不直接写 User 表,避免与主端下发冲突)。

type Cert added in v0.7.16

type Cert struct {
	Id        uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	Name      string `json:"name" gorm:"uniqueIndex"` // 域名(含 *.example.com)或 self-signed;线路按它选证书
	Source    string `json:"source"`                  // acme | selfsign | external
	CertFile  string `json:"certFile"`
	KeyFile   string `json:"keyFile"`
	Method    string `json:"method"`    // ACME 的验证方式:http | cloudflare | manual
	AutoRenew bool   `json:"autoRenew"` // 到期前 30 天自动续期(手动 DNS 的不能)
	Staging   bool   `json:"staging"`
	CreatedAt int64  `json:"createdAt"`
}

Cert 这台服务器证书库里的一张证书。各机各管各的,不随快照同步(见 runner/certstore.go)。

type CertBrief added in v0.7.16

type CertBrief struct {
	Name       string   `json:"name"`
	Domains    []string `json:"domains,omitempty"`
	SelfSigned bool     `json:"selfSigned,omitempty"`
	NotAfter   int64    `json:"notAfter"`
	Default    bool     `json:"default,omitempty"` // 线路默认证书
}

CertBrief 一台服务器有哪张证书(副机随报告上来,存在 Node.Certs,不含私钥与路径)。

type Change

type Change struct {
	Id       uint64          `json:"id" gorm:"primaryKey;autoIncrement"`
	DateTime int64           `json:"dateTime"`
	Actor    string          `json:"actor"`
	Key      string          `json:"key"`
	Action   string          `json:"action"`
	Obj      json.RawMessage `json:"obj"`
}

Change 审计日志。

type ExtNode

type ExtNode struct {
	Id        uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	Name      string `json:"name" gorm:"uniqueIndex"`
	Type      string `json:"type"`   // link | sub
	Value     string `json:"value"`  // 分享链接 或 订阅 URL
	Prefix    string `json:"prefix"` // 节点名前缀(可空),如 "[中转] "
	Enabled   bool   `json:"enabled" gorm:"default:true"`
	Sort      int    `json:"sort"`
	Remark    string `json:"remark"`
	LastFetch int64  `json:"lastFetch"`
	LastError string `json:"lastError"`
	NodeCount int    `json:"nodeCount"`
	Cache     string `json:"cache,omitempty"` // 外部订阅抓取到的内容(主机抓取,随快照下发副机)
	// 输出到用户订阅前的筛选与改名,都按节点原名记(订阅刷新后顺序会变,原名才认得出)。
	Hidden  json.RawMessage `json:"hidden,omitempty"`  // 手动隐藏的节点 []原名
	Renames json.RawMessage `json:"renames,omitempty"` // 改名 {原名: 新名}
	Exclude string          `json:"exclude"`           // 名字含这些关键词的不输出,逗号分隔(官网、到期、剩余流量这类信息节点)
}

ExtNode 外部节点:一条分享链接,或一个外部订阅地址;分配给用户后聚合进该用户的订阅。

type LimitState added in v0.6.0

type LimitState struct {
	Id          uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	RuleId      uint   `json:"ruleId" gorm:"uniqueIndex:idx_limit_rule_user,priority:1"`
	UserId      uint   `json:"userId" gorm:"uniqueIndex:idx_limit_rule_user,priority:2;index"`
	UserName    string `json:"userName"`
	RuleName    string `json:"ruleName"`
	UpMbps      int    `json:"upMbps"`
	DownMbps    int    `json:"downMbps"`
	TightenOnly bool   `json:"tightenOnly"`
	Since       int64  `json:"since"`
	Until       int64  `json:"until"`
	Reason      string `json:"reason"` // 触发原因,如 "10 分钟内 1.2 GB" / "时段 19:00 到 23:00"
}

LimitState 一条生效中的规则限速:主机写、随快照下发副机,主副机计算限速时叠加到用户自己的限速上。 Until 为 0 = 时段规则(随窗口结束删除);突发规则到期即失效,副机据此在主机失联时也能自行放开。

type Line

type Line struct {
	Id         uint            `json:"id" gorm:"primaryKey;autoIncrement"`
	Name       string          `json:"name" gorm:"uniqueIndex"`
	Protocol   string          `json:"protocol"`          // hysteria2 | anytls | shadowsocks
	Port       int             `json:"port" gorm:"index"` // 端口只在同一台服务器上才会撞:部署范围没有交集的线路可以同端口
	UpstreamId uint            `json:"upstreamId"`        // 0 = direct
	Options    json.RawMessage `json:"options"`           // 协议入站附加参数(obfs、method、padding_scheme 等)
	// Addrs 订阅里对外公布的连接地址列表 [{server, server_port?, remark?, sni?}]。
	// 空 = 用入口节点主机 + 本线路端口(常态);非空 = 逐地址各出一条链接/代理。
	// 也是多入口的承载:每个入口一条 addr。
	Addrs json.RawMessage `json:"addrs,omitempty"`
	// NodeIds 该线路部署到哪些服务器 [1,2];空 = 全部服务器。渲染与订阅都按此过滤。
	NodeIds json.RawMessage `json:"nodeIds,omitempty"`
	// NodeFamily 双栈服务器上这条线路用哪个 IP 版本 {"服务器 id":"v4"|"v6"};没写的服务器跟随它自己的设置(Node.AddrFamily)。
	NodeFamily json.RawMessage `json:"nodeFamily,omitempty"`
	// Tls 线路 TLS 配置 {mode: cert|reality|none, reality:{private_key, public_key, short_ids, handshake_server, handshake_port}}。
	// 空 = 按协议默认(hy2/anytls/tuic/trojan 用节点证书,vless 用 reality,其余无)。
	Tls json.RawMessage `json:"tls,omitempty"`
	// Transport vless/vmess/trojan 的传输层(sing-box transport 对象:ws/grpc/httpupgrade/http);空 = TCP。
	Transport json.RawMessage `json:"transport,omitempty"`
	// RouteRules 分流规则 [{type, values, to}]:按目标分给不同出口,没命中的走 UpstreamId;空 = 不分流(见 render.RouteRule)。
	RouteRules json.RawMessage `json:"routeRules,omitempty"`
	Enabled    bool            `json:"enabled" gorm:"default:true"`
	Sort       int             `json:"sort"`
}

Line 线路 = 用户在订阅里看到的一个节点。 合并了旧面板的"入站 + 路由规则":一条线路即 一个入口协议+端口 → 一个上游。 端口在所有入口服务器上一致,配置由 Hub 按服务器渲染下发。

type LineRef added in v0.4.19

type LineRef struct {
	LineId  uint   `json:"lineId"`
	NodeIds []uint `json:"nodeIds,omitempty"`
}

LineRef 是接口里表达"线路 × 服务器"分配的方式:NodeIds 为空 = 该线路的全部服务器。

type Node

type Node struct {
	Id       uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	Name     string `json:"name" gorm:"uniqueIndex"`
	Domain   string `json:"domain"`
	ApiUrl   string `json:"apiUrl"`
	Token    string `json:"-"`
	Insecure bool   `json:"insecure"` // 副机面板用自签证书时跳过校验
	IsLocal  bool   `json:"isLocal"`
	Enabled  bool   `json:"enabled" gorm:"default:true"`
	Sort     int    `json:"sort"`
	// Addr 订阅里节点的连接地址(可填 IP);空 = 自动用该服务器探测到的公网 IP。域名仍作 SNI,绕开大陆 DNS 污染。
	Addr string `json:"addr"`
	// PublicIP 该服务器自动探测到的公网 IP(本机由 runner 写入,副机随报告上报):有 IPv4 时是 IPv4,纯 IPv6 机器是 IPv6。
	PublicIP string `json:"publicIp"`
	// PublicIP6 该服务器探测到的公网 IPv6;没有 IPv6(或副机版本旧、不上报)时为空。
	PublicIP6 string `json:"publicIp6"`
	// AddrFamily Addr 留空时订阅里用哪个探测地址:"" = IPv4(默认),"v6" = IPv6;选的那个没探测到就用另一个。
	AddrFamily string `json:"addrFamily"`
	// Ratio 流量倍率:经该服务器的流量按倍率计入用户用量(2 = 双倍扣量);0/1 = 原样。
	Ratio float64 `json:"ratio" gorm:"default:1"`
	// CertFP 勾了"跳过证书校验"时记住的副机证书 SHA-256 指纹(首次连接写入),之后指纹变了就拒绝连接;空 = 还没记。
	CertFP string `json:"certFp,omitempty"`
	// Certs 这台服务器证书库的清单 []CertBrief(本机由 runner 写入,副机随报告上报)。线路编辑框与订阅的 SNI 用它。
	Certs json.RawMessage `json:"certs,omitempty"`
}

Node 入口服务器。IsLocal 标记 Hub 所在机;副机通过 ApiUrl+Token 管理。

type Plan

type Plan struct {
	Id uint `json:"id" gorm:"primaryKey;autoIncrement"`
	// ResellerId 归属:0=主面板;代理只看得到也只能用自己建的套餐(名称在各自范围内唯一)
	ResellerId  uint            `json:"resellerId" gorm:"uniqueIndex:idx_plans_owner_name,priority:1;index"`
	Name        string          `json:"name" gorm:"uniqueIndex:idx_plans_owner_name,priority:2"`
	VolumeGB    float64         `json:"volumeGb"` // 0=不限;可以是小数(0.1 = 约 100 MB)
	Days        int             `json:"days"`     // 0=不限
	DeviceLimit int             `json:"deviceLimit"`
	SpeedUp     int             `json:"speedUp"`
	SpeedDown   int             `json:"speedDown"`
	AutoReset   bool            `json:"autoReset"`
	ResetDays   int             `json:"resetDays"`
	FirstUse    bool            `json:"firstUse"`            // 有时长的套餐从首次连接开始计时,而不是从套用那一刻
	LineIds     json.RawMessage `json:"lineIds,omitempty"`   // 空=不改动用户线路
	LineNodes   json.RawMessage `json:"lineNodes,omitempty"` // 线路 → 服务器范围 {"3":[1,2]};没写的线路 = 全部服务器
	Desc        string          `json:"desc"`
	Sort        int             `json:"sort"`
}

Plan 套餐:配额/时长/设备/限速/线路的模板,用于建号、续费与批量操作。

type ReachCheck added in v0.6.12

type ReachCheck struct {
	Id      uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	NodeId  uint   `json:"nodeId" gorm:"index"`
	At      int64  `json:"at"`
	Verdict string `json:"verdict"`
	Auto    bool   `json:"auto"`
	Detail  string `json:"detail"`
}

All 供 AutoMigrate 使用。 ReachCheck 一次大陆连通检测(每台服务器只留最近几十条)。Detail 是完整结果的 JSON,界面展开明细时用。

type Reseller added in v0.2.0

type Reseller struct {
	Id          uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	Name        string `json:"name" gorm:"uniqueIndex"`
	Password    string `json:"-"` // bcrypt;空=首次登录时自行设置
	TotpSecret  string `json:"-"`
	TotpEnabled bool   `json:"totpEnabled"`
	Volume      int64  `json:"volume"` // 名下用户用量之和的上限,字节,0=不限
	// 代理已用 = 名下用户的全时用量之和 + UsedCarried - UsedBase。
	// 全时用量(up+down+total_up+total_down)只增不减,所以代理自己重置/续费/周期清零都改不动额度;
	// 删用户时把它的全时用量结转到 UsedCarried,免得删号就能洗掉;只有主面板"重置流量"会抬高 UsedBase。
	UsedCarried int64 `json:"usedCarried" gorm:"default:0;not null"`
	UsedBase    int64 `json:"usedBase" gorm:"default:0;not null"`
	// ClaimBefore 空密码"首次登录设密码"的截止时间(建号/重置密码时给 24 小时);
	// 过了这个点仍未设密码就必须让主面板重新重置,否则账号会一直敞着等人认领。
	ClaimBefore int64  `json:"claimBefore"`
	Expiry      int64  `json:"expiry"`      // unix 秒,0=不限;到期后其用户一并停用
	SpeedUp     int    `json:"speedUp"`     // 带宽池(上行):名下用户合计上行速率上限,每台服务器各一份,Mbps,0=不限
	SpeedDown   int    `json:"speedDown"`   // 带宽池(下行),同上
	DeviceLimit int    `json:"deviceLimit"` // 设备池:名下用户同时在线的不同设备(源 IP)总数上限,跨服务器并集,0=不限
	UserLimit   int    `json:"userLimit"`   // 最多能建多少个用户,0=不限
	Enabled     bool   `json:"enabled" gorm:"default:true"`
	Remark      string `json:"remark"`
	CreatedAt   int64  `json:"createdAt" gorm:"default:0;not null"`
	LastLogins  string `json:"lastLogins"`
	// 代理自己的订阅落地页设置(文案留空则用主面板的;两个开关与主面板取与)
	PageEnabled bool `json:"pageEnabled" gorm:"default:true"`
	ShareOn     bool `json:"shareOn" gorm:"default:true"`
	// ProfileTitle 客户端里显示的订阅名(Profile-Title 头);留空跟随主面板
	ProfileTitle string `json:"profileTitle"`
	PageTitle    string `json:"pageTitle"`
	PageNotice   string `json:"pageNotice"`
	PageSupport  string `json:"pageSupport"`
	PageBuyURL   string `json:"pageBuyURL"` // 落地页 / 404 页上「选购订阅」按钮的地址;留空用主面板的
	// 代理自己的外部 API:在代理面板"我的账号"里开启并取令牌,接口与主面板的 v1 相同,作用域限定为该代理名下
	ApiEnabled bool   `json:"apiEnabled"`
	ApiToken   string `json:"-" gorm:"index"`
	// Depleted 流量额度已用尽:主机每分钟判定并写入,随快照下发副机。为真时名下用户不下发数据面、订阅返回 404,
	// 用户行本身不改(以前是把他名下的用户全部 enabled=false,补量后又整体复活,连手动停用的一起)。
	Depleted bool `json:"depleted"`
}

Reseller 代理:自带面板,能在自己额度内建用户。其用户的流量与设备数全部归到代理名下。

type ResellerLine added in v0.2.0

type ResellerLine struct {
	ResellerId uint `json:"resellerId" gorm:"primaryKey;autoIncrement:false"`
	LineId     uint `json:"lineId" gorm:"primaryKey;autoIncrement:false"`
}

ResellerLine 代理可用线路(主面板分配),代理只能把这些线路分给自己的用户。

type ResellerLineNode added in v0.4.19

type ResellerLineNode struct {
	ResellerId uint `json:"resellerId" gorm:"primaryKey;autoIncrement:false"`
	LineId     uint `json:"lineId" gorm:"primaryKey;autoIncrement:false"`
	NodeId     uint `json:"nodeId" gorm:"primaryKey;autoIncrement:false"`
}

ResellerLineNode 代理的线路授权同样可以按服务器收窄。

type Rule added in v0.6.0

type Rule struct {
	Id          uint            `json:"id" gorm:"primaryKey;autoIncrement"`
	ResellerId  uint            `json:"resellerId" gorm:"index"` // 归属:0 = 主面板(预留给代理面板自建规则)
	Name        string          `json:"name"`
	Enabled     bool            `json:"enabled"`
	Kind        string          `json:"kind"` // schedule | burst
	AllUsers    bool            `json:"allUsers"`
	UserIds     json.RawMessage `json:"userIds,omitempty"`
	ResellerIds json.RawMessage `json:"resellerIds,omitempty"`
	PlanIds     json.RawMessage `json:"planIds,omitempty"` // 指定套餐的用户(动态,以后套用这个套餐的也算)
	// 时段(面板时区):Days "1,2,5"(1 = 周一,空 = 每天);Start / End "HH:MM",结束早于开始 = 跨午夜,相等 = 全天
	Days  string `json:"days"`
	Start string `json:"start"`
	End   string `json:"end"`
	// 突发:最近 WindowMin 分钟内上下行合计达到 ThresholdBytes → 限速 PenaltyMin 分钟,到期自动解除,再达到再限
	WindowMin      int   `json:"windowMin"`
	ThresholdBytes int64 `json:"thresholdBytes"`
	PenaltyMin     int   `json:"penaltyMin"`
	// 限到多少 Mbps:0 = 该方向不改
	UpMbps   int `json:"upMbps"`
	DownMbps int `json:"downMbps"`
	// TightenOnly 只升不降:结果不会高于用户自己的限速;关掉后规则值直接覆盖(可用于放宽)
	TightenOnly bool   `json:"tightenOnly"`
	Remark      string `json:"remark"`
	Sort        int    `json:"sort"`
	CreatedAt   int64  `json:"createdAt"`
}

Rule 限速规则:时段(schedule)或突发(burst)。主机每 10 秒判定,命中时给目标用户写一条 LimitState。 目标可叠加:全部用户 / 指定用户 / 指定代理名下的全部用户 / 指定套餐的用户(后两种是动态的,以后才归入的也算)。

type Session added in v0.5.0

type Session struct {
	Token    string `json:"-" gorm:"primaryKey"`
	User     string `json:"user"`
	Reseller uint   `json:"reseller" gorm:"index"`
	Pending  bool   `json:"pending"`
	Exp      int64  `json:"exp" gorm:"index"`
}

Session 面板与代理面板的登录会话:以前只在内存里,每次更新 / 重启所有人都要重新登录。 Token 存的是令牌(随机部分加凭据指纹)的 SHA-256 十六进制,不是令牌本身;Reseller 非 0 为代理会话;Pending 为代理首登待设密码。

type Setting

type Setting struct {
	Id    uint   `json:"id" gorm:"primaryKey;autoIncrement"`
	Key   string `json:"key" gorm:"uniqueIndex"`
	Value string `json:"value"`
}

Setting 面板设置,key/value。角色开关也存这里:nodeMode=false 为主(HK),true 为副(TW)。

type Stats

type Stats struct {
	Id        uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
	DateTime  int64  `json:"dateTime" gorm:"uniqueIndex:idx_stats_bucket,priority:3"`
	Resource  string `json:"resource" gorm:"uniqueIndex:idx_stats_bucket,priority:1"` // line | upstream | user
	Tag       string `json:"tag" gorm:"uniqueIndex:idx_stats_bucket,priority:2"`
	Direction bool   `json:"direction" gorm:"uniqueIndex:idx_stats_bucket,priority:4"`
	Traffic   int64  `json:"traffic"`
}

Stats 流量时序(bucket 聚合,四元唯一键+累加合并模型,天然支持多机合并)。

type SubLog

type SubLog struct {
	Id     uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
	Ts     int64  `json:"ts" gorm:"index"`
	User   string `json:"user" gorm:"index"`
	Ip     string `json:"ip"`
	Ua     string `json:"ua"`
	Format string `json:"format"` // link | clash
	Status int    `json:"status"`
}

SubLog 订阅访问日志。

type TrafficCursor

type TrafficCursor struct {
	NodeId   uint   `json:"nodeId" gorm:"primaryKey;autoIncrement:false"`
	UserName string `json:"userName" gorm:"primaryKey"`
	Up       int64  `json:"up"`
	Down     int64  `json:"down"`
}

TrafficCursor 主端:对某副机某用户已计入聚合的单调计数快照。 副机计数器回绕(换机重装)时快照归零重认,保证不重复计、不漏计。

type Upstream

type Upstream struct {
	Id      uint            `json:"id" gorm:"primaryKey;autoIncrement"`
	Name    string          `json:"name" gorm:"uniqueIndex"`
	Type    string          `json:"type"`
	Options json.RawMessage `json:"options"`
	Sort    int             `json:"sort"`
	// FromLine / FromNode 这条上游是本面板的一条线路(链式代理):Type 与 Options 由线路算出来,线路或服务器地址变了自动重算。
	// 0 = 普通上游。RelayCreds 是上游连那条线路用的专用凭据,渲染时作为内部用户挂到目标线路的入站上。
	FromLine   uint            `json:"fromLine" gorm:"default:0;not null"`
	FromNode   uint            `json:"fromNode" gorm:"default:0;not null"`
	RelayCreds json.RawMessage `json:"relayCreds,omitempty"`
}

Upstream 上游落地(旧面板的出站)。warp 本地代理也是一个 Upstream(type=socks 指向 127.0.0.1:40000)。 direct 不入库,渲染时内置。

type User

type User struct {
	Id          uint            `json:"id" gorm:"primaryKey;autoIncrement"`
	Enabled     bool            `json:"enabled" gorm:"default:true"`
	Name        string          `json:"name" gorm:"uniqueIndex"`
	Credentials json.RawMessage `json:"credentials,omitempty"` // 按协议存凭据,从旧库原样保留
	Volume      int64           `json:"volume"`                // 字节,0=不限
	Expiry      int64           `json:"expiry"`                // unix 秒,0=不限
	Up          int64           `json:"up"`
	Down        int64           `json:"down"`
	TotalUp     int64           `json:"totalUp"`
	TotalDown   int64           `json:"totalDown"`
	AutoReset   bool            `json:"autoReset"`
	ResetDays   int             `json:"resetDays"`
	NextReset   int64           `json:"nextReset"`
	DeviceLimit int             `json:"deviceLimit"` // 同时在线设备(源IP)上限,0=不限
	SpeedUp     int             `json:"speedUp"`     // 上行 Mbps,0=不限
	SpeedDown   int             `json:"speedDown"`   // 下行 Mbps,0=不限
	Remark      string          `json:"remark"`
	Desc        string          `json:"desc"`
	CreatedAt   int64           `json:"createdAt" gorm:"default:0;not null"`
	OnlineAt    int64           `json:"onlineAt" gorm:"default:0;not null"`
	ResellerId  uint            `json:"resellerId" gorm:"index"` // 归属代理,0=主面板直属
	SubToken    string          `json:"subToken" gorm:"index"`   // 代理建的用户用随机令牌做订阅地址(主面板用户为空,按用户名)
	ShareToken  string          `json:"shareToken" gorm:"index"` // 临时共享订阅令牌,空=未开启
	ShareCreds  json.RawMessage `json:"shareCreds,omitempty"`    // 共享地址专用凭据(与本人凭据不同,取消即失效)
	ShareAt     int64           `json:"shareAt"`                 // 令牌生成时间
	// PlanId 所属套餐:最后一次套用的,或手动归入的;0 = 不属于任何套餐。限速规则可以按它选用户(动态,以后套用的也算)。
	PlanId uint `json:"planId" gorm:"default:0;not null;index"`
	// ActivateDays 首次连接后多少天到期;0 = 不用。第一次产生流量时换算成 Expiry 并清零,在那之前 Expiry 为 0。
	ActivateDays int `json:"activateDays" gorm:"default:0;not null"`
	// DisabledReason 为什么被停用:manual(管理员 / 代理 / 外部 API 手动)、quota(超量)、expired(到期);启用时为空。
	// 自动恢复(补量、周期重置、延期)只对自动原因生效,手动停的人不会因为清了流量就复活。
	DisabledReason string `json:"disabledReason"`
}

User 订阅用户。配额/流量为两台服务器聚合值,判定只在主端进行。

type UserExt

type UserExt struct {
	UserId uint `json:"userId" gorm:"primaryKey;autoIncrement:false"`
	ExtId  uint `json:"extId" gorm:"primaryKey;autoIncrement:false"`
}

UserExt 用户-外部节点 多对多。

type UserLine

type UserLine struct {
	UserId uint `json:"userId" gorm:"primaryKey;autoIncrement:false"`
	LineId uint `json:"lineId" gorm:"primaryKey;autoIncrement:false"`
}

UserLine 用户-线路 多对多。

type UserLineNode added in v0.4.19

type UserLineNode struct {
	UserId uint `json:"userId" gorm:"primaryKey;autoIncrement:false"`
	LineId uint `json:"lineId" gorm:"primaryKey;autoIncrement:false"`
	NodeId uint `json:"nodeId" gorm:"primaryKey;autoIncrement:false"`
}

UserLineNode 把用户在某条线路上的范围收窄到具体服务器: 一条线路部署在 A、B 两台时,用户可以只拿 A 上的那一个入口。 没有任何行 = 该线路的全部服务器(老数据、以及"全选"时都是这种,以后新加的服务器自动包含)。

Jump to

Keyboard shortcuts

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